SINFONI Pipeline Reference Manual  2.6.0
sinfo_baryvel.c
1 /* *
2  * This file is part of the ESO SINFONI Pipeline *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18  * */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2012-03-02 08:42:20 $
23  * $Revision: 1.3 $
24  * $Name: not supported by cvs2svn $
25  *
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 
34 /*---------------------------------------------------------------------------*/
48 /*---------------------------------------------------------------------------*/
49 
50 /*----------------------------------------------------------------------------
51  Includes
52  ---------------------------------------------------------------------------*/
53 
54 #include <sinfo_baryvel.h>
55 
56 #include <sinfo_pfits.h>
57 #include <sinfo_utils.h>
58 #include <sinfo_error.h>
59 #include <sinfo_msg.h>
60 #include <sinfo_functions.h>
61 
62 #include <cpl.h>
63 
64 #include <math.h>
65 
66 #define H_GEOLAT "ESO TEL GEOLAT"
67 #define H_GEOLON "ESO TEL GEOLON"
68 #define H_UTC "UTC"
69 
70 /*-----------------------------------------------------------------------------
71  Local functions
72  ---------------------------------------------------------------------------*/
73 
74 static double sinfo_pfits_get_geolat(const cpl_propertylist * plist);
75 static double sinfo_pfits_get_geolon(const cpl_propertylist * plist);
76 static double sinfo_pfits_get_utc(const cpl_propertylist * plist);
77 
78 
79 
80 static void deg2dms(double in_val,
81  double *degs,
82  double *minutes,
83  double *seconds);
84 
85 static void deg2hms(double in_val,
86  double *hour,
87  double *min,
88  double *sec);
89 
90 static void compxy(double inputr[19], char inputc[4],
91  double outputr[4],
92  double utr, double mod_juldat);
93 
94 static void barvel(double DJE, double DEQ,
95  double DVELH[4], double DVELB[4]);
96 
97 
98 
99 
100 /*--------------------------------------------------------------------------*/
101 
102 /*--------------------------------------------------------------------------*/
108 /*--------------------------------------------------------------------------*/
109 static double sinfo_pfits_get_geolat(const cpl_propertylist * plist)
110 {
111  double returnvalue = 0;
112 
113  check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLAT),
114  "Error reading keyword '%s'", H_GEOLAT);
115 
116  cleanup:
117  return returnvalue;
118 }
119 
120 /*--------------------------------------------------------------------------*/
126 /*--------------------------------------------------------------------------*/
127 static double sinfo_pfits_get_geolon(const cpl_propertylist * plist)
128 {
129  double returnvalue = 0;
130 
131  check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLON),
132  "Error reading keyword '%s'", H_GEOLON);
133 
134  cleanup:
135  return returnvalue;
136 }
137 
138 
139 
140 
141 /*---------------------------------------------------------------------------*/
147 /*---------------------------------------------------------------------------*/
148 static double sinfo_pfits_get_utc(const cpl_propertylist * plist)
149 {
150  double returnvalue = 0;
151 
152  check(returnvalue=cpl_propertylist_get_double(plist, H_UTC),
153  "Error reading keyword '%s'", H_UTC);
154 
155  cleanup:
156  return returnvalue;
157 }
158 
159 
160 
161 #if 0 /* Not used / needed.
162  We simply get the julian date from the input FITS header */
163 
164 // SUBROUTINE JULDAT(INDATE,UTR,JD)
165 //C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166 //C
167 //C.IDENTIFICATION
168 //C FORTRAN subroutine JULDAT version 1.0 870102
169 //C original coding: D. Gillet ESO - Garching
170 //C variables renamed and restructured: D. Baade ST-ECF, Garching
171 //C
172 //C.KEYWORDS
173 //C geocentric Julian date
174 //C
175 //C.PURPOSE
176 //C calculate geocentric Julian date for any civil date (time in UT)
177 //C
178 //C.ALGORITHM
179 //C adapted from MEEUS J.,1980, ASTRONOMICAL FORMULAE FOR CALCULATORS
180 //C
181 //C.INPUT/OUTPUT
182 //C the following are passed from and to the calling program:
183 //C INDATE(3) : civil date as year,month,day OR year.fraction
184 //C UT : universal time expressed in real hours
185 //C JD : real geocentric Julian date
186 //C
187 //C.REVISIONS
188 //C made to accept also REAL dates D. Baade 910408
189 //C
190 //C---------------------------------------------------------------------------
191 //C
192 
193 static void
194 juldat(double *INDATE,
195  double UTR,
196  double *JD)
197 {
198  double UT;
199 
200  int DATE[4];
201 
202  UT=UTR / 24.0;
203 
204  /*
205  CHECK FORMAT OF DATE: may be either year,month,date OR year.fraction,0,0
206  (Note that the fraction of the year must NOT include fractions of a day.)
207  For all other formats exit and terminate also calling command sequence.
208 
209  IF ((INDATE(1)-INT(INDATE(1))).GT.1.0E-6) THEN
210  IF ((INDATE(2).GT.1.0E-6).OR.(INDATE(3).GT.1.0E-6))
211  + CALL STETER(1,'Error: Date was entered in wrong format.')
212 
213  copy date input buffer copy to other buffer so that calling program
214  does not notice any changes
215 
216  FIRST CASE: format was year.fraction
217 
218  DATE(1)=INT(INDATE(1))
219  FRAC=INDATE(1)-DATE(1)
220  DATE(2)=1
221  DATE(3)=1
222  ELSE
223 
224  SECOND CASE: format was year,month,day
225  */
226 
227  DATE[1]=sinfo_round_double(INDATE[1]);
228 
229  FRAC = 0;
230 
231  DATE[2]=sinfo_round_double(INDATE[2]);
232 
233  DATE[3]=sinfo_round_double(INDATE[3]);
234 
235  if ((DATE[2] == 0) && (DATE[3] == 0)) {
236 
237  DATE[2]=1;
238 
239  DATE[3]=1;
240 
241  }
242 
243  /*
244  from here on, the normal procedure applies which is based on the
245  format year,month,day:
246  */
247  if (DATE[2] > 2) {
248  YP=DATE[1];
249  P=DATE[2];
250  } else {
251  YP=DATE[1]-1;
252  P=DATE(2)+12.0;
253  }
254 
255  C = DATE[1] + DATE[2]*1.E-2 + DATE[3]*1.E-4 + UT*1.E-6;
256 
257  if (C > 1582.1015E0) {
258  IA=(int) (YP/100.D0);
259  A=IA;
260  IB=2-IA+((int)(A/4.D0));
261  } else {
262  IB=0;
263  }
264 
265  *JD = ((int) (365.25E0*YP)) + ((int)(30.6001D0*(P+1.D0))) + DATE[3] + UT
266  + IB + 1720994.5E0;
267 
268  /*
269  finally, take into account fraction of year (if any), respect leap
270  year conventions
271  */
272  if (FRAC > 1.0E-6) {
273  ND=365;
274 
275  IF (C >= 1582.1015E0) {
276  IC = DATE[1] % 4;
277  if (IC == 0) {
278  ND=366;
279  IC = DATE[1] % 100;
280  if (IC == 0) {
281  IC = DATE[1] % 400;
282  if (IC != 0) ND=365;
283  }
284  }
285  }
286 
287  if (fabs(FRAC*ND-sinfo_round_double(FRAC*ND)) > 0.3) {
288  sinfo_msg_warning("Fraction of year MAY not correspond to "
289  "integer number of days");
290  }
291 
292  *JD = *JD+sinfo_round_double(FRAC*ND);
293  }
294 
295  return;
296 }
297 
298 #endif
299 
303 #define MIDAS_BUG 0
304 /*---------------------------------------------------------------------------*/
312 /*---------------------------------------------------------------------------*/
313 
314 static void
315 deg2hms(double in_val,
316  double *hours,
317  double *minutes,
318  double *seconds)
319 {
320  double tmp;
321  char sign;
322  if (in_val < 0) {
323  in_val = fabs(in_val);
324  sign = '-';
325  }
326  else {
327  sign = '+';
328  }
329 
330  tmp = in_val / 15;
331 
332  /* takes the integer part = hours */
333 #if MIDAS_BUG
334  *hours= sinfo_round_double(tmp);
335 #else
336  *hours= (int) tmp;
337 #endif
338 
339  /* takes the mantissa */
340  tmp = tmp - *hours;
341  /* converts the mantissa in minutes */
342  tmp = tmp * 60;
343 
344  /* takes the integer part = minutes */
345 #if MIDAS_BUG
346  *minutes= sinfo_round_double(tmp);
347 #else
348  *minutes= (int) tmp;
349 #endif
350 
351  /* takes the mantissa */
352  tmp = tmp - *minutes;
353 
354  /* converts the mantissa in seconds = seconds (with decimal) */
355  *seconds= tmp * 60;
356 
357  /* Rather than returning it explicitly, just attach sign to hours */
358  if (sign == '-') *hours = -(*hours);
359 
360  return;
361 }
362 
363 /*---------------------------------------------------------------------------*/
371 /*---------------------------------------------------------------------------*/
372 
373 static void
374 deg2dms(double in_val,
375  double *degs,
376  double *minutes,
377  double *seconds)
378 {
379  deg2hms(in_val*15, degs, minutes, seconds);
380 }
381 
382 
383 
384 
385 
386 /* @cond Convert FORTRAN indexing -> C indexing */
387 #define DCFEL(x,y) dcfel[y][x]
388 #define DCFEPS(x,y) dcfeps[y][x]
389 #define CCSEL(x,y) ccsel[y][x]
390 #define DCARGS(x,y) dcargs[y][x]
391 #define CCAMPS(x,y) ccamps[y][x]
392 #define CCSEC(x,y) ccsec[y][x]
393 #define DCARGM(x,y) dcargm[y][x]
394 #define CCAMPM(x,y) ccampm[y][x]
395 #define DCEPS(x) dceps[x]
396 #define FORBEL(x) forbel[x]
397 #define SORBEL(x) sorbel[x]
398 #define SN(x) sn[x]
399 #define SINLP(x) sinlp[x]
400 #define COSLP(x) coslp[x]
401 #define CCPAMV(x) ccpamv[x]
402 /* @endcond */
403 /*---------------------------------------------------------------------------*/
416 /*---------------------------------------------------------------------------*/
417 
418 
419 static
420 void barvel(double DJE, double DEQ,
421  double DVELH[4], double DVELB[4])
422 {
423  double sn[5];
424  double DT,DTL,DTSQ;
425  double DRD,DRLD;
426  double DXBD,DYBD,DZBD,DZHD,DXHD,DYHD;
427  double DYAHD,DZAHD,DYABD,DZABD;
428  double DEPS,PHI,PHID,PSID,DPARAM,PARAM;
429 
430  double PERTL,PERTLD,PERTRD,PERTP,PERTR,PERTPD;
431  double SINA,TL;
432  double COSA,ESQ;
433  double A,B,F,SINF,COSF,T,TSQ,TWOE,TWOG;
434 
435  double DPSI,D1PDRO,DSINLS;
436  double DCOSLS,DSINEP,DCOSEP;
437  double forbel[8], sorbel[18], sinlp[5], coslp[5];
438  double SINLM,COSLM,SIGMA;
439  /* int IDEQ; */
440  int K,N;
441 
442  double *E = sorbel + 1 - 1;
443  double *G = forbel + 1 - 1;
444  double DC2PI = 6.2831853071796E0;
445  double CC2PI = 6.283185; /* ??? */
446 
447  double DC1 = 1.0;
448  double DCT0 = 2415020.0E0;
449  double DCJUL = 36525.0E0;
450 
451  double dcfel[][4] = { {0, 0, 0, 0},
452  {0, 1.7400353E+00, 6.2833195099091E+02, 5.2796E-06},
453  {0, 6.2565836E+00, 6.2830194572674E+02,-2.6180E-06},
454  {0, 4.7199666E+00, 8.3997091449254E+03,-1.9780E-05},
455  {0, 1.9636505E-01, 8.4334662911720E+03,-5.6044E-05},
456  {0, 4.1547339E+00, 5.2993466764997E+01, 5.8845E-06},
457  {0, 4.6524223E+00, 2.1354275911213E+01, 5.6797E-06},
458  {0, 4.2620486E+00, 7.5025342197656E+00, 5.5317E-06},
459  {0, 1.4740694E+00, 3.8377331909193E+00, 5.6093E-06} };
460 
461  double dceps[4] = {0, 4.093198E-01,-2.271110E-04,-2.860401E-08};
462 
463  double ccsel[][4] = { {0, 0, 0, 0},
464  {0, 1.675104E-02, -4.179579E-05, -1.260516E-07},
465  {0, 2.220221E-01, 2.809917E-02, 1.852532E-05},
466  {0, 1.589963E+00, 3.418075E-02, 1.430200E-05},
467  {0, 2.994089E+00, 2.590824E-02, 4.155840E-06},
468  {0, 8.155457E-01, 2.486352E-02, 6.836840E-06},
469  {0, 1.735614E+00, 1.763719E-02, 6.370440E-06},
470  {0, 1.968564E+00, 1.524020E-02, -2.517152E-06},
471  {0, 1.282417E+00, 8.703393E-03, 2.289292E-05},
472  {0, 2.280820E+00, 1.918010E-02, 4.484520E-06},
473  {0, 4.833473E-02, 1.641773E-04, -4.654200E-07},
474  {0, 5.589232E-02, -3.455092E-04, -7.388560E-07},
475  {0, 4.634443E-02, -2.658234E-05, 7.757000E-08},
476  {0, 8.997041E-03, 6.329728E-06, -1.939256E-09},
477  {0, 2.284178E-02, -9.941590E-05, 6.787400E-08},
478  {0, 4.350267E-02, -6.839749E-05, -2.714956E-07},
479  {0, 1.348204E-02, 1.091504E-05, 6.903760E-07},
480  {0, 3.106570E-02, -1.665665E-04, -1.590188E-07} };
481 
482 
483  double dcargs[][3] = { {0, 0, 0},
484  {0, 5.0974222E+00, -7.8604195454652E+02},
485  {0, 3.9584962E+00, -5.7533848094674E+02},
486  {0, 1.6338070E+00, -1.1506769618935E+03},
487  {0, 2.5487111E+00, -3.9302097727326E+02},
488  {0, 4.9255514E+00, -5.8849265665348E+02},
489  {0, 1.3363463E+00, -5.5076098609303E+02},
490  {0, 1.6072053E+00, -5.2237501616674E+02},
491  {0, 1.3629480E+00, -1.1790629318198E+03},
492  {0, 5.5657014E+00, -1.0977134971135E+03},
493  {0, 5.0708205E+00, -1.5774000881978E+02},
494  {0, 3.9318944E+00, 5.2963464780000E+01},
495  {0, 4.8989497E+00, 3.9809289073258E+01},
496  {0, 1.3097446E+00, 7.7540959633708E+01},
497  {0, 3.5147141E+00, 7.9618578146517E+01},
498  {0, 3.5413158E+00, -5.4868336758022E+02} };
499 
500 
501  double ccamps[][6] =
502  {{0, 0, 0, 0, 0, 0},
503  {0, -2.279594E-5, 1.407414E-5, 8.273188E-6, 1.340565E-5, -2.490817E-7},
504  {0, -3.494537E-5, 2.860401E-7, 1.289448E-7, 1.627237E-5, -1.823138E-7},
505  {0, 6.593466E-7, 1.322572E-5, 9.258695E-6, -4.674248E-7, -3.646275E-7},
506  {0, 1.140767E-5, -2.049792E-5, -4.747930E-6, -2.638763E-6, -1.245408E-7},
507  {0, 9.516893E-6, -2.748894E-6, -1.319381E-6, -4.549908E-6, -1.864821E-7},
508  {0, 7.310990E-6, -1.924710E-6, -8.772849E-7, -3.334143E-6, -1.745256E-7},
509  {0, -2.603449E-6, 7.359472E-6, 3.168357E-6, 1.119056E-6, -1.655307E-7},
510  {0, -3.228859E-6, 1.308997E-7, 1.013137E-7, 2.403899E-6, -3.736225E-7},
511  {0, 3.442177E-7, 2.671323E-6, 1.832858E-6, -2.394688E-7, -3.478444E-7},
512  {0, 8.702406E-6, -8.421214E-6, -1.372341E-6, -1.455234E-6, -4.998479E-8},
513  {0, -1.488378E-6, -1.251789E-5, 5.226868E-7, -2.049301E-7, 0.0E0},
514  {0, -8.043059E-6, -2.991300E-6, 1.473654E-7, -3.154542E-7, 0.0E0},
515  {0, 3.699128E-6, -3.316126E-6, 2.901257E-7, 3.407826E-7, 0.0E0},
516  {0, 2.550120E-6, -1.241123E-6, 9.901116E-8, 2.210482E-7, 0.0E0},
517  {0, -6.351059E-7, 2.341650E-6, 1.061492E-6, 2.878231E-7, 0.0E0}};
518 
519 
520 
521  double CCSEC3 = -7.757020E-08;
522 
523  double ccsec[][4] = { {0, 0, 0, 0},
524  {0, 1.289600E-06, 5.550147E-01, 2.076942E+00},
525  {0, 3.102810E-05, 4.035027E+00, 3.525565E-01},
526  {0, 9.124190E-06, 9.990265E-01, 2.622706E+00},
527  {0, 9.793240E-07, 5.508259E+00, 1.559103E+01}};
528 
529  double DCSLD = 1.990987E-07, CCSGD = 1.990969E-07;
530 
531  double CCKM = 3.122140E-05, CCMLD = 2.661699E-06, CCFDI = 2.399485E-07;
532 
533  double dcargm[][3] = {{0, 0, 0},
534  {0, 5.1679830E+00, 8.3286911095275E+03},
535  {0, 5.4913150E+00, -7.2140632838100E+03},
536  {0, 5.9598530E+00, 1.5542754389685E+04}};
537 
538  double ccampm[][5] = {{0, 0, 0, 0, 0},
539  {0, 1.097594E-01, 2.896773E-07, 5.450474E-02, 1.438491E-07},
540  {0, -2.223581E-02, 5.083103E-08, 1.002548E-02, -2.291823E-08},
541  {0, 1.148966E-02, 5.658888E-08, 8.249439E-03, 4.063015E-08} };
542 
543  double ccpamv[] = {0, 8.326827E-11, 1.843484E-11, 1.988712E-12, 1.881276E-12};
544 
545  double DC1MME = 0.99999696E0;
546 
547  /* not used later
548  * IDEQ=DEQ; */
549 
550 
551  DT=(DJE-DCT0)/DCJUL;
552 
553  T=DT;
554 
555  DTSQ=DT*DT;
556 
557  TSQ=DTSQ;
558 
559  double DML = 0; /* Suppress warning */
560 
561  /* special case K == 1 */
562  DML=fmod(DCFEL(1,1)+DT*DCFEL(2,1)+DTSQ*DCFEL(3,1),DC2PI);
563 
564  /* other cases K> 1 */
565  for (K = 2; K <= 8; K++) {
566 
567  FORBEL(K-1)=fmod(DCFEL(1,K)+DT*DCFEL(2,K)+DTSQ*DCFEL(3,K),DC2PI);
568 
569  }
570 
571  DEPS=fmod(DCEPS(1)+DT*DCEPS(2)+DTSQ*DCEPS(3), DC2PI);
572 
573  for (K = 1; K <= 17; K++) {
574 
575  SORBEL(K)=fmod(CCSEL(1,K)+T*CCSEL(2,K)+TSQ*CCSEL(3,K),CC2PI);
576 
577  }
578 
579  for (K = 1; K <= 4; K++) {
580 
581  A=fmod(CCSEC(2,K)+T*CCSEC(3,K),CC2PI);
582 
583  SN(K)=sin(A);
584 
585  }
586 
587  PERTL = CCSEC(1,1) *SN(1) +CCSEC(1,2)*SN(2)
588  +(CCSEC(1,3)+T*CCSEC3)*SN(3) +CCSEC(1,4)*SN(4);
589 
590  PERTLD=0.0;
591  PERTR =0.0;
592  PERTRD=0.0;
593 
594  for (K = 1; K <= 15; K++) {
595 
596  A=fmod(DCARGS(1,K)+DT*DCARGS(2,K), DC2PI);
597 
598  COSA=cos(A);
599 
600  SINA=sin(A);
601 
602  PERTL =PERTL+CCAMPS(1,K)*COSA+CCAMPS(2,K)*SINA;
603 
604  PERTR =PERTR+CCAMPS(3,K)*COSA+CCAMPS(4,K)*SINA;
605 
606  if (K >= 11) break;
607 
608  PERTLD=PERTLD+(CCAMPS(2,K)*COSA-CCAMPS(1,K)*SINA)*CCAMPS(5,K);
609 
610  PERTRD=PERTRD+(CCAMPS(4,K)*COSA-CCAMPS(3,K)*SINA)*CCAMPS(5,K);
611 
612  }
613 
614 
615  ESQ=E[1]*E[1];
616 
617  DPARAM=DC1-ESQ;
618 
619  PARAM=DPARAM;
620 
621  TWOE=E[1]+E[1];
622 
623  TWOG=G[1]+G[1];
624 
625  PHI=TWOE*((1.0-ESQ*0.125 )*sin(G[1])+E[1]*0.625 *sin(TWOG)
626  +ESQ*0.5416667 *sin(G[1]+TWOG) ) ;
627 
628  F=G[1]+PHI;
629 
630  SINF=sin(F);
631 
632  COSF=cos(F);
633 
634  DPSI=DPARAM/(DC1+E[1]*COSF);
635 
636  PHID=TWOE*CCSGD*((1.0+ESQ*1.5 )*COSF+E[1]*(1.25 -SINF*SINF*0.5 ));
637 
638  PSID=CCSGD*E[1]*SINF/sqrt(PARAM);
639 
640  D1PDRO=(DC1+PERTR);
641 
642  DRD=D1PDRO*(PSID+DPSI*PERTRD);
643 
644  DRLD=D1PDRO*DPSI*(DCSLD+PHID+PERTLD);
645 
646  DTL=fmod(DML+PHI+PERTL, DC2PI);
647 
648  DSINLS=sin(DTL);
649 
650  DCOSLS=cos(DTL);
651 
652  DXHD = DRD*DCOSLS-DRLD*DSINLS;
653 
654  DYHD = DRD*DSINLS+DRLD*DCOSLS;
655 
656  PERTL =0.0;
657 
658  PERTLD=0.0;
659 
660  PERTP =0.0;
661 
662  PERTPD=0.0;
663 
664  for (K = 1; K <= 3; K++) {
665  A=fmod(DCARGM(1,K)+DT*DCARGM(2,K), DC2PI);
666 
667  SINA =sin(A);
668 
669  COSA =cos(A);
670 
671  PERTL =PERTL +CCAMPM(1,K)*SINA;
672 
673  PERTLD=PERTLD+CCAMPM(2,K)*COSA;
674 
675  PERTP =PERTP +CCAMPM(3,K)*COSA;
676 
677  PERTPD=PERTPD-CCAMPM(4,K)*SINA;
678  }
679 
680  TL=FORBEL(2)+PERTL;
681 
682  SINLM=sin(TL);
683 
684  COSLM=cos(TL);
685 
686  SIGMA=CCKM/(1.0+PERTP);
687 
688  A=SIGMA*(CCMLD+PERTLD);
689 
690  B=SIGMA*PERTPD;
691 
692  DXHD=DXHD+A*SINLM+B*COSLM;
693 
694  DYHD=DYHD-A*COSLM+B*SINLM;
695 
696  DZHD= -SIGMA*CCFDI* cos(FORBEL(3));
697 
698  DXBD=DXHD*DC1MME;
699 
700  DYBD=DYHD*DC1MME;
701 
702  DZBD=DZHD*DC1MME;
703 
704  for (K = 1; K <= 4; K++) {
705 
706  double PLON=FORBEL(K+3);
707 
708  double POMG=SORBEL(K+1);
709 
710  double PECC=SORBEL(K+9);
711 
712  TL=fmod(PLON+2.0*PECC* sin(PLON-POMG), CC2PI);
713 
714  SINLP(K)= sin(TL);
715 
716  COSLP(K)= cos(TL);
717 
718  DXBD=DXBD+CCPAMV(K)*(SINLP(K)+PECC*sin(POMG));
719 
720  DYBD=DYBD-CCPAMV(K)*(COSLP(K)+PECC*cos(POMG));
721 
722  DZBD=DZBD-CCPAMV(K)*SORBEL(K+13)*cos(PLON-SORBEL(K+5));
723 
724  }
725 
726  DCOSEP=cos(DEPS);
727  DSINEP=sin(DEPS);
728  DYAHD=DCOSEP*DYHD-DSINEP*DZHD;
729  DZAHD=DSINEP*DYHD+DCOSEP*DZHD;
730  DYABD=DCOSEP*DYBD-DSINEP*DZBD;
731  DZABD=DSINEP*DYBD+DCOSEP*DZBD;
732 
733  DVELH[1]=DXHD;
734  DVELH[2]=DYAHD;
735  DVELH[3]=DZAHD;
736 
737  DVELB[1]=DXBD;
738  DVELB[2]=DYABD;
739  DVELB[3]=DZABD;
740 
741  for (N = 1; N <= 3; N++) {
742  DVELH[N]=DVELH[N]*1.4959787E8;
743  DVELB[N]=DVELB[N]*1.4959787E8;
744  }
745  return;
746 }
747 
748 
749 
750 
751 /*--------------------------------------------------------------------------*/
773 /*--------------------------------------------------------------------------*/
774 static void
775 compxy(double inputr[19], char inputc[4],
776  double outputr[4],
777  double utr, double mod_juldat)
778 {
779  double STR;
780  double t0, dl, theta0, pe, st0hg, stg;
781  double jd, jd0h;
782  double dvelb[4], dvelh[4];
783  double alp, del, beov, berv, EDV;
784  double HAR, phi, heov, herv;
785  double *rbuf;
786  char inpsgn[4];
787  double *olong, *olat, *alpha, *delta;
788  char signs[] = "+++";
789  rbuf = inputr;
790  inpsgn[1] = inputc[1];
791  inpsgn[2] = inputc[2];
792  inpsgn[3] = inputc[3];
793  olong = rbuf + 7 - 1;
794  olat = rbuf + 10 - 1;
795  alpha = rbuf + 13 - 1;
796  delta = rbuf + 16 - 1;
797  // ... convert UT to real hours, calculate Julian date
798  /* We know this one already but convert seconds -> hours */
799  utr /= 3600;
800 
801 
802  jd = mod_juldat + 2400000.5;
803 
804  // ... likewise convert longitude and latitude of observatory to real hours
805  // ... and degrees, respectively; take care of signs
806  // ... NOTE: east longitude is assumed for input !!
807 
808  if (olong[1] < 0 || olong[2] < 0 ||
809  olong[3] < 0 || inpsgn[1] == '-') {
810  signs[1] = '-';
811  olong[1] = fabs(olong[1]);
812  olong[2] = fabs(olong[2]);
813  olong[3] = fabs(olong[3]);
814  }
815  dl = olong[1]+olong[2]/60. +olong[3]/3600.;
816  if (signs[1] == '-') dl = -dl;
817  dl = -dl*24. /360.;
818 
819  if (olat[1] < 0 || olat[2] < 0 ||
820  olat[3] < 0 || inpsgn[2] == '-') {
821  signs[2] = '-';
822 
823  olat[1] = fabs(olat[1]);
824  olat[2] = fabs(olat[2]);
825  olat[3] = fabs(olat[3]);
826 
827  }
828 
829  phi = olat[1]+olat[2]/60. +olat[3]/3600.;
830 
831  if (signs[2] == '-') phi = -phi;
832 
833  phi = phi*M_PI/180. ;
834 
835  // ... convert right ascension and declination to real radians
836 
837  alp = (alpha[1]*3600. +alpha[2]*60. +alpha[3])*M_PI/(12. *3600. );
838 
839  if (delta[1] < 0 || delta[2] < 0 ||
840  delta[3] < 0 || inpsgn[3] == '-') {
841 
842  signs[3] = '-';
843 
844  delta[1] = fabs(delta[1]);
845  delta[2] = fabs(delta[2]);
846  delta[3] = fabs(delta[3]);
847 
848  }
849 
850  del = (delta[1]*3600.0 + delta[2]*60. + delta[3])
851  * M_PI/(3600. *180. );
852 
853 
854 
855  if (signs[3] == '-') del = - del;
856 
857  // ... calculate earth's orbital velocity in rectangular coordinates X,Y,Z
858  // ... for both heliocentric and barycentric frames (DVELH, DVELB)
859  // ... Note that setting the second argument of BARVEL to zero as done below
860  // ... means that the input coordinates will not be corrected for precession.
861 
862 
863  barvel(jd, 0.0, dvelh, dvelb);
864 
865  // ... with the rectangular velocity components known, the respective projections
866  // ... HEOV and BEOV on a given line of sight (ALP,DEL) can be determined:
867 
868  // ... REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B17
869 
870  beov =
871  dvelb[1]*cos(alp)*cos(del)+
872  dvelb[2]*sin(alp)*cos(del)+
873  dvelb[3]*sin(del);
874 
875  heov =
876  dvelh[1]*cos(alp)*cos(del)+
877  dvelh[2]*sin(alp)*cos(del)+
878  dvelh[3]*sin(del);
879 
880 
881  // ... For determination also of the contribution due to the diurnal rotation of
882  // ... the earth (EDV), the hour angle (HAR) is needed at which the observation
883  // ... was made which requires conversion of UT to sidereal time (ST).
884 
885  // ... Therefore, first compute ST at 0 hours UT (ST0HG)
886 
887  // ... REFERENCE : MEEUS J.,1980,ASTRONOMICAL FORMULAE FOR CALCULATORS
888 
889 
890  jd0h = jd - (utr/24.0);
891 
892  t0 = (jd0h-2415020. )/36525. ;
893 
894 
895  theta0 = 0.276919398 +100.0021359 *t0+0.000001075 *t0*t0 ;
896 
897  pe = (int) theta0;
898 
899  theta0 = theta0 - pe;
900 
901  st0hg = theta0*24. ;
902 
903  // ... now do the conversion UT -> ST (MEAN SIDEREAL TIME)
904 
905  // ... REFERENCE : THE ASTRONOMICAL ALMANAC 1983, P B7
906  // ... IN 1983: 1 MEAN SOLAR DAY = 1.00273790931 MEAN SIDEREAL DAYS
907  // ... ST WITHOUT EQUATION OF EQUINOXES CORRECTION => ACCURACY +/- 1 SEC
908  //
909  stg = st0hg+utr*1.00273790931 ;
910 
911  if (stg < dl) stg = stg +24. ;
912 
913  STR = stg-dl;
914 
915 
916  if (STR >= 24. ) STR = STR-24. ;
917 
918  STR = STR*M_PI/12. ;
919 
920  HAR = STR-alp;
921 
922 
923  EDV = -0.4654 * sin(HAR)* cos(del)* cos(phi);
924 
925  // ... the total correction (in km/s) is the sum of orbital and diurnal components
926 
927 
928  herv=heov+EDV;
929  berv=beov+EDV;
930 
931  /* The following is not needed. Do not translate */
932 
933 #if 0
934  // ... Calculation of the barycentric and heliocentric correction times
935  // ... (BCT and HCT) requires knowledge of the earth's position in its
936  // ... orbit. Subroutine BARCOR returns the rectangular barycentric (DCORB)
937  // ... and heliocentric (DCORH) coordinates.
938 
939  // CALL BARCOR(DCORH,DCORB)
940 
941  // ... from this, the correction times (in days) can be determined:
942  // ... (REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B16)
943 
944  // BCT=+0.0057756D0*(DCORB(1)*DCOS(ALP)*DCOS(DEL)+
945  // 1 DCORB(2)*DSIN(ALP)*DCOS(DEL)+
946  // 2 DCORB(3)* DSIN(DEL))
947  // HCT=+0.0057756D0*(DCORH(1)*DCOS(ALP)*DCOS(DEL)+
948  // 1 DCORH(2)*DSIN(ALP)*DCOS(DEL)+
949  // 2 DCORH(3)* DSIN(DEL))
950 
951  //... write results to keywords
952 
953  // CALL STKWRD('OUTPUTD',BCT,1,1,KUN,STAT) ! barycentric correction time
954  // CALL STKWRD('OUTPUTD',HCT,2,1,KUN,STAT) ! heliocentric correction time
955 #endif
956 
957  rbuf[1] = berv; /* barocentric RV correction */
958  rbuf[2] = herv; /* heliocentric RV correction */
959  rbuf[3] = EDV; /* diurnal RV correction */
960 
961 
962  outputr[1] = rbuf[1];
963  outputr[2] = rbuf[2];
964  outputr[3] = rbuf[3];
965 
966  return;
967 }
968 
969 
970 
971 /*----------------------------------------------------------------------------*/
978 /*----------------------------------------------------------------------------*/
979 cpl_error_code
980 sinfo_baryvel(const cpl_propertylist *raw_header,
981  double *bary_corr,
982  double *helio_corr)
983 {
984 
985  double outputr[4];
986 
987  char inputc[] = "X+++"; /* 0th index not used */
988 
989  double rneg = 1.0;
990 
991  double inputr[19]; /* Do not use the zeroth element */
992 
993 
994 /*
995  qc_ra = m$value({p1},O_POS(1))
996  qc_dec = m$value({p1},O_POS(2))
997  qc_geolat = m$value({p1},{h_geolat})
998  qc_geolon = m$value({p1},{h_geolon})
999  qc_obs_time = m$value({p1},O_TIME(7)) !using an image as input it take the
1000  !date from the descriptor O_TIME(1,2,3)
1001  !and the UT from O_TIME(5)
1002 */
1003  double qc_ra;
1004  double qc_dec;
1005  double qc_geolat;
1006  double qc_geolon;
1007 
1008  double utr;
1009  double mod_juldat;
1010 
1011  double ra_hour, ra_min, ra_sec;
1012  double dec_deg, dec_min, dec_sec;
1013  double lat_deg, lat_min, lat_sec;
1014  double lon_deg, lon_min, lon_sec;
1015 
1016  check( qc_ra = sinfo_pfits_get_ra(raw_header), /* in degrees */
1017  "Error getting object right ascension");
1018  check( qc_dec = sinfo_pfits_get_dec(raw_header),
1019  "Error getting object declination");
1020 
1021  check( qc_geolat = sinfo_pfits_get_geolat(raw_header),
1022  "Error getting telescope latitude");
1023  check( qc_geolon = sinfo_pfits_get_geolon(raw_header),
1024  "Error getting telescope longitude");
1025 
1026  /* double qc_obs_time = sinfo_pfits_get_exptime(raw_header); Not used! */
1027 
1028  check( utr = sinfo_pfits_get_utc(raw_header),
1029  "Error reading UTC");
1030  check( mod_juldat = sinfo_pfits_get_mjdobs(raw_header),
1031  "Error julian date");
1032 
1033  deg2hms(qc_ra, &ra_hour, &ra_min, &ra_sec);
1034  deg2dms(qc_dec, &dec_deg, &dec_min, &dec_sec);
1035  deg2dms(qc_geolat, &lat_deg, &lat_min, &lat_sec);
1036  deg2dms(qc_geolon, &lon_deg, &lon_min, &lon_sec);
1037 
1038 
1039  inputr[7] = lon_deg;
1040  inputr[8] = lon_min;
1041  inputr[9] = lon_sec;
1042 
1043 
1044  rneg = (inputr[7]*3600.)+(inputr[8]*60.)+inputr[9];
1045 
1046  inputc[1] = (lon_deg >= 0) ? '+' : '-';
1047 
1048  if (rneg < 0) inputc[1] = '-';
1049 
1050 
1051  inputr[10] = lat_deg;
1052  inputr[11] = lat_min;
1053  inputr[12] = lat_sec;
1054 
1055 
1056  rneg = (inputr[10]*3600.)+(inputr[11]*60.)+inputr[12];
1057 
1058  inputc[2] = (lat_deg >= 0) ? '+' : '-';
1059 
1060  if (rneg < 0) inputc[2] = '-';
1061 
1062 
1063  inputr[13] = ra_hour;
1064  inputr[14] = ra_min;
1065  inputr[15] = ra_sec;
1066 
1067 
1068  inputr[16] = dec_deg;
1069  inputr[17] = dec_min;
1070  inputr[18] = dec_sec;
1071 
1072 
1073  inputc[3] = (dec_deg >= 0) ? '+' : '-';
1074 
1075  rneg = (inputr[16]*3600.)+(inputr[17]*60.)+inputr[18];
1076 
1077  if (rneg < 0) inputc[3] = '-';
1078 
1079 
1080 //C INPUTR/R/1/3 date: year,month,day
1081 //C INPUTR/R/4/3 universal time: hour,min,sec
1082 //C INPUTR/R/7/3 EAST longitude of observatory: degree,min,sec !! NOTE
1083 //C INPUTR/R/10/3 latitude of observatory: degree,min,sec
1084 //C INPUTR/R/13/3 right ascension: hour,min,sec
1085 //C INPUTR/R/16/3 declination: degree,min,sec
1086 
1087  /* compute the corrections */
1088  compxy(inputr, inputc, outputr, utr, mod_juldat);
1089 
1090  sinfo_msg_debug(" Total barycentric RV correction: %f km/s", outputr[1]);
1091  sinfo_msg_debug(" Total heliocentric RV correction: %f km/s", outputr[2]);
1092  sinfo_msg_debug(" (incl. diurnal RV correction of %f km/s)", outputr[3]);
1093 
1094 
1095  *bary_corr = outputr[1];
1096  *helio_corr = outputr[2];
1097 
1098  cleanup:
1099  if (cpl_error_get_code() != CPL_ERROR_NONE) {
1100  sinfo_check_rec_status(0);
1101  }
1102  return cpl_error_get_code();
1103 }
#define sinfo_msg_debug(...)
Print a debug message.
Definition: sinfo_msg.h:103
#define sinfo_msg_warning(...)
Print an warning message.
Definition: sinfo_msg.h:93