sinfo_baryvel.c

00001 /*                                                                            *
00002  *   This file is part of the ESO SINFONI Pipeline                            *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                    *
00004  *                                                                            *
00005  *   This library is free software; you can redistribute it and/or modify     *
00006  *   it under the terms of the GNU General Public License as published by     *
00007  *   the Free Software Foundation; either version 2 of the License, or        *
00008  *   (at your option) any later version.                                      *
00009  *                                                                            *
00010  *   This program is distributed in the hope that it will be useful,          *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00013  *   GNU General Public License for more details.                             *
00014  *                                                                            *
00015  *   You should have received a copy of the GNU General Public License        *
00016  *   along with this program; if not, write to the Free Software              *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA     *
00018  *                                                                            */
00019 
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2009/04/28 11:42:18 $
00023  * $Revision: 1.2 $
00024  * $Name: sinfo-2_2_5 $
00025  * $Log: sinfo_baryvel.c,v $
00026  * Revision 1.2  2009/04/28 11:42:18  amodigli
00027  * now return cpl_error_code
00028  *
00029  * Revision 1.1  2009/01/02 08:27:58  amodigli
00030  * added to repository
00031  *
00032  * Revision 1.8  2007/06/06 08:17:33  amodigli
00033  * replace tab with 4 spaces
00034  *
00035  */
00036 
00037 #ifdef HAVE_CONFIG_H
00038 #  include <config.h>
00039 #endif
00040 
00041 
00042 /*---------------------------------------------------------------------------*/
00056 /*---------------------------------------------------------------------------*/
00059 /*----------------------------------------------------------------------------
00060   Includes
00061   ---------------------------------------------------------------------------*/
00062 
00063 #include <sinfo_baryvel.h>
00064 
00065 #include <sinfo_pfits.h>
00066 #include <sinfo_utils.h>
00067 #include <sinfo_error.h>
00068 #include <sinfo_msg.h>
00069 #include <sinfo_functions.h>
00070 
00071 #include <cpl.h>
00072 
00073 #include <math.h>
00074 
00075 #define H_GEOLAT "ESO TEL GEOLAT"
00076 #define H_GEOLON "ESO TEL GEOLON"
00077 #define H_UTC "UTC"
00078 
00079 /*-----------------------------------------------------------------------------
00080   Local functions
00081   ---------------------------------------------------------------------------*/
00082 
00083 static double sinfo_pfits_get_geolat(const cpl_propertylist * plist);
00084 static double sinfo_pfits_get_geolon(const cpl_propertylist * plist);
00085 static double sinfo_pfits_get_utc(const cpl_propertylist * plist);
00086 
00087 
00088 
00089 static void deg2dms(double in_val, 
00090             double *degs,
00091             double *minutes,
00092             double *seconds);
00093 
00094 static void deg2hms(double in_val, 
00095             double *hour,
00096             double *min,
00097             double *sec);
00098 
00099 static void compxy(double inputr[19], char inputc[4],
00100            double outputr[4],
00101            double utr, double mod_juldat);
00102 
00103 static void barvel(double DJE, double DEQ,
00104            double DVELH[4], double DVELB[4]);
00105 
00106 
00107 
00108 
00109 /*--------------------------------------------------------------------------*/
00110 
00111 /*--------------------------------------------------------------------------*/
00117 /*--------------------------------------------------------------------------*/
00118 static double sinfo_pfits_get_geolat(const cpl_propertylist * plist)
00119 {
00120     double returnvalue = 0;
00121     
00122     check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLAT), 
00123        "Error reading keyword '%s'", H_GEOLAT);
00124     
00125   cleanup:
00126     return returnvalue;
00127 }
00128 
00129 /*--------------------------------------------------------------------------*/
00135 /*--------------------------------------------------------------------------*/
00136 static double sinfo_pfits_get_geolon(const cpl_propertylist * plist)
00137 {
00138     double returnvalue = 0;
00139 
00140     check(returnvalue=cpl_propertylist_get_double(plist, H_GEOLON), 
00141        "Error reading keyword '%s'", H_GEOLON);
00142       
00143   cleanup:
00144     return returnvalue;
00145 }
00146 
00147 
00148 
00149 
00150 /*---------------------------------------------------------------------------*/
00156 /*---------------------------------------------------------------------------*/
00157 static double sinfo_pfits_get_utc(const cpl_propertylist * plist)
00158 {
00159     double returnvalue = 0;
00160 
00161     check(returnvalue=cpl_propertylist_get_double(plist, H_UTC), 
00162        "Error reading keyword '%s'", H_UTC);
00163      
00164   cleanup:
00165     return returnvalue;
00166 }
00167 
00168 
00169 
00170 #if 0   /* Not used / needed.
00171        We simply get the julian date from the input FITS header */
00172 
00173 //      SUBROUTINE JULDAT(INDATE,UTR,JD)
00174 //C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00175 //C
00176 //C.IDENTIFICATION
00177 //C  FORTRAN subroutine                    JULDAT     version 1.0       870102
00178 //C  original coding:                      D. Gillet        ESO - Garching
00179 //C  variables renamed and restructured:   D. Baade         ST-ECF, Garching
00180 //C
00181 //C.KEYWORDS
00182 //C  geocentric Julian date
00183 //C
00184 //C.PURPOSE
00185 //C  calculate geocentric Julian date for any civil date (time in UT)
00186 //C
00187 //C.ALGORITHM
00188 //C adapted from MEEUS J.,1980, ASTRONOMICAL FORMULAE FOR CALCULATORS
00189 //C
00190 //C.INPUT/OUTPUT
00191 //C the following are passed from and to the calling program:
00192 //C  INDATE(3)    :         civil date as year,month,day OR year.fraction
00193 //C  UT           :         universal time expressed in real hours
00194 //C  JD           :         real geocentric Julian date
00195 //C
00196 //C.REVISIONS
00197 //C made to accept also REAL dates         D. Baade             910408
00198 //C
00199 //C---------------------------------------------------------------------------
00200 //C
00201 
00202 static void 
00203 juldat(double *INDATE,
00204        double UTR,
00205        double *JD)
00206 {
00207   double UT;
00208 
00209   int DATE[4];
00210 
00211   UT=UTR / 24.0;
00212 
00213   /*
00214     CHECK FORMAT OF DATE: may be either year,month,date OR year.fraction,0,0 
00215     (Note that the fraction of the year must NOT include fractions of a day.)
00216     For all other formats exit and terminate also calling command sequence.
00217   
00218     IF ((INDATE(1)-INT(INDATE(1))).GT.1.0E-6) THEN 
00219     IF ((INDATE(2).GT.1.0E-6).OR.(INDATE(3).GT.1.0E-6)) 
00220     +       CALL   STETER(1,'Error: Date was entered in wrong format.')
00221 
00222     copy date input buffer copy to other buffer so that calling program 
00223     does not notice any changes
00224 
00225     FIRST CASE: format was year.fraction
00226 
00227     DATE(1)=INT(INDATE(1))
00228     FRAC=INDATE(1)-DATE(1)
00229     DATE(2)=1
00230     DATE(3)=1
00231     ELSE
00232   
00233     SECOND CASE: format was year,month,day
00234   */
00235 
00236   DATE[1]=sinfo_round_double(INDATE[1]);
00237 
00238   FRAC = 0;
00239 
00240   DATE[2]=sinfo_round_double(INDATE[2]);
00241 
00242   DATE[3]=sinfo_round_double(INDATE[3]);
00243 
00244   if ((DATE[2] == 0) &&  (DATE[3] == 0)) {
00245 
00246     DATE[2]=1;
00247 
00248     DATE[3]=1;
00249 
00250   }
00251 
00252   /*
00253     from here on, the normal procedure applies which is based on the 
00254     format year,month,day:
00255   */
00256   if (DATE[2] > 2) {
00257     YP=DATE[1];
00258     P=DATE[2];
00259   } else {
00260     YP=DATE[1]-1;
00261     P=DATE(2)+12.0;
00262   }
00263 
00264   C = DATE[1] + DATE[2]*1.E-2 + DATE[3]*1.E-4 + UT*1.E-6;
00265 
00266   if (C  >   1582.1015E0) {
00267     IA=(int) (YP/100.D0);
00268     A=IA;
00269     IB=2-IA+((int)(A/4.D0));
00270   } else {
00271     IB=0;
00272   }
00273 
00274   *JD = ((int) (365.25E0*YP)) + ((int)(30.6001D0*(P+1.D0))) + DATE[3] + UT
00275     + IB + 1720994.5E0;
00276 
00277   /*
00278     finally, take into account fraction of year (if any), respect leap
00279     year conventions
00280   */
00281   if (FRAC > 1.0E-6) {
00282     ND=365;
00283 
00284     IF (C >= 1582.1015E0) {
00285       IC = DATE[1] % 4;
00286       if (IC == 0) {
00287         ND=366;
00288         IC = DATE[1] % 100;
00289         if (IC == 0) {
00290       IC = DATE[1] % 400;
00291       if (IC != 0) ND=365;
00292         }
00293       }
00294     }
00295 
00296     if (fabs(FRAC*ND-sinfo_round_double(FRAC*ND)) > 0.3) {
00297       sinfo_msg_warning("Fraction of year MAY not correspond to "
00298             "integer number of days");
00299     }
00300 
00301     *JD = *JD+sinfo_round_double(FRAC*ND);
00302   }
00303 
00304   return;
00305 }
00306 
00307 #endif
00308 
00312 #define MIDAS_BUG 0
00313 /*---------------------------------------------------------------------------*/
00321 /*---------------------------------------------------------------------------*/
00322 
00323 static void
00324 deg2hms(double in_val, 
00325     double *hours,
00326     double *minutes,
00327     double *seconds)
00328 {
00329   double tmp;
00330   char sign;
00331   if (in_val < 0) {
00332     in_val = fabs(in_val);
00333     sign = '-';
00334   }
00335   else {
00336     sign = '+';
00337   }
00338 
00339   tmp   = in_val / 15;
00340 
00341   /* takes the integer part = hours */
00342 #if MIDAS_BUG
00343   *hours= sinfo_round_double(tmp);
00344 #else
00345   *hours= (int) tmp;
00346 #endif
00347 
00348   /* takes the mantissa */
00349   tmp   = tmp - *hours;
00350   /* converts the mantissa in minutes */
00351   tmp   = tmp * 60;
00352 
00353   /* takes the integer part = minutes */
00354 #if MIDAS_BUG
00355   *minutes= sinfo_round_double(tmp);
00356 #else
00357   *minutes= (int) tmp;
00358 #endif
00359 
00360   /* takes the mantissa */
00361   tmp   = tmp - *minutes;
00362 
00363   /* converts the mantissa in seconds = seconds (with decimal) */
00364   *seconds= tmp * 60;
00365 
00366   /* Rather than returning it explicitly, just  attach sign to hours */
00367   if (sign == '-') *hours = -(*hours);
00368 
00369   return;
00370 }
00371 
00372 /*---------------------------------------------------------------------------*/
00380 /*---------------------------------------------------------------------------*/
00381 
00382 static void
00383 deg2dms(double in_val, 
00384     double *degs,
00385     double *minutes,
00386     double *seconds)
00387 {
00388   deg2hms(in_val*15, degs, minutes, seconds);
00389 }
00390 
00391 
00392 
00393 
00394 
00395 /* @cond Convert FORTRAN indexing -> C indexing */
00396 #define DCFEL(x,y)  dcfel[y][x]
00397 #define DCFEPS(x,y) dcfeps[y][x]
00398 #define CCSEL(x,y)  ccsel[y][x]
00399 #define DCARGS(x,y) dcargs[y][x]
00400 #define CCAMPS(x,y) ccamps[y][x]
00401 #define CCSEC(x,y)  ccsec[y][x]
00402 #define DCARGM(x,y) dcargm[y][x]
00403 #define CCAMPM(x,y) ccampm[y][x]
00404 #define DCEPS(x)    dceps[x]
00405 #define FORBEL(x)   forbel[x]
00406 #define SORBEL(x)   sorbel[x]
00407 #define SN(x)       sn[x]
00408 #define SINLP(x)    sinlp[x]
00409 #define COSLP(x)    coslp[x]
00410 #define CCPAMV(x)   ccpamv[x]
00411 /* @endcond */
00412 /*---------------------------------------------------------------------------*/
00425 /*---------------------------------------------------------------------------*/
00426 
00427 
00428 static 
00429 void barvel(double DJE, double DEQ,
00430         double DVELH[4], double DVELB[4])
00431 {
00432   double sn[5];
00433   double DT,DTL,DTSQ,DLOCAL;
00434   double DRD,DRLD;
00435   double DXBD,DYBD,DZBD,DZHD,DXHD,DYHD;
00436   double DYAHD,DZAHD,DYABD,DZABD;
00437   double DML,DEPS,PHI,PHID,PSID,DPARAM,PARAM;
00438   double PLON,POMG,PECC;
00439   double PERTL,PERTLD,PERTRD,PERTP,PERTR,PERTPD;
00440   double SINA,TL;
00441   double COSA,ESQ;
00442   double A,B,F,SINF,COSF,T,TSQ,TWOE,TWOG;
00443 
00444   double DPSI,D1PDRO,DSINLS;
00445   double DCOSLS,DSINEP,DCOSEP;
00446   double forbel[8], sorbel[18], sinlp[5], coslp[5];
00447   double SINLM,COSLM,SIGMA;
00448   int IDEQ,K,N;
00449 
00450   double *E = sorbel + 1 - 1;
00451   double *G = forbel + 1 - 1;
00452   double DC2PI = 6.2831853071796E0;
00453   double CC2PI = 6.283185;             /* ??? */
00454 
00455   double DC1 = 1.0;
00456   double DCT0 = 2415020.0E0;
00457   double DCJUL = 36525.0E0;
00458 
00459   double dcfel[][4] = { {0, 0, 0, 0},
00460             {0, 1.7400353E+00, 6.2833195099091E+02, 5.2796E-06},
00461             {0, 6.2565836E+00, 6.2830194572674E+02,-2.6180E-06},
00462             {0, 4.7199666E+00, 8.3997091449254E+03,-1.9780E-05},
00463             {0, 1.9636505E-01, 8.4334662911720E+03,-5.6044E-05},
00464             {0, 4.1547339E+00, 5.2993466764997E+01, 5.8845E-06},
00465             {0, 4.6524223E+00, 2.1354275911213E+01, 5.6797E-06},
00466             {0, 4.2620486E+00, 7.5025342197656E+00, 5.5317E-06},
00467             {0, 1.4740694E+00, 3.8377331909193E+00, 5.6093E-06} };
00468     
00469   double dceps[4] = {0, 4.093198E-01,-2.271110E-04,-2.860401E-08};
00470 
00471   double ccsel[][4] = { {0, 0, 0, 0},
00472             {0, 1.675104E-02, -4.179579E-05, -1.260516E-07},
00473             {0, 2.220221E-01,  2.809917E-02,  1.852532E-05},
00474             {0, 1.589963E+00,  3.418075E-02,  1.430200E-05},
00475             {0, 2.994089E+00,  2.590824E-02,  4.155840E-06},
00476             {0, 8.155457E-01,  2.486352E-02,  6.836840E-06},
00477             {0, 1.735614E+00,  1.763719E-02,  6.370440E-06},
00478             {0, 1.968564E+00,  1.524020E-02, -2.517152E-06},
00479             {0, 1.282417E+00,  8.703393E-03,  2.289292E-05},
00480             {0, 2.280820E+00,  1.918010E-02,  4.484520E-06},
00481             {0, 4.833473E-02,  1.641773E-04, -4.654200E-07},
00482             {0, 5.589232E-02, -3.455092E-04, -7.388560E-07},
00483             {0, 4.634443E-02, -2.658234E-05,  7.757000E-08},
00484             {0, 8.997041E-03,  6.329728E-06, -1.939256E-09},
00485             {0, 2.284178E-02, -9.941590E-05,  6.787400E-08},
00486             {0, 4.350267E-02, -6.839749E-05, -2.714956E-07},
00487             {0, 1.348204E-02,  1.091504E-05,  6.903760E-07},
00488             {0, 3.106570E-02, -1.665665E-04, -1.590188E-07} };
00489 
00490 
00491   double dcargs[][3] = { {0, 0, 0},
00492              {0, 5.0974222E+00, -7.8604195454652E+02},
00493              {0, 3.9584962E+00, -5.7533848094674E+02},
00494              {0, 1.6338070E+00, -1.1506769618935E+03},
00495              {0, 2.5487111E+00, -3.9302097727326E+02},
00496              {0, 4.9255514E+00, -5.8849265665348E+02},
00497              {0, 1.3363463E+00, -5.5076098609303E+02},
00498              {0, 1.6072053E+00, -5.2237501616674E+02},
00499              {0, 1.3629480E+00, -1.1790629318198E+03},
00500              {0, 5.5657014E+00, -1.0977134971135E+03},
00501              {0, 5.0708205E+00, -1.5774000881978E+02},
00502              {0, 3.9318944E+00,  5.2963464780000E+01},
00503              {0, 4.8989497E+00,  3.9809289073258E+01},
00504              {0, 1.3097446E+00,  7.7540959633708E+01},
00505              {0, 3.5147141E+00,  7.9618578146517E+01},
00506              {0, 3.5413158E+00, -5.4868336758022E+02} };
00507 
00508 
00509   double ccamps[][6] = 
00510     {{0, 0, 0, 0, 0, 0},
00511      {0, -2.279594E-5,  1.407414E-5,  8.273188E-6,  1.340565E-5, -2.490817E-7},
00512      {0, -3.494537E-5,  2.860401E-7,  1.289448E-7,  1.627237E-5, -1.823138E-7},
00513      {0,  6.593466E-7,  1.322572E-5,  9.258695E-6, -4.674248E-7, -3.646275E-7},
00514      {0,  1.140767E-5, -2.049792E-5, -4.747930E-6, -2.638763E-6, -1.245408E-7},
00515      {0,  9.516893E-6, -2.748894E-6, -1.319381E-6, -4.549908E-6, -1.864821E-7},
00516      {0,  7.310990E-6, -1.924710E-6, -8.772849E-7, -3.334143E-6, -1.745256E-7},
00517      {0, -2.603449E-6,  7.359472E-6,  3.168357E-6,  1.119056E-6, -1.655307E-7},
00518      {0, -3.228859E-6,  1.308997E-7,  1.013137E-7,  2.403899E-6, -3.736225E-7},
00519      {0,  3.442177E-7,  2.671323E-6,  1.832858E-6, -2.394688E-7, -3.478444E-7},
00520      {0,  8.702406E-6, -8.421214E-6, -1.372341E-6, -1.455234E-6, -4.998479E-8},
00521      {0, -1.488378E-6, -1.251789E-5,  5.226868E-7, -2.049301E-7,  0.0E0},
00522      {0, -8.043059E-6, -2.991300E-6,  1.473654E-7, -3.154542E-7,  0.0E0},
00523      {0,  3.699128E-6, -3.316126E-6,  2.901257E-7,  3.407826E-7,  0.0E0},
00524      {0,  2.550120E-6, -1.241123E-6,  9.901116E-8,  2.210482E-7,  0.0E0},
00525      {0, -6.351059E-7,  2.341650E-6,  1.061492E-6,  2.878231E-7,  0.0E0}};
00526 
00527 
00528 
00529   double CCSEC3 = -7.757020E-08;
00530 
00531   double ccsec[][4] = { {0, 0, 0, 0},
00532             {0, 1.289600E-06,  5.550147E-01,  2.076942E+00},
00533             {0, 3.102810E-05,  4.035027E+00,  3.525565E-01},
00534             {0, 9.124190E-06,  9.990265E-01,  2.622706E+00},
00535             {0, 9.793240E-07,  5.508259E+00,  1.559103E+01}};
00536 
00537   double DCSLD =  1.990987E-07, CCSGD = 1.990969E-07;
00538 
00539   double CCKM = 3.122140E-05, CCMLD = 2.661699E-06, CCFDI = 2.399485E-07;
00540 
00541   double dcargm[][3] = {{0, 0, 0},
00542             {0, 5.1679830E+00,  8.3286911095275E+03},
00543             {0, 5.4913150E+00, -7.2140632838100E+03},
00544             {0, 5.9598530E+00,  1.5542754389685E+04}};
00545 
00546   double ccampm[][5] = {{0, 0, 0, 0, 0},
00547             {0,  1.097594E-01,  2.896773E-07,  5.450474E-02,  1.438491E-07},
00548             {0, -2.223581E-02,  5.083103E-08,  1.002548E-02, -2.291823E-08},
00549             {0,  1.148966E-02,  5.658888E-08,  8.249439E-03,  4.063015E-08} };
00550 
00551   double ccpamv[] = {0, 8.326827E-11, 1.843484E-11, 1.988712E-12, 1.881276E-12};
00552 
00553   double DC1MME = 0.99999696E0;
00554 
00555   IDEQ=DEQ;
00556 
00557   DT=(DJE-DCT0)/DCJUL;
00558 
00559   T=DT;
00560 
00561   DTSQ=DT*DT;
00562 
00563   TSQ=DTSQ;
00564 
00565   DML = 0;  /* Suppress warning */
00566   for (K = 1; K <= 8; K++) {
00567 
00568     DLOCAL=fmod(DCFEL(1,K)+DT*DCFEL(2,K)+DTSQ*DCFEL(3,K),DC2PI);
00569 
00570     if (K == 1)  DML=DLOCAL;
00571 
00572     if (K != 1)  FORBEL(K-1)=DLOCAL;
00573   }
00574 
00575   DEPS=fmod(DCEPS(1)+DT*DCEPS(2)+DTSQ*DCEPS(3), DC2PI);
00576 
00577   for (K = 1; K <= 17; K++) {
00578 
00579     SORBEL(K)=fmod(CCSEL(1,K)+T*CCSEL(2,K)+TSQ*CCSEL(3,K),CC2PI);
00580 
00581   }
00582 
00583   for (K = 1; K <= 4; K++) {
00584 
00585     A=fmod(CCSEC(2,K)+T*CCSEC(3,K),CC2PI);
00586 
00587     SN(K)=sin(A);
00588 
00589   }
00590 
00591   PERTL =  CCSEC(1,1)          *SN(1) +CCSEC(1,2)*SN(2)
00592     +(CCSEC(1,3)+T*CCSEC3)*SN(3) +CCSEC(1,4)*SN(4);
00593 
00594   PERTLD=0.0;
00595   PERTR =0.0;
00596   PERTRD=0.0;
00597 
00598   for (K = 1; K <= 15; K++) {
00599 
00600     A=fmod(DCARGS(1,K)+DT*DCARGS(2,K), DC2PI);
00601 
00602     COSA=cos(A);
00603 
00604     SINA=sin(A);
00605 
00606     PERTL =PERTL+CCAMPS(1,K)*COSA+CCAMPS(2,K)*SINA;
00607 
00608     PERTR =PERTR+CCAMPS(3,K)*COSA+CCAMPS(4,K)*SINA;
00609 
00610     if (K >= 11) break;
00611 
00612     PERTLD=PERTLD+(CCAMPS(2,K)*COSA-CCAMPS(1,K)*SINA)*CCAMPS(5,K);
00613 
00614     PERTRD=PERTRD+(CCAMPS(4,K)*COSA-CCAMPS(3,K)*SINA)*CCAMPS(5,K);
00615 
00616   }
00617 
00618 
00619   ESQ=E[1]*E[1];
00620 
00621   DPARAM=DC1-ESQ;
00622 
00623   PARAM=DPARAM;
00624 
00625   TWOE=E[1]+E[1];
00626 
00627   TWOG=G[1]+G[1];
00628 
00629   PHI=TWOE*((1.0-ESQ*0.125  )*sin(G[1])+E[1]*0.625  *sin(TWOG)
00630         +ESQ*0.5416667  *sin(G[1]+TWOG) ) ;
00631     
00632   F=G[1]+PHI;
00633 
00634   SINF=sin(F);
00635 
00636   COSF=cos(F);
00637 
00638   DPSI=DPARAM/(DC1+E[1]*COSF);
00639 
00640   PHID=TWOE*CCSGD*((1.0+ESQ*1.5  )*COSF+E[1]*(1.25  -SINF*SINF*0.5  ));
00641 
00642   PSID=CCSGD*E[1]*SINF/sqrt(PARAM);
00643 
00644   D1PDRO=(DC1+PERTR);
00645 
00646   DRD=D1PDRO*(PSID+DPSI*PERTRD);
00647 
00648   DRLD=D1PDRO*DPSI*(DCSLD+PHID+PERTLD);
00649 
00650   DTL=fmod(DML+PHI+PERTL, DC2PI);
00651 
00652   DSINLS=sin(DTL);
00653 
00654   DCOSLS=cos(DTL);
00655 
00656   DXHD = DRD*DCOSLS-DRLD*DSINLS;
00657 
00658   DYHD = DRD*DSINLS+DRLD*DCOSLS;
00659 
00660   PERTL =0.0;
00661 
00662   PERTLD=0.0;
00663 
00664   PERTP =0.0;
00665 
00666   PERTPD=0.0;
00667 
00668   for (K = 1; K <= 3; K++) {
00669     A=fmod(DCARGM(1,K)+DT*DCARGM(2,K), DC2PI);
00670 
00671     SINA  =sin(A);
00672 
00673     COSA  =cos(A);
00674 
00675     PERTL =PERTL +CCAMPM(1,K)*SINA;
00676 
00677     PERTLD=PERTLD+CCAMPM(2,K)*COSA;
00678 
00679     PERTP =PERTP +CCAMPM(3,K)*COSA;
00680 
00681     PERTPD=PERTPD-CCAMPM(4,K)*SINA;
00682   }
00683     
00684   TL=FORBEL(2)+PERTL;
00685 
00686   SINLM=sin(TL);
00687 
00688   COSLM=cos(TL);
00689 
00690   SIGMA=CCKM/(1.0+PERTP);
00691 
00692   A=SIGMA*(CCMLD+PERTLD);
00693 
00694   B=SIGMA*PERTPD;
00695 
00696   DXHD=DXHD+A*SINLM+B*COSLM;
00697 
00698   DYHD=DYHD-A*COSLM+B*SINLM;
00699 
00700   DZHD=    -SIGMA*CCFDI* cos(FORBEL(3));
00701 
00702   DXBD=DXHD*DC1MME;
00703 
00704   DYBD=DYHD*DC1MME;
00705 
00706   DZBD=DZHD*DC1MME;
00707 
00708   for (K = 1; K <= 4; K++) {
00709 
00710     PLON=FORBEL(K+3);
00711 
00712     POMG=SORBEL(K+1);
00713 
00714     PECC=SORBEL(K+9);
00715 
00716     TL=fmod(PLON+2.0*PECC* sin(PLON-POMG), CC2PI);
00717 
00718     SINLP(K)= sin(TL);
00719 
00720     COSLP(K)= cos(TL);
00721 
00722     DXBD=DXBD+CCPAMV(K)*(SINLP(K)+PECC*sin(POMG));
00723 
00724     DYBD=DYBD-CCPAMV(K)*(COSLP(K)+PECC*cos(POMG));
00725 
00726     DZBD=DZBD-CCPAMV(K)*SORBEL(K+13)*cos(PLON-SORBEL(K+5));
00727 
00728   }
00729     
00730   DCOSEP=cos(DEPS);
00731   DSINEP=sin(DEPS);
00732   DYAHD=DCOSEP*DYHD-DSINEP*DZHD;
00733   DZAHD=DSINEP*DYHD+DCOSEP*DZHD;
00734   DYABD=DCOSEP*DYBD-DSINEP*DZBD;
00735   DZABD=DSINEP*DYBD+DCOSEP*DZBD;
00736 
00737   DVELH[1]=DXHD;
00738   DVELH[2]=DYAHD;
00739   DVELH[3]=DZAHD;
00740 
00741   DVELB[1]=DXBD;
00742   DVELB[2]=DYABD;
00743   DVELB[3]=DZABD;
00744 
00745   for (N = 1; N <= 3; N++) {
00746     DVELH[N]=DVELH[N]*1.4959787E8;
00747     DVELB[N]=DVELB[N]*1.4959787E8;
00748   }
00749   return;
00750 }
00751 
00752 
00753 
00754 
00755 /*--------------------------------------------------------------------------*/
00777 /*--------------------------------------------------------------------------*/
00778 static void
00779 compxy(double inputr[19], char inputc[4],
00780        double outputr[4],
00781        double utr, double mod_juldat)
00782 {
00783   double STR;
00784   double t0, dl, theta0, pe, st0hg, stg;
00785   double jd, jd0h;
00786   double dvelb[4], dvelh[4];
00787   double alp, del, beov, berv, EDV;
00788   double HAR, phi, heov, herv;
00789   double *rbuf;
00790   char inpsgn[4];
00791   double *olong, *olat, *alpha, *delta;
00792   char signs[] = "+++";
00793   rbuf = inputr;
00794   inpsgn[1] = inputc[1];
00795   inpsgn[2] = inputc[2];
00796   inpsgn[3] = inputc[3];
00797   olong = rbuf + 7 - 1;
00798   olat  = rbuf + 10 - 1;
00799   alpha = rbuf + 13 - 1;
00800   delta = rbuf + 16 - 1;
00801   // ... convert UT to real hours, calculate Julian date
00802   /* We know this one already but convert seconds -> hours */
00803   utr /= 3600;
00804 
00805 
00806   jd = mod_juldat + 2400000.5;
00807   
00808   // ... likewise convert longitude and latitude of observatory to real hours
00809   // ... and degrees, respectively; take care of signs
00810   // ... NOTE: east longitude is assumed for input !!
00811 
00812   if (olong[1] < 0 || olong[2] < 0 ||
00813       olong[3] < 0 || inpsgn[1] == '-') {
00814     signs[1] = '-';
00815     olong[1] = fabs(olong[1]);
00816     olong[2] = fabs(olong[2]);
00817     olong[3] = fabs(olong[3]);
00818   }
00819   dl = olong[1]+olong[2]/60.  +olong[3]/3600.;
00820   if (signs[1]   == '-') dl = -dl;
00821   dl = -dl*24.  /360.;
00822 
00823   if (olat[1] < 0 || olat[2] < 0 ||
00824       olat[3] < 0 || inpsgn[2] == '-') {
00825     signs[2] = '-';
00826  
00827     olat[1] = fabs(olat[1]);
00828     olat[2] = fabs(olat[2]);
00829     olat[3] = fabs(olat[3]);
00830 
00831   }
00832 
00833   phi = olat[1]+olat[2]/60.  +olat[3]/3600.;
00834 
00835   if (signs[2]   == '-') phi = -phi;
00836 
00837   phi = phi*M_PI/180. ;
00838 
00839   // ... convert right ascension and declination to real radians
00840 
00841   alp = (alpha[1]*3600. +alpha[2]*60. +alpha[3])*M_PI/(12.  *3600.  );
00842 
00843   if (delta[1] < 0 || delta[2] < 0 ||
00844       delta[3] < 0 || inpsgn[3] == '-') {
00845 
00846     signs[3] = '-';
00847 
00848     delta[1] = fabs(delta[1]);
00849     delta[2] = fabs(delta[2]);
00850     delta[3] = fabs(delta[3]);
00851 
00852   }
00853 
00854   del = (delta[1]*3600.0  + delta[2]*60.   + delta[3])
00855     * M_PI/(3600. *180. );
00856 
00857 
00858 
00859   if (signs[3]   == '-') del = - del;
00860 
00861   // ... calculate earth's orbital velocity in rectangular coordinates X,Y,Z
00862   // ... for both heliocentric and barycentric frames (DVELH, DVELB)
00863   // ... Note that setting the second argument of BARVEL to zero as done below
00864   // ... means that the input coordinates will not be corrected for precession.
00865 
00866 
00867   barvel(jd, 0.0, dvelh, dvelb);
00868 
00869   // ... with the rectangular velocity components known, the respective projections
00870   // ... HEOV and BEOV on a given line of sight (ALP,DEL) can be determined:
00871 
00872   // ... REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B17
00873 
00874   beov =
00875     dvelb[1]*cos(alp)*cos(del)+
00876     dvelb[2]*sin(alp)*cos(del)+
00877     dvelb[3]*sin(del);
00878       
00879   heov =
00880     dvelh[1]*cos(alp)*cos(del)+
00881     dvelh[2]*sin(alp)*cos(del)+
00882     dvelh[3]*sin(del);
00883       
00884 
00885   // ... For determination also of the contribution due to the diurnal rotation of
00886   // ... the earth (EDV), the hour angle (HAR) is needed at which the observation
00887   // ... was made which requires conversion of UT to sidereal time (ST).
00888 
00889   // ... Therefore, first compute ST at 0 hours UT (ST0HG)
00890 
00891   // ... REFERENCE : MEEUS J.,1980,ASTRONOMICAL FORMULAE FOR CALCULATORS
00892 
00893 
00894   jd0h = jd - (utr/24.0);
00895       
00896   t0 = (jd0h-2415020.  )/36525. ;
00897       
00898 
00899   theta0 = 0.276919398  +100.0021359  *t0+0.000001075  *t0*t0 ;
00900 
00901   pe = (int) theta0;
00902 
00903   theta0 = theta0 - pe;
00904 
00905   st0hg = theta0*24. ;
00906 
00907   // ... now do the conversion UT -> ST (MEAN SIDEREAL TIME)
00908 
00909   // ... REFERENCE : THE ASTRONOMICAL ALMANAC 1983, P B7
00910   // ... IN 1983: 1 MEAN SOLAR DAY = 1.00273790931 MEAN SIDEREAL DAYS
00911   // ... ST WITHOUT EQUATION OF EQUINOXES CORRECTION => ACCURACY +/- 1 SEC
00912   //
00913   stg = st0hg+utr*1.00273790931 ;
00914       
00915   if (stg < dl) stg = stg +24. ;
00916 
00917   STR = stg-dl;
00918 
00919 
00920   if (STR >= 24. ) STR = STR-24. ;
00921 
00922   STR = STR*M_PI/12. ;
00923 
00924   HAR = STR-alp;
00925       
00926 
00927   EDV = -0.4654  * sin(HAR)* cos(del)* cos(phi);
00928 
00929   // ... the total correction (in km/s) is the sum of orbital and diurnal components
00930 
00931 
00932   herv=heov+EDV;
00933   berv=beov+EDV;
00934 
00935   /* The following is not needed. Do not translate */
00936 
00937 #if 0
00938   // ... Calculation of the barycentric and heliocentric correction times
00939   // ... (BCT and HCT) requires knowledge of the earth's position in its
00940   // ... orbit. Subroutine BARCOR returns the rectangular barycentric (DCORB)
00941   // ... and heliocentric (DCORH) coordinates.
00942 
00943   //      CALL BARCOR(DCORH,DCORB)
00944 
00945   // ... from this, the correction times (in days) can be determined:
00946   // ... (REFERENCE: THE ASTRONOMICAL ALMANAC 1982 PAGE:B16)
00947 
00948   //      BCT=+0.0057756D0*(DCORB(1)*DCOS(ALP)*DCOS(DEL)+
00949   //     1                DCORB(2)*DSIN(ALP)*DCOS(DEL)+
00950   //     2                DCORB(3)*          DSIN(DEL))
00951   //      HCT=+0.0057756D0*(DCORH(1)*DCOS(ALP)*DCOS(DEL)+
00952   //     1                DCORH(2)*DSIN(ALP)*DCOS(DEL)+
00953   //     2                DCORH(3)*          DSIN(DEL))
00954 
00955   //... write results to keywords
00956 
00957   //      CALL STKWRD('OUTPUTD',BCT,1,1,KUN,STAT)    ! barycentric correction time
00958   //      CALL STKWRD('OUTPUTD',HCT,2,1,KUN,STAT)    ! heliocentric correction time
00959 #endif
00960 
00961   rbuf[1] = berv;   /* barocentric RV correction */
00962   rbuf[2] = herv;   /* heliocentric RV correction */
00963   rbuf[3] = EDV;    /* diurnal RV correction */
00964 
00965 
00966   outputr[1] = rbuf[1];
00967   outputr[2] = rbuf[2];
00968   outputr[3] = rbuf[3];
00969 
00970   return;
00971 }
00972 
00973 
00974 
00975 /*----------------------------------------------------------------------------*/
00982 /*----------------------------------------------------------------------------*/
00983 cpl_error_code
00984 sinfo_baryvel(const cpl_propertylist *raw_header,
00985          double *bary_corr,
00986          double *helio_corr)
00987 {
00988 
00989     double outputr[4];
00990 
00991     char inputc[] = "X+++";       /* 0th index not used */
00992 
00993     double rneg = 1.0;
00994 
00995     double inputr[19];                  /* Do not use the zeroth element */
00996 
00997 
00998 /*
00999   qc_ra       = m$value({p1},O_POS(1))
01000   qc_dec      = m$value({p1},O_POS(2))
01001   qc_geolat   = m$value({p1},{h_geolat})
01002   qc_geolon   = m$value({p1},{h_geolon})
01003   qc_obs_time = m$value({p1},O_TIME(7))  !using an image as input it take the
01004                                          !date from the descriptor O_TIME(1,2,3)
01005                                          !and the UT from O_TIME(5)
01006 */
01007     double qc_ra;
01008     double qc_dec;
01009     double qc_geolat;
01010     double qc_geolon;
01011 
01012     double utr;
01013     double mod_juldat;
01014 
01015     double ra_hour, ra_min, ra_sec;
01016     double dec_deg, dec_min, dec_sec;
01017     double lat_deg, lat_min, lat_sec;
01018     double lon_deg, lon_min, lon_sec;
01019 
01020     check( qc_ra       = sinfo_pfits_get_ra(raw_header),  /* in degrees */
01021        "Error getting object right ascension");
01022     check( qc_dec      = sinfo_pfits_get_dec(raw_header),
01023        "Error getting object declination");
01024 
01025     check( qc_geolat   = sinfo_pfits_get_geolat(raw_header),
01026        "Error getting telescope latitude");
01027     check( qc_geolon   = sinfo_pfits_get_geolon(raw_header),
01028        "Error getting telescope longitude");
01029 
01030     /* double qc_obs_time = sinfo_pfits_get_exptime(raw_header);   Not used! */
01031 
01032     check( utr         = sinfo_pfits_get_utc(raw_header),
01033        "Error reading UTC");
01034     check( mod_juldat  = sinfo_pfits_get_mjdobs(raw_header),
01035        "Error julian date");
01036 
01037     deg2hms(qc_ra,     &ra_hour, &ra_min, &ra_sec);
01038     deg2dms(qc_dec,    &dec_deg, &dec_min, &dec_sec);
01039     deg2dms(qc_geolat, &lat_deg, &lat_min, &lat_sec);
01040     deg2dms(qc_geolon, &lon_deg, &lon_min, &lon_sec);
01041 
01042 
01043     inputr[7] = lon_deg;
01044     inputr[8] = lon_min;
01045     inputr[9] = lon_sec;
01046 
01047 
01048     rneg = (inputr[7]*3600.)+(inputr[8]*60.)+inputr[9];
01049 
01050     inputc[1] = (lon_deg >= 0) ? '+' : '-';
01051 
01052     if (rneg < 0) inputc[1] = '-';
01053 
01054 
01055     inputr[10] = lat_deg;
01056     inputr[11] = lat_min;
01057     inputr[12] = lat_sec;
01058 
01059 
01060     rneg = (inputr[10]*3600.)+(inputr[11]*60.)+inputr[12];
01061 
01062     inputc[2] = (lat_deg >= 0) ? '+' : '-';
01063 
01064     if (rneg < 0) inputc[2] = '-';
01065 
01066 
01067     inputr[13] = ra_hour;
01068     inputr[14] = ra_min;
01069     inputr[15] = ra_sec;
01070 
01071 
01072     inputr[16] = dec_deg;
01073     inputr[17] = dec_min;
01074     inputr[18] = dec_sec;
01075 
01076 
01077     inputc[3] = (dec_deg >= 0) ? '+' : '-';
01078 
01079     rneg = (inputr[16]*3600.)+(inputr[17]*60.)+inputr[18];
01080 
01081     if (rneg < 0) inputc[3] = '-';
01082     
01083 
01084 //C  INPUTR/R/1/3    date: year,month,day
01085 //C  INPUTR/R/4/3    universal time: hour,min,sec
01086 //C  INPUTR/R/7/3    EAST longitude of observatory: degree,min,sec  !! NOTE
01087 //C  INPUTR/R/10/3   latitude of observatory: degree,min,sec
01088 //C  INPUTR/R/13/3   right ascension: hour,min,sec
01089 //C  INPUTR/R/16/3   declination: degree,min,sec
01090 
01091     /* compute the corrections */
01092     compxy(inputr, inputc, outputr, utr, mod_juldat);
01093 
01094    sinfo_msg_debug("        Total barycentric RV correction:  %f km/s", outputr[1]);
01095    sinfo_msg_debug("        Total heliocentric RV correction: %f km/s", outputr[2]);
01096    sinfo_msg_debug("          (incl. diurnal RV correction of %f km/s)", outputr[3]);
01097 
01098 
01099    *bary_corr = outputr[1];
01100    *helio_corr = outputr[2];
01101 
01102   cleanup:
01103     if (cpl_error_get_code() != CPL_ERROR_NONE) {
01104        sinfo_check_rec_status(0);
01105     }
01106     return cpl_error_get_code();
01107 }

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1