IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13950


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

Location:
trunk/psLib/src
Files:
5 edited

Legend:

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

    r11674 r13950  
    88 *  @author Robert Daniel DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2007-02-07 01:15:49 $
     10 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2007-06-22 02:28:48 $
    1212 *
    1313 *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
     
    9393    psMetadata* eocMetadata = psMetadataConfigRead(NULL,
    9494                              &nFail,
    95                               p_psTimeConfigFileName(),
     95                              p_psTimeConfigFilename(NULL),
    9696                              true);
    9797    //Make sure reading of config file worked correctly
  • 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
  • trunk/psLib/src/astro/psTime.h

    r11668 r13950  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-02-06 21:36:09 $
     13 *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-06-22 02:28:48 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7575
    7676
    77 // get the pslib.config filename by checking environment variable first, then original installation area.
    78 const char *p_psTimeConfigFileName();
    79 
    80 
    8177/** Initialize time data.
    8278 *
    83  * Reads config and data files associated with various time conversions.
    84  *
    85  * @return bool:    True for success, false for failure.
    86  */
    87 bool p_psTimeInit(
    88     const char *fileName               ///< File name containing config/data info
    89 );
    90 
    91 /** Initialize time data.
    92  *
    93  *  Reads the configuration file and sets up the appropriate psTimeTables and predictions.
    94  */
    95 void psTimeInitialize(
    96     const char *timeConfig             ///< psTime configuration file
    97 );
    98 
    99 /** Free memory persistant time data.
    100  *
    101  * Frees time data to be held in memory until the end of successful program execution.
    102  *
    103  * @return void:    void.
    104  */
     79 *  Sets the configuration file and sets up the appropriate psTimeTables and predictions.
     80 */
     81bool psTimeInit(
     82    const char *filename                ///< psTime configuration file
     83);
     84
     85
     86/** Frees memory that was allocated by psTime functions.
     87 *
     88 *  Allows a subsequent search for leaked memory.
     89 *
     90 * @return true on sucess.
     91*/
    10592bool p_psTimeFinalize(void);
    10693
     
    476463);
    477464
     465// used by p_psEOCInit()
     466const char *p_psTimeConfigFilename(const char *filename);
     467
    478468/// @}
    479469
  • trunk/psLib/src/sys/psConfigure.c

    r12757 r13950  
    1313 *  @author Robert DeSonia, MHPCC
    1414 *
    15  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2007-04-06 00:04:15 $
     15 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2007-06-22 02:28:48 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2626#include <stdlib.h>
    2727#include <string.h>
     28
     29#include "psAbort.h"
    2830#include "psTrace.h"
    2931#include "psString.h"
     
    9496
    9597
    96 void psLibInit(const char* timeConfig)
     98bool psLibInit(const char* timeConfig)
    9799{
    98100    // XXX: Still needs error codes to be set
    99101
    100102    if (timeConfig && strlen(timeConfig) > 0) {
    101         if (!p_psTimeInit(timeConfig)) {
     103        if (!psTimeInit(timeConfig)) {
    102104            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    103105                    _("Failed to initialize %s."), "psTime");
    104             return;
     106            return false;
    105107        }
    106108    }
     
    111113        atexit(&p_psMemoryCheck);
    112114    }
     115
     116    return true;
    113117}
    114118
     
    122126    // Free the time tables
    123127    if (!p_psTimeFinalize()) {
    124         psError(PS_ERR_UNKNOWN, false,
    125                 _("Failed to finalize %s."), "psTime");
    126         return;
     128        psAbort(_("Failed to finalize psTime."));
    127129    }
    128130
    129131    // Free the precession tables
    130132    if (!p_psEOCFinalize()) {
    131         psError(PS_ERR_UNKNOWN, false,
    132                 _("Failed to finalize %s."), "psEOC");
    133         return;
     133        psAbort(_("Failed to finalize psEOC."));
    134134    }
    135135
     
    139139    // Free the error system
    140140    psErrorClear();
    141 
    142141}
  • trunk/psLib/src/sys/psConfigure.h

    r11694 r13950  
    1111 *  @author Robert DeSonia, MHPCC
    1212 *
    13  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2007-02-08 01:59:28 $
     13 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2007-06-22 02:28:48 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5050 *
    5151 */
    52 void psLibInit(
     52bool psLibInit(
    5353    const char* timeConfig           ///< Filename of config file for psTime.
    5454);
Note: See TracChangeset for help on using the changeset viewer.