1 /*********************************************************************
2 Spectral lines.
3 This is part of GNU Astronomy Utilities (Gnuastro) package.
4 
5 Original author:
6      Mohammad Akhlaghi <mohammad@akhlaghi.org>
7 Contributing author(s):
8 Copyright (C) 2019-2021, Free Software Foundation, Inc.
9 
10 Gnuastro is free software: you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation, either version 3 of the License, or (at your
13 option) any later version.
14 
15 Gnuastro is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
22 **********************************************************************/
23 #include <config.h>
24 
25 #include <math.h>
26 #include <stdio.h>
27 #include <errno.h>
28 #include <error.h>
29 #include <string.h>
30 #include <stdlib.h>
31 
32 #include <gnuastro/speclines.h>
33 
34 
35 /*********************************************************************/
36 /*************        Internal names and codes         ***************/
37 /*********************************************************************/
38 /* Return line's name as literal string. */
39 char *
gal_speclines_line_name(int linecode)40 gal_speclines_line_name(int linecode)
41 {
42   switch(linecode)
43     {
44     case GAL_SPECLINES_SIIRED:           return GAL_SPECLINES_NAME_SIIRED;
45     case GAL_SPECLINES_SII:              return GAL_SPECLINES_NAME_SII;
46     case GAL_SPECLINES_SIIBLUE:          return GAL_SPECLINES_NAME_SIIBLUE;
47     case GAL_SPECLINES_NIIRED:           return GAL_SPECLINES_NAME_NIIRED;
48     case GAL_SPECLINES_NII:              return GAL_SPECLINES_NAME_NII;
49     case GAL_SPECLINES_HALPHA:           return GAL_SPECLINES_NAME_HALPHA;
50     case GAL_SPECLINES_NIIBLUE:          return GAL_SPECLINES_NAME_NIIBLUE;
51     case GAL_SPECLINES_OIIIRED_VIS:      return GAL_SPECLINES_NAME_OIIIRED_VIS;
52     case GAL_SPECLINES_OIII_VIS:         return GAL_SPECLINES_NAME_OIII_VIS;
53     case GAL_SPECLINES_OIIIBLUE_VIS:     return GAL_SPECLINES_NAME_OIIIBLUE_VIS;
54     case GAL_SPECLINES_HBETA:            return GAL_SPECLINES_NAME_HBETA;
55     case GAL_SPECLINES_HEII_VIS:         return GAL_SPECLINES_NAME_HEII_VIS;
56     case GAL_SPECLINES_HGAMMA:           return GAL_SPECLINES_NAME_HGAMMA;
57     case GAL_SPECLINES_HDELTA:           return GAL_SPECLINES_NAME_HDELTA;
58     case GAL_SPECLINES_HEPSILON:         return GAL_SPECLINES_NAME_HEPSILON;
59     case GAL_SPECLINES_NEIII:            return GAL_SPECLINES_NAME_NEIII;
60     case GAL_SPECLINES_OIIRED:           return GAL_SPECLINES_NAME_OIIRED;
61     case GAL_SPECLINES_OII:              return GAL_SPECLINES_NAME_OII;
62     case GAL_SPECLINES_OIIBLUE:          return GAL_SPECLINES_NAME_OIIBLUE;
63     case GAL_SPECLINES_BLIMIT:           return GAL_SPECLINES_NAME_BLIMIT;
64     case GAL_SPECLINES_MGIIRED:          return GAL_SPECLINES_NAME_MGIIRED;
65     case GAL_SPECLINES_MGII:             return GAL_SPECLINES_NAME_MGII;
66     case GAL_SPECLINES_MGIIBLUE:         return GAL_SPECLINES_NAME_MGIIBLUE;
67     case GAL_SPECLINES_CIIIRED:          return GAL_SPECLINES_NAME_CIIIRED;
68     case GAL_SPECLINES_CIII:             return GAL_SPECLINES_NAME_CIII;
69     case GAL_SPECLINES_CIIIBLUE:         return GAL_SPECLINES_NAME_CIIIBLUE;
70     case GAL_SPECLINES_SiIIIRED:         return GAL_SPECLINES_NAME_SiIIIRED;
71     case GAL_SPECLINES_SiIII:            return GAL_SPECLINES_NAME_SiIII;
72     case GAL_SPECLINES_SiIIIBLUE:        return GAL_SPECLINES_NAME_SiIIIBLUE;
73     case GAL_SPECLINES_OIIIRED_UV:       return GAL_SPECLINES_NAME_OIIIRED_UV;
74     case GAL_SPECLINES_OIII_UV:          return GAL_SPECLINES_NAME_OIII_UV;
75     case GAL_SPECLINES_OIIIBLUE_UV:      return GAL_SPECLINES_NAME_OIIIBLUE_UV;
76     case GAL_SPECLINES_HEII_UV:          return GAL_SPECLINES_NAME_HEII_UV;
77     case GAL_SPECLINES_CIVRED:           return GAL_SPECLINES_NAME_CIVRED;
78     case GAL_SPECLINES_CIV:              return GAL_SPECLINES_NAME_CIV;
79     case GAL_SPECLINES_CIVBLUE:          return GAL_SPECLINES_NAME_CIVBLUE;
80     case GAL_SPECLINES_NV:               return GAL_SPECLINES_NAME_NV;
81     case GAL_SPECLINES_LYALPHA:          return GAL_SPECLINES_NAME_LYALPHA;
82     case GAL_SPECLINES_LYBETA:           return GAL_SPECLINES_NAME_LYBETA;
83     case GAL_SPECLINES_LYGAMMA:          return GAL_SPECLINES_NAME_LYGAMMA;
84     case GAL_SPECLINES_LYDELTA:          return GAL_SPECLINES_NAME_LYDELTA;
85     case GAL_SPECLINES_LYEPSILON:        return GAL_SPECLINES_NAME_LYEPSILON;
86     case GAL_SPECLINES_LYLIMIT:          return GAL_SPECLINES_NAME_LYLIMIT;
87     default: return NULL;
88     }
89   return NULL;
90 }
91 
92 
93 
94 
95 
96 /* Return the code of the given line name. */
97 int
gal_speclines_line_code(char * name)98 gal_speclines_line_code(char *name)
99 {
100   if( !strcmp(name, GAL_SPECLINES_NAME_SIIRED) )
101     return GAL_SPECLINES_SIIRED;
102   else if( !strcmp(name, GAL_SPECLINES_NAME_SII) )
103     return GAL_SPECLINES_SII;
104   else if( !strcmp(name, GAL_SPECLINES_NAME_SIIBLUE) )
105     return GAL_SPECLINES_SIIBLUE;
106   if( !strcmp(name, GAL_SPECLINES_NAME_NIIRED) )
107     return GAL_SPECLINES_NIIRED;
108   else if( !strcmp(name, GAL_SPECLINES_NAME_NII) )
109     return GAL_SPECLINES_NII;
110   else if( !strcmp(name, GAL_SPECLINES_NAME_HALPHA) )
111     return GAL_SPECLINES_HALPHA;
112   else if( !strcmp(name, GAL_SPECLINES_NAME_NIIBLUE) )
113     return GAL_SPECLINES_NIIBLUE;
114   else if( !strcmp(name, GAL_SPECLINES_NAME_OIIIRED_VIS) )
115     return GAL_SPECLINES_OIIIRED_VIS;
116   else if( !strcmp(name, GAL_SPECLINES_NAME_OIII_VIS) )
117     return GAL_SPECLINES_OIII_VIS;
118   else if( !strcmp(name, GAL_SPECLINES_NAME_OIIIBLUE_VIS) )
119     return GAL_SPECLINES_OIIIBLUE_VIS;
120   else if( !strcmp(name, GAL_SPECLINES_NAME_HBETA) )
121     return GAL_SPECLINES_HBETA;
122   else if( !strcmp(name, GAL_SPECLINES_NAME_HEII_VIS) )
123     return GAL_SPECLINES_HEII_VIS;
124   else if( !strcmp(name, GAL_SPECLINES_NAME_HGAMMA) )
125     return GAL_SPECLINES_HGAMMA;
126   else if( !strcmp(name, GAL_SPECLINES_NAME_HDELTA) )
127     return GAL_SPECLINES_HDELTA;
128   else if( !strcmp(name, GAL_SPECLINES_NAME_HEPSILON) )
129     return GAL_SPECLINES_HEPSILON;
130   else if( !strcmp(name, GAL_SPECLINES_NAME_NEIII) )
131     return GAL_SPECLINES_NEIII;
132   else if( !strcmp(name, GAL_SPECLINES_NAME_OIIRED) )
133     return GAL_SPECLINES_OIIRED;
134   else if( !strcmp(name, GAL_SPECLINES_NAME_OII) )
135     return GAL_SPECLINES_OII;
136   else if( !strcmp(name, GAL_SPECLINES_NAME_OIIBLUE) )
137     return GAL_SPECLINES_OIIBLUE;
138   else if( !strcmp(name, GAL_SPECLINES_NAME_BLIMIT) )
139     return GAL_SPECLINES_BLIMIT;
140   else if( !strcmp(name, GAL_SPECLINES_NAME_MGIIRED) )
141     return GAL_SPECLINES_MGIIRED;
142   else if( !strcmp(name, GAL_SPECLINES_NAME_MGII) )
143     return GAL_SPECLINES_MGII;
144   else if( !strcmp(name, GAL_SPECLINES_NAME_MGIIBLUE) )
145     return GAL_SPECLINES_MGIIBLUE;
146   else if( !strcmp(name, GAL_SPECLINES_NAME_CIIIRED) )
147     return GAL_SPECLINES_CIIIRED;
148   else if( !strcmp(name, GAL_SPECLINES_NAME_CIII) )
149     return GAL_SPECLINES_CIII;
150   else if( !strcmp(name, GAL_SPECLINES_NAME_CIIIBLUE) )
151     return GAL_SPECLINES_CIIIBLUE;
152   else if( !strcmp(name, GAL_SPECLINES_NAME_SiIIIRED) )
153     return GAL_SPECLINES_SiIIIRED;
154   else if( !strcmp(name, GAL_SPECLINES_NAME_SiIII) )
155     return GAL_SPECLINES_SiIII;
156   else if( !strcmp(name, GAL_SPECLINES_NAME_SiIIIBLUE) )
157     return GAL_SPECLINES_SiIIIBLUE;
158   else if( !strcmp(name, GAL_SPECLINES_NAME_OIIIRED_UV) )
159     return GAL_SPECLINES_OIIIRED_UV;
160   else if( !strcmp(name, GAL_SPECLINES_NAME_OIII_UV) )
161     return GAL_SPECLINES_OIII_UV;
162   else if( !strcmp(name, GAL_SPECLINES_NAME_OIIIBLUE_UV) )
163     return GAL_SPECLINES_OIIIBLUE_UV;
164   else if( !strcmp(name, GAL_SPECLINES_NAME_HEII_UV) )
165     return GAL_SPECLINES_HEII_UV;
166   else if( !strcmp(name, GAL_SPECLINES_NAME_CIVRED) )
167     return GAL_SPECLINES_CIVRED;
168   else if( !strcmp(name, GAL_SPECLINES_NAME_CIV) )
169     return GAL_SPECLINES_CIV;
170   else if( !strcmp(name, GAL_SPECLINES_NAME_CIVBLUE) )
171     return GAL_SPECLINES_CIVBLUE;
172   else if( !strcmp(name, GAL_SPECLINES_NAME_NV) )
173     return GAL_SPECLINES_NV;
174   else if( !strcmp(name, GAL_SPECLINES_NAME_LYALPHA) )
175     return GAL_SPECLINES_LYALPHA;
176   else if( !strcmp(name, GAL_SPECLINES_NAME_LYBETA) )
177     return GAL_SPECLINES_LYBETA;
178   else if( !strcmp(name, GAL_SPECLINES_NAME_LYGAMMA) )
179     return GAL_SPECLINES_LYGAMMA;
180   else if( !strcmp(name, GAL_SPECLINES_NAME_LYDELTA) )
181     return GAL_SPECLINES_LYDELTA;
182   else if( !strcmp(name, GAL_SPECLINES_NAME_LYEPSILON) )
183     return GAL_SPECLINES_LYEPSILON;
184   else if( !strcmp(name, GAL_SPECLINES_NAME_LYLIMIT) )
185     return GAL_SPECLINES_LYLIMIT;
186   else return GAL_SPECLINES_INVALID;
187   return GAL_SPECLINES_INVALID;
188 }
189 
190 
191 
192 
193 
194 /* Return the wavelength (in Angstroms) of given line. */
195 double
gal_speclines_line_angstrom(int linecode)196 gal_speclines_line_angstrom(int linecode)
197 {
198   switch(linecode)
199     {
200     case GAL_SPECLINES_SIIRED:        return GAL_SPECLINES_ANGSTROM_SIIRED;
201     case GAL_SPECLINES_SII:           return GAL_SPECLINES_ANGSTROM_SII;
202     case GAL_SPECLINES_SIIBLUE:       return GAL_SPECLINES_ANGSTROM_SIIBLUE;
203     case GAL_SPECLINES_NIIRED:        return GAL_SPECLINES_ANGSTROM_NIIRED;
204     case GAL_SPECLINES_NII:           return GAL_SPECLINES_ANGSTROM_NII;
205     case GAL_SPECLINES_HALPHA:        return GAL_SPECLINES_ANGSTROM_HALPHA;
206     case GAL_SPECLINES_NIIBLUE:       return GAL_SPECLINES_ANGSTROM_NIIBLUE;
207     case GAL_SPECLINES_OIIIRED_VIS:   return GAL_SPECLINES_ANGSTROM_OIIIRED_VIS;
208     case GAL_SPECLINES_OIII_VIS:      return GAL_SPECLINES_ANGSTROM_OIII_VIS;
209     case GAL_SPECLINES_OIIIBLUE_VIS:  return GAL_SPECLINES_ANGSTROM_OIIIBLUE_VIS;
210     case GAL_SPECLINES_HBETA:         return GAL_SPECLINES_ANGSTROM_HBETA;
211     case GAL_SPECLINES_HEII_VIS:      return GAL_SPECLINES_ANGSTROM_HEII_VIS;
212     case GAL_SPECLINES_HGAMMA:        return GAL_SPECLINES_ANGSTROM_HGAMMA;
213     case GAL_SPECLINES_HDELTA:        return GAL_SPECLINES_ANGSTROM_HDELTA;
214     case GAL_SPECLINES_HEPSILON:      return GAL_SPECLINES_ANGSTROM_HEPSILON;
215     case GAL_SPECLINES_NEIII:         return GAL_SPECLINES_ANGSTROM_NEIII;
216     case GAL_SPECLINES_OIIRED:        return GAL_SPECLINES_ANGSTROM_OIIRED;
217     case GAL_SPECLINES_OII:           return GAL_SPECLINES_ANGSTROM_OII;
218     case GAL_SPECLINES_OIIBLUE:       return GAL_SPECLINES_ANGSTROM_OIIBLUE;
219     case GAL_SPECLINES_BLIMIT:        return GAL_SPECLINES_ANGSTROM_BLIMIT;
220     case GAL_SPECLINES_MGIIRED:       return GAL_SPECLINES_ANGSTROM_MGIIRED;
221     case GAL_SPECLINES_MGII:          return GAL_SPECLINES_ANGSTROM_MGII;
222     case GAL_SPECLINES_MGIIBLUE:      return GAL_SPECLINES_ANGSTROM_MGIIBLUE;
223     case GAL_SPECLINES_CIIIRED:       return GAL_SPECLINES_ANGSTROM_CIIIRED;
224     case GAL_SPECLINES_CIII:          return GAL_SPECLINES_ANGSTROM_CIII;
225     case GAL_SPECLINES_CIIIBLUE:      return GAL_SPECLINES_ANGSTROM_CIIIBLUE;
226     case GAL_SPECLINES_SiIIIRED:      return GAL_SPECLINES_ANGSTROM_SiIIIRED;
227     case GAL_SPECLINES_SiIII:         return GAL_SPECLINES_ANGSTROM_SiIII;
228     case GAL_SPECLINES_SiIIIBLUE:     return GAL_SPECLINES_ANGSTROM_SiIIIBLUE;
229     case GAL_SPECLINES_OIIIRED_UV:    return GAL_SPECLINES_ANGSTROM_OIIIRED_UV;
230     case GAL_SPECLINES_OIII_UV:       return GAL_SPECLINES_ANGSTROM_OIII_UV;
231     case GAL_SPECLINES_OIIIBLUE_UV:   return GAL_SPECLINES_ANGSTROM_OIIIBLUE_UV;
232     case GAL_SPECLINES_HEII_UV:       return GAL_SPECLINES_ANGSTROM_HEII_UV;
233     case GAL_SPECLINES_CIVRED:        return GAL_SPECLINES_ANGSTROM_CIVRED;
234     case GAL_SPECLINES_CIV:           return GAL_SPECLINES_ANGSTROM_CIV;
235     case GAL_SPECLINES_CIVBLUE:       return GAL_SPECLINES_ANGSTROM_CIVBLUE;
236     case GAL_SPECLINES_NV:            return GAL_SPECLINES_ANGSTROM_NV;
237     case GAL_SPECLINES_LYALPHA:       return GAL_SPECLINES_ANGSTROM_LYALPHA;
238     case GAL_SPECLINES_LYBETA:        return GAL_SPECLINES_ANGSTROM_LYBETA;
239     case GAL_SPECLINES_LYGAMMA:       return GAL_SPECLINES_ANGSTROM_LYGAMMA;
240     case GAL_SPECLINES_LYDELTA:       return GAL_SPECLINES_ANGSTROM_LYDELTA;
241     case GAL_SPECLINES_LYEPSILON:     return GAL_SPECLINES_ANGSTROM_LYEPSILON;
242     case GAL_SPECLINES_LYLIMIT:       return GAL_SPECLINES_ANGSTROM_LYLIMIT;
243     default:
244       error(EXIT_FAILURE, 0, "%s: '%d' not recognized line identifier",
245             __func__, linecode);
246     }
247   return NAN;
248 }
249 
250 
251 
252 
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 /*********************************************************************/
270 /*************             Redshifted lines            ***************/
271 /*********************************************************************/
272 double
gal_speclines_line_redshift(double obsline,double restline)273 gal_speclines_line_redshift(double obsline, double restline)
274 {
275   return (obsline/restline)-1;
276 }
277 
278 
279 
280 
281 
282 double
gal_speclines_line_redshift_code(double obsline,int linecode)283 gal_speclines_line_redshift_code(double obsline, int linecode)
284 {
285   double restline=gal_speclines_line_angstrom(linecode);
286   return (obsline/restline)-1;
287 }
288