IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2048


Ignore:
Timestamp:
Oct 11, 2004, 3:34:09 PM (22 years ago)
Author:
desonia
Message:

adjusted the psTime functions to conform to SDRS and made psGrommitAlloc
set all the inputs to slaAoppa function.

Location:
trunk/psLib
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psCoord.h

    r1496 r2048  
    1111*  @author George Gusciora, MHPCC
    1212*
    13 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-08-12 01:23:20 $
     13*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-10-12 01:34:09 $
    1515*
    1616*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5353 *
    5454 */
    55 typedef struct
     55typedef struct psSphere
    5656{
    5757    double r;                   ///< RA
  • trunk/psLib/src/astro/psTime.c

    r2032 r2048  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-09 00:17:14 $
     13 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-10-12 01:34:09 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psAbort.h"
    2828#include "psImage.h"
     29#include "psCoord.h"
    2930
    3031#include "psAstronomyErrors.h"
     32
     33#ifndef SER7_FILE
     34#define SER7_FILE "../../data/ser7.dat"
     35#endif
     36
     37#ifndef TAIUTC_FILE
     38#define TAIUTC_FILE "../../data/tai-utc.dat"
     39#endif
    3140
    3241/** Sidereal angular conversion from seconds to radians for GMST in seconds (i.e. pi/(180*240)) */
     
    6170
    6271                /** Preprocessor macro to check for null psTime struct */
    63                 #define CHECK_NULL_TIME(TIME,RETURN)                                                                         \
    64                 if(TIME == NULL) {                                                                                           \
    65                     psError(__func__,"NULL value not allowed");                                                              \
    66                     return RETURN;                                                                                           \
     72                #define CHECK_NULL_TIME(TIME,RETURN) \
     73                if(TIME == NULL) { \
     74                    psError(__func__,"NULL value not allowed"); \
     75                    return RETURN; \
    6776                }
    6877
    6978                /** Preprocessor macro to allocate psTime struct */
    70                 #define ALLOC_TIME(TIME)                                                                                     \
    71                 TIME = (psTime*)psAlloc(sizeof(psTime));                                                                     \
    72 if (TIME == NULL) {                                                                                          \
    73     psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);                                   \
    74 }                                                                                                            \
    75 TIME->sec = 0;                                                                                               \
    76 TIME->usec = 0;                                                                                              \
     79                #define ALLOC_TIME(TIME) \
     80                TIME = (psTime*)psAlloc(sizeof(psTime)); \
     81if (TIME == NULL) { \
     82    psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); \
     83} \
     84TIME->sec = 0; \
     85TIME->usec = 0; \
    7786TIME->type = PS_TIME_TAI;
    7887
    79 
    80 psImage* readTaiUtcFile(char *fileName)
     88/** Read TAI/UTC data file.
     89 *
     90 *  Reads TAI/UTC data file.
     91 *
     92 *  @return  psImage*: Two-dimensional array with table data.
     93 */
     94static psImage* readTaiUtcFile(
     95    const char *fileName                      ///< Name of file to read.
     96);
     97
     98
     99/** Read SER7 data file.
     100 *
     101 *  Reads SER7 data file.
     102 *
     103 *  @return  psImage*: Two-dimensional array with table data.
     104 */
     105static psImage* readSer7File(
     106    const char *fileName                      ///< Name of file to read.
     107);
     108
     109
     110/** Read finals data file.
     111 *
     112 *  Reads finals data file.
     113 *
     114 *  @return  psImage*: Two-dimensional array with table data.
     115 */
     116/* not yet used
     117static psImage* readFinalsFile(
     118    char *fileName                      ///< Name of file to read.
     119);
     120*/
     121
     122/** Read EOPC data file.
     123 *
     124 *  Reads EOPC data file.
     125 *
     126 *  @return  psImage*: Two-dimensional array with table data.
     127 */
     128/* not yet used
     129static psImage* readEopcFile(
     130    char *fileName                      ///< Name of file to read.
     131);
     132*/
     133
     134/** Lookup and interpolate TAI-UTC data
     135 *
     136 *  Interpolates TAI-UTC data, given time in MJD format.
     137 *
     138 *  @return  double: Interpolated value.
     139 */
     140static double lookupTaiUtcTable(
     141    const psTime *time                        ///< time to lookup.
     142);
     143
     144/** Lookup and interpolate polar or UT1-UTC data
     145 *
     146 *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
     147 *
     148 *  @return  double: Interpolated value.
     149 */
     150static double lookupSer7Table(
     151    const psTime *time,                        ///< time to lookup.
     152    int col                              ///< Column to lookup.
     153);
     154
     155static psImage* readTaiUtcFile(const char *fileName)
    81156{
    82157    char line[LINESIZE];
     
    113188    *(unsigned int *)&table->numRows = j;
    114189
     190    p_psMemSetPersistent(table,true);
     191    p_psMemSetPersistent(table->data.V,true);
     192    p_psMemSetPersistent(table->rawDataBuffer,true);
     193
    115194    return table;
    116195}
    117196
    118 psImage* readSer7File(char *fileName)
     197static psImage* readSer7File(const char *fileName)
    119198{
    120199    bool beginRecord = false;
     
    160239    *(unsigned int *)&table->numRows = j;
    161240
     241    p_psMemSetPersistent(table,true);
     242    p_psMemSetPersistent(table->data.V,true);
     243    p_psMemSetPersistent(table->rawDataBuffer,true);
     244
    162245    return table;
    163246}
    164247
    165 psImage* readEopcFile(char *fileName)
     248/* Not yet used...
     249static psImage* readEopcFile(char *fileName)
    166250{
    167251    char line[LINESIZE];
     
    171255    psImage *table = NULL;
    172256    FILE *fd = NULL;
    173 
    174 
     257 
     258 
    175259    fd=fopen(fileName, "r");
    176260    if(fd==NULL) {
     
    178262        return NULL ;
    179263    }
    180 
     264 
    181265    // Table shouldn't be larger than 2500 rows. All columns are read.
    182266    table  = psImageAlloc(11, maxLines, PS_TYPE_F64);
     
    186270        }
    187271    }
    188 
     272 
    189273    while(fgets(line, LINESIZE, fd) != NULL) {
    190274        if(j>=maxLines) {
     
    197281               ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);
    198282    }
    199 
     283 
    200284    *(unsigned int *)&table->numRows = j;
    201 
     285 
    202286    return table;
    203287}
    204 
    205 psImage* readFinalsFile(char *fileName)
     288 
     289static psImage* readFinalsFile(char *fileName)
    206290{
    207291    char line[LINESIZE];
     
    210294    psImage *table = NULL;
    211295    FILE *fd = NULL;
    212 
    213 
     296 
     297 
    214298    fd=fopen(fileName, "r");
    215299    if(fd==NULL) {
     
    217301        return NULL ;
    218302    }
    219 
     303 
    220304    // Table shouldn't be larger than 15000 rows. Select columns are read.
    221305    table  = psImageAlloc(6, maxLines, PS_TYPE_F64);
     
    226310            psFree(table);
    227311        }
    228 
     312 
    229313        psF64 *ptr = table->data.F64[j++];
    230314        ptr = table->data.F64[j++];
    231 
     315 
    232316        // Sometimes there are blank entries in this table, so check for a space to determine if there is no entry
    233317        if(*(line+7) == ' ') {                   // MJD
     
    236320            *ptr = atof(line+7);
    237321        }
    238 
     322 
    239323        if(*(line+18) == ' ') {                  // Polar motion X
    240324            *(ptr+1) = 0.0;
     
    242326            *(ptr+1) = atof(line+18);
    243327        }
    244 
     328 
    245329        if(*(line+27) == ' ') {                  // Polar motion X error
    246330            *(ptr+2) = 0.0;
     
    248332            *(ptr+2) = atof(line+27);
    249333        }
    250 
     334 
    251335        if(*(line+37) == ' ') {                  // Polar motion Y
    252336            *(ptr+3) = 0.0;
     
    254338            *(ptr+3) = atof(line+37);
    255339        }
    256 
     340 
    257341        if(*(line+46) == ' ') {                  // Polar motion Y error
    258342            *(ptr+4) = 0.0;
     
    260344            *(ptr+4) = atof(line+46);
    261345        }
    262 
     346 
    263347        if(*(line+58) == ' ') {                  // UT1-UTC
    264348            *(ptr+5) = 0.0;
     
    267351        }
    268352    }
    269 
     353 
    270354    *(unsigned int *)&table->numRows = j;
    271 
     355 
    272356    return table;
    273357}
    274 
    275 
    276 double lookupTaiUtcTable(psImage *table, psTime *time)
     358*/
     359
     360static double lookupTaiUtcTable(const psTime *time)
    277361{
    278362    int hiIdx = 0;
     
    286370    double const2 = 0.0;
    287371    double const3 = 0.0;
    288 
     372    static psImage* table = NULL;
     373
     374    if (table == NULL) {
     375        table = readTaiUtcFile(TAIUTC_FILE);
     376        if (table == NULL) {
     377            psAbort(__func__,"Failed to read tai-utc.dat file");
     378        }
     379    }
    289380
    290381    // Number of rows is the number of rows of data read from the data file
     
    337428}
    338429
    339 double lookupSer7Table(psImage *table, psTime *time, int col)
     430static double lookupSer7Table(const psTime *time, int col)
    340431{
    341432    int hiIdx = 0;
     
    345436    double denom = 0.0;
    346437    double mjdUtc = 0.0;
    347 
     438    static psImage* table = NULL;
     439
     440    if (table == NULL) {
     441        table = readSer7File(SER7_FILE);
     442        if (table == NULL) {
     443            psAbort(__func__,"Failed to read the ser7.dat file.");
     444        }
     445    }
    348446
    349447    // Number of rows is the number of rows of data read from the data file
     
    404502    // Add most leapseconds to UTC time to get TAI time if necessary
    405503    if(type == PS_TIME_TAI) {
    406         time->sec += psGetTAIDelta(time);
     504        time->sec += psTimeGetTAIDelta(time);
    407505    }
    408506
     
    420518    }
    421519
    422     delta = psGetTAIDelta(time);
     520    delta = psTimeGetTAIDelta(time);
    423521
    424522    if(type == PS_TIME_UTC) {
     
    461559        taiTime = psMemIncrRefCounter(time);
    462560        ALLOC_TIME(utcTime);
    463         utcTime->sec = taiTime->sec - psGetTAIDelta(time);
     561        utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
    464562        utcTime->usec = taiTime->usec;
    465563        utcTime->type = PS_TIME_UTC;
     
    467565        utcTime = psMemIncrRefCounter(time);
    468566        ALLOC_TIME(taiTime);
    469         taiTime->sec = utcTime->sec + psGetTAIDelta(time);
     567        taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
    470568        taiTime->usec = utcTime->usec;
    471569        taiTime->type = PS_TIME_TAI;
     
    475573    ALLOC_TIME(ut1UtcDelta);
    476574    ut1UtcDelta->type = PS_TIME_UTC;
    477     ut1UtcDelta->usec = psGetUT1Delta(utcTime)*1e6;
     575    ut1UtcDelta->usec = psTimeGetUT1Delta(utcTime)*1e6;
    478576    ut1Time = psTimeAdd(utcTime, ut1UtcDelta);
    479577
     
    516614}
    517615
    518 double psGetUT1Delta(psTime *time)
    519 {
    520     static psImage* iersTable = NULL;
    521     double ut1UtcDeltaUsec = 0.0;
    522 
    523 
    524     if (iersTable == NULL) {
    525         iersTable = readSer7File("../../data/ser7.dat");
    526         p_psMemSetPersistent(iersTable,true);
    527         p_psMemSetPersistent(iersTable->data.V,true);
    528         p_psMemSetPersistent(iersTable->rawDataBuffer,true);
    529     }
    530 
    531     ut1UtcDeltaUsec = lookupSer7Table(iersTable, time, 6)*1.0e6;
    532 
    533     return ut1UtcDeltaUsec;
    534 }
    535 
    536 double psGetTAIDelta(psTime *time)
    537 {
    538     double delta = 0.0;
    539     static psImage* taiUtcTable = NULL;
    540 
    541 
    542     if (taiUtcTable == NULL) {
    543         taiUtcTable = readTaiUtcFile("../../data/tai-utc.dat");
    544         p_psMemSetPersistent(taiUtcTable,true);
    545         p_psMemSetPersistent(taiUtcTable->data.V,true);
    546         p_psMemSetPersistent(taiUtcTable->rawDataBuffer,true);
    547     }
    548     delta = lookupTaiUtcTable(taiUtcTable, time);
    549 
    550     return delta;
    551 }
    552 
    553 psF64 psTimeLeapseconds(const psTime *time1, const psTime *time2)
    554 {
    555     psF64 diff = 0.0;
     616double psTimeGetUT1Delta(const psTime *time)
     617{
     618    return lookupSer7Table(time, 6);
     619}
     620
     621struct psSphere* psTimeGetPoleCoords(const psTime* time)
     622{
     623
     624    double x = lookupSer7Table((psTime*)time, 4);
     625    double y = lookupSer7Table((psTime*)time, 5);
     626
     627    struct psSphere* output = psAlloc(sizeof(psSphere));
     628    output->r = x * M_PI / 648000.0; // x in arcsec converted to radians, i.e., x/60/60*M_PI/180
     629    output->d = y * M_PI / 648000.0;
     630
     631    return output;
     632}
     633
     634double psTimeGetTAIDelta(const psTime *time)
     635{
     636    return lookupTaiUtcTable(time);
     637}
     638
     639long psTimeLeapseconds(const psTime *time1, const psTime *time2)
     640{
     641    long diff = 0;
    556642
    557643    // NULL error checks
     
    559645    CHECK_NULL_TIME(time2,0);
    560646
    561     diff = fabs(psGetTAIDelta((psTime*)time1)-psGetTAIDelta((psTime*)time2));
     647    diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
    562648
    563649    return diff;
    564650}
    565651
    566 double psTimeToJD(psTime *time)
     652double psTimeToJD(const psTime *time)
    567653{
    568654    double jd = 0.0;
     
    582668}
    583669
    584 double psTimeToMJD(psTime *time)
     670double psTimeToMJD(const psTime *time)
    585671{
    586672    double mjd = 0.0;
     
    600686}
    601687
    602 char* psTimeToISO(psTime *time)
     688char* psTimeToISOTime(const psTime *time)
    603689{
    604690    int ms = 0;
     
    634720}
    635721
    636 struct timeval psTimeToTimeval(psTime *time)
     722struct timeval psTimeToTimeval(const psTime *time)
    637723{
    638724    struct timeval timevalTime;
     
    648734}
    649735
    650 struct tm* psTimeToTM(psTime *time)
     736struct tm* psTimeToTM(const psTime *time)
    651737{
    652738    long cent = 0;
     
    711797}
    712798
    713 psTime* psJDToTime(double time)
     799psTime* psTimeFromJD(double time)
    714800{
    715801    double days = 0.0;
     
    734820}
    735821
    736 psTime* psMJDToTime(double time)
     822psTime* psTimeFromMJD(double time)
    737823{
    738824    double days = 0.0;
     
    757843}
    758844
    759 psTime* psISOToTime(char *time)
     845psTime* psTimeFromISOTime(const char *time)
    760846{
    761847    char tempString[MAX_TIME_STRING_LENGTH];
     
    826912
    827913    // Convert tm time to psTime
    828     outTime = psTMToTime(&tmTime);
     914    outTime = psTimeFromTM(&tmTime);
    829915    outTime->usec = millisecond * 1000;
    830916
     
    832918}
    833919
    834 psTime* psTimevalToTime(struct timeval *time)
     920psTime* psTimeFromTimeval(const struct timeval *time)
    835921{
    836922    psTime *outTime = NULL;
     
    850936}
    851937
    852 psTime* psTMToTime(struct tm* time)
     938psTime* psTimeFromTM(const struct tm* time)
    853939{
    854940    long year;
     
    905991}
    906992
    907 psTime* psTimeAdd(psTime *tai1, psTime *tai2)
     993psTime* psTimeAdd(const psTime *tai1, const psTime *tai2)
    908994{
    909995    psTime *outTime = NULL;
     
    9291015}
    9301016
    931 psTime* psTimeSub(psTime *tai1, psTime *tai2)
     1017psTime* psTimeSubtract(const psTime *tai1, const psTime *tai2)
    9321018{
    9331019    psTime *outTime = NULL;
     
    9531039}
    9541040
    955 psTime* psTimeDelta(psTime *tai1, psTime *tai2)
     1041psTime* psTimeDelta(const psTime *tai1, const psTime *tai2)
    9561042{
    9571043    psTime *outTime = NULL;
  • trunk/psLib/src/astro/psTime.h

    r1788 r2048  
    5454 *  @author Ross Harman, MHPCC
    5555 *
    56  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    57  *  @date $Date: 2004-09-11 00:55:13 $
     56 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     57 *  @date $Date: 2004-10-12 01:34:09 $
    5858 *
    5959 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6969#include "psType.h"
    7070#include "psImage.h"
     71
     72struct psSphere;
    7173
    7274/// @addtogroup Time
     
    138140 *  @return  double: Time difference.
    139141 */
    140 double psGetUT1Delta(
    141     psTime *time                        ///< psTime to be looked up.
     142double psTimeGetUT1Delta(
     143    const psTime *time                  ///< psTime to be looked up.
    142144);
    143145
     
    148150 *  @return  double: Time difference.
    149151 */
    150 double psGetTAIDelta(
    151     psTime *time                        ///< psTime to be looked up.
     152double psTimeGetTAIDelta(
     153    const psTime *time                  ///< psTime to be looked up.
    152154);
    153155
     
    158160 *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
    159161 */
    160 /*psSphere* psGetPoleCoords(
    161     psTime *time                        ///< psTime determine polar orientation.
    162 );*/
     162struct psSphere* psTimeGetPoleCoords(
     163                const psTime *time                  ///< psTime determine polar orientation.
     164            );
    163165
    164166/** Calculate the number of leapseconds between two times.
     
    166168 *  Calculates the number of leapseconds between two times.
    167169 *
    168  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
    169  */
    170 psF64 psTimeLeapseconds(
    171     const psTime *time1,                ///< First input time.
    172     const psTime *time2                 ///< Second input time.
     170 *  @return  long: leapseconds added between given times
     171 */
     172long psTimeLeapseconds(
     173    const psTime* time1,                ///< First input time.
     174    const psTime* time2                 ///< Second input time.
    173175);
    174176
     
    180182 */
    181183double psTimeToJD(
    182     psTime *time                        ///< Input time to be converted.
     184    const psTime* time                  ///< Input time to be converted.
    183185);
    184186/** Convert psTime to modified Julian date time.
     
    189191 */
    190192double psTimeToMJD(
    191     psTime *time                        ///< Input time to be converted.
     193    const psTime* time                  ///< Input time to be converted.
    192194);
    193195
     
    199201 *  @return  char*: Pointer null terminated array of chars in ISO time.
    200202 */
    201 char* psTimeToISO(
    202     psTime *time                        ///< Input time to be converted.
     203char* psTimeToISOTime(
     204    const psTime* time                  ///< Input time to be converted.
    203205);
    204206
     
    210212 */
    211213struct timeval psTimeToTimeval(
    212                 psTime *time                        ///< Input time to be converted.
     214                const psTime* time                  ///< Input time to be converted.
    213215            );
    214216
     
    221223 */
    222224struct tm* psTimeToTM(
    223                 psTime *time                        ///< Input time to be converted.
     225                const psTime *time                  ///< Input time to be converted.
    224226            );
    225227
     
    230232 *  @return  psTime: time.
    231233 */
    232 psTime* psJDToTime(
     234psTime* psTimeFromJD(
    233235    double time                         ///< Input time to be converted.
    234236);
     
    240242 *  @return  psTime: time.
    241243 */
    242 psTime* psMJDToTime(
     244psTime* psTimeFromMJD(
    243245    double time                         ///< Input time to be converted.
    244246);
     
    250252 *  @return  psTime*: time
    251253 */
    252 psTime* psISOToTime(
    253     char *time                          ///< Input time to be converted.
     254psTime* psTimeFromISOTime(
     255    const char* time                    ///< Input time to be converted.
    254256);
    255257
     
    260262 *  @return  psTime*: time.
    261263 */
    262 psTime* psTimevalToTime(
    263     struct timeval *time                ///< Input time to be converted.
     264psTime* psTimeFromTimeval(
     265    const struct timeval *time          ///< Input time to be converted.
    264266);
    265267
     
    271273 *  @return  psTime*: time.
    272274 */
    273 psTime* psTMToTime(
    274     struct tm *time                     ///< Input time to be converted.
     275psTime* psTimeFromTM(
     276    const struct tm *time               ///< Input time to be converted.
    275277);
    276278
     
    282284 */
    283285psTime* psTimeAdd(
    284     psTime *tai1,                       ///< First TAI time.
    285     psTime *tai2                        ///< Second TAI time.
     286    const psTime *tai1,                 ///< First TAI time.
     287    const psTime *tai2                  ///< Second TAI time.
    286288);
    287289
     
    292294 *  @return  psTime*: time.
    293295 */
    294 psTime* psTimeSub(
    295     psTime *tai1,                       ///< First TAI time.
    296     psTime *tai2                        ///< Second TAI time.
     296psTime* psTimeSubtract(
     297    const psTime *tai1,                 ///< First TAI time.
     298    const psTime *tai2                  ///< Second TAI time.
    297299);
    298300
     
    305307 */
    306308psTime* psTimeDelta(
    307     psTime *tai1,                       ///< First TAI time.
    308     psTime *tai2                        ///< Second TAI time.
    309 );
    310 
    311 
    312 /** Read TAI/UTC data file.
    313  *
    314  *  Reads TAI/UTC data file.
    315  *
    316  *  @return  psImage*: Two-dimensional array with table data.
    317  */
    318 psImage* readTaiUtcFile(
    319     char *fileName                      ///< Name of file to read.
    320 );
    321 
    322 
    323 /** Read SER7 data file.
    324  *
    325  *  Reads SER7 data file.
    326  *
    327  *  @return  psImage*: Two-dimensional array with table data.
    328  */
    329 psImage* readSer7File(
    330     char *fileName                      ///< Name of file to read.
    331 );
    332 
    333 /** Read finals data file.
    334  *
    335  *  Reads finals data file.
    336  *
    337  *  @return  psImage*: Two-dimensional array with table data.
    338  */
    339 psImage* readFinalsFile(
    340     char *fileName                      ///< Name of file to read.
    341 );
    342 
    343 /** Read EOPC data file.
    344  *
    345  *  Reads EOPC data file.
    346  *
    347  *  @return  psImage*: Two-dimensional array with table data.
    348  */
    349 psImage* readEopcFile(
    350     char *fileName                      ///< Name of file to read.
    351 );
    352 
    353 /** Lookup and interpolate TAI-UTC data
    354  *
    355  *  Interpolates TAI-UTC data, given time in MJD format.
    356  *
    357  *  @return  double: Interpolated value.
    358  */
    359 double lookupTaiUtcTable(
    360     psImage *table,                     ///< Table with data.
    361     psTime *time                        ///< time to lookup.
    362 );
    363 
    364 /** Lookup and interpolate polar or UT1-UTC data
    365  *
    366  *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
    367  *
    368  *  @return  double: Interpolated value.
    369  */
    370 double lookupSer7Table(
    371     psImage *table,                      ///< Table with data.
    372     psTime *time,                        ///< time to lookup.
    373     int col                              ///< Column to lookup.
    374 );
     309    const psTime *tai1,                 ///< First TAI time.
     310    const psTime *tai2                  ///< Second TAI time.
     311);
     312
    375313/// @}
    376314
  • trunk/psLib/src/astronomy/psAstrometry.c

    r2001 r2048  
    88 *  @author George Gusciora, MHPCC
    99 *
    10  *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-10-07 19:16:46 $
     10 *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-10-12 01:34:09 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    455455psGrommit* psGrommitAlloc(const psExposure* exp)
    456456{
     457    double* AOPRMS = psAlloc(sizeof(double)*14);
     458
    457459    if (exp == NULL) {
    458460        psAbort(__func__, "the 'exp' parameter is NULL\n");
    459461    }
    460462
    461     double date = TBD;  // XXX: "mjd" in psExposure will become a psTime
    462     // from which it will be possible to get UTC.
    463     double dut = 0.0;
    464     double elongm = TBD; // XXX
    465     double phim = TBD;   // XXX
    466     double hm = TBD;     // XXX
    467     double xp = 0.0;
    468     double yp = 0.0;
     463    double date = psTimeToMJD(exp->time);
     464    double dut = psTimeGetUT1Delta(exp->time);
     465    double elongm = exp->observatory->longitude;
     466    double phim = exp->observatory->latitude;
     467    double hm = exp->observatory->height;
     468
     469    psSphere* polarMotion = psTimeGetPoleCoords(exp->time);
     470    double xp = polarMotion->r;
     471    double yp = polarMotion->d;
     472    psFree(polarMotion);
     473
    469474    double tdk = exp->temperature;
    470475    double pmb = exp->pressure;
    471476    double rh = exp->humidity;
    472477    double wl = exp->wavelength;
    473     double tlr = TBD;    // XXX
    474     double *AOPRMS = NULL;
     478    double tlr = exp->observatory->tlr;
    475479
    476480    slaAoppa(date, dut, elongm, phim, hm, xp, yp,
     
    493497    *(double *)&grommit->siderealTime = AOPRMS[13];
    494498
     499    psFree(AOPRMS);
     500
    495501    return (grommit);
    496502}
  • trunk/psLib/src/astronomy/psAstrometry.h

    r2001 r2048  
    88*  @author George Gusciora, MHPCC
    99*
    10 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-10-07 19:16:46 $
     10*  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2004-10-12 01:34:09 $
    1212*
    1313*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    192192{
    193193    const char* name;                  ///< Name of observatory
    194     const double latitude;             ///< Latitude of observatory, east positive
    195     const double longitude;            ///< Longitude of observatory
    196     const double height;               ///< Height of observatory
     194    const double latitude;             ///< Latitude of observatory, east positive (degrees?)
     195    const double longitude;            ///< Longitude of observatory (degrees?)
     196    const double height;               ///< Height of observatory in meters
    197197    const double tlr;                  ///< Tropospheric Lapse Rate
    198198}
     
    214214    const double azimuth;              ///< Azimuth
    215215    const psTime* time;                ///< Time of observation
    216     const float rotAngle;              ///< Rotator position angle
    217     const float temperature;           ///< Air temperature, for estimating refraction
    218     const float pressure;              ///< Air pressure, for calculating refraction
     216    const float rotAngle;              ///< Rotator position angle in degrees? XXX: see bug#209
     217    const float temperature;           ///< Air temperature in Kelvin
     218    const float pressure;              ///< Air pressure in mB
    219219    const float humidity;              ///< Relative humidity, for refraction
    220220    const float exposureTime;          ///< Exposure time
    221     const float wavelength;            ///< Wavelength
     221    const float wavelength;            ///< Wavelength in microns
    222222    const psObservatory* observatory;  ///< Observatory data
    223223
  • trunk/psLib/src/astronomy/psCoord.h

    r1496 r2048  
    1111*  @author George Gusciora, MHPCC
    1212*
    13 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-08-12 01:23:20 $
     13*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2004-10-12 01:34:09 $
    1515*
    1616*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5353 *
    5454 */
    55 typedef struct
     55typedef struct psSphere
    5656{
    5757    double r;                   ///< RA
  • trunk/psLib/src/astronomy/psTime.c

    r2032 r2048  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-09 00:17:14 $
     13 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-10-12 01:34:09 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psAbort.h"
    2828#include "psImage.h"
     29#include "psCoord.h"
    2930
    3031#include "psAstronomyErrors.h"
     32
     33#ifndef SER7_FILE
     34#define SER7_FILE "../../data/ser7.dat"
     35#endif
     36
     37#ifndef TAIUTC_FILE
     38#define TAIUTC_FILE "../../data/tai-utc.dat"
     39#endif
    3140
    3241/** Sidereal angular conversion from seconds to radians for GMST in seconds (i.e. pi/(180*240)) */
     
    6170
    6271                /** Preprocessor macro to check for null psTime struct */
    63                 #define CHECK_NULL_TIME(TIME,RETURN)                                                                         \
    64                 if(TIME == NULL) {                                                                                           \
    65                     psError(__func__,"NULL value not allowed");                                                              \
    66                     return RETURN;                                                                                           \
     72                #define CHECK_NULL_TIME(TIME,RETURN) \
     73                if(TIME == NULL) { \
     74                    psError(__func__,"NULL value not allowed"); \
     75                    return RETURN; \
    6776                }
    6877
    6978                /** Preprocessor macro to allocate psTime struct */
    70                 #define ALLOC_TIME(TIME)                                                                                     \
    71                 TIME = (psTime*)psAlloc(sizeof(psTime));                                                                     \
    72 if (TIME == NULL) {                                                                                          \
    73     psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);                                   \
    74 }                                                                                                            \
    75 TIME->sec = 0;                                                                                               \
    76 TIME->usec = 0;                                                                                              \
     79                #define ALLOC_TIME(TIME) \
     80                TIME = (psTime*)psAlloc(sizeof(psTime)); \
     81if (TIME == NULL) { \
     82    psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); \
     83} \
     84TIME->sec = 0; \
     85TIME->usec = 0; \
    7786TIME->type = PS_TIME_TAI;
    7887
    79 
    80 psImage* readTaiUtcFile(char *fileName)
     88/** Read TAI/UTC data file.
     89 *
     90 *  Reads TAI/UTC data file.
     91 *
     92 *  @return  psImage*: Two-dimensional array with table data.
     93 */
     94static psImage* readTaiUtcFile(
     95    const char *fileName                      ///< Name of file to read.
     96);
     97
     98
     99/** Read SER7 data file.
     100 *
     101 *  Reads SER7 data file.
     102 *
     103 *  @return  psImage*: Two-dimensional array with table data.
     104 */
     105static psImage* readSer7File(
     106    const char *fileName                      ///< Name of file to read.
     107);
     108
     109
     110/** Read finals data file.
     111 *
     112 *  Reads finals data file.
     113 *
     114 *  @return  psImage*: Two-dimensional array with table data.
     115 */
     116/* not yet used
     117static psImage* readFinalsFile(
     118    char *fileName                      ///< Name of file to read.
     119);
     120*/
     121
     122/** Read EOPC data file.
     123 *
     124 *  Reads EOPC data file.
     125 *
     126 *  @return  psImage*: Two-dimensional array with table data.
     127 */
     128/* not yet used
     129static psImage* readEopcFile(
     130    char *fileName                      ///< Name of file to read.
     131);
     132*/
     133
     134/** Lookup and interpolate TAI-UTC data
     135 *
     136 *  Interpolates TAI-UTC data, given time in MJD format.
     137 *
     138 *  @return  double: Interpolated value.
     139 */
     140static double lookupTaiUtcTable(
     141    const psTime *time                        ///< time to lookup.
     142);
     143
     144/** Lookup and interpolate polar or UT1-UTC data
     145 *
     146 *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
     147 *
     148 *  @return  double: Interpolated value.
     149 */
     150static double lookupSer7Table(
     151    const psTime *time,                        ///< time to lookup.
     152    int col                              ///< Column to lookup.
     153);
     154
     155static psImage* readTaiUtcFile(const char *fileName)
    81156{
    82157    char line[LINESIZE];
     
    113188    *(unsigned int *)&table->numRows = j;
    114189
     190    p_psMemSetPersistent(table,true);
     191    p_psMemSetPersistent(table->data.V,true);
     192    p_psMemSetPersistent(table->rawDataBuffer,true);
     193
    115194    return table;
    116195}
    117196
    118 psImage* readSer7File(char *fileName)
     197static psImage* readSer7File(const char *fileName)
    119198{
    120199    bool beginRecord = false;
     
    160239    *(unsigned int *)&table->numRows = j;
    161240
     241    p_psMemSetPersistent(table,true);
     242    p_psMemSetPersistent(table->data.V,true);
     243    p_psMemSetPersistent(table->rawDataBuffer,true);
     244
    162245    return table;
    163246}
    164247
    165 psImage* readEopcFile(char *fileName)
     248/* Not yet used...
     249static psImage* readEopcFile(char *fileName)
    166250{
    167251    char line[LINESIZE];
     
    171255    psImage *table = NULL;
    172256    FILE *fd = NULL;
    173 
    174 
     257 
     258 
    175259    fd=fopen(fileName, "r");
    176260    if(fd==NULL) {
     
    178262        return NULL ;
    179263    }
    180 
     264 
    181265    // Table shouldn't be larger than 2500 rows. All columns are read.
    182266    table  = psImageAlloc(11, maxLines, PS_TYPE_F64);
     
    186270        }
    187271    }
    188 
     272 
    189273    while(fgets(line, LINESIZE, fd) != NULL) {
    190274        if(j>=maxLines) {
     
    197281               ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);
    198282    }
    199 
     283 
    200284    *(unsigned int *)&table->numRows = j;
    201 
     285 
    202286    return table;
    203287}
    204 
    205 psImage* readFinalsFile(char *fileName)
     288 
     289static psImage* readFinalsFile(char *fileName)
    206290{
    207291    char line[LINESIZE];
     
    210294    psImage *table = NULL;
    211295    FILE *fd = NULL;
    212 
    213 
     296 
     297 
    214298    fd=fopen(fileName, "r");
    215299    if(fd==NULL) {
     
    217301        return NULL ;
    218302    }
    219 
     303 
    220304    // Table shouldn't be larger than 15000 rows. Select columns are read.
    221305    table  = psImageAlloc(6, maxLines, PS_TYPE_F64);
     
    226310            psFree(table);
    227311        }
    228 
     312 
    229313        psF64 *ptr = table->data.F64[j++];
    230314        ptr = table->data.F64[j++];
    231 
     315 
    232316        // Sometimes there are blank entries in this table, so check for a space to determine if there is no entry
    233317        if(*(line+7) == ' ') {                   // MJD
     
    236320            *ptr = atof(line+7);
    237321        }
    238 
     322 
    239323        if(*(line+18) == ' ') {                  // Polar motion X
    240324            *(ptr+1) = 0.0;
     
    242326            *(ptr+1) = atof(line+18);
    243327        }
    244 
     328 
    245329        if(*(line+27) == ' ') {                  // Polar motion X error
    246330            *(ptr+2) = 0.0;
     
    248332            *(ptr+2) = atof(line+27);
    249333        }
    250 
     334 
    251335        if(*(line+37) == ' ') {                  // Polar motion Y
    252336            *(ptr+3) = 0.0;
     
    254338            *(ptr+3) = atof(line+37);
    255339        }
    256 
     340 
    257341        if(*(line+46) == ' ') {                  // Polar motion Y error
    258342            *(ptr+4) = 0.0;
     
    260344            *(ptr+4) = atof(line+46);
    261345        }
    262 
     346 
    263347        if(*(line+58) == ' ') {                  // UT1-UTC
    264348            *(ptr+5) = 0.0;
     
    267351        }
    268352    }
    269 
     353 
    270354    *(unsigned int *)&table->numRows = j;
    271 
     355 
    272356    return table;
    273357}
    274 
    275 
    276 double lookupTaiUtcTable(psImage *table, psTime *time)
     358*/
     359
     360static double lookupTaiUtcTable(const psTime *time)
    277361{
    278362    int hiIdx = 0;
     
    286370    double const2 = 0.0;
    287371    double const3 = 0.0;
    288 
     372    static psImage* table = NULL;
     373
     374    if (table == NULL) {
     375        table = readTaiUtcFile(TAIUTC_FILE);
     376        if (table == NULL) {
     377            psAbort(__func__,"Failed to read tai-utc.dat file");
     378        }
     379    }
    289380
    290381    // Number of rows is the number of rows of data read from the data file
     
    337428}
    338429
    339 double lookupSer7Table(psImage *table, psTime *time, int col)
     430static double lookupSer7Table(const psTime *time, int col)
    340431{
    341432    int hiIdx = 0;
     
    345436    double denom = 0.0;
    346437    double mjdUtc = 0.0;
    347 
     438    static psImage* table = NULL;
     439
     440    if (table == NULL) {
     441        table = readSer7File(SER7_FILE);
     442        if (table == NULL) {
     443            psAbort(__func__,"Failed to read the ser7.dat file.");
     444        }
     445    }
    348446
    349447    // Number of rows is the number of rows of data read from the data file
     
    404502    // Add most leapseconds to UTC time to get TAI time if necessary
    405503    if(type == PS_TIME_TAI) {
    406         time->sec += psGetTAIDelta(time);
     504        time->sec += psTimeGetTAIDelta(time);
    407505    }
    408506
     
    420518    }
    421519
    422     delta = psGetTAIDelta(time);
     520    delta = psTimeGetTAIDelta(time);
    423521
    424522    if(type == PS_TIME_UTC) {
     
    461559        taiTime = psMemIncrRefCounter(time);
    462560        ALLOC_TIME(utcTime);
    463         utcTime->sec = taiTime->sec - psGetTAIDelta(time);
     561        utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
    464562        utcTime->usec = taiTime->usec;
    465563        utcTime->type = PS_TIME_UTC;
     
    467565        utcTime = psMemIncrRefCounter(time);
    468566        ALLOC_TIME(taiTime);
    469         taiTime->sec = utcTime->sec + psGetTAIDelta(time);
     567        taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
    470568        taiTime->usec = utcTime->usec;
    471569        taiTime->type = PS_TIME_TAI;
     
    475573    ALLOC_TIME(ut1UtcDelta);
    476574    ut1UtcDelta->type = PS_TIME_UTC;
    477     ut1UtcDelta->usec = psGetUT1Delta(utcTime)*1e6;
     575    ut1UtcDelta->usec = psTimeGetUT1Delta(utcTime)*1e6;
    478576    ut1Time = psTimeAdd(utcTime, ut1UtcDelta);
    479577
     
    516614}
    517615
    518 double psGetUT1Delta(psTime *time)
    519 {
    520     static psImage* iersTable = NULL;
    521     double ut1UtcDeltaUsec = 0.0;
    522 
    523 
    524     if (iersTable == NULL) {
    525         iersTable = readSer7File("../../data/ser7.dat");
    526         p_psMemSetPersistent(iersTable,true);
    527         p_psMemSetPersistent(iersTable->data.V,true);
    528         p_psMemSetPersistent(iersTable->rawDataBuffer,true);
    529     }
    530 
    531     ut1UtcDeltaUsec = lookupSer7Table(iersTable, time, 6)*1.0e6;
    532 
    533     return ut1UtcDeltaUsec;
    534 }
    535 
    536 double psGetTAIDelta(psTime *time)
    537 {
    538     double delta = 0.0;
    539     static psImage* taiUtcTable = NULL;
    540 
    541 
    542     if (taiUtcTable == NULL) {
    543         taiUtcTable = readTaiUtcFile("../../data/tai-utc.dat");
    544         p_psMemSetPersistent(taiUtcTable,true);
    545         p_psMemSetPersistent(taiUtcTable->data.V,true);
    546         p_psMemSetPersistent(taiUtcTable->rawDataBuffer,true);
    547     }
    548     delta = lookupTaiUtcTable(taiUtcTable, time);
    549 
    550     return delta;
    551 }
    552 
    553 psF64 psTimeLeapseconds(const psTime *time1, const psTime *time2)
    554 {
    555     psF64 diff = 0.0;
     616double psTimeGetUT1Delta(const psTime *time)
     617{
     618    return lookupSer7Table(time, 6);
     619}
     620
     621struct psSphere* psTimeGetPoleCoords(const psTime* time)
     622{
     623
     624    double x = lookupSer7Table((psTime*)time, 4);
     625    double y = lookupSer7Table((psTime*)time, 5);
     626
     627    struct psSphere* output = psAlloc(sizeof(psSphere));
     628    output->r = x * M_PI / 648000.0; // x in arcsec converted to radians, i.e., x/60/60*M_PI/180
     629    output->d = y * M_PI / 648000.0;
     630
     631    return output;
     632}
     633
     634double psTimeGetTAIDelta(const psTime *time)
     635{
     636    return lookupTaiUtcTable(time);
     637}
     638
     639long psTimeLeapseconds(const psTime *time1, const psTime *time2)
     640{
     641    long diff = 0;
    556642
    557643    // NULL error checks
     
    559645    CHECK_NULL_TIME(time2,0);
    560646
    561     diff = fabs(psGetTAIDelta((psTime*)time1)-psGetTAIDelta((psTime*)time2));
     647    diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
    562648
    563649    return diff;
    564650}
    565651
    566 double psTimeToJD(psTime *time)
     652double psTimeToJD(const psTime *time)
    567653{
    568654    double jd = 0.0;
     
    582668}
    583669
    584 double psTimeToMJD(psTime *time)
     670double psTimeToMJD(const psTime *time)
    585671{
    586672    double mjd = 0.0;
     
    600686}
    601687
    602 char* psTimeToISO(psTime *time)
     688char* psTimeToISOTime(const psTime *time)
    603689{
    604690    int ms = 0;
     
    634720}
    635721
    636 struct timeval psTimeToTimeval(psTime *time)
     722struct timeval psTimeToTimeval(const psTime *time)
    637723{
    638724    struct timeval timevalTime;
     
    648734}
    649735
    650 struct tm* psTimeToTM(psTime *time)
     736struct tm* psTimeToTM(const psTime *time)
    651737{
    652738    long cent = 0;
     
    711797}
    712798
    713 psTime* psJDToTime(double time)
     799psTime* psTimeFromJD(double time)
    714800{
    715801    double days = 0.0;
     
    734820}
    735821
    736 psTime* psMJDToTime(double time)
     822psTime* psTimeFromMJD(double time)
    737823{
    738824    double days = 0.0;
     
    757843}
    758844
    759 psTime* psISOToTime(char *time)
     845psTime* psTimeFromISOTime(const char *time)
    760846{
    761847    char tempString[MAX_TIME_STRING_LENGTH];
     
    826912
    827913    // Convert tm time to psTime
    828     outTime = psTMToTime(&tmTime);
     914    outTime = psTimeFromTM(&tmTime);
    829915    outTime->usec = millisecond * 1000;
    830916
     
    832918}
    833919
    834 psTime* psTimevalToTime(struct timeval *time)
     920psTime* psTimeFromTimeval(const struct timeval *time)
    835921{
    836922    psTime *outTime = NULL;
     
    850936}
    851937
    852 psTime* psTMToTime(struct tm* time)
     938psTime* psTimeFromTM(const struct tm* time)
    853939{
    854940    long year;
     
    905991}
    906992
    907 psTime* psTimeAdd(psTime *tai1, psTime *tai2)
     993psTime* psTimeAdd(const psTime *tai1, const psTime *tai2)
    908994{
    909995    psTime *outTime = NULL;
     
    9291015}
    9301016
    931 psTime* psTimeSub(psTime *tai1, psTime *tai2)
     1017psTime* psTimeSubtract(const psTime *tai1, const psTime *tai2)
    9321018{
    9331019    psTime *outTime = NULL;
     
    9531039}
    9541040
    955 psTime* psTimeDelta(psTime *tai1, psTime *tai2)
     1041psTime* psTimeDelta(const psTime *tai1, const psTime *tai2)
    9561042{
    9571043    psTime *outTime = NULL;
  • trunk/psLib/src/astronomy/psTime.h

    r1788 r2048  
    5454 *  @author Ross Harman, MHPCC
    5555 *
    56  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    57  *  @date $Date: 2004-09-11 00:55:13 $
     56 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     57 *  @date $Date: 2004-10-12 01:34:09 $
    5858 *
    5959 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6969#include "psType.h"
    7070#include "psImage.h"
     71
     72struct psSphere;
    7173
    7274/// @addtogroup Time
     
    138140 *  @return  double: Time difference.
    139141 */
    140 double psGetUT1Delta(
    141     psTime *time                        ///< psTime to be looked up.
     142double psTimeGetUT1Delta(
     143    const psTime *time                  ///< psTime to be looked up.
    142144);
    143145
     
    148150 *  @return  double: Time difference.
    149151 */
    150 double psGetTAIDelta(
    151     psTime *time                        ///< psTime to be looked up.
     152double psTimeGetTAIDelta(
     153    const psTime *time                  ///< psTime to be looked up.
    152154);
    153155
     
    158160 *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
    159161 */
    160 /*psSphere* psGetPoleCoords(
    161     psTime *time                        ///< psTime determine polar orientation.
    162 );*/
     162struct psSphere* psTimeGetPoleCoords(
     163                const psTime *time                  ///< psTime determine polar orientation.
     164            );
    163165
    164166/** Calculate the number of leapseconds between two times.
     
    166168 *  Calculates the number of leapseconds between two times.
    167169 *
    168  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
    169  */
    170 psF64 psTimeLeapseconds(
    171     const psTime *time1,                ///< First input time.
    172     const psTime *time2                 ///< Second input time.
     170 *  @return  long: leapseconds added between given times
     171 */
     172long psTimeLeapseconds(
     173    const psTime* time1,                ///< First input time.
     174    const psTime* time2                 ///< Second input time.
    173175);
    174176
     
    180182 */
    181183double psTimeToJD(
    182     psTime *time                        ///< Input time to be converted.
     184    const psTime* time                  ///< Input time to be converted.
    183185);
    184186/** Convert psTime to modified Julian date time.
     
    189191 */
    190192double psTimeToMJD(
    191     psTime *time                        ///< Input time to be converted.
     193    const psTime* time                  ///< Input time to be converted.
    192194);
    193195
     
    199201 *  @return  char*: Pointer null terminated array of chars in ISO time.
    200202 */
    201 char* psTimeToISO(
    202     psTime *time                        ///< Input time to be converted.
     203char* psTimeToISOTime(
     204    const psTime* time                  ///< Input time to be converted.
    203205);
    204206
     
    210212 */
    211213struct timeval psTimeToTimeval(
    212                 psTime *time                        ///< Input time to be converted.
     214                const psTime* time                  ///< Input time to be converted.
    213215            );
    214216
     
    221223 */
    222224struct tm* psTimeToTM(
    223                 psTime *time                        ///< Input time to be converted.
     225                const psTime *time                  ///< Input time to be converted.
    224226            );
    225227
     
    230232 *  @return  psTime: time.
    231233 */
    232 psTime* psJDToTime(
     234psTime* psTimeFromJD(
    233235    double time                         ///< Input time to be converted.
    234236);
     
    240242 *  @return  psTime: time.
    241243 */
    242 psTime* psMJDToTime(
     244psTime* psTimeFromMJD(
    243245    double time                         ///< Input time to be converted.
    244246);
     
    250252 *  @return  psTime*: time
    251253 */
    252 psTime* psISOToTime(
    253     char *time                          ///< Input time to be converted.
     254psTime* psTimeFromISOTime(
     255    const char* time                    ///< Input time to be converted.
    254256);
    255257
     
    260262 *  @return  psTime*: time.
    261263 */
    262 psTime* psTimevalToTime(
    263     struct timeval *time                ///< Input time to be converted.
     264psTime* psTimeFromTimeval(
     265    const struct timeval *time          ///< Input time to be converted.
    264266);
    265267
     
    271273 *  @return  psTime*: time.
    272274 */
    273 psTime* psTMToTime(
    274     struct tm *time                     ///< Input time to be converted.
     275psTime* psTimeFromTM(
     276    const struct tm *time               ///< Input time to be converted.
    275277);
    276278
     
    282284 */
    283285psTime* psTimeAdd(
    284     psTime *tai1,                       ///< First TAI time.
    285     psTime *tai2                        ///< Second TAI time.
     286    const psTime *tai1,                 ///< First TAI time.
     287    const psTime *tai2                  ///< Second TAI time.
    286288);
    287289
     
    292294 *  @return  psTime*: time.
    293295 */
    294 psTime* psTimeSub(
    295     psTime *tai1,                       ///< First TAI time.
    296     psTime *tai2                        ///< Second TAI time.
     296psTime* psTimeSubtract(
     297    const psTime *tai1,                 ///< First TAI time.
     298    const psTime *tai2                  ///< Second TAI time.
    297299);
    298300
     
    305307 */
    306308psTime* psTimeDelta(
    307     psTime *tai1,                       ///< First TAI time.
    308     psTime *tai2                        ///< Second TAI time.
    309 );
    310 
    311 
    312 /** Read TAI/UTC data file.
    313  *
    314  *  Reads TAI/UTC data file.
    315  *
    316  *  @return  psImage*: Two-dimensional array with table data.
    317  */
    318 psImage* readTaiUtcFile(
    319     char *fileName                      ///< Name of file to read.
    320 );
    321 
    322 
    323 /** Read SER7 data file.
    324  *
    325  *  Reads SER7 data file.
    326  *
    327  *  @return  psImage*: Two-dimensional array with table data.
    328  */
    329 psImage* readSer7File(
    330     char *fileName                      ///< Name of file to read.
    331 );
    332 
    333 /** Read finals data file.
    334  *
    335  *  Reads finals data file.
    336  *
    337  *  @return  psImage*: Two-dimensional array with table data.
    338  */
    339 psImage* readFinalsFile(
    340     char *fileName                      ///< Name of file to read.
    341 );
    342 
    343 /** Read EOPC data file.
    344  *
    345  *  Reads EOPC data file.
    346  *
    347  *  @return  psImage*: Two-dimensional array with table data.
    348  */
    349 psImage* readEopcFile(
    350     char *fileName                      ///< Name of file to read.
    351 );
    352 
    353 /** Lookup and interpolate TAI-UTC data
    354  *
    355  *  Interpolates TAI-UTC data, given time in MJD format.
    356  *
    357  *  @return  double: Interpolated value.
    358  */
    359 double lookupTaiUtcTable(
    360     psImage *table,                     ///< Table with data.
    361     psTime *time                        ///< time to lookup.
    362 );
    363 
    364 /** Lookup and interpolate polar or UT1-UTC data
    365  *
    366  *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
    367  *
    368  *  @return  double: Interpolated value.
    369  */
    370 double lookupSer7Table(
    371     psImage *table,                      ///< Table with data.
    372     psTime *time,                        ///< time to lookup.
    373     int col                              ///< Column to lookup.
    374 );
     309    const psTime *tai1,                 ///< First TAI time.
     310    const psTime *tai2                  ///< Second TAI time.
     311);
     312
    375313/// @}
    376314
  • trunk/psLib/test/astronomy/tst_psAstrometry.c

    r2006 r2048  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2004-10-07 19:51:30 $
     7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2004-10-12 01:34:09 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1919static int testExposureAlloc(void);
    2020static int testObservatoryAlloc(void);
     21static int testFPAAlloc(void);
     22// static int testGrommitAlloc(void);
    2123
    2224testDescription tests[] = {
    2325                              {testExposureAlloc,735,"psExposureAlloc",0,false},
    2426                              {testObservatoryAlloc,736,"psObservatoryAlloc",0,false},
     27                              {testFPAAlloc,739,"psFPAAlloc",0,false},
    2528                              {NULL}
    2629                          };
     
    119122    char* name = "The Kaiser Royal Observatory";
    120123    psObservatory* obs = psObservatoryAlloc(name,
    121                                             20.7, 156.3, 3055.0, 9.0);
    122 
    123     if (fabs(obs->latitude - 20.7) > DBL_EPSILON) {
     124                                            20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 9.0);
     125
     126    if (fabs(obs->latitude - 20.7*M_PI/180.0) > DBL_EPSILON) {
    124127        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set latitude.");
    125128        return 1;
    126129    }
    127130
    128     if (fabs(obs->longitude - 156.3) > DBL_EPSILON) {
     131    if (fabs(obs->longitude - 156.3*M_PI/180.0) > DBL_EPSILON) {
    129132        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set longitude.");
    130133        return 2;
     
    152155
    153156    psObservatory* obs2 = psObservatoryAlloc(NULL,
    154                           20.7, 156.3, 3055.0, 9.0);
     157                          20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 9.0);
    155158
    156159    if (obs2->name != NULL) {
     
    164167    return 0;
    165168}
     169
     170static int testFPAAlloc(void)
     171{
     172
     173    psTime* now = psTimeGetTime(PS_TIME_UTC);
     174    char* name = "The Kaiser Royal Observatory";
     175
     176    psObservatory* obs = psObservatoryAlloc(name,
     177                                            20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 0.0065f);
     178
     179    psExposure* exp = psExposureAlloc(1.0, 2.0, 3.0, 4.0, 5.0,
     180                                      now, 6.0f, 260.0f, 1013.0f, 0.7f, 10.0f, 0.650f, obs);
     181
     182    /*
     183        1. Call psFPAAlloc with nChips > 0 and a non-NULL psExposure.
     184        a) Verify that the psExposure reference is: 1. is set in struct as
     185        exposure; 2. its reference count is incremented.
     186        b) Verify that the chip attribute is of the size specified by the
     187        parameter nChips and that the chips array elements are all NULL.
     188        c) verify that all other references in the struct is NULL.
     189    */
     190
     191    psFPA* fpa = psFPAAlloc(8, exp);
     192
     193    if (fpa == NULL) {
     194        psLogMsg(__func__,PS_LOG_ERROR,
     195                 "psFPAAlloc returned a NULL.");
     196        return 1;
     197    }
     198
     199    if (fpa->exposure != exp) {
     200        psLogMsg(__func__,PS_LOG_ERROR,
     201                 "psFPAAlloc did not set the exposure.");
     202        return 2;
     203    }
     204
     205    if (psMemGetRefCounter(exp) != 2) {
     206        psLogMsg(__func__,PS_LOG_ERROR,
     207                 "psFPAAlloc did not increment reference counter for exposure.");
     208        return 3;
     209    }
     210
     211    if (fpa->chips->n != 8) {
     212        psLogMsg(__func__,PS_LOG_ERROR,
     213                 "psFPAAlloc did not set the number of chips properly.");
     214        return 4;
     215    }
     216
     217    for (int lcv=0; lcv < 8; lcv++) {
     218        if (fpa->chips->data[lcv] != NULL) {
     219            psLogMsg(__func__,PS_LOG_ERROR,
     220                     "psFPAAlloc did not set chip %d to NULL.", lcv);
     221            return 5;
     222        }
     223    }
     224
     225    if (fpa->metadata != NULL) {
     226        psLogMsg(__func__,PS_LOG_ERROR,
     227                 "psFPAAlloc did not set metadata to NULL.");
     228        return 6;
     229    }
     230
     231    if (fpa->fromTangentPlane != NULL) {
     232        psLogMsg(__func__,PS_LOG_ERROR,
     233                 "psFPAAlloc did not set fromTangentPlane to NULL.");
     234        return 7;
     235    }
     236
     237    if (fpa->toTangentPlane != NULL) {
     238        psLogMsg(__func__,PS_LOG_ERROR,
     239                 "psFPAAlloc did not set toTangentPlane to NULL.");
     240        return 8;
     241    }
     242
     243    if (fpa->pattern != NULL) {
     244        psLogMsg(__func__,PS_LOG_ERROR,
     245                 "psFPAAlloc did not set pattern to NULL.");
     246        return 9;
     247    }
     248
     249    if (fpa->grommit == NULL) {
     250        psLogMsg(__func__,PS_LOG_ERROR,
     251                 "psFPAAlloc did not set grommit using given exposure.");
     252        return 10;
     253    }
     254
     255    if (fpa->colorPlus != NULL) {
     256        psLogMsg(__func__,PS_LOG_ERROR,
     257                 "psFPAAlloc did not set colorPlus to NULL.");
     258        return 11;
     259    }
     260
     261    if (fpa->colorMinus != NULL) {
     262        psLogMsg(__func__,PS_LOG_ERROR,
     263                 "psFPAAlloc did not set colorMinus to NULL.");
     264        return 12;
     265    }
     266
     267    if (fpa->projection != NULL) {
     268        psLogMsg(__func__,PS_LOG_ERROR,
     269                 "psFPAAlloc did not set projection to NULL.");
     270        return 13;
     271    }
     272
     273    /*
     274        2. Call psFPAAlloc with nChips = 0. Verify that the chips array is
     275           zero in size and the program execution does not stop.
     276    */
     277
     278    psFPA* fpa2 = psFPAAlloc(0,exp);
     279
     280    if (fpa2->chips->n != 0) {
     281        psLogMsg(__func__,PS_LOG_ERROR,
     282                 "psFPAAlloc did not set the number of chips properly.");
     283        return 14;
     284    }
     285
     286    /*
     287        3. Call psFPAAlloc with a NULL psExposure. Verify that the program
     288           execution doe not stop and the exposure attribute is NULL.
     289    */
     290
     291    psFPA* fpa3 = psFPAAlloc(4,NULL);
     292    if (fpa3->exposure != NULL) {
     293        psLogMsg(__func__,PS_LOG_ERROR,
     294                 "psFPAAlloc did not set the exposure to NULL given NULL parameter.");
     295        return 15;
     296    }
     297
     298    /*
     299        4. Call psFPAAlloc and set all references in the struct to a memory
     300           buffer. Verify that psFree cleans up all the buffers referenced in
     301           the struct, i.e., there is no memory leaks generated.
     302    */
     303
     304    for (int lcv=0; lcv < 8; lcv++) {
     305        fpa->chips->data[lcv] = psAlloc(4);
     306    }
     307
     308    fpa->metadata = psAlloc(4);
     309    fpa->fromTangentPlane = psAlloc(4);
     310    fpa->toTangentPlane = psAlloc(4);
     311    fpa->pattern = psAlloc(4);
     312    fpa->colorPlus  = psAlloc(4);
     313    fpa->colorMinus  = psAlloc(4);
     314    fpa->projection  = psAlloc(4);
     315
     316    psFree(fpa3);
     317    psFree(fpa2);
     318    psFree(fpa);
     319    psFree(exp);
     320    psFree(obs);
     321
     322    return 0;
     323}
  • trunk/psLib/test/astronomy/tst_psTime_01.c

    r2030 r2048  
    2323 *  @author  Ross Harman, MHPCC
    2424 *
    25  *  @version $Revision: 1.11 $  $Name: not supported by cvs2svn $
    26  *  @date  $Date: 2004-10-08 23:30:47 $
     25 *  @version $Revision: 1.12 $  $Name: not supported by cvs2svn $
     26 *  @date  $Date: 2004-10-12 01:34:09 $
    2727 *
    2828 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6262    printPositiveTestHeader(stdout,"psTime", "Convert psTime to ISO time");
    6363    char *isoString;
    64     isoString = psTimeToISO(testTime);
     64    isoString = psTimeToISOTime(testTime);
    6565    printf("%s\n", isoString);
    6666    if(strncmp(isoString, testString, 256)) {
     
    7474    printPositiveTestHeader(stdout,"psTime", "Convert ISO time to psTime");
    7575    psTime *timeD = NULL;
    76     timeD = psISOToTime(isoString);
     76    timeD = psTimeFromISOTime(isoString);
    7777    printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeD->sec, (psU32)timeD->usec);
    7878    psFree(isoString);
     
    118118    printPositiveTestHeader(stdout,"psTime", "Convert MJD time to psTime");
    119119    psTime *timeH = NULL;
    120     timeH = psMJDToTime(mjdTime);
     120    timeH = psTimeFromMJD(mjdTime);
    121121    printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeH->sec, (psU32)timeH->usec);
    122122    psFree(timeH);
     
    135135    printPositiveTestHeader(stdout,"psTime", "Convert JD time to psTime");
    136136    psTime *timeJ = NULL;
    137     timeJ = psJDToTime(jdTime);
     137    timeJ = psTimeFromJD(jdTime);
    138138    printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeJ->sec, (psU32)timeJ->usec);
    139139    psFree(timeJ);
     
    152152    printPositiveTestHeader(stdout,"psTime", "Convert timeval time to psTime");
    153153    psTime *timeL = NULL;
    154     timeL = psTimevalToTime(&timevalTime);
     154    timeL = psTimeFromTimeval(&timevalTime);
    155155    printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeL->sec, (psU32)timeL->usec);
    156156    psFree(timeL);
     
    175175    printPositiveTestHeader(stdout, "psTime", "Convert tm time to psTime");
    176176    psTime *timeN = NULL;
    177     timeN = psTMToTime(tmTime);
     177    timeN = psTimeFromTM(tmTime);
    178178    printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeN->sec, (psU32)timeN->usec);
    179179    psFree(timeN);
     
    186186    char *testString2 = "2004-09-10T1:00:00.00Z";
    187187    psTime* testTime2 = NULL;
    188     testTime2 = psISOToTime(testString2);
     188    testTime2 = psTimeFromISOTime(testString2);
    189189    double dblTime = psTimeToLST(testTime2, 1);
    190190    printf("LST (rad): %lf\n", dblTime);
  • trunk/psLib/test/astronomy/tst_psTime_02.c

    r2024 r2048  
    99 *  @author  Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
    12  *  @date  $Date: 2004-10-08 22:58:47 $
     11 *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
     12 *  @date  $Date: 2004-10-12 01:34:09 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2424    // Test A - Incorrect ISO time data
    2525    printNegativeTestHeader(stdout,"psTime", "Incorrect ISO time data", "Time not allowed", 0);
    26     psISOToTime("2004-99-21T18:22:24.272Z");
    27     psISOToTime("2004-07-99T18:22:24.272Z");
    28     psISOToTime("2004-07-21T99:22:24.272Z");
    29     psISOToTime("2004-07-21T18:99:24.272Z");
    30     psISOToTime("2004-07-21T18:22:99.272Z");
    31     psISOToTime("2004-07-21T18:22:24.-999Z");
     26    psTimeFromISOTime("2004-99-21T18:22:24.272Z");
     27    psTimeFromISOTime("2004-07-99T18:22:24.272Z");
     28    psTimeFromISOTime("2004-07-21T99:22:24.272Z");
     29    psTimeFromISOTime("2004-07-21T18:99:24.272Z");
     30    psTimeFromISOTime("2004-07-21T18:22:99.272Z");
     31    psTimeFromISOTime("2004-07-21T18:22:24.-999Z");
    3232    printFooter(stdout, "psTime", "Incorrect ISO time data", true);
    3333
     
    3636    printNegativeTestHeader(stdout,"psTime", "Attempt to use null timeval",
    3737                            "Null value for timeval arg not allowed", 0);
    38     psTimevalToTime(NULL);
     38    psTimeFromTimeval(NULL);
    3939    printFooter(stdout, "psTime", "Attempt to use null timeval", true);
    4040
Note: See TracChangeset for help on using the changeset viewer.