{'fraction_non_alphanumeric': 0.03163748954466081, 'fraction_numerical': 0.01361762073165363, 'mean_word_length': 4.562647947106359, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
GALA: an automatic tool for the abundance analysis of stellar spectra

GALA is a freely distributed Fortran code to derive automatically the atmospheric parameters (temperature, gravity, microturbulent velocity and overall metallicity) and abundances for individual species of stellar spectra using the classical method based on the equivalent widths of metallic lines. The abundances of individual spectral lines are derived by using the WIDTH9 code developed by R. L. Kurucz. GALA is designed to obtain the best model atmosphere, by optimizing temperature, surface gravity, microturbulent velocity and metallicity, after rejecting the discrepant lines. Finally, it computes accurate internal errors for each atmospheric parameter and abundance. The code permits to obtain chemical abundances and atmospheric parameters for large stellar samples in a very short time, thus making GALA an useful tool in the epoch of the multi-object spectrographs and large surveys. An extensive set of tests with both synthetic and observed spectra is performed and discussed to explore the capabilities and robustness of the code.


INTRODUCTION
The last decade has seen a significant improvement in the study of the chemical composition of the stellar populations (in our Galaxy and its satellites), thanks to the 8-10 meters class telescopes, coupled with the design of several multi-object mid/high-resolution spectrographs, e.g. FLAMES mounted at the Very Large Telescope, AAOmega at the Anglo-Australian Telescope, DEIMOS at the Keck Observatory and HYDRA at the Blanco Telescope of the Cerro Tololo Inter-American Observatory. These instruments have allowed to enlarge the statistical significance of the acquired stellar spectra, but also they have required a relevant effort to manage such large databases.
The next advent of new surveys aimed to collect huge samples of mid-high resolution stellar spectra, as for instance the European Space Agency Gaia mission, the Gaia-ESO Survey committed by the European Southern Observatory (Gilmore et al. 2012), the APOGEE Survey at the Apache Point Observatory (Allende Prieto et al. 2008), and the RAVE Survey at the Anglo-Australian Observatory (Steinmetz et al. 2006), will make available in real time to the astronomical community an enormous volume of data. Other spectroscopic surveys have been already performed, like BRAVA (Kunder et al. 2012) and ARGOS (Freeman et al. 2013), both dedicated to the study of the Galactic Bulge. Also, other multi-object spectrographs are planned or proposed for the next years, i.e. HERMES (Barden et al. 2010) at the Anglo-Australian Observatory, 4MOST (de Jong 2011) at the New Technology Telescope and MOONS (Cirasuolo et al. 2011) at the Very Large Telescope. This perspective, coupled with the huge amount of high quality spectra available in the main on-line archives (and not yet totally analysed) clarifies the urgency to develop automatic tools able to rapidly and reliably manage such samples of spectra.
In the last years several codes aimed at the automatic 1 Based on observations collected at the ESO-VLT under programs 65.L-0165, 165.L-0263, 073.D-0211, 080.D-0368, 083.D-0208 and 266.D-5655 and on data available in the ELODIE archive. This research has also made use of the SIMBAD database, operated at CDS, Strasbourg, France. measurements of the chemical abundances have been already developed. They are mainly based on the comparison between the observed spectrum and grids of synthetic spectra, for instance ABBO (Bonifacio & Caffau 2003), MATISSE (Recio-Blanco, Bijaoui & de Laverny 2006), SME (Valenti & Piskunov 1996), SPADES (Posbic et al. 2012), MyGIsFOS (Sbordone et al. 2010). In particular, in these codes the main effort has been devoted to robustly determine the atmospheric parameters (and hence the elemental abundances) for low (<50) signal-to-noise (SNR) spectra and generally to develop an algorithm able to accurately treat different kind of stars (in terms of metallicity and stellar parameters).
In this paper we present and discuss a new code (named GALA) specifically designed for automatically determining the atmospheric parameters by using the observed equivalent widths (EWs) of metallic lines in stellar spectra, at variance with the majority of the available automated codes. GALA is a tool developed within Cosmic-Lab, a 5-years project funded by the European Research Council and it is freely available at the website of the project http://www.cosmic-lab.eu/Cosmic-Lab/Products.html.
The paper is structured as follows: Section 2 discusses the outline of the classical method to derive the main parameters and the interplay occurring among them; Section 3 describes the algorithm; Section 4 describes the identification and the rejection of the outliers and Section 5 discusses other aspects of the code. Section 6 provides a complete description of the uncertainties in the calculations. Finally, Sections 7, 8 and 9 discuss a number of tests performed to check the stability and the performances of GALA.

THE METHOD
The main advantage of inferring the stellar atmospheric parameters from the EWs is its reproducibility: any researcher can directly compare its own results about a given star with other analysis based on the same approach. This allows to distinguish between discrepancies due to the method (i.e. the measured EWs) and those due to the physical assumptions of the analysis (model atmospheres, atomic data...). On the other side, one of the most critical aspects of this method is the particular accuracy needed in the definition of the linelist, by excluding blended lines. In fact, the codes developed to calculate the abundance from the measured EW compare the latter with the theoretical strength of the line, changing the abundance until the observed and theoretical EW match within a convergence range. The theoretical line profile is usually calculated including the continuum opacity sources but neglecting the contribution of the neighboring lines (see Castelli 2005a, for details), hence the spectral lines to be analysed with this technique are to be checked accurately against blending (a practice not always performed). Otherwise, the use of synthetic spectra allows to also use blended features (and in principle to exploit the information derived from all the pixels), but it is more expensive in terms of computing time, because large grids of spectra must to be computed, at different parameters and with different chemical compositions, and each change in the atomic data leads to a recomputation of the synthetic spectra.

The classical spectroscopic method
The main parameters that define the model atmosphere, namely the effective temperature (T eff ), the surface gravity (log g), the microturbulent velocity (v t ) and the overall metallicity ([M/H] 2 ) are constrained through four constraints: 1. Temperature: the best value of T eff is derived by imposing the so-called excitation equilibrium, requiring that there is no correlation between the abundance and the excitation potential χ of the neutral iron lines. The number of electrons populating each energy level is basically a function of T eff , according to the Boltzmann equation. If we assume a wrong T eff in the analysis of a given stellar spectrum, we need different abundances for matching the observed profile of transitions with different χ. For instance, the use of a value of T eff too large will lead to under-populate the lower energy levels, thus the predicted line profile for low-χ transitions will be too shallow and a higher abundance will be needed to match the line profile. On the other hand, a wrong (too low) T eff will lead to a deeper line profile for the low χ transitions. For this reason, a wrong, too large value of T eff will introduce an anticorrelation between abundances and χ, and in the same way, a positive correlation is expected in the case of the adoption of a value of T eff too small; 2. Surface gravity: the best value of log g is derived with the so-called ionization equilibrium method, requiring that for a given species, the same abundance (within the uncertainties) has been obtained from lines of two ionization states (typically, neutral and singly ionized lines). Being the gravity a direct measure of the pressure of the photosphere, variations of log g lead to variations of the ionized lines (very sensitive to the electronic pressure), while the neutral lines are basically insensitive to this parameter. This method assumes implicitly that the energy levels of a given species are populated according to the Boltzmann and Saha equations (thus, under Local Thermodynamical Equilibrium (LTE) conditions). Possible departures from this assumption (especially critical for metal-poor and/or low-gravity stars) could alter the derived gravity when it is derived from the ionization balance, because non-LTE effects affect mainly the neutral lines (even if the precise magnitude of the departures from LTE for the iron lines is still matter of debate). As sanity check, following the suggestion by Edvardsson (1988), surface gravities determined from the ionization equilibria have to be "checked -when possible -with gravities determined from the wings of pressure broadened metal lines"; 3. Microturbulent velocity: v t is computed by requiring that there is no correlation between the iron abundance and the line strength (see Mucciarelli 2011, for a discussion about different approaches). The microturbulent velocity affects mainly the moderate/strong lines located along the flat regime of the curve of growth, while the lines along the linear part of the curve of growth are mainly sensitive to the abundance instead of the velocity fields. The necessity to introduce the microturbulent velocity as an additional broadening (added in quadrature to the Doppler broadening) arises from the fact that the non-thermal motions (basically due to the onset of the convection in the photosphere) are generally not well described by the 1-dimensional, static model atmospheres. Citing Kurucz (2005), microturbulent velocity is a parameter that is generally not considered physically except in the Sun, because in the Sun the velocity fields can be derived as a function of the optical depth through the analysis of the intensity spectrum (as performed by Fontenla, Avrett & Loeser 1993). For the other stars v t represents only a corrective factor that minimizes the line-to-line scatter for a given species and it compensates (at least partially) to the incomplete description of the convection as implemented in the 1-dimensional model atmospheres; 4. Metallicity: [M/H] is chosen according to the average iron content of the star, assuming [Fe/H] as a proxy of the overall metallicity. Generally, [Fe/H] is adopted as a good proxy of the metallicity because of its large number of available lines, but it does not indicate necessarily the overall metallicity of the studied star. In fact, iron is generally not the most abundant element in the stars, while elements as C, N and O would be the best tracers of the stellar metallicity (but they are difficult to measure).
Because of its statistical nature, the spectroscopic optimization of all the parameters simultaneously can be performed only if we have a sufficient number of Fe lines, distributed in a large range of EW and χ and in two levels of ionization. Alternatively, T eff and log g can be inferred from the photometry (for instance with the isochrone-fitting technique or employing empirical or theoretical T eff -color relations) or by fitting the wings of damped lines (as the hydrogen Balmer lines or the Mg b triplet) sensitive to the parameters, and only v t needs to be tuned spectroscopically (following the approach described above). Note that some authors consider the method to derive the parameters based on these constraints only as sanity checks performed a posteriori on the photometric parameters, while other authors rely on these constraints to infer the best parameters.

The interplay among the parameters
In light of the method described above, it is worth to bear in mind that the atmospheric parameters are correlated with each other. In fact, the strongest lines are typically those with low χ: Fig. 1 plots all the transitions in the range λ= 4000-8000Å and with χ <10 eV in the Kurucz/Castelli database 3 in the plane χ vs log(g f ) − θχ 4 . As mentioned in Section 2.1, T eff and χ are strictly linked, and there is also a connection between v t and the line strength. Hence, the statistical correlation between χ and the line strength leads to a correlation between T eff and v t . Thus, a variation of T eff implies a variation of v t . Also, variations of T eff and v t will change differently the abundances derived from different levels of ionization (hence, the gravity). Let us consider an ATLAS9 model atmosphere computed with T eff =4500 K, log g=1.5, v t =2 km/s and [M/H]=-1.0 dex ) and a set of neutral and singly ionized iron lines (predicted to be unblended through the inspection of a synthetic spectrum calculated with the same parameters and convoluted at a spectral resolution of 45000). The EWs of these transitions are computed by integrating the theoretical line profile through the WID subroutine implemented in the WIDTH9 code (Castelli 2005a). This means that each of these EWs will provide exactly [El/H]=-1.0 dex when they are analysed by using the model atmosphere described above.
The analysis of these lines (adopting always the same set of EWs) is repeated investigating a regular grid of the atmospheric parameters, namely T eff = 3600-5400 K, log g= 0.5-2.5, v t = 1.0-3.0 km/s, steps of δT eff = 200 K, δlogg= 0.2, δv t = 0.5 km/s and assuming for all the models [M/H]= -1.0 dex. Fig. 2, 3 and 4 display the quite complex interplay occurring among the atmospheric parameters.
• Fig. 2 shows the behaviour of the slope S χ of the A(Fe)-χ relation for the above sample of lines as a function of T eff , keeping gravity fixed, but varying the microturbulent velocity. The thick grey line connects points calculated with the original v t of the model. The global trend is basically linear, at least if we consider a range of ±1000 K around the original T eff . The inset panel shows the behaviour of T eff for which S χ is zero (thus, the best T eff ) as a function of v t and considering different gravities. The derived best temperature increases with increasing v t (at fixed log g); the gravity has only a second-order effect and it does not change the general behaviour of the best T eff as function of v t .
FIG. 2.-Main panel: behaviour of the slope Sχ of the A(Fe)-χ relation as a function of T eff assuming log g= 1.5 and for different values of vt (dashed curves). The thick grey curve represents the behaviour computed for the original microturbulent velocity (vt = 2.0 km/s). Horizontal dashed line is the zero value (according to the excitation equilibrium). The inset panel shows the behaviour of the best value of T eff (for which Sχ= 0) as a function of the used vt (empty squares) and for different gravities; black points are referred to the original gravity (log g=1.5).
• Fig. 3 summaryzes the behaviour of the slope S EW R of the A(Fe)-EWR relation as a function of v t (where EWR indicates the reduced EW, defined as EWR=lg(EW /λ)), keeping gravity fixed at the original value but varying T eff . For a given temperature, the slope decreases increasing v t , with a behaviour that becomes less steep at v t larger than the original value. The effect of the T eff is appreciable for T eff larger than the original value, while for lower T eff all the curve are very similar to each other. The inset shows the change of the best value of v t (for which the slope of the A(Fe)-EWR relation is zero) as a function of T eff and for different log g. The observed trend is quite complex: basically, we note that the best value of v t is very sensitive to T eff , when the latter is overestimated with respect to the true temperature, but with a negligible dependence from gravity, while the behaviour is the opposite when T eff is under-estimated, with a degeneracy between T eff and the best v t but a consistent dependence from gravity.
FIG. 3.-Main panel: behaviour of the slope S EW R of the A(Fe)-EWR relation as a function of vt assuming log g= 1.5 and for different T eff (dashed curves). The thick grey curve represents the behaviour computed for the original temperature (T eff = 4500 K). Horizontal dashed line is the zero value. The inset panel shows the behaviour of the best value of the microturbulent velocity vt (for which S EW R = 0) as a function of the used T eff (empty squares) and for different values of gravities; black points are referred to the original gravity (log g=1.5).
• Fig. 4 shows the behaviour of the difference between A(Fe I) and A(Fe II) as a function of log g, assuming v t = 2 km/s and for different T eff . The general behaviour is linear and the iron difference increases considerably increasing temperature. The best value of gravity (see the inset in Fig. 4) is highly sensitive to changes in T eff , with δlogg/δT eff ≃1 dex/300 K in the investigated case, but for a fixed T eff turns out to be marginally sensitive to v t (this is due to the fact that the Fe II lines are basically distributed in strength in a similar way to the Fe I lines).
It is important to bear in mind that the these considerations are appropriate for the investigated case of a late-type star but the dependencies among the parameters can be different for different regimes of atmospheric parameters and/or metallicity. However, the example presented above demonstrates that an analytic approach to derive the best model atmosphere is discouraged because it needs to know the precise topography A(Fe II) as a function of log g assuming vt= 2.0 km/s and for different T eff (dashed curves). The thick grey curve represents the behaviour computed for the original temperature (T eff = 4500 K). Horizontal dashed line is the zero value (according to the ionization equilibrium). The inset panel shows the behaviour of the best log g (for which A(Fe I)= (Fe II)) as a function of the used T eff (empty squares) and for different gravities; black points are referred to the original microturbulent velocity (vt= 2.0 km/s). of the parameters space and requires the inspection of a large number of model atmospheres.

GALA
GALA is a program written in standard Fortran 77, that uses the WIDTH9 code developed by R. L. Kurucz in its Linux version (Sbordone et al. 2004) to derive the chemical abundances of single, unblended absorption lines starting from their measured EWs. We used our own version of WIDTH9, modified in order to have a more flexible format for the input/output files with respect to the standard version of the code available in the website of F. Castelli, while the input physics and the method to derive the abundances are unchanged.
GALA is specifically designed to 1. choose the best model atmosphere by using the observed EWs of metallic lines; 2. manage the input/output files of the WIDTH9 code; 3. provide statistical and graphical tools to evaluate the quality of the final solution and the uncertainty of the derived parameters.
GALA is designed to handle both ATLAS9 ) and MARCS (Gustafsson et al. 2008) model atmospheres, that are the most popular employed dataset of models. The current version has been compiled with the Intel Fortran Compiler (versions 11, 12 and 13) and tested on the Leopard, Snow Leopard and Lion Mac OSX systems, and on the Ubuntu, Fedora and Mandriva Linux platforms.
3.1. Optimization parameters GALA has been designed to perform the classical chemical analysis based on the EWs in an automated way. The user can choose to perform a full spectroscopic optimization of the parameters or to optimize only some parameters, keeping the other parameters fixed to the specified input values.
The algorithm optmizes one parameter at a time, checking continuously if the new value of a given parameter changes the validity of the previously optmized ones.
For each atmospheric parameter X (corresponding to T eff , log g, v t and [M/H]) we adopt a specific optimization parameter C(X), defined in a way that it turns out to be zero when the best value of the X parameter has been found. Hence, GALA varies X until a positive/negative pair of the C(X) is found, thus bracketing the zero value corresponding to the best value. Thus, the condition C(X)= 0 identifies X=X as best value of the given parameter. Finally, the best solution converges to a set of parameters which verifies simultaneously the constraints described in Section 2.1. When the atmospheric parameters have been found, the abundances of all the elements for which EWs have been provided are derived.
According to the literature, the adopted C(X) have been defined to parametrize the conditions listed in Section 2.1: to constrain T eff ; the lower panel of Fig. 5 shows the change of this slope for a set of theoretical EWs computed with the correct T eff (grey points) and with temperatures varied by ±500 K (empty points). The variation of T eff produces a change of the slope (but also a change in the y-intercept); 2. the angular coefficient of the A(Fe)-EWR relation (S EW R ) to constrain v t . The upper panel of Fig. 5 shows the same set of theoretical EWs analysed with different v t ; 3. the difference of the mean abundances obtained from Fe I and Fe II lines to constrain the gravity; 4. the average Fe abundance to constrain the metallicity of the model.
If the errors in the EW measurement (σ EW ) are provided as an input, the slopes are computed taking into account the abundance uncertainties of the individual lines; the uncertainty on the iron abundance of a given line is estimated from the difference of the iron abundance computed for the input EW and for EW+σ EW 5 . In the A(Fe)-χ plane the uncertainties of χ are reasonably assumed negligible, because the uncertainties of χ are typically less than 0.01 eV, while in the A(Fe)-EWR plane the least square fit takes into account the uncertainties in both the axis (following the prescriptions by Press et al. 1992).
The flexibility of GALA permits to simultaneously deal with stars of different spectral types. This is made by considering that a large number of Fe I lines is generally available for F-G-K spectral types stars, whereas they are less numerous (or lacking) in O-B-A stars, for which a large number of Fe II lines is typically available. Also, in some spectral regions there is a large number of lines for other iron-peak elements 5 The uncertainties in A(Fe) are assumed symmetric with respect to the variations of the EW (±σ EW ); we checked that this assumption is correct at a level of ∼0.01 dex. (mainly Ni, Cr and Ti). For this reason, GALA is designed to optimize the parameters also using other lines instead of Fe I lines, by appropriately configuring the code. In the following, we will refer to the optimization made by using Fe I for T eff and v t , but our considerations are valid also for other elements with a sufficient number of lines.
3.2. The main structure GALA is structured in three main Working-Blocks: (1) the Guess Working-Block is aimed at finding the guess atmospheric parameters in a fast way (this is especially useful in cases of large uncertainties or in lacking of first-guess value for the parameters); (2) the Analysis Working-Block which finds the best model atmosphere through a local minimization and starting from the guess parameters provided by the user or obtained through the previous block; (3) the Refinement Working-Block that refines the solution, starting from the atmospheric parameters obtained in the previous block.
GALA can be flexibly configured to use different combinations of the three main Working-Blocks. We defer the reader to Section 8.4 for a discussion of the effects of the Working-Blocks. In the following we describe the algorithm of each block and the cases in which they are recommended.

Guess Working-Block
If the atmospheric parameters are poorly known, this Working-Block verifies them quickly by exploring the parameters space in a coarse grid. Thus, it saves a large amount of time if the initial parameters are far away from the correct solution.
1. As a first step, the abundances for each line are derived with the input parameters and some lines are labelled as outliers and excluded from the analysis (the criteria of the rejection are described in Sect. 4). The surviving lines will be used in this Working-Block and no other line rejection will be performed until convergence.
2. The metallicity of the model is eventually readjusted according to the average iron abundance.
3. S χ is computed with the input T eff and with a T eff varied by +500K (if S χ is positive) or -500 K (if S χ is negative). This procedure is repeated until a pair of positive/negative values of S χ is found, thus to bracket the T eff value for which S χ = 0. The behaviour of S χ as a function of T eff is described with a linear relation, finding the value of T eff for which S χ = 0. The description of this relation with a linear fit is legitimate as long as the employed T eff range is relatively small (in this case 500 K), because for larger range the behaviour of S χ as a function of T eff could become non linear (mainly due to the interplay with the other parameters).
4. The new value of T eff is adopted to find a new value of v t , following the same approach used for T eff and searching for a positive/negative pair of S EWR over a range of 0.5 km/s. 5. Finally, a new value of log g is found, starting from the T eff and v t derived above, by searching for a positive/negative pair of ∆(Fe), over a range of 0.5 dex in gravity.
The entire procedure (from the optimization of [M/H] to that of log g) is repeated for a number of iterations chosen by the user and finally a new set of input parameters is found. Generally three/four iterations are sufficient to find a good solution. The final solution is accurate enough to identify the neighborhood of the real solution in the parameters space but it could be unreliable since it needs to be checked for the covariances among the parameters (which is the task of the Analysis Working-Block.

Analysis Working-Block
This Working-Block performs a complete optimization starting from the input parameters provided by the users or from those obtained with the Guess Working-Block. This block is developed to find a robust solution under the assumption that the input values are reasonably close to the real solution. When good priors are available (for instance, in the case of stellar cluster stars) this block is sufficient to find the solution, without the use of the guess block. Otherwise, when the guess model is uncertain (for instance, in the case of field stars for whose reddening, distance and evaluative mass could be highly uncertain, or, generally, in the case of inaccurate photometry), the analysis block is recommended to be used after the guess block. Fig. 6 shows as a flow chart the main steps of this Working-Block.
The following iterative procedure is performed: 1. The procedure starts by computing the abundances using the guess parameters and performing a new line rejection (independent from that of the previous block). FIG 5. The surface gravity is varied until a positive/negative pairs of ∆(Fe) is found. If the output log g differs from the input value, GALA returns to (2) with the last obtained model atmosphere and the entire procedure is repeated.
6. When a model that satisfies simultaneously the four constraints is found, the procedure ends and the next star is analysed.
We stress that the method employed in this Working-Block is very robust but it has the disadvantage of being slow if the guess parameters are far from the local solution.

Refinement Working-Block
This block allows to repeat the previous Working-Block using the solution obtained in the previous block as a starting point. A new rejection of the outliers is performed and the same approach of the Analysis Working-Block is used. This block can be useful to refine locally the solution when the first block is switched off.
The main advantage of the Refinement Working-Block is that the new line-rejection is performed by using accurate atmospheric parameters (because obtained from the Analysis Working-Block). As will be discuss in Section 4, the linerejection performed on abundance distributions obtained with wrong parameters can be risky, losing some useful lines.

WEEDING OUT THE OUTLIERS
The detection and the rejection of lines with discrepant abundances are crucial aspects of the procedure and require some additional discussion. Before ruling out a line from the line list, we need to understand the origin of the detected discrepancy. Basically, the main reasons for a discrepant abundance are: (1) inaccurate atomic data (i.e. oscillator strengths) that can under-or over-estimate the abundance; (2) unrecognized blends with other lines (providing systematically overestimated abundances); (3) inaccurate EW measurement. The first two cases can be partially avoided with an effort during the definition of the adopted linelist, including only transitions with accurate log gf and checking each transition against blending, according to the atmospheric parameters and the spectral resolution.
GALA rejects the lines according to the following criteria: 1. lines weaker or stronger than the input EWR thresholds are rejected, in order to exclude either weak and/or strong lines. In fact, weak lines can be heavily affected by the noise, whereas strong lines can be too sensitive to v t and/or they can have damping wings for which the fit with a Gaussian profile could be inappropriate, providing a systematic under-estimate of the EW; 2. lines whose uncertainty on the EW measurement is larger than an input threshold chosen by the user and expressed as a percentage. Note that not all the codes developed to measure EWs provide an estimate of the EW error, despite the importance of this quantity. For instance, among the publicly available codes aimed to measure EWs, DAOSPEC (Stetson & Pancino 2008) and EWDET (Ramirez et al. 2001) provide accurate uncertainty evaluations for each line, while SPECTRE (Fitzpatrick & Sneden 1987) and ARES (Sousa et al. 2007) do not include EW error calculations. For this reason GALA works even if σ EW are not provided, although this affects the final solution accuracy, because all the transitions will be weighed equally, despite their different measurement quality; 3. lines are rejected according to their distance from the best-fit lines computed in the A(Fe)-χ and A(Fe)-EWR planes through a σ-rejection algorithm. A σ-rejection from the best-fit lines in the planes used for the optimization is more robust with respect to a simple σrejection based on the abundance distribution. In the latter case, there is the risk to lose some lines important for the analysis, thus biassing the results. Fig 7 explains this aspect: we consider a synthetic spectrum of a giant star (T eff = 4500 K) and we measure the EWs after the injection of Poissonian noise in the spectrum in order to reproduce a reasonable good SNR (∼30). Fig. 7 shows the distribution of the Fe I lines in the A(Fe)-χ plane when the chemical analysis is performed by using a wrong model atmosphere with T eff = 5200 K (thus leading to an anticorrelation between A(Fe I) and χ). In the upper panel the outliers were rejected according to the median value of the abundance distribution, shown as gray solid line, while the two dashed lines mark ±3σ level and black points are the surviving lines. In the lower panel the rejection is performed according to the distance from the best-fit line (shown as solid line while the two dashed lines mark ±3σ level). It is evident that in the first case the majority of the discarded lines are those with low χ (thus, the most sensitive to the T eff changes), with the risk of introducing a bias in the T eff determination. On the other hand, the method of rejection shown in the lower panel of Fig. 7 preserves the low-χ lines, guaranteeing the correctness of the final solution.
FIG. 7.-Behaviour of the Fe I abundances as a function of the excitation potential for a synthetic spectrum computed assuming T eff = 4500 K but analysed with a model atmosphere with T eff = 5200 K. Black circles are the lines survived after the line-rejection procedure and the empty points the rejected lines. Upper panel shows the results by adopting a rejection based on the abundance distribution; the solid line indicates the median abundance and the dashed lines mark ±3σ level. The lower panel shows the results by using the procedure employed by GALA: solid line is the best-fit line and the dashed lines mark ±3σ from the best-fit line.
An important point is that the outlier rejection in GALA is not performed independently in each iteration of the code, but only at the beginning of each Working-Block. This is especially important, because it allows to use always the same sample of lines during the optimization process, avoiding the risk to introduce spurious trends in the behaviour of the given optimization parameter as a function of the corresponding atmospheric parameters. In fact, the values of C(X) derived from two different sets of lines of the same spectrum, but for which an independent rejection of the outliers has been performed, cannot be directly compared to each other to derive X. In particular, this effect is magnified in cases of small number of lines, where the impact of the lines rejection can be critical.

A comment about the gravity
The most difficult parameter to be constrained with the classical spectroscopic method is the gravity. This because of the relatively small number of available Fe II lines, which can vary in the visual range from a handful of transitions up to ∼20, depending on the spectral region and/or the metallicity (for instance, some high-resolution spectra with a small wavelength coverage, as the GIRAFFE@VLT or the Hy-dra@BlancoTelescope spectra, can be totally lacking in Fe II lines).
GALA is equipped with different options to optimize log g: (1) the normal optimization by using the difference between the average abundances from neutral and singly ionized iron lines (as described above); (2) the gravity is computed from the Stefan-Boltzmann equation, by providing in input the term ǫ = log(4GMπσ/L), where G is the gravitational constant, σ the Boltzmann constant and M and L are the mass and the luminosity of the star. Thus, during the optimization process, the gravity is re-computed (as log g= ǫ-4logT eff ) in each iteration according to the new value of T eff ; (3) the gravity is computed by assuming a quadratic relation log g= A+B·T eff +C·T 2 eff and providing in input the coefficients A, B, C. This option is useful when the investigated stars belong for instance to the same stellar cluster and log g and T eff can be parametrized by a simple relation (i.e. as that described by a theoretical isochrone for a given evolutionary stage).
The user can choose the way to treat log g (fixed or optimized following one of the methods described above); if the optimization of log g from the iron lines is requested but no Fe II lines are available, GALA will try to use the second option (lines of other elements in different stages of ionization), or eventually will fix log g to the input value.

Model atmospheres
The algorithm used in GALA is basically independent from the code adopted to derive the abundances and from the model atmospheres. GALA is designed to manage both the two most used and publicly available models atmospheres, namely ATLAS9 and MARCS: • ATLAS9: The suite of Kurucz codes represents the only suite of open-source and free programs to face the different aspects of the chemical analysis (model atmospheres, abundance calculations, spectral synthesis), allowing any user to compute new models and upgrade parts of the codes. GALA includes a dynamic call to the ATLAS9 code 6 . Any time GALA needs to investigate a given set of atmospheric parameters, ATLAS9 is called, a new model atmosphere is computed and finally it is stored in a directory. The latter is checked by GALA whenever a model atmosphere is requested, and ATLAS9 called only if the model is lacking. The convergence of the new model atmosphere is checked for each atmospheric layer. Following the prescriptions by Castelli (1988), we require errors less than 1% and 10% for the flux and the flux derivative, respectively. Additional information about the calculation for each model atmosphere is saved. In the current version, GALA is able to manage the grid of ATLAS9 models by  and the new grid 6 The ATLAS9 source code is available at the website http://wwwuser.oat.ts.astro.it/castelli/sources/atlas9codes.html of models calculated by Meszaros et al. (2012) for the APOGEE survey.
• MARCS: At variance with ATLAS9, for the MARCS models the code to compute new model atmospheres is not released to the community. However, the Uppsala group provides a large grid of the MARCS models on their website 7 . When GALA works with these grids (including both plane-parallel and spherical symmetry), new models are computed by interpolating into the Uppsala grid by using the code developed by T. Masseron (Masseron 2006) 8 . This code has been modified in order to put the interpolated MARCS models in ATLAS9 format to use with WIDTH9.
Note that the automatization of the chemical analysis based on EWs needs a wide grid of model atmospheres (both to interpolate and compute new models) linked to the code in order to freely explore the parameter space. Thus, GALA is linked to the ATLAS9 grid both with solar-scaled and α-enhanced chemical composition and to the MARCS grid with standard composition. Also, the use of other models or model grids can be easily implemented in the code. Sometimes, peculiar analysis or tests need to use specific models, for instance for the Sun (see the set of solar model atmospheres available in the website of F. Castelli) or with arbitrary chemical compositions, as those computed with the ATLAS12 code (Castelli 2005b). When a specific, single model is called, all the optimization options are automatically swichted off.

Exit options
GALA is equipped with a number of exit flags in order to avoid infinite loops or unforeseen cases stopping the analysis of the entire input list of stars. We summarize here the main exit options: (1) the user can set among the input parameters the maximum number of allowed iterations for each star. When the code reaches this value it stops the analysis, moving to the next star. Generally this parameter depends on the adopted grid steps and if the input atmospheric parameters are close or not to the real parameters. When the Guess Working-Block is used, typically the analysis block converges in 3-5 iterations; (2) if the dispersion around the mean of the abundances of the lines used for the optimization (after the line rejection) exceeds a threshold value GALA skips the star. In fact, very large dispersions can possibly suggests some problems in the EW measurements; (3) if the number of the lines used for the optimization (after the line rejection) is smaller than a threshold, the optimization is not performed and the atmospheric parameters are fixed to the input guess values; (4) the procedure is stopped if the requested atmospheric parameter is outside the adopted grid of model atmospheres; (5) GALA skips the analysis of the star if the call to the model atmosphere fails (problems in the ATLAS9 models computation or in the MARCS models interpolation) and the required model is not created. Otherwise, if the ATLAS9 model is calculated but some atmospheric layers do not converge (according to the criteria discussed above) GALA continues the analysis but it advises the user of the number of unconverged layers.

UNCERTAINTIES
The code is equipped with different recipes to compute the uncertainties on each derived abundance. Several sources of error can affect the determination of chemical abundances, mainly the uncertainties due to the EW measurements and to the adopted loggf (that are random errors from line to line) and those arising from the choice of the atmospheric parameters (that are random errors from star to star but systematic from line to line in a given star). These uncertainties are quantified by GALA while other sources of errors (as the choice of the abundance calculation code or the adoption of the grid of model atmospheres) are neglected because considered external errors.

Abundances statistical errors
The statistical uncertainty on the abundance of each element is computed by considering only the surviving lines after the rejection process (see Sect. 4). When the uncertainty on the EW is provided for each individual line (thus allowing to compute the abundance error for each transition), the mean abundance is computed by weighing the abundance of each line on its error, otherwise simple average and dispersion are computed. For those elements for which only one line is available, the error in abundance is obtained by varying the EW of 1σ EW (if the EW uncertainties are provided). Otherwise, the adopted value is zero. As customary, the final statistical error on the abundance ratios is defined as σ/ √ N lines .
6.2. Uncertainties on the atmospheric parameters GALA estimates the internal error for each stellar parameter that has been derived from the spectroscopic analysis. The uncertainties of T eff , v t and log g are estimated propagating the errors of the corresponding optimization parameter: ( δC(Xi) δXi ) where X i are T eff , log g and v t , C(X i ) indicates the optimization parameters defined in Section 3.1, and σ C(Xi) are the corresponding uncertainties.
The terms δC(Xi) δXi (which parametrize how the slopes and the iron difference vary with the appropriate parameters) are calculated numerically, by varying X i locally around the final best value, assuming the step used in the optimization process and recomputing the corresponding C(X i ).
The terms C(X i ) are computed by applying a Jackknife bootstrapping technique (see Lupton 1993). The quoted quantities are recomputed by leaving out from the sample each time one different spectral line (thus, given a sample of N lines, each C(X) is computed N times by considering a subsample of N-1 lines). The uncertainty on the parameter X is σ Jack = √ N − 1σ sub , where σ sub is the standard deviation of the C(X) distribution derived from N sub-samples. The σ Jack takes into account the uncertainty arising from the sample size and the line distribution, and this resampling method is especially useful to estimate the bias arising from the lines statistics. Note that the computation of the slopes is performed taking into account the effect of the EW and abundance uncertainties of each individual line. Thus, the uncertainty in the atmospheric parameter X i becomes It is worth to notice that these uncertainties represent the internal error in the derived parameters and are strongly dependent on the number of used lines and on the distribution of the lines (weak and strong transitions for the estimate of v t and low and high χ lines for T eff ). Other factors that can affect the determination of the parameters (for instance, the threshold adopted in the EWs and in σ EW ) are not included in the error budgets and they can be considered as external errors. Finally, the error due to the adopted grid size could be considered as a systematic uncertainty (being the same for all the analysed stars) and eventually added in quadrature to the internal error estimated by GALA. 6.3. Abundances uncertainties due to the atmospheric parameters The evaluation of the uncertainties arising from the atmospheric parameters is a more complex task. Generally these errors are referred to as "systematic" uncertainties but this nomenclature is rather imprecise. In fact, the variation of a given parameter changes the abundance derived from the lines of the same element in a similar way (for instance, an increase of T eff increases the abundance of all the iron lines). However, this error will be different from star to star, due to the different number of lines, strength and χ distributions, EWs quality and so on. Thus, the uncertainties from the atmospheric parameters should be considered as random errors, when we compare different stars (but they are systematic uncertainties from line to line).
Several recipes are proposed in the literature. The most common method is to re-compute the abundances changing each time one parameter only, and keeping fixed the other ones to their best estimates. Then, the corresponding variations in the abundances are added in quadrature. This approach is the most conservative, because it neglects the covariance terms arising from the interplay among the parameters (see Sect. 2.2), providing only an upper limit for the total error budget. GALA follows the approach described by Cayrel et al. (2004) to naturally take into account the covariance terms. When the optimization process is ended, the analysis is repeated by altering the final T eff by +σ Teff and -σ Teff (these uncertainties are calculated as described in Section 6.2), and reoptimizing the other parameters. The net variation of each chemical abundance with respect to the original value is assumed as final uncertainty due to the atmospheric parameters and including naturally the covariance terms. Additionally, under request, also the abundance variations following the classical approach to vary one only parameter each time (keeping the other parameters fixed) are calculated, leaving the user free to use this information as preferred.
6.4. Quality parameter for the final solution GALA provides also a check parameter, useful to judge the quality of the global solution and to identify rapidly stars with unsatisfactory solutions. For each model used during the optimization process a merit function F merit is defined as: taking into account the values of the optimization parameters and the corresponding uncertainties. In an ideal case, F merit is zero if the three optimization parameters are exactly zero. Generally, all the solutions with F merit ≃1 are valid and equally acceptable, while values of F merit >>1 are suspect and point out that at least one of the parameters is not well constrained within the quoted uncertainty. Note that F merit provides only an indication if the solution is acceptable or not, but it does not specify which parameter is not well defined. Summaryzing, when the full optimization process is completed, GALA will provide for each analysed element the (weighted) mean abundance, the dispersion and the number of used lines (which provide the statistical uncertainty), the net variation in abundance due to the new optimization with T eff + σ Teff and that with T eff − σ Teff (which provide the uncertainty owing to the choice of stellar parameters). Also, for each atmospheric parameters the quoted internal uncertainties are computed. Finally, the quality parameter F merit is provided to evaluate the goodness of the solution as whole.

DEPENDENCE ON SNR
We performed a number of experiments to test the stability and reliability of the derived atmospheric parameters with GALA at different noise conditions. We performed two kind of experiments, described in the following: the first based on a grid of synthetic spectra of abundances and atmospheric parameters known a priori, in order to estimate the reliability of the code as a function of the parameters and the signalto-noise; the second group of tests is based on real spectra already analysed in literature. In the following, the EWs were measured by means of DAOSPEC (Stetson & Pancino 2008) adopting a Gaussian profile for the line fitting.

Synthetic spectra at different noise conditions
We analysed with GALA a grid of synthetic spectra, computed to mimic the UVES@VLT high resolution spectra with the 580 Red Arm setup. The grid of synthetic spectra includes SNR of 20, 30, 50, 100 per pixel for two different sets of atmospheric parameters: T eff = 4500 K, logg=1.5, v t = 2 km/s, [M/H]= -1.0 dex to simulate a giant star, and T eff = 6000 K, logg=4.5, v t = 1 km/s, [M/H]= -1.0 dex to simulate a dwarf star. The spectra were computed with the following procedure: (1) for a given model atmosphere, two synthetic spectra were calculated with the SYNTHE code over the wavelength range covered by the two CCDs of the 580 UVES Red Arm grating and then convoluted with a Gaussian profile in order to mimic the formal UVES instrumental broadening; (2) the spectra were rebinned to a constant pixel-size (δλ= 0.0147 and 0.0174 pixel/Å for the lower and upper chips respectively); (3) the synthetic spectra (normalized to unity) were multiplied with the efficiency curve computed by the FLAMES-UVES ESO Time Calculator in order to model the shape of the templates as realistically as possible; (4) Poissonian noise was injected in the spectra to simulate different noise conditions. Basically, the SNR varies along the spectrum, as a function of the efficiency (and thus of the wavelength). The noise was added in any spectrum according to the curve of SNR as a function of λ provided by the FLAMES-UVES ESO Time Calculator. For each SNR a sample of 200 synthetic spectra were generated. Fig. 8 summarizes the average values obtained for each MonteCarlo sample for each atmospheric parameter as a function of SNR; the errorbars indicate the dispersion around the mean. Results of the simulations of the giant star model atmosphere are shown in the upper panels of each window, while the lower panels summaryze the results for the dwarf star simulations. Basically, the original parameters of the synthetic spectra (marked in Fig. 8 as dashed horizontal lines) are recovered with small dispersions and without any significant bias. The major departure from the original values is observed in the microturbulent velocities (both dwarf and giant) at SNR= 20, because of the loss of weak lines.

Real echelle spectra at different noise conditions
The previous test provides an indication about the stability of the method against the SNR, starting from spectra their parameters are known a priori. However, the employed noise model is a simplification because it does not take into account some effects that can also heavily affect the measurement of the EWs, such as the correlation of the noise among adjacent pixels, flat-fielding residuals, failures in the echelle orders merging, presence of spectral impurities. Also, the atomic data of the analysed lines are the same used in the computation of the synthetic spectra, thus excluding from the final line-to-line dispersion the random error due to the uncertainty on the atomic data.
In order to provide an additional test about the performance of GALA in conditions of different noise, we performed a simple experiment on the spectra acquired with UVES@FLAMES of the giants star NGC 1786-1501 in the Large Magellanic Cloud globular cluster NGC 1786 (see Mucciarelli et al. 2009Mucciarelli et al. , 2010. This is a sample of 8 spectra with the same exposure time (∼45 min) obtained under the same seeing conditions was secured, with a typical SNR per pixel of 20 for each exposure. We used this dataset in order to obtain 8 spectra with different SNR ranging from ∼20 to ∼60 depending on the number of exposures averaged: the spectrum with the lowest SNR is just one exposure, the spectrum with the largest SNR the average of all the 8 acquired exposures. The derived parameters for each spectrum are showed in Fig. 9 as a function of SNR. The errorbars are derived by applying the Jackknife bootstrap technique for T eff , log g and v t , while for [Fe/H] we used the dispersion by the mean as estimate of the error.
We note that the parameters are well constrained with small uncertainties for spectra with low SNR: this is not a numerical artifact of the code but it is due to the large number of transitions available in the UVES spectra, coupled with an accurate rejection of the outliers and the use of the uncertainties for each individual line in the slopes computations. Also, we note that major departures from the final parameters are again in the determination of v t at SNR= 20: the derived low value of v t is due to the fact that at low SNR several weak lines (useful to constrain the microturbulent velocity) are not well measured (then discarded by GALA) or not identified in the noise envelope by DAOSPEC. Note that the derived trend of v t as a function of SNR shows the same behaviour found and discussed by Mucciarelli (2011). In this section we describe a convenient and robust method for performing abundance analysis with GALA, applied to the case of 4 stars (namely, the Sun, Arcturus, HD 84937 and µLeonis) of different metallicity and evolutionary stage and whose parameters are well established among the closest F-G-K stars. We retrieved high-resolution (∼45000) spectra from the ESO 9 (for Sun, Arcturus and HD 84937) and ELODIE 10 (for µLeonis) archives. 9 http://archive.eso.org/eso/eso_archive_main.html 10 http://atlas.obs-hp.fr/elodie/ 8.1. Selection of the lines For each star we defined a suitable linelist of Fe I and Fe II transitions, starting from the most updated version of the Kurucz/Castelli lines dataset 11 . We apply an iterative procedure to define the linelist. Assuming that the parameters of the targets are not known a priori, we performed a first analysis by using a preliminary linelist including only laboratory transitions with χ <6 eV and log (gf)>-5 dex. Such a linelist is not checked against the spectral blendings arising from the adopted spectral resolution and the atmospheric parameters and it is used only to perform a preliminary analysis. With the derived new parameters we define a new linelist for each star. The lines are selected by the inspection of synthetic spectra computed with the new parameters and convoluted with a Gaussian profile in order to reproduce the observed spectral resolution. At this step, only iron transitions predicted to be unblended are taken into account and used for the new analysis.

EWs measurements
EWs are measured by using the code DAOSPEC which adopts a saturated Gaussian function to fit the line profile and an unique value for the full width half maximum (FWHM) for all the lines. We start from the FWHM derived from the nominal spectral resolution of the spectra, leaving DAOSPEC free to re-adjust the value of FWHM according to the global residual of the fitting procedure. The measurement of EWs is repeated by using the optmized FWHM value as a new input value, until convergence is reached at a level of 0.1 pixel. The formal error of the fit provided by DAOSPEC is used as 1σ uncertainty on the EW measurement.

Analysis with GALA
The programme stars are analysed by employing all the three Working-Blocks, requiring a spectroscopic optimization of T eff , log g, v t and [M/H] and starting in all cases from the same set of guess parameters (namely T eff = 5000, logg= 2.5, [M/H]= -1.0 dex and v t = 1.5 km/s). The optimization is performed by exploring the parameters space in small steps of δT eff = 50 K, δlog g= 0.1 and δv t = 0.1 km/s; the metallicity is investigated by adopting the step of the ATLAS9 grids (δ[M/H]= 0.5 dex).
In the first run, we analysed the programme stars assuming the same configuration for the input parameters of GALA, in particular we included only lines with σ EW <10% and with EWR>-5.8 (corresponding to ∼10 mÅ at 6000Å). After a first run of GALA, we refined the maximum allowed EWR, that depends mainly by the onset of the saturation along the curve of growth (and thus it is different for stars with different atmospheric parameters). We adopted as maximum allowed value, EWR= -4.65 for Arcturus and µLeonis, and -4.95 for the Sun and HD 84937. These values are chosen on the basis of the visual inspection of the curve of growth, in order to exclude too strong lines, for which the Gaussian approximation can fail. After a first run of GALA, the linelist is refined by using the new parameters obtained by GALA as described above and the procedure repeated. Table 1 summaryzes the derived atmospheric parameters (with the corresponding Jackknife uncertainties) and the [Fe/H] I and [Fe/H] II abundance ratios, together with the two errorbars due to the atmospheric parameters and the internal error computed as σ/ √ (N lines ). We compare our results with those available in literature (and listed in Table 1 as reference). We derive for the Sun T eff = 5800±64 K, log g= 4.50±0.18, v t = 1.20±0.13 km/s and [Fe/H]=-0.01±0.03 dex (where the errorbar is the sum in quadrature of the individual uncertainties listed in Table  1). Our results for T eff and log g agree very well with those listed in the compilation of the NASA website 12 . Concerning the microtubulent velocities, values available in literature range from 0.8 km/s (Biemont et al. 1981) to 1.35 km/s (Steffen, Ludwig & Caffau 2009). A value of 1 km/s is typically adopted as representative for the Sun in several chemical analysis (see Caffau et al. 2011).
Our analysis of Arcturus provides T eff = 4300±60 K, log g=1.60±0.06 and v t = 1.50±0.06 km/s, with an iron abundance [Fe/H]= -0.51±0.05. These results well match the recent analysis of Arcturus by Ramirez & Allende Prieto (2011) that provide an accurate determination of the atmospheric parameters and the chemical composition; in particular T eff and log g are derived in an independent way with respect to our approach, finding T eff = 4286±30 K (by fitting the observed spectral energy distribution), log g=1.66±0.05 (through the trigonometric parallax), while v t turns out to be 1.74 km/s (by using the same approach used in GALA). The final iron abundance is [Fe/H]= -0.52±0.04 dex. In both cases, the agreement with the literature values is good. Finally, Fig. 10 shows as example the graphical output of GALA for Arcturus. Note that the value of the microturbulent velocities is omitted by Cayrel de Strobel, Soubiran & Ralite (2001) because the listed authors in their compilation use different definitions for this parameter (see Mucciarelli 2011, for a review of the different approaches) or assume a representative value. For HD 84937 the values of v t range from 0.8 up to 1.7 km/s, while our value is slightly lower. Also for µLeonis the range of values for v t is wide (from 1.2 up to 2.2 km/s) but our value agrees with this value. Basically, the agreement with the values listed by Cayrel de Strobel, Soubiran & Ralite (2001) is good, but for the gravity of HD 84937, for which we derive a lower value; this difference can be partially explained in light of the different v t .

Stability against the initial parameters
A relevant feature of an automatic procedure to infer parameters and abundances is its stability against the input atmospheric parameters. In order to assess the effect of different first guess parameters, we analyse the spectrum of Arcturus by investigating a regular grid of input parameters with T eff ranging from 3800 to 4800 K (in steps of 100 K) and log g from 1.0 to 2.2 (in steps of 0.1). Fig. 11 shows the grid of the input parameters in the T eff -log g plane (empty points) with the position of the derived parameters (black points); the upper panel summarizes the results when GALA is used without the Refinement Working-Block, while the lower panel shows the results obtained by employing also the refinement option. The recovered parameters cover a small range: in the first run the dispersion of the mean is of 46 K for T eff and 0.09 for log g, while these values drop to 25 K and 0.05 respectively, when the Refinement Working-Block is enabled.

A TEST ON GLOBULAR CLUSTERS
Globular clusters are ideal templates to check the capability of our procedure deriving reliable atmospherical parameters, because of the homogeneity (in terms of metallicity, age and distance) of their stellar content. Thus, the derived parameters for stars in a given globular cluster can be easy compared with theoretical isochrones in the T eff -log g plane.
We apply the same procedure described in Sect. 8 to analyse a set of high-resolution spectra for stars in the globular cluster NGC 6752, ranging from the Turn-Off up to the bright portion of the Red Giant Branch. The spectra have been retrieved by the ESO archive 13 and reduced with the standard ESO pipeline 14 . They are from different observing programmes and with different SNR, including giant stars crossing the Red Giant Branch Bump region observed with UVES@VLT (slit mode) within the ESO Large Program 65.L-0165 with very high (>200) SNR, the stars in the bright portion of the Red Giant Branch observed with UVES-FLAMES@VLT (fiber mode) within the Galactic globular clusters survey presented by Carretta et al. (2009)  The main panel of Fig. 12 shows the position of the final parameters derived with GALA in the T eff -log g plane. Also, two theoretical isochrones with an age of 12 Gyr and a metallicity of Z= 0.0006 (assuming an α-enhanced chemical mixture) are shown as reference (grey curve is from BaSTI database by Pietrinferni et al. (2006) and black curve from Padua database by Girardi et al. 2000). In the lower panel, we show the behaviour of the [Fe/H] ratio as a function of T e f f . No significant trend is found, while the star-to-star scatter increases with increasing T e f f because of the lower SNR.
The parameters derived with GALA well reproduce the behaviour predicted by the theoretical models for a old simple stellar population with the same metallicity of the cluster, confirming the physical reliability of the final solution. Also, we note that the errorbars, both in T eff and log g, change according to the quality of the spectra, ranging from ∼30 K and ∼0.15 for the giants with the highest SNR up to ∼200 K and ∼0.5 for the dwarf stars with the lower SNR.
The entire sample of 52 stars provides an average iron abundance of [Fe/H]I=-1.63 dex (σ= 0.06 dex). This value is consistent with the previous estimates available in literature that point out an iron content ranging from [Fe/H]=-1.62 (Grundahl et al. 2002) up to [Fe/H]=-1.42 dex (Gratton et al. 2001). In this comparison we cannot take into account the different adopted solar values. The stars in common with Carretta et al. (2009)  Also for the stars in common with Yong et al. (2005) the agreement is excellent (also because these spectra have very high SNR and a large wavelength coverage, thus allowing the measurements of a large number of Fe I and Fe II lines): T GALA e f f -T Yong e f f =-1 K (σ= 32 K), logg GALA -logg Yong =-0.39 (σ= 0.11) and [Fe/H] GALA -[Fe/H] Yong =+0.00 dex (σ= 0.06 dex). The comparison with the analysis of the Turn-Off and Sub-Giant Branch stars by Gratton et al. (2001) is not trivial, because they derived the atmospheric parameters from median spectra for the two groups of stars. The temperatures have been derived by fitting the wings of the H α , while the gravities have been obtained from the position of the stars in the Color-Magnitude Diagram. When we compared the parameters by Gratton et al. (2001) with the average values obtained by our analysis of individual stars, the agreement is not perfect but consistent within the uncertainties: we find < T GALA

SUMMARY
In this paper we have presented a new, automatic tool to perform accurate analysis of stellar spectra. GALA is designed to perform automatically the search for the best atmospheric parameters T e f f , log g, v t and the overall metallicity [M/H] for moderate and high resolution stellar absorption spectra, by using the EWs of metallic lines. Also, GALA provides the abundance of each individual line for which the user provides the EW, as well as the average abundance for each atomic species.
The source code of GALA is freely available at the website http://www.cosmic-lab.eu/Cosmic-Lab/Products.html, together with the user manual (including the information about installation, configuration of the input files and how to obtain and properly use the model atmospheres) and an example of the input files as reference. The main advantages of the code are the capability: 1. to optimize all the parameters or only part of them. The code is versatile in order to perform different kind of analysis (full or partial spectroscopic analysis, experiments about the guess parameters...) and adopting different recipes to derive log g; 2. to perform a careful rejection of the outliers according to the line strength, the EW quality and the line distribution in the A(Fe)-χ and A(Fe)-EWR planes; 3. to estimate for each individual star the internal errors for (a) the optimized parameters by adopting the Jackknife bootstrapping technique, and (b) the derived uncertainties due to the choice of atmospheric parameters, following both the prescriptions by Cayrel et al. (2004) and the classical method of altering one parameter at a time.
We have performed an extensive set of test with both synthetic and observed spectra, in order to assess the performances of the code.
1. Experiments with synthetic spectra (whose atmospheric parameters are known a priori) with the injection of Poission noise to simulate different noise conditions show a high stability of the code to recover the atmospheric parameters, without significant bias. The major departure from the original values is found in the microturbulent velocity of low (∼20) SNR spectra, due to the systematic loss of weak lines.
2. A set of FLAMES-UVES spectra of the LMC giant star NGC 1786-1501 observed with different signal-tonoise (from ∼20 up to ∼60) has been analysed with GALA, confirming that our procedure well constrains the parameters also in case of low spectral quality. Also in this case, we found that the largest departures are for the microturbulent velocity in the spectra with low SNR, because the weak lines are not well measured or not detectable in the noise envelope, leading to an underestimate of this parameter.
3. We analysed 4 stars (namely, the Sun, Arcturus, HD 84937 and µLeonis) of different metallicity and evolutionary stage and whose parameters are well established among the closest F-G-K stars. We described an efficient method (including the line selection, the measurement of the EWs and the chemical analysis) to best exploit the capabilities of GALA. Our results for these stars (both for atmospheric parameters and [Fe/H] ratio) well agree with those available in literature.
4. Finally, we analysed a sample of 52 stars of the Galactic globular cluster NGC 6752, in different evolutionary stages. The derived T e f f and log g well follow the predictions of theoretical isochrones with the appropriate age and chemical composition for this cluster. Also, the derived iron content nicely agrees with the previous estimates of other works.
The code permits to obtain chemical abundances and atmospheric parameters for large stellar samples in a very short time, thus making GALA an useful tool in the epoch of the multi-object spectrographs and large surveys. Because of its nature of open source code, GALA will be implemented in the next releases according to the feedback with the users. In particular, we plan to include in the code new grids of ODFs and models that will be publicly released in the future. Also, GALA will be constantly updated in order to include variations and changes in ATLAS9 and MARCS models, as well as in the ATLAS9 code.
The authors warmly thank Fiorella Castelli, Thomas Masseron, Piercarlo Bonifacio and Andrea Negri for useful comments, discussions and suggestions. We thanks the anonymous referee for a careful reading of the paper and helpful comments. This research is part of the project COSMIC-LAB funded by the European Research Council (under contract ERC-2010-AdG-267675).