IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 21, 2007, 4:28:48 PM (19 years ago)
Author:
jhoblitt
Message:

change psLibInit() to return a boolean status
change psLibFinalize() to abort on error as psError() may not/should not be working after invoking this function
change psTimeInitialize() to return a bool status
change psTimeInitialize() to deffer the actual loading of the "time tables"
rename psTimeInitialize() -> psTimeInit()
rename p_psTimeConfigFileName() -> p_psTimeConfigFilename()
change p_psTimeConfigFilename() to accept a filename argument
p_psTimeConfigFilename() now either return's the current conf files name when passed NULL or sets it to the "filename" parameter that is passed in
change all psTime* functions to make sure that the "time tables" have been initalized before using them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psTime.c

    r13930 r13950  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.112 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-06-21 18:46:38 $
     12 *  @version $Revision: 1.113 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2007-06-22 02:28:48 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6868#define NSEC_PER_DAY 86400000000000.0
    6969
     70// Time config file path
     71static char *timeConfig = NULL;
     72
    7073/** Time metadata read from config file */
    7174static psMetadata *timeMetadata = NULL;
     
    9699static psTime* convertTimeUTCUT1(psTime* time);
    97100
     101static bool p_psTimeInit(const char *fileName);
    98102
    99103/** Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
     
    164168}
    165169
    166 // get the pslib.config filename by checking environment variable first, then original installation area.
    167 const char* p_psTimeConfigFileName()
    168 {
    169     const char* filename = getenv("PS_CONFIG_FILE");
    170 
    171     if (filename == NULL) { // environment variable not found
    172         filename = PS_CONFIG_FILE_DEFAULT; // this should come from configure.ac
    173     }
    174 
    175     return filename;
     170// get the pslib.config filename by checking environment variable first, then
     171// the possiblity set config file name, then the original installation area.
     172const char *p_psTimeConfigFilename(const char *filename)
     173{
     174    // if filename is provided, set timeConfig to this value
     175    if (filename) {
     176        psFree(timeConfig);
     177        timeConfig = psStringCopy(filename);
     178        psMemSetPersistent(timeConfig, true);
     179        return timeConfig;
     180    }
     181
     182    // check the env var first
     183    const char *PS_CONFIG_FILE = getenv("PS_CONFIG_FILE");
     184    if (PS_CONFIG_FILE) {
     185        return PS_CONFIG_FILE;
     186    }
     187
     188    // check timeConfig var 2nd
     189    if (timeConfig) {
     190        return timeConfig;
     191    }
     192
     193    // fall back to the default, this should come from configure.ac
     194    return PS_CONFIG_FILE_DEFAULT;
    176195}
    177196
     
    191210
    192211    // Check if psTime tables are already loaded
    193     if(!p_psTimeInit(p_psTimeConfigFileName())) {
     212    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
    194213        *status = PS_LOOKUP_ERROR;
    195214        return NAN;
     
    269288    }
    270289
     290    // XXX this is not thread safe as the persistence setting is global
    271291    const bool initialPersistence =
    272292        p_psMemAllocatePersistent(true); // All memory allocated below is "persistent"
     
    881901    if((bulletin != PS_IERS_A) && (bulletin != PS_IERS_B)) {
    882902        psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid bulletin specified %d",bulletin);
     903        return NAN;
     904    }
     905
     906    // Check if psTime tables are already loaded
     907    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
     908        psError(PS_ERR_UNKNOWN, true, "failed to init time tables.");
    883909        return NAN;
    884910    }
     
    10651091    }
    10661092
     1093    // Check if psTime tables are already loaded
     1094    if(!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
     1095        psError(PS_ERR_UNKNOWN, true, "failed to init time tables.");
     1096        return NULL;
     1097    }
     1098
    10671099    // Attempt to find value through table lookup and interpolation
    10681100    mjd = psTimeToMJD(time);
     
    11941226
    11951227    // Check if psTime tables are loaded/loadable
    1196     if(!p_psTimeInit(p_psTimeConfigFileName())) {
     1228    if (!p_psTimeInit(p_psTimeConfigFilename(NULL))) {
    11971229        psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Failed to open file %s."),
    1198                 p_psTimeConfigFileName());
     1230                p_psTimeConfigFilename(NULL));
    11991231        return NAN;
    12001232    }
     
    17121744    // Error checks
    17131745    PS_ASSERT_PTR_NON_NULL(time,NULL);
    1714     PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NULL);
     1746    PS_ASSERT_INT_WITHIN_RANGE(time->nsec, (psU32)0, (psU32)((1e9)-1), NULL);
    17151747
    17161748    // Convert time to TAI if necessary, but without changing input arguments
     
    17961828}
    17971829
    1798 void psTimeInitialize(const char *timeConfig)
    1799 {
    1800     p_psTimeInit(timeConfig);
     1830// delay actual init until a timefunction is used
     1831bool psTimeInit(const char *filename)
     1832{
     1833    // at present, this function can not fail
     1834    p_psTimeConfigFilename(filename);
     1835
     1836    return true;
    18011837}
    18021838
Note: See TracChangeset for help on using the changeset viewer.