Changeset 4059 for trunk/psLib/test/astronomy/tst_psTime_01.c
- Timestamp:
- May 31, 2005, 12:02:28 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/astronomy/tst_psTime_01.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astronomy/tst_psTime_01.c
r3712 r4059 4 4 * 5 5 * This test driver contains the following tests for psTime: 6 * A) Get current TAI time7 * B) Print test time8 * C) Convert psTime to ISO time9 * D) Convert ISO time to psTime10 * E) Convert psTime to UTC time11 * F) Convert UTC time to psTime12 * G) Convert psTime to MJD time13 * H) Convert MJD time to psTime14 * I) Convert psTime to JD time15 * J) Convert JD time to psTime16 * K) Convert psTime to timeval time17 * L) Convert timeval time to psTime18 * M) Convert psTime to tm time19 * N) Convert tm time to psTime6 * 1) Allocate psTime structure 7 * 2) Get current time 8 * 3) Get UT1 UTC delta 9 * 4) Convert psTime to MJD 10 * 5) Convert psTime to JD 11 * 6) Convert psTime to ISO 12 * 7) Convert psTime to timeval 13 * 8) Create psTime from MJD 14 * 9) Create psTime from JD 15 * 10) Create psTime from ISO 16 * 11) Create psTime from timeval 17 * 12) Create psTime from TM 18 * 13) Convert time between different types 19 * 20 20 * O) Convert psTime time to LMST 21 * P) Free data22 21 * 23 22 * @author Ross Harman, MHPCC 23 * @author Eric Van Alst, MHPCC 24 24 * 25 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $26 * @date $Date: 2005-0 4-19 02:13:53$25 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 26 * @date $Date: 2005-05-31 21:56:31 $ 27 27 * 28 28 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 */ 31 31 32 #include <string.h>33 32 #include "pslib_strict.h" 34 33 #include "psTest.h" 34 #include <string.h> 35 36 #define ERROR_TOL 0.0001 37 38 static psS32 testTimeAlloc(void); 39 static psS32 testTimeGetNow(void); 40 static psS32 testTimeGetUT1Delta(void); 41 static psS32 testTimeToMJD(void); 42 static psS32 testTimeToJD(void); 43 static psS32 testTimeToISO(void); 44 static psS32 testTimeToTimeval(void); 45 static psS32 testTimeFromMJD(void); 46 static psS32 testTimeFromJD(void); 47 static psS32 testTimeFromISO(void); 48 static psS32 testTimeFromTimeval(void); 49 static psS32 testTimeFromTM(void); 50 static psS32 testTimeConvert(void); 51 52 testDescription tests[] = { 53 {testTimeAlloc,000,"psTimeAlloc",0,false}, 54 {testTimeGetNow,000,"psTimeGetNow",0,false}, 55 {testTimeGetUT1Delta,000,"psTimeGetUT1Delta",0,false}, 56 {testTimeToMJD,000,"psTimeToMJD",0,false}, 57 {testTimeToJD,000,"psTimeToJD",0,false}, 58 {testTimeToISO,000,"psTimeToISO",0,false}, 59 {testTimeToTimeval,000,"psTimeToTimeval",0,false}, 60 {testTimeFromMJD,000,"psTimeFromMJD",0,false}, 61 {testTimeFromJD,000,"psTimeFromJD",0,false}, 62 {testTimeFromISO,000,"psTimeFromISO",0,false}, 63 {testTimeFromTimeval,000,"psTimeFromTimeval",0,false}, 64 {testTimeFromTM,000,"p_psTimeFromTM",0,false}, 65 {testTimeConvert,000,"psTimeConvert",0,false}, 66 {NULL} 67 }; 68 69 // Test Time 1 : July 21, 2004 18:22:24.3 70 // MJD = 53207.765559 71 // JD = 2453208.265559 72 // UTC Test Time 1 73 const psS64 testTime1SecondsUTC = 1090434144; 74 const psU32 testTime1NanosecondsUTC = 272044000; 75 // TAI Test Time 1 76 const psS64 testTime1SecondsTAI = 1090434176; 77 const psU32 testTime1NanosecondsTAI = 272044000; 78 const psF64 testTime1MJDTAI = 53207.76592937; 79 const psF64 testTime1JDTAI = 2453208.26592937; 80 81 // TT Test Time 1 82 const psS64 testTime1SecondsTT = 1090434208; 83 const psU32 testTime1NanosecondsTT = 456044000; 84 // Expected UT1-UTC IERS A & B 85 const psF64 testTime1UT1DeltaBullA = -0.457233186; 86 const psF64 testTime1UT1DeltaBullB = -0.457227; 87 // UT1 Test Time 1 88 const psS64 testTime1SecondsUT1 = 1090434143; 89 const psU32 testTime1NanosecondsUT1 = 814810814; 90 // Expected MJD & JD 91 const psF64 testTime1MJD = 53207.765559; 92 const psF64 testTime1JD = 2453208.265559; 93 // Expected ISO string 94 const char* testTime1Str = "2004-07-21T18:22:24,2Z"; 95 const char* testTime1StrLeap = "2004-07-21T18:22:60,2Z"; 96 // Expected timeval values 97 const psS32 testTime1TimevalSec = 1090434144; 98 const psS32 testTime1TimevalUsec = 272044; 99 100 // Test Time 2 : Jan. 1, 1973 00:00:00.0000 101 // MJD = 41683.0000 102 // JD = 2441683.5000 103 const psS64 testTime2SecondsUTC = 94694400; 104 const psU32 testTime2NanosecondsUTC = 0; 105 106 // Expected UT1-UTC IERS A & B 107 const psF64 testTime2UT1DeltaBullA = 0.000000; 108 const psF64 testTime2UT1DeltaBullB = 0.000000; 109 110 // Test Time 3 : Sept. 21, 2006 00:00:00.0000 111 // MJD = 53999 112 // JD = 2453999.5 113 const psS64 testTime3SecondsUTC = 1158796800; 114 const psU32 testTime3NanosecondsUTC = 0; 115 // Expected UT1-UTC IERS A & B 116 const psF64 testTime3UT1DeltaBullA = -0.63574; 117 const psF64 testTime3UT1DeltaBullB = -0.63574; 118 119 // Test Time 4 : Jan. 1, 1969 00:00:00.0000 120 // MJD = 40222 121 // JD = 2440222.5 122 const psS64 testTime4SecondsUTC = -31536000; 123 const psU32 testTime4NanosecondsUTC = 0; 124 // Expected MJD and JD 125 const psF64 testTime4MJD = 40222.0; 126 const psF64 testTime4JD = 2440222.5; 127 128 // Test Time 5 : Dec 31, 0001 BC 23:59:59 129 // MJD = -1397755 130 // JD = 1002245.4999 131 const psS64 testTime5SecondsUTC = -62125920001; 132 const psU32 testTime5NanosecondsUTC = 0; 133 134 // Test Time 6 : Jan. 1, 10000 AD 00:00:00 135 const psS64 testTime6SecondsUTC = 253202544001; 136 const psU32 testTime6NanosecondsUTC = 0; 137 138 // Test Time 7 : Jan. 1, 2004 00:00:00,0 139 const psS64 testTime7Seconds = 1072915200; 140 const psU32 testTime7Nanoseconds = 0; 141 const psS32 testTime7TmYear = 104; 142 const psS32 testTime7TmMon = 0; 143 const psS32 testTime7TmDay = 1; 144 const psS32 testTime7TmHour = 0; 145 const psS32 testTime7TmMin = 0; 146 const psS32 testTime7TmSec = 0; 147 148 // Test Time 8 : Dec. 31, 2003 00:00:00,0 149 const psS64 testTime8Seconds = 1072828800; 150 const psU32 testTime8Nanoseconds = 0; 151 const psS32 testTime8TmYear = 103; 152 const psS32 testTime8TmMon = 11; 153 const psS32 testTime8TmDay = 31; 154 const psS32 testTime8TmHour = 0; 155 const psS32 testTime8TmMin = 0; 156 const psS32 testTime8TmSec = 0; 35 157 36 158 psS32 main(psS32 argc, char* argv[]) 37 159 { 38 ps Time *testTime;39 char *testString = "2004-07-21T18:22:24.272Z"; 40 160 psLogSetLevel(PS_LOG_INFO); 161 162 // Initialize library internal structures 41 163 psLibInit(true,"psTime.config"); 42 164 43 // Test time was taken at July 21, 2004 at 18:22:24.272044 44 testTime = (psTime*)psAlloc(sizeof(psTime)); 45 testTime->sec = 1090434144; 46 testTime->nsec = 272044000; 47 testTime->type = PS_TIME_TAI; 48 49 // Test A - Get current TAI time 50 printPositiveTestHeader(stdout,"psTime", "Get current TAI time"); 51 psTime *timeA = NULL; 52 timeA = psTimeGetNow(PS_TIME_TAI); 53 psFree(timeA); 54 printFooter(stdout, "psTime", "Get current TAI time", true); 55 56 57 // Test B - Print test time 58 printPositiveTestHeader(stdout,"psTime", "Print test time"); 59 printf("Test time: Seconds = %lld Nanoseconds = %u\n", 60 (long long int)testTime->sec, 61 testTime->nsec); 62 printFooter(stdout, "psTime", "Print test time", true); 63 64 65 // Test C - Convert psTime to ISO time 66 printPositiveTestHeader(stdout,"psTime", "Convert psTime to ISO time"); 67 char *isoString; 68 isoString = psTimeToISO(testTime); 69 printf("%s\n", isoString); 70 if(strncmp(isoString, testString, 256)) { 71 printf("ERROR - ISO string incorrect\n"); 72 printf("Returned: %s\n", isoString); 73 } 74 printFooter(stdout, "psTime", "Convert psTime to ISO time", true); 75 76 77 // Test D - Convert ISO time to psTime 78 printPositiveTestHeader(stdout,"psTime", "Convert ISO time to psTime"); 79 psTime *timeD = NULL; 80 timeD = psTimeFromISO(isoString); 81 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 82 (long long int)timeD->sec, 83 timeD->nsec); 84 psFree(isoString); 85 psFree(timeD); 86 printFooter(stdout, "psTime", "Convert ISO time to psTime", true); 87 88 89 // Test E - Convert TAI to UTC time 90 printPositiveTestHeader(stdout,"psTime", "Convert psTime time to UTC time"); 91 psTime *timeE = NULL; 92 timeE = (psTime*)psAlloc(sizeof(psTime)); 93 timeE->sec = 1090434144; 94 timeE->nsec = 272044000; 95 timeE->type = PS_TIME_TAI; 96 timeE = psTimeConvert(timeE, PS_TIME_UTC); 97 psFree(timeE); 98 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 99 (long long int)timeE->sec, 100 timeE->nsec); 101 printFooter(stdout, "psTime", "Convert psTime time to UTC time", true); 102 103 104 // Test F - Convert UTC time to psTime 105 printPositiveTestHeader(stdout,"psTime", "Convert UTC time to psTime"); 106 psTime *timeF = NULL; 107 timeF = (psTime*)psAlloc(sizeof(psTime)); 108 timeF->sec = 1090434112; 109 timeF->nsec = 272044000; 110 timeF->type = PS_TIME_UTC; 111 timeF = psTimeConvert(timeF, PS_TIME_TAI); 112 psFree(timeF); 113 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 114 (long long int)timeF->sec, 115 timeF->nsec); 116 printFooter(stdout, "psTime", "Convert UTC time to psTime", true); 117 118 119 // Test G - Convert psTime to MJD time 120 printPositiveTestHeader(stdout,"psTime", "Convert psTime to MJD time"); 121 double mjdTime = 0.0; 122 mjdTime = psTimeToMJD(testTime); 123 printf("MJD = %f\n", mjdTime); 124 printFooter(stdout, "psTime", "Convert psTime to MJD time", true); 125 126 127 // Test H - Convert MJD time to psTime 128 printPositiveTestHeader(stdout,"psTime", "Convert MJD time to psTime"); 129 psTime *timeH = NULL; 130 timeH = psTimeFromMJD(mjdTime); 131 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 132 (long long int)timeH->sec, 133 timeH->nsec); 134 psFree(timeH); 135 printFooter(stdout, "psTime", "Convert MJD time to psTime", true); 136 137 138 // Test I - Convert psTime to JD time 139 printPositiveTestHeader(stdout,"psTime", "Convert psTime to JD time"); 140 double jdTime = 0.0; 141 jdTime = psTimeToJD(testTime); 142 printf("JD = %f\n", jdTime); 143 printFooter(stdout, "psTime", "Convert psTime to JD time", true); 144 145 146 // Test J - Convert JD time to psTime 147 printPositiveTestHeader(stdout,"psTime", "Convert JD time to psTime"); 148 psTime *timeJ = NULL; 149 timeJ = psTimeFromJD(jdTime); 150 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 151 (long long int)timeJ->sec, 152 timeJ->nsec); 153 psFree(timeJ); 154 printFooter(stdout, "psTime", "Convert JD time to psTime", true); 155 156 157 // Test K - Convert psTime to timeval time 158 printPositiveTestHeader(stdout,"psTime", "Convert psTime to timeval time"); 159 struct timeval timevalTime; 160 timevalTime = psTimeToTimeval(testTime); 161 printf("timevalTime: Seconds = %lld Microseconds = %lld\n", 162 (long long int)timevalTime.tv_sec, 163 (long long int)timevalTime.tv_usec); 164 printFooter(stdout, "psTime", "Convert psTime to timeval time", true); 165 166 167 // Test L - Convert timeval time to psTime 168 printPositiveTestHeader(stdout,"psTime", "Convert timeval time to psTime"); 169 psTime *timeL = NULL; 170 timeL = psTimeFromTimeval(&timevalTime); 171 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 172 (long long int)timeL->sec, 173 timeL->nsec); 174 psFree(timeL); 175 printFooter(stdout, "psTime", "Convert timeval time to psTime", true); 176 177 178 // Test M - Convert psTime to tm time 179 printPositiveTestHeader(stdout,"psTime", "Convert psTime to tm time"); 180 struct tm *tmTime; 181 tmTime = psTimeToTM(testTime); 182 printf("tmTime:\n"); 183 printf("tmTime->tm_year = %d\n", tmTime->tm_year); 184 printf("tmTime->tm_mon = %d\n", tmTime->tm_mon); 185 printf("tmTime->tm_mday = %d\n", tmTime->tm_mday); 186 printf("tmTime->tm_hour = %d\n", tmTime->tm_hour); 187 printf("tmTime->tm_min = %d\n", tmTime->tm_min); 188 printf("tmTime->tm_sec = %d\n", tmTime->tm_sec); 189 printFooter(stdout, "psTime", "Convert psTime to tm time", true); 190 191 192 // Test N - Convert tm time to psTime 193 printPositiveTestHeader(stdout, "psTime", "Convert tm time to psTime"); 194 psTime *timeN = NULL; 195 timeN = psTimeFromTM(tmTime); 196 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 197 (long long int)timeN->sec, 198 timeN->nsec); 199 psFree(timeN); 165 if( !runTestSuite(stderr,"psTime",tests,argc,argv)) { 166 return 1; 167 } 168 169 // Cleanup library 170 psLibFinalize(); 171 172 return 0; 173 } 174 175 psS32 testTimeAlloc(void) 176 { 177 psTime* time = NULL; 178 179 // Allocate new psTime with valid time type 180 time = psTimeAlloc(PS_TIME_TAI); 181 if(time == NULL) { 182 psError(PS_ERR_UNKNOWN,true,"Return NULL when psTime object ptr expected"); 183 return 1; 184 } 185 // Verify members set properly 186 if(time->type != PS_TIME_TAI) { 187 psError(PS_ERR_UNKNOWN,true,"Member type = %d not as expected %d",time->type,PS_TIME_TAI); 188 return 2; 189 } 190 if((time->sec != 0) && (time->nsec != 0) && (time->leapsecond != false)) { 191 psError(PS_ERR_UNKNOWN,true,"Members not set appropriately"); 192 return 3; 193 } 194 psFree(time); 195 196 // Allocate new psTime with invalid time type 197 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 198 time = psTimeAlloc(-100); 199 if(time != NULL) { 200 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time type"); 201 return 4; 202 } 203 204 return 0; 205 } 206 psS32 testTimeGetNow(void) 207 { 208 psTime* timeNow = NULL; 209 210 // Get current time and verify return is psTime structure 211 timeNow = psTimeGetNow(PS_TIME_TAI); 212 if(timeNow == NULL) { 213 psError(PS_ERR_UNKNOWN,true,"Did not return valid psTime struct"); 214 return 1; 215 } 216 if(timeNow->type != PS_TIME_TAI) { 217 psError(PS_ERR_UNKNOWN,true,"Time type %d not as expected %d", 218 timeNow->type, PS_TIME_TAI); 219 return 2; 220 } 221 psFree(timeNow); 222 223 // Attempt to get time with invalid type 224 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time type"); 225 timeNow = psTimeGetNow(-100); 226 if(timeNow != NULL) { 227 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time type"); 228 return 3; 229 } 230 231 return 0; 232 } 233 234 psS32 testTimeGetUT1Delta(void) 235 { 236 psTime* time = NULL; 237 psF64 ut1Delta = 0.0; 238 239 // Attempt to convert NULL time 240 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 241 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 242 if( !isnan(ut1Delta)) { 243 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for NULL psTime"); 244 return 1; 245 } 246 247 // Attempt to convert invalid time 248 time = psTimeAlloc(PS_TIME_TAI); 249 time->sec = 1; 250 time->nsec = 2e9; 251 time->leapsecond = false; 252 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 253 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 254 if( !isnan(ut1Delta)) { 255 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid time"); 256 return 2; 257 } 258 259 // Attempt to convert time with invalid bulletin 260 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid bulletin"); 261 time->nsec = 2; 262 ut1Delta = psTimeGetUT1Delta(time,-100); 263 if( !isnan(ut1Delta)) { 264 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid bulletin"); 265 return 3; 266 } 267 268 // Attempt to get delta with valid time and bulletin A 269 time->sec = testTime1SecondsUTC; 270 time->nsec = testTime1NanosecondsUTC; 271 time->type = PS_TIME_UTC; 272 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_A); 273 if(fabs(ut1Delta - testTime1UT1DeltaBullA) > ERROR_TOL) { 274 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 1 bulletin A", 275 ut1Delta,testTime1UT1DeltaBullA); 276 return 4; 277 } 278 279 // Attempt to get delta with valid time and bulletin B 280 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 281 if(fabs(ut1Delta - testTime1UT1DeltaBullB) > ERROR_TOL) { 282 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 1 bulletin B", 283 ut1Delta,testTime1UT1DeltaBullB); 284 return 5; 285 } 286 287 // Attempt to get delta with valid time and bulletin A 288 time->sec = testTime2SecondsUTC; 289 time->nsec = testTime2NanosecondsUTC; 290 time->type = PS_TIME_UTC; 291 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message predating table"); 292 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_A); 293 if(fabs(ut1Delta - testTime2UT1DeltaBullA) > ERROR_TOL) { 294 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 2 bulletin A", 295 ut1Delta,testTime2UT1DeltaBullA); 296 return 6; 297 } 298 299 // Attempt to get delta with valid time and bulletin B 300 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message predating table"); 301 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 302 if(fabs(ut1Delta - testTime2UT1DeltaBullB) > ERROR_TOL) { 303 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 2 bulletin B", 304 ut1Delta,testTime2UT1DeltaBullB); 305 return 7; 306 } 307 308 // Attempt to get delta with valid time and bulletin A 309 time->sec = testTime3SecondsUTC; 310 time->nsec = testTime3NanosecondsUTC; 311 time->type = PS_TIME_UTC; 312 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message postdating table"); 313 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_A); 314 if(fabs(ut1Delta - testTime3UT1DeltaBullA) > ERROR_TOL) { 315 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 3 bulletin A", 316 ut1Delta,testTime3UT1DeltaBullA); 317 return 8; 318 } 319 320 // Attempt to get delta with valid time and bulletin B 321 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message postdating table"); 322 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 323 if(fabs(ut1Delta - testTime3UT1DeltaBullB) > ERROR_TOL) { 324 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 3 bulletin B", 325 ut1Delta,testTime3UT1DeltaBullB); 326 return 9; 327 } 328 329 psFree(time); 330 331 return 0; 332 } 333 334 psS32 testTimeToMJD(void) 335 { 336 psTime* time = NULL; 337 psF64 mjd = 0.0; 338 339 // Attempt to convert with time NULL 340 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 341 mjd = psTimeToMJD(NULL); 342 if(!isnan(mjd)) { 343 psError(PS_ERR_UNKNOWN,true,"Expected NaN for NULL time"); 344 return 1; 345 } 346 347 // Attempt to convert invalid time 348 time = psTimeAlloc(PS_TIME_UTC); 349 time->sec = 1; 350 time->nsec = 2e9; 351 time->leapsecond = false; 352 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 353 mjd = psTimeToMJD(time); 354 if( !isnan(mjd)) { 355 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid time"); 356 return 2; 357 } 358 359 // Check valid time conversion to MJD after 1/1/1970 epoch 360 time->sec = testTime1SecondsUTC; 361 time->nsec = testTime1NanosecondsUTC; 362 mjd = psTimeToMJD(time); 363 if(fabs(mjd - testTime1MJD) > ERROR_TOL) { 364 psError(PS_ERR_UNKNOWN,true,"Expected MJD = %lf not as expected %lf", 365 mjd, testTime1MJD); 366 return 3; 367 } 368 369 // Check valid time conversion to MJD before 1/1/1970 epoch 370 time->sec = testTime4SecondsUTC; 371 time->nsec = testTime4NanosecondsUTC; 372 mjd = psTimeToMJD(time); 373 if(fabs(mjd - testTime4MJD) > ERROR_TOL) { 374 psError(PS_ERR_UNKNOWN,true,"Expected MJD = %lf not as expected %lf", 375 mjd, testTime4MJD); 376 return 4; 377 } 378 379 psFree(time); 380 381 return 0; 382 } 383 384 psS32 testTimeToJD(void) 385 { 386 psTime* time = NULL; 387 psF64 jd = 0.0; 388 389 // Attempt to convert with time NULL 390 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 391 jd = psTimeToJD(NULL); 392 if(!isnan(jd)) { 393 psError(PS_ERR_UNKNOWN,true,"Expected NaN for NULL time"); 394 return 1; 395 } 396 397 // Attempt to convert invalid time 398 time = psTimeAlloc(PS_TIME_UTC); 399 time->sec = 1; 400 time->nsec = 2e9; 401 time->leapsecond = false; 402 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 403 jd = psTimeToJD(time); 404 if( !isnan(jd)) { 405 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid time"); 406 return 2; 407 } 408 409 // Check valid time conversion to MJD after 1/1/1970 epoch 410 time->sec = testTime1SecondsUTC; 411 time->nsec = testTime1NanosecondsUTC; 412 jd = psTimeToJD(time); 413 if(fabs(jd - testTime1JD) > ERROR_TOL) { 414 psError(PS_ERR_UNKNOWN,true,"Expected JD = %lf not as expected %lf", 415 jd, testTime1JD); 416 return 3; 417 } 418 419 // Check valid time conversion to MJD before 1/1/1970 epoch 420 time->sec = testTime4SecondsUTC; 421 time->nsec = testTime4NanosecondsUTC; 422 jd = psTimeToJD(time); 423 if(fabs(jd - testTime4JD) > ERROR_TOL) { 424 psError(PS_ERR_UNKNOWN,true,"Expected JD = %lf not as expected %lf", 425 jd, testTime4JD); 426 return 4; 427 } 428 429 psFree(time); 430 431 return 0; 432 } 433 434 psS32 testTimeToISO(void) 435 { 436 psTime* time = NULL; 437 char* timeStr = NULL; 438 439 // Attempt to convert with NULL time 440 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 441 timeStr = psTimeToISO(time); 442 if(timeStr != NULL) { 443 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected"); 444 return 1; 445 } 446 447 // Attempt to convert invalid time 448 time = psTimeAlloc(PS_TIME_UTC); 449 time->sec = 1; 450 time->nsec = 2e9; 451 time->leapsecond = false; 452 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 453 timeStr = psTimeToISO(time); 454 if( timeStr != NULL) { 455 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 456 return 2; 457 } 458 459 // Verify return NULL for time prior to year 0000 460 time->sec = testTime5SecondsUTC; 461 time->nsec = testTime5NanosecondsUTC; 462 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for time prior year 0000"); 463 timeStr = psTimeToISO(time); 464 if(timeStr != NULL) { 465 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for time prior to year 0000"); 466 return 3; 467 } 468 469 // Verify return NULL for time after to year 9999 470 time->sec = testTime6SecondsUTC; 471 time->nsec = testTime6NanosecondsUTC; 472 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for time after year 9999"); 473 timeStr = psTimeToISO(time); 474 if(timeStr != NULL) { 475 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for time after to year 9999"); 476 return 4; 477 } 478 479 // Verify return string with valid time 480 time->sec = testTime1SecondsUTC; 481 time->nsec = testTime1NanosecondsUTC; 482 timeStr = psTimeToISO(time); 483 if(strcmp(timeStr,testTime1Str) != 0) { 484 psError(PS_ERR_UNKNOWN,true,"String %s not as expected %s", 485 timeStr, testTime1Str); 486 return 5; 487 } 488 psFree(timeStr); 489 490 // Verify return string with valid time and leap second set 491 time->sec = testTime1SecondsUTC; 492 time->nsec = testTime1NanosecondsUTC; 493 time->leapsecond = true; 494 timeStr = psTimeToISO(time); 495 if(strcmp(timeStr,testTime1StrLeap) != 0) { 496 psError(PS_ERR_UNKNOWN,true,"String %s not as expected %s", 497 timeStr, testTime1StrLeap); 498 return 6; 499 } 500 psFree(timeStr); 501 psFree(time); 502 503 return 0; 504 } 505 506 psS32 testTimeToTimeval(void) 507 { 508 psTime* time = NULL; 509 struct timeval* timevalTime = NULL; 510 511 // Attempt to convert with NULL time 512 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 513 timevalTime = psTimeToTimeval(time); 514 if(timevalTime != NULL) { 515 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected"); 516 return 1; 517 } 518 519 // Attempt to convert invalid time 520 time = psTimeAlloc(PS_TIME_UTC); 521 time->sec = 1; 522 time->nsec = 2e9; 523 time->leapsecond = false; 524 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 525 timevalTime = psTimeToTimeval(time); 526 if( timevalTime != NULL) { 527 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 528 return 2; 529 } 530 531 // Attempt to convert invalid time 532 time->sec = -1; 533 time->nsec = 0; 534 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 535 timevalTime = psTimeToTimeval(time); 536 if( timevalTime != NULL) { 537 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 538 return 2; 539 } 540 541 // Verify convert to timeval with valid time 542 time->sec = testTime1SecondsUTC; 543 time->nsec = testTime1NanosecondsUTC; 544 timevalTime = psTimeToTimeval(time); 545 if(timevalTime->tv_sec != testTime1TimevalSec) { 546 psError(PS_ERR_UNKNOWN,true,"Timeval seconds %ld not as expectd %ld", 547 timevalTime->tv_sec,testTime1TimevalSec); 548 return 4; 549 } 550 if(timevalTime->tv_usec != testTime1TimevalUsec) { 551 psError(PS_ERR_UNKNOWN,true,"Timeval useconds %ld not as expected %ld", 552 timevalTime->tv_usec,testTime1TimevalUsec); 553 return 5; 554 } 555 556 psFree(timevalTime); 557 psFree(time); 558 559 return 0; 560 } 561 562 psS32 testTimeFromMJD(void) 563 { 564 psTime* time = NULL; 565 566 // Attempt to convert valid time to psTime 567 time = psTimeFromMJD(testTime1MJDTAI); 568 if(time->type != PS_TIME_TAI) { 569 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 570 time->type,PS_TIME_TAI); 571 return 1; 572 } 573 if(time->sec != testTime1SecondsTAI) { 574 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 575 (long int)time->sec,testTime1SecondsTAI); 576 return 2; 577 } 578 psFree(time); 579 580 // Attempt to convert valid time before 1970 epoch 581 time = psTimeFromMJD(testTime4MJD); 582 if(time->type != PS_TIME_TAI) { 583 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 584 time->type,PS_TIME_TAI); 585 return 3; 586 } 587 if(time->sec != testTime4SecondsUTC) { 588 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 589 (long int)time->sec,testTime4SecondsUTC); 590 return 4; 591 } 592 psFree(time); 593 594 return 0; 595 } 596 597 psS32 testTimeFromJD(void) 598 { 599 psTime* time = NULL; 600 601 // Attempt to convert valid time to psTime 602 time = psTimeFromJD(testTime1JDTAI); 603 if(time->type != PS_TIME_TAI) { 604 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 605 time->type,PS_TIME_TAI); 606 return 1; 607 } 608 if(time->sec != testTime1SecondsTAI) { 609 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 610 (long int)time->sec,(long int)testTime1SecondsTAI); 611 return 2; 612 } 613 psFree(time); 614 615 // Attempt to convert valid time before 1970 epoch 616 time = psTimeFromJD(testTime4JD); 617 if(time->type != PS_TIME_TAI) { 618 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 619 time->type,PS_TIME_TAI); 620 return 3; 621 } 622 if(time->sec != testTime4SecondsUTC) { 623 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 624 (long int)time->sec,testTime4SecondsUTC); 625 return 4; 626 } 627 psFree(time); 628 629 return 0; 630 } 631 632 psS32 testTimeFromISO(void) 633 { 634 psTime* time = NULL; 635 636 // Attempt to convert NULL string 637 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL ISO string"); 638 time = psTimeFromISO(NULL); 639 if(time != NULL) { 640 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected for NULL ISO string"); 641 return 1; 642 } 643 644 // Convert valid ISO string 645 time = psTimeFromISO(testTime1Str); 646 if(time->type != PS_TIME_TAI) { 647 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 648 time->type, PS_TIME_TAI); 649 return 2; 650 } 651 if(time->sec != testTime1SecondsUTC) { 652 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 653 (long int)time->sec,testTime1SecondsTAI); 654 return 3; 655 } 656 psFree(time); 657 658 // Attempt to convert invalid ISO string 659 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid ISO string"); 660 time = psTimeFromISO("Here I am"); 661 if(time != NULL) { 662 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected for invalid ISO string"); 663 return 4; 664 } 665 psFree(time); 666 667 return 0; 668 } 669 670 psS32 testTimeFromTimeval(void) 671 { 672 psTime* time = NULL; 673 struct timeval* timevalTime = NULL; 674 675 // Attempt to create psTime from NULL timeval ptr 676 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL timeval"); 677 time = psTimeFromTimeval(NULL); 678 if(time != NULL) { 679 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL timeval ptr"); 680 return 1; 681 } 682 683 // Convert valid timeval structure 684 timevalTime = (struct timeval*)psAlloc(sizeof(struct timeval)); 685 timevalTime->tv_sec = testTime1SecondsTAI; 686 timevalTime->tv_usec = testTime1NanosecondsTAI / 1000; 687 time = psTimeFromTimeval(timevalTime); 688 if(time == NULL) { 689 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return value for valid timeval"); 690 return 2; 691 } 692 if(time->type != PS_TIME_TAI) { 693 psError(PS_ERR_UNKNOWN,true,"psTime type %d not as expected %d", 694 time->type, PS_TIME_TAI); 695 return 3; 696 } 697 if(time->sec != testTime1SecondsTAI) { 698 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 699 time->sec, testTime1SecondsTAI); 700 return 4; 701 } 702 if(time->nsec != testTime1NanosecondsTAI) { 703 psError(PS_ERR_UNKNOWN,true,"psTime nanosec %ld not as expected %ld", 704 time->nsec, testTime1NanosecondsTAI); 705 return 5; 706 } 707 psFree(timevalTime); 708 psFree(time); 709 710 return 0; 711 } 712 713 psS32 testTimeFromTM(void) 714 { 715 psTime* time = NULL; 716 struct tm* tmTime = NULL; 717 718 // Attempt to convert from NULL tm structure ptr 719 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL tm ptr"); 720 time = p_psTimeFromTM(tmTime); 721 if(time != NULL) { 722 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL tm ptr"); 723 return 1; 724 } 725 726 // Verify convert for valid tm structure 727 tmTime = (struct tm*)psAlloc(sizeof(struct tm)); 728 tmTime->tm_year = testTime7TmYear; 729 tmTime->tm_mon = testTime7TmMon; 730 tmTime->tm_mday = testTime7TmDay; 731 tmTime->tm_hour = testTime7TmHour; 732 tmTime->tm_min = testTime7TmMin; 733 tmTime->tm_sec = testTime7TmSec; 734 time = p_psTimeFromTM(tmTime); 735 if(time == NULL) { 736 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return value for valid tm structure"); 737 return 2; 738 } 739 if(time->sec != testTime7Seconds) { 740 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 741 (long int)time->sec, (long int)testTime7Seconds); 742 return 3; 743 } 744 if(time->nsec != testTime7Nanoseconds) { 745 psError(PS_ERR_UNKNOWN,true,"psTime nanoseconds %ld not as expected %ld", 746 time->nsec, testTime7Nanoseconds); 747 return 4; 748 } 200 749 psFree(tmTime); 201 printFooter(stdout, "psTime", "Convert tm time to psTime", true); 202 203 204 // Test O - psTime to LMST 205 printPositiveTestHeader(stdout, "psTime", "Convert psTime time to LST"); 206 char *testString2 = "2004-09-10T1:00:00.00Z"; 207 psTime* testTime2 = NULL; 208 testTime2 = psTimeFromISO(testString2); 209 double dblTime = psTimeToLMST(testTime2, 1); 210 printf("LST (rad): %lf\n", dblTime); 211 psFree(testTime2); 212 printFooter(stdout, "psTime", "Convert psTime time to LST", true); 213 214 215 // Test P - Free data 216 printPositiveTestHeader(stdout, "psMetadata", "Test P - Free data"); 217 psFree(testTime); 218 psLibFinalize(); 219 if( psMemCheckLeaks(0, NULL, stdout,false) != 0 ) { 220 psError(PS_ERR_UNKNOWN,true,"Memory leaks detected"); 750 psFree(time); 751 752 // Verify convert for valid tm structure 753 tmTime = (struct tm*)psAlloc(sizeof(struct tm)); 754 tmTime->tm_year = testTime8TmYear; 755 tmTime->tm_mon = testTime8TmMon; 756 tmTime->tm_mday = testTime8TmDay; 757 tmTime->tm_hour = testTime8TmHour; 758 tmTime->tm_min = testTime8TmMin; 759 tmTime->tm_sec = testTime8TmSec; 760 time = p_psTimeFromTM(tmTime); 761 if(time == NULL) { 762 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return value for valid tm structure"); 763 return 2; 764 } 765 if(time->sec != testTime8Seconds) { 766 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 767 (long int)time->sec, (long int)testTime8Seconds); 768 return 3; 769 } 770 if(time->nsec != testTime8Nanoseconds) { 771 psError(PS_ERR_UNKNOWN,true,"psTime nanoseconds %ld not as expected %ld", 772 time->nsec, testTime8Nanoseconds); 773 return 4; 774 } 775 psFree(tmTime); 776 psFree(time); 777 778 return 0; 779 } 780 781 psS32 testTimeConvert(void) 782 { 783 psTime* time1 = NULL; 784 psTime* time2 = NULL; 785 786 // Attempt to convert NULL time 787 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 788 time2 = psTimeConvert(time1,PS_TIME_TAI); 789 // Verify return value is NULL 790 if(time2 != NULL) { 791 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL time specified"); 792 return 1; 793 } 794 795 // Attempt to convert to invalid type 796 time1 = psTimeAlloc(PS_TIME_TAI); 797 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 798 time2 = psTimeConvert(time1,-100); 799 // Verify return value is NULL 800 if(time2 != time1) { 801 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 802 return 2; 803 } 804 time1->type = PS_TIME_UTC; 805 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 806 time2 = psTimeConvert(time1,-100); 807 // Verify return value is NULL 808 if(time2 != time1) { 809 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 810 return 2; 811 } 812 time1->type = PS_TIME_TT; 813 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 814 time2 = psTimeConvert(time1,-100); 815 // Verify return value is NULL 816 if(time2 != time1) { 817 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 818 return 2; 819 } 820 time1->type = -100; 821 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 822 time2 = psTimeConvert(time1,PS_TIME_TAI); 823 // Verify return value is NULL 824 if(time2 != time1) { 825 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 826 return 2; 827 } 828 829 // Attempt to convert with invalid time nsec > 1e9 830 time1->nsec = 2e9; 831 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 832 time2 = psTimeConvert(time1,PS_TIME_TAI); 833 if(time2 != time1) { 834 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid time specified"); 835 return 3; 836 } 837 838 //Attempt to convert a time to the same type 839 time2 = NULL; 840 time1->sec = 1; 841 time1->nsec = 2; 842 time1->type = PS_TIME_TAI; 843 time1->leapsecond = false; 844 time2 = psTimeConvert(time1,PS_TIME_TAI); 845 if(time2 != time1) { 846 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion to same type"); 847 return 4; 848 } 849 // Verify time not changed 850 if((time2->sec != 1) || (time2->nsec != 2) || (time2->type != PS_TIME_TAI) || 851 (time2->leapsecond != false) ) { 852 psError(PS_ERR_UNKNOWN,true,"Time member changes when no change expected"); 853 return 5; 854 } 855 856 // Attempt to convert a UTC time to a TAI 857 time2 = NULL; 858 time1->sec = testTime1SecondsUTC; 859 time1->nsec = testTime1NanosecondsUTC; 860 time1->type = PS_TIME_UTC; 861 time1->leapsecond = false; 862 time2 = psTimeConvert(time1,PS_TIME_TAI); 863 if(time2 != time1) { 864 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UTC to TAI"); 865 return 6; 866 } 867 // Verify time type 868 if(time2->type != PS_TIME_TAI) { 869 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 870 time2->type, PS_TIME_TAI); 871 return 7; 872 } 873 // Verify time is TAI as expected 874 if(time2->sec != testTime1SecondsTAI) { 875 psError(PS_ERR_UNKNOWN,true,"TAI seconds = %ld not as expected %ld",(long int)time2->sec, 876 (long int)testTime1SecondsTAI); 877 return 7; 878 } 879 if(time2->nsec != testTime1NanosecondsTAI) { 880 psError(PS_ERR_UNKNOWN,true,"TAI nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 881 (long int)testTime1NanosecondsTAI); 882 return 8; 883 } 884 885 // Attempt to convert a UTC time to a TT 886 time2 = NULL; 887 time1->sec = testTime1SecondsUTC; 888 time1->nsec = testTime1NanosecondsUTC; 889 time1->type = PS_TIME_UTC; 890 time1->leapsecond = false; 891 time2 = psTimeConvert(time1,PS_TIME_TT); 892 if(time2 != time1) { 893 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UTC to TT"); 894 return 6; 895 } 896 // Verify time type 897 if(time2->type != PS_TIME_TT) { 898 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 899 time2->type, PS_TIME_TT); 900 return 7; 901 } 902 // Verify time is TT as expected 903 if(time2->sec != testTime1SecondsTT) { 904 psError(PS_ERR_UNKNOWN,true,"TT seconds = %ld not as expected %ld",(long int)time2->sec, 905 (long int)testTime1SecondsTT); 906 return 7; 907 } 908 if(time2->nsec != testTime1NanosecondsTT) { 909 psError(PS_ERR_UNKNOWN,true,"TT nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 910 (long int)testTime1NanosecondsTT); 911 return 8; 912 } 913 914 // Attempt to convert a UTC time to UT1 915 time2 = NULL; 916 time1->sec = testTime1SecondsUTC; 917 time1->nsec = testTime1NanosecondsUTC; 918 time1->type = PS_TIME_UTC; 919 time1->leapsecond = false; 920 time2 = psTimeConvert(time1,PS_TIME_UT1); 921 if(time1 != time2) { 922 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UTC to UT1"); 923 return 9; 924 } 925 // Verify time type 926 if(time2->type != PS_TIME_UT1) { 927 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 928 time2->type, PS_TIME_UT1); 929 return 7; 930 } 931 // Verify time is UT1 as expected 932 if(time2->sec != testTime1SecondsUT1) { 933 psError(PS_ERR_UNKNOWN,true,"UT1 seconds = %ld not as expected %ld",(long int)time2->sec, 934 (long int)testTime1SecondsUT1); 935 return 9; 936 } 937 if(time2->nsec != testTime1NanosecondsUT1) { 938 psError(PS_ERR_UNKNOWN,true,"UT1 nanoseconds = %d not as expected %d",time2->nsec, 939 testTime1NanosecondsUT1); 221 940 return 10; 222 941 } 223 psMemCheckCorruption(0); 224 psS32 nBad = psMemCheckCorruption(0); 225 if(nBad) { 226 printf("ERROR: Found %d bad memory blocks\n", nBad); 227 } 228 printFooter(stdout, "psMetadata", "Test P - Free data", true); 229 230 return 0; 231 } 942 943 // Attempt to convert a TAI time to UTC 944 time2 = NULL; 945 time1->sec = testTime1SecondsTAI; 946 time1->nsec = testTime1NanosecondsTAI; 947 time1->type = PS_TIME_TAI; 948 time1->leapsecond = false; 949 time2 = psTimeConvert(time1,PS_TIME_UTC); 950 if(time2 != time1) { 951 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TAI to UTC"); 952 return 11; 953 } 954 // Verify time type 955 if(time2->type != PS_TIME_UTC) { 956 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 957 time2->type, PS_TIME_UTC); 958 return 7; 959 } 960 // Verify time is UTC as expected 961 if(time2->sec != testTime1SecondsUTC) { 962 psError(PS_ERR_UNKNOWN,true,"UTC seconds = %ld not as expected %ld",(long int)time2->sec, 963 (long int)testTime1SecondsUTC); 964 return 12; 965 } 966 if(time2->nsec != testTime1NanosecondsUTC) { 967 psError(PS_ERR_UNKNOWN,true,"UTC nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 968 (long int)testTime1NanosecondsUTC); 969 return 13; 970 } 971 972 // Attempt to convert a TAI time to TT 973 time2 = NULL; 974 time1->sec = testTime1SecondsTAI; 975 time1->nsec = testTime1NanosecondsTAI; 976 time1->type = PS_TIME_TAI; 977 time1->leapsecond = false; 978 time2 = psTimeConvert(time1,PS_TIME_TT); 979 if(time2 != time1) { 980 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TAI to TT"); 981 return 14; 982 } 983 // Verify time type 984 if(time2->type != PS_TIME_TT) { 985 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 986 time2->type, PS_TIME_TT); 987 return 7; 988 } 989 // Verify time is TT as expected 990 if(time2->sec != testTime1SecondsTT) { 991 psError(PS_ERR_UNKNOWN,true,"TT seconds = %ld not as expected %ld",(long int)time2->sec, 992 (long int)testTime1SecondsTT); 993 return 15; 994 } 995 if(time2->nsec != testTime1NanosecondsTT) { 996 psError(PS_ERR_UNKNOWN,true,"TT nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 997 (long int)testTime1NanosecondsTT); 998 return 16; 999 } 1000 1001 // Attempt to convert a TAI time to UT1 1002 time2 = NULL; 1003 time1->sec = testTime1SecondsTAI; 1004 time1->nsec = testTime1NanosecondsTAI; 1005 time1->type = PS_TIME_TAI; 1006 time1->leapsecond = false; 1007 time2 = psTimeConvert(time1,PS_TIME_UT1); 1008 if(time1 != time2) { 1009 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TAI to UT1"); 1010 return 9; 1011 } 1012 // Verify time type 1013 if(time2->type != PS_TIME_UT1) { 1014 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1015 time2->type, PS_TIME_UT1); 1016 return 7; 1017 } 1018 // Verify time is UT1 as expected 1019 if(time2->sec != testTime1SecondsUT1) { 1020 psError(PS_ERR_UNKNOWN,true,"UT1 seconds = %ld not as expected %ld",(long int)time2->sec, 1021 (long int)testTime1SecondsUT1); 1022 return 9; 1023 } 1024 if(time2->nsec != testTime1NanosecondsUT1) { 1025 psError(PS_ERR_UNKNOWN,true,"UT1 nanoseconds = %d not as expected %d",time2->nsec, 1026 testTime1NanosecondsUT1); 1027 return 10; 1028 } 1029 1030 // Attempt to convert a TT time to UTC 1031 time2 = NULL; 1032 time1->sec = testTime1SecondsTT; 1033 time1->nsec = testTime1NanosecondsTT; 1034 time1->type = PS_TIME_TT; 1035 time1->leapsecond = false; 1036 time2 = psTimeConvert(time1,PS_TIME_UTC); 1037 if(time2 != time1) { 1038 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TT to UTC"); 1039 return 17; 1040 } 1041 // Verify time type 1042 if(time2->type != PS_TIME_UTC) { 1043 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1044 time2->type, PS_TIME_UTC); 1045 return 7; 1046 } 1047 // Verify time is UTC as expected 1048 if(time2->sec != testTime1SecondsUTC) { 1049 psError(PS_ERR_UNKNOWN,true,"UTC seconds = %ld not as expected %ld",(long int)time2->sec, 1050 (long int)testTime1SecondsUTC); 1051 return 18; 1052 } 1053 if(time2->nsec != testTime1NanosecondsUTC) { 1054 psError(PS_ERR_UNKNOWN,true,"UTC nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 1055 (long int)testTime1NanosecondsUTC); 1056 return 19; 1057 } 1058 1059 // Attempt to convert a TT time to TAI 1060 time2 = NULL; 1061 time1->sec = testTime1SecondsTT; 1062 time1->nsec = testTime1NanosecondsTT; 1063 time1->type = PS_TIME_TT; 1064 time1->leapsecond = false; 1065 time2 = psTimeConvert(time1,PS_TIME_TAI); 1066 if(time2 != time1) { 1067 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TT to TAI"); 1068 return 20; 1069 } 1070 // Verify time type 1071 if(time2->type != PS_TIME_TAI) { 1072 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1073 time2->type, PS_TIME_TAI); 1074 return 7; 1075 } 1076 // Verify time is TAI as expected 1077 if(time2->sec != testTime1SecondsTAI) { 1078 psError(PS_ERR_UNKNOWN,true,"TAI seconds = %ld not as expected %ld",(long int)time2->sec, 1079 (long int)testTime1SecondsTAI); 1080 return 21; 1081 } 1082 if(time2->nsec != testTime1NanosecondsTAI) { 1083 psError(PS_ERR_UNKNOWN,true,"TT nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 1084 (long int)testTime1NanosecondsTAI); 1085 return 22; 1086 } 1087 1088 // Attempt to convert a TT time to UT1 1089 time2 = NULL; 1090 time1->sec = testTime1SecondsTT; 1091 time1->nsec = testTime1NanosecondsTT; 1092 time1->type = PS_TIME_TT; 1093 time1->leapsecond = false; 1094 time2 = psTimeConvert(time1,PS_TIME_UT1); 1095 if(time1 != time2) { 1096 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TT to UT1"); 1097 return 9; 1098 } 1099 // Verify time type 1100 if(time2->type != PS_TIME_UT1) { 1101 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1102 time2->type, PS_TIME_UT1); 1103 return 7; 1104 } 1105 // Verify time is UT1 as expected 1106 if(time2->sec != testTime1SecondsUT1) { 1107 psError(PS_ERR_UNKNOWN,true,"UT1 seconds = %ld not as expected %ld",(long int)time2->sec, 1108 (long int)testTime1SecondsUT1); 1109 return 9; 1110 } 1111 if(time2->nsec != testTime1NanosecondsUT1) { 1112 psError(PS_ERR_UNKNOWN,true,"UT1 nanoseconds = %d not as expected %d",time2->nsec, 1113 testTime1NanosecondsUT1); 1114 return 10; 1115 } 1116 1117 // Attempt to convert from UT1 to TAI, UTC, TT 1118 time2 = NULL; 1119 time1->sec = 1; 1120 time1->nsec = 2; 1121 time1->type = PS_TIME_UT1; 1122 time1->leapsecond = false; 1123 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message converting from UT1"); 1124 time2 = psTimeConvert(time1,PS_TIME_UTC); 1125 if(time2 != time1) { 1126 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UT1"); 1127 return 23; 1128 } 1129 1130 psFree(time1); 1131 1132 return 0; 1133 } 1134 1135 //psS32 testTimeOther(void) 1136 //{ 1137 // psTime *testTime; 1138 // char *testString = "2004-07-21T18:22:24.272Z"; 1139 // 1140 // psLibInit(true,"psTime.config"); 1141 // 1142 // Test time was taken at July 21, 2004 at 18:22:24.272044 1143 // testTime = (psTime*)psAlloc(sizeof(psTime)); 1144 // testTime->sec = 1090434144; 1145 // testTime->nsec = 272044000; 1146 // testTime->type = PS_TIME_TAI; 1147 1148 // Test O - psTime to LMST 1149 // printPositiveTestHeader(stdout, "psTime", "Convert psTime time to LST"); 1150 // char *testString2 = "2004-09-10T1:00:00.00Z"; 1151 // psTime* testTime2 = NULL; 1152 // testTime2 = psTimeFromISO(testString2); 1153 // double dblTime = psTimeToLMST(testTime2, 1); 1154 // printf("LST (rad): %lf\n", dblTime); 1155 // psFree(testTime2); 1156 // printFooter(stdout, "psTime", "Convert psTime time to LST", true); 1157 1158 1159 // return 0; 1160 //}
Note:
See TracChangeset
for help on using the changeset viewer.
