38 #include <giastroutils.h>
50 static const cxdouble TINY = 1.e-12;
52 static const cxdouble RV_DPI =
53 3.1415926535897932384626433832795028841971693993751;
55 static const cxdouble DEG_TO_RAD =
56 0.017453292519943295769236907684886127134428718885417;
58 static const cxdouble SEC_TO_DEG = 15. / 3600.;
83 inline static cxdouble
84 _giraffe_compute_zdistance(cxdouble hourangle, cxdouble delta,
88 cxdouble p0 = sin(latitude) * sin(delta);
89 cxdouble p1 = cos(latitude) * cos(delta);
90 cxdouble z = p0 + cos(hourangle) * p1;
93 z = z < 0. ? -TINY : TINY;
117 inline static cxdouble
118 _giraffe_compute_airmass_young_irvine(cxdouble secz)
121 return secz * (1. - 0.0012 * (pow(secz, 2.) - 1.));
141 inline static cxdouble
142 _giraffe_compute_airmass_young(cxdouble secz)
145 cxdouble z = 1. / secz;
149 x = 1.002432 * z * z + 0.148386 * z + 0.0096467;
150 y = z * z * z + 0.149864 * z * z + 0.0102963 * z + 0.000303978;
186 cxdouble exptime, cxdouble latitude)
189 const cxchar*
const fctid =
"giraffe_compute_airmass";
194 const cxdouble weights[] = {1. / 6., 2. / 3., 1. / 6.};
202 const cxdouble airmass_upper_limit = 10.;
206 cxdouble hourangle = 0.;
207 cxdouble airmass = 0.;
214 hourangle = lst * SEC_TO_DEG - alpha;
222 if (hourangle < -180.) {
226 if (hourangle > 180.) {
236 latitude *= DEG_TO_RAD;
237 hourangle *= DEG_TO_RAD;
248 z = _giraffe_compute_zdistance(hourangle, delta, latitude);
250 if (fabs(z) < TINY) {
251 cpl_msg_debug(fctid,
"Airmass computation failed. Object is "
252 "below the horizon.");
256 airmass = _giraffe_compute_airmass_young(z);
260 const cxint nweights = CX_N_ELEMENTS(weights);
264 cxdouble timestep = exptime / (nweights - 1) * SEC_TO_DEG *
268 airmass *= weights[0];
270 for (i = 1; i < nweights; i++) {
272 z = _giraffe_compute_zdistance(hourangle + i * timestep,
275 if (fabs(z) < TINY) {
277 cpl_msg_debug(fctid,
"Airmass computation failed. Object "
278 "is below the horizon.");
283 airmass += weights[i] * _giraffe_compute_airmass_young(z);
290 if (airmass > airmass_upper_limit) {
291 cpl_msg_debug(fctid,
"Airmass larger than %f", airmass_upper_limit);