Changeset 2273 for trunk/psLib/src/astronomy
- Timestamp:
- Nov 3, 2004, 3:05:00 PM (22 years ago)
- Location:
- trunk/psLib/src/astronomy
- Files:
-
- 7 edited
-
psAstrometry.c (modified) (3 diffs)
-
psAstronomyErrors.dat (modified) (1 diff)
-
psAstronomyErrors.h (modified) (2 diffs)
-
psCoord.c (modified) (8 diffs)
-
psMetadata.c (modified) (25 diffs)
-
psMetadataIO.c (modified) (23 diffs)
-
psTime.c (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psAstrometry.c
r2222 r2273 8 8 * @author George Gusciora, MHPCC 9 9 * 10 * @version $Revision: 1. 49$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-1 0-27 23:49:00$10 * @version $Revision: 1.50 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-11-04 01:04:57 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 25 25 #include "psError.h" 26 26 #include "psConstants.h" 27 #include "psAstronomyErrors.h" 28 27 29 #include "slalib.h" 28 30 … … 868 870 // generate an error if cell->toTP is not linear. 869 871 if (0 == isProjectionLinear(cell->toTP)) { 870 psError(__func__, "the cell->toTP transfrom is not linear.\n"); 872 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 873 PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM, 874 "cell to tangent plane"); 871 875 } 872 876 -
trunk/psLib/src/astronomy/psAstronomyErrors.dat
r2204 r2273 7 7 # N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME 8 8 #################################################################### 9 psTime_FILE_NOT_FOUND Failed to open file %s. No %s information is available. 10 psTime_FILE_TOO_MANY_ROWS Too many rows found in file %s. Max number of rows allowed is %d. 11 psTime_TIME_POSTDATES_TABLE Specified psTime postdates (%g) the table of %s information. 12 psTime_TIME_PREDATES_TABLE Specified psTime predates (%g) the table of %s information. 13 psTime_TABLE_DUPLICATE_ROWS The %s table was found to have two rows of the same time value. 14 psTime_TYPE_UNKNOWN Specified type, %d, is not supported. 15 psTime_TYPE_MISMATCH Specified psTime parameters must have same type. 16 psTime_GET_TOD_FAILED Failed to determine the current time from gettimeofday function. 17 psTime_CONVERT_TIME_TO_STRING_FAILED Failed to convert a time via strftime function. 18 psTime_APPEND_MSEC_FAILED Failed to append millisecond to time string with snprintf function. 19 psTime_USEC_INVALID The psTime usec attribute value, %u, is invalid. Must be less than 1e6. 20 psTime_ISOTIME_MALFORMED Specified ISO Time string, '%s', is malformed. Must be in 'YYYY-MM-DDThh:mm:ss.sss' format. 21 # 22 psCoord_PROJECTION_TYPE_UNDEFINED The projection type, %s, is undefined. 23 psCoord_PROJECTION_TYPE_UNKNOWN The projection type, %d, is unknown. 24 psCoord_UNITS_UNKNOWN Specified units, 0x%x, is not supported. 25 psCoord_OFFSET_MODE_UNKNOWN Specified offset mode, 0x%x, is not supported. 26 # 27 psAstrometry_NONLINEAR_TRANSFORM The %s transfrom is not linear. Only linear transforms are supported. 28 # 29 psMetadata_METATYPE_INVALID Specified psMetadataType, %d, is not supported. 30 psMetadata_ADD_LIST_FAILED Failed to add metadata item, %s, to items list. 31 psMetadata_ADD_TABLE_FAILED Failed to add metadata item, %s, to items table. 32 psMetadata_REMOVE_LIST_FAILED Failed to remove metadata item, %s, from metadata list. 33 psMetadata_REMOVE_LIST_INDEX_FAILED Failed to remove metadata item, at index %d, from metadata list. 34 psMetadata_REMOVE_TABLE_FAILED Failed to remove metadata item, %s, from metadata table. 35 psMetadata_ADD_COLLECTION_FAILED Failed to add metadata item, %s, to metadata collection list. 36 psMetadata_ADD_FAILED Failed to add metadata item to metadata collection list. 37 psMetadata_FIND_FAILED Could not find metadata item, %s. 38 psMetadata_FIND_INDEX_FAILED Could not find metadata item at index %d. 39 # 40 psMetadataIO_TYPE_INVALID Specified type, %d, is not supported. 41 psMetadataIO_EXTNUM_NOTPOSITIVE Specified extension number, %d, is invalid. Value must be positive if no extension name is given. 42 psMetadataIO_FITS_METATYPE_INVALID Specified FITS metadata type, %c, is not supported. 43 psMetadataIO_ADD_FAILED Failed to add metadata item, %s. 44 psMetadataIO_FILE_OPEN_FAILED Failed to open file '%s'. Check if it exists and it has the proper permissions. 45 psMetadataIO_FILE_MULTIPLE_CHAR More than one '%c' character not allowed. Found on line %d of %s. 46 psMetadataIO_FILE_ELEMENT_NULL Failed to read a metadata %s on line %d of %s. 47 psMetadataIO_FILE_TYPE_INVALID Metadata type '%s', found on line %d of %s, is not invalid. 48 psMetadataIO_OVERWRITE_ITEM Duplicate Metadata item, %s, found on line %d of %s. Overwrite not allowed. 49 psMetadataIO_PARSE_FAILED Failed to parse the value '%s' of metadata item %s, type %s, on line %d of %s. 50 51 -
trunk/psLib/src/astronomy/psAstronomyErrors.h
r2210 r2273 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-1 0-27 19:35:55$9 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-11-04 01:04:57 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 31 31 //~Start #define PS_ERRORTEXT_$1 "$2" 32 #define PS_ERRORTEXT_psTime_FILE_NOT_FOUND "Failed to open file %s. No %s information is available." 33 #define PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS "Too many rows found in file %s. Max number of rows allowed is %d." 34 #define PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE "Specified psTime postdates (%g) the table of %s information." 35 #define PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE "Specified psTime predates (%g) the table of %s information." 36 #define PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS "The %s table was found to have two rows of the same time value." 37 #define PS_ERRORTEXT_psTime_TYPE_UNKNOWN "Specified type, %d, is not supported." 38 #define PS_ERRORTEXT_psTime_TYPE_MISMATCH "Specified psTime parameters must have same type." 39 #define PS_ERRORTEXT_psTime_GET_TOD_FAILED "Failed to determine the current time from gettimeofday function." 40 #define PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED "Failed to convert a time via strftime function." 41 #define PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED "Failed to append millisecond to time string with snprintf function." 42 #define PS_ERRORTEXT_psTime_USEC_INVALID "The psTime usec attribute value, %u, is invalid. Must be less than 1e6." 43 #define PS_ERRORTEXT_psTime_ISOTIME_MALFORMED "Specified ISO Time string, '%s', is malformed. Must be in 'YYYY-MM-DDThh:mm:ss.sss' format." 44 #define PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED "The projection type, %s, is undefined." 45 #define PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNKNOWN "The projection type, %d, is unknown." 46 #define PS_ERRORTEXT_psCoord_UNITS_UNKNOWN "Specified units, 0x%x, is not supported." 47 #define PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN "Specified offset mode, 0x%x, is not supported." 48 #define PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM "The %s transfrom is not linear. Only linear transforms are supported. " 49 #define PS_ERRORTEXT_psMetadata_METATYPE_INVALID "Specified psMetadataType, %d, is not supported." 50 #define PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED "Failed to add metadata item, %s, to items list." 51 #define PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED "Failed to add metadata item, %s, to items table." 52 #define PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED "Failed to remove metadata item, %s, from metadata list." 53 #define PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED "Failed to remove metadata item, at index %d, from metadata list." 54 #define PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED "Failed to remove metadata item, %s, from metadata table." 55 #define PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED "Failed to add metadata item, %s, to metadata collection list." 56 #define PS_ERRORTEXT_psMetadata_ADD_FAILED "Failed to add metadata item to metadata collection list." 57 #define PS_ERRORTEXT_psMetadata_FIND_FAILED "Could not find metadata item, %s." 58 #define PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED "Could not find metadata item at index %d." 59 #define PS_ERRORTEXT_psMetadataIO_TYPE_INVALID "Specified type, %d, is not supported." 60 #define PS_ERRORTEXT_psMetadataIO_EXTNUM_NOTPOSITIVE "Specified extension number, %d, is invalid. Value must be positive if no extension name is given." 61 #define PS_ERRORTEXT_psMetadataIO_FITS_METATYPE_INVALID "Specified FITS metadata type, %c, is not supported." 62 #define PS_ERRORTEXT_psMetadataIO_ADD_FAILED "Failed to add metadata item, %s." 63 #define PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED "Failed to open file '%s'. Check if it exists and it has the proper permissions." 64 #define PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR "More than one '%c' character not allowed. Found on line %d of %s." 65 #define PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL "Failed to read a metadata %s on line %d of %s." 66 #define PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID "Metadata type '%s', found on line %d of %s, is not invalid." 67 #define PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM "Duplicate Metadata item, %s, found on line %d of %s. Overwrite not allowed." 68 #define PS_ERRORTEXT_psMetadataIO_PARSE_FAILED "Failed to parse the value '%s' of metadata item %s, type %s, on line %d of %s." 32 69 //~End 33 70 -
trunk/psLib/src/astronomy/psCoord.c
r2221 r2273 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1.3 2$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-1 0-27 23:31:43$12 * @version $Revision: 1.33 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-11-04 01:04:57 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include "psConstants.h" 28 28 #include "psError.h" 29 #include "psAstronomyErrors.h" 29 30 #include <math.h> 30 31 #include <float.h> … … 278 279 279 280 } else if (projection->type == PS_PROJ_PAR) { 280 psError(__func__, "The projection type PS_PROJ_PAR is undefined.\n"); 281 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 282 PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED, 283 "PS_PROJ_PAR"); 281 284 282 285 } else if (projection->type == PS_PROJ_GLS) { 283 psError(__func__, "The projection type PS_PROJ_GLS is undefined.\n"); 286 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 287 PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED, 288 "PS_PROJ_GLS"); 284 289 } else { 285 psError(__func__, "Unknown projection type.\n"); 290 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 291 PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNKNOWN, 292 projection->type); 286 293 } 287 294 … … 333 340 334 341 } else if (projection->type == PS_PROJ_PAR) { 335 psError(__func__, "The projection type PS_PROJ_PAR is undefined.\n"); 342 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 343 PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED, 344 "PS_PROJ_PAR"); 336 345 337 346 } else if (projection->type == PS_PROJ_GLS) { 338 psError(__func__, "The projection type PS_PROJ_GLG is undefined.\n"); 347 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 348 PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED, 349 "PS_PROJ_GLS"); 339 350 } else { 340 psError(__func__, "Unknown projection type.\n"); 351 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 352 PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNKNOWN, 353 projection->type); 341 354 } 342 355 … … 407 420 } else if (unit == PS_RADIAN) {} 408 421 else { 409 psError(__func__, "Unknown offset unit: 0x%x\n", unit); 422 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 423 PS_ERRORTEXT_psCoord_UNITS_UNKNOWN, 424 unit); 410 425 } 411 426 … … 413 428 } 414 429 415 psError(__func__, "Unrecognized offset mode\n"); 430 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 431 PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN, 432 mode); 416 433 return (NULL); 417 434 } … … 469 486 tmpD = offset->d; 470 487 } else { 471 psError(__func__, "Unknown offset unit: 0x%x\n", unit); 488 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 489 PS_ERRORTEXT_psCoord_UNITS_UNKNOWN, 490 unit); 472 491 } 473 492 … … 483 502 } 484 503 485 psError(__func__, "Unrecognized offset mode\n"); 504 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 505 PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN, 506 mode); 507 486 508 return (NULL); 487 509 } -
trunk/psLib/src/astronomy/psMetadata.c
r2204 r2273 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-1 0-27 00:57:30$14 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-11-04 01:04:57 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 #include "psMetadata.h" 36 36 #include "psString.h" 37 #include "psAstronomyErrors.h" 38 #include "psConstants.h" 37 39 38 40 /******************************************************************************/ … … 123 125 124 126 125 if (name == NULL) { 126 psError(__func__, "Null value for name not allowed"); 127 return NULL; 128 } 127 PS_PTR_CHECK_NULL(name,NULL); 128 129 129 // Allocate metadata item 130 130 metadataItem = (psMetadataItem* ) psAlloc(sizeof(psMetadataItem)); … … 147 147 // Set metadata item type 148 148 metadataItem->type = type; 149 metadataItem->data.V = NULL; 150 151 // Allocate metadata items with same name. 152 metadataItem->items = psListAlloc(NULL); 153 154 // Allocate and set metadata item name 155 metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 156 vsprintf(metadataItem->name, name, argPtr); 149 157 150 158 // Set metadata item value 151 159 switch (type) { 152 160 case PS_META_ITEM_SET: 153 metadataItem->data.V = NULL;154 161 break; 155 162 case PS_META_BOOL: … … 180 187 case PS_META_UNKNOWN: 181 188 default: 182 psError(__func__, "Invalid psMetadataType: %d", type); 183 } 184 185 // Allocate and set metadata item name 186 metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 187 vsprintf(metadataItem->name, name, argPtr); 188 189 // Allocate metadata items with same name. 190 metadataItem->items = psListAlloc(NULL); 189 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 190 PS_ERRORTEXT_psMetadata_METATYPE_INVALID, 191 type); 192 psFree(metadataItem); 193 metadataItem = NULL; 194 } 191 195 192 196 return metadataItem; … … 224 228 psMetadataType newType = PS_META_ITEM_SET; 225 229 226 if(md == NULL) { 227 psError( __func__, "Null metadata collection not allowed" ); 228 return false; 229 } 230 231 if(metadataItem == NULL) { 232 psError( __func__, "Null metadata item not allowed" ); 233 return false; 234 } 230 PS_PTR_CHECK_NULL(md,NULL); 231 PS_PTR_CHECK_NULL(md->table,NULL); 232 PS_PTR_CHECK_NULL(md->list,NULL); 233 PS_PTR_CHECK_NULL(metadataItem,NULL); 234 PS_PTR_CHECK_NULL(metadataItem->name,NULL); 235 235 236 236 newType = metadataItem->type; 237 238 237 mdTable = md->table; 239 if(mdTable == NULL) {240 psError( __func__, "Null metadata table not allowed" );241 return false;242 }243 244 238 mdList = md->list; 245 if(mdList == NULL) {246 psError( __func__, "Null metadata list not allowed");247 return false;248 }249 250 239 key = metadataItem->name; 251 if(key == NULL) {252 psError(__func__, "Null key item not allowed");253 return false;254 }255 240 256 241 // See if key is already in table … … 262 247 // Add leaf node to existing folder node 263 248 if(!psListAdd(existingEntry->items, PS_LIST_TAIL, metadataItem)) { 264 psError( __func__, "Couldn't add metadata item to items list. Name: %s", 265 metadataItem->name ); 249 psError(PS_ERR_UNKNOWN,false, 250 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 251 metadataItem->name ); 266 252 return false; 267 253 } … … 272 258 273 259 if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, existingEntry)) { 274 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 260 psError(PS_ERR_UNKNOWN,false, 261 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 262 key); 275 263 psFree(newFolderEntry); 276 264 return false; … … 278 266 279 267 if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, metadataItem)) { 280 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 268 psError(PS_ERR_UNKNOWN,false, 269 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 270 key); 281 271 psFree(newFolderEntry); 282 272 return false; … … 284 274 285 275 if(!psHashRemove(mdTable, key)) { 286 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 276 psError(PS_ERR_UNKNOWN,false, 277 PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, 278 key); 287 279 psFree(newFolderEntry); 288 280 return false; … … 290 282 291 283 if(!psHashAdd(mdTable, key, newFolderEntry)) { 292 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 284 psError(PS_ERR_UNKNOWN,false, 285 PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED, 286 key); 293 287 psFree(newFolderEntry); 294 288 return false; … … 301 295 // Folder node replaces leaf or folder node - Put old node into new folder and remove from table 302 296 if(!psListAdd(metadataItem->items, PS_LIST_TAIL, existingEntry)) { 303 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key); 297 psError(PS_ERR_UNKNOWN,false, 298 PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED, 299 key); 304 300 return false; 305 301 } 306 302 307 303 if(!psHashRemove(mdTable, key)) { 308 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key); 304 psError(PS_ERR_UNKNOWN,false, 305 PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, 306 key); 309 307 return false; 310 308 } 311 309 312 310 if(!psHashAdd(mdTable, key, metadataItem)) { 313 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 311 psError(PS_ERR_UNKNOWN,false, 312 PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED, 313 key); 314 314 return false; 315 315 } … … 319 319 // Node doesn't exist - Add new metadata item to metadata collection's hash 320 320 if(!psHashAdd(mdTable, key, metadataItem)) { 321 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key); 321 psError(PS_ERR_UNKNOWN,false, 322 PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED, 323 key); 322 324 return false; 323 325 } … … 328 330 if(metadataItem->type != PS_META_ITEM_SET) { 329 331 if(!psListAdd(mdList, location, metadataItem)) { 330 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s", 331 metadataItem->name ); 332 psError(PS_ERR_UNKNOWN,false, 333 PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED, 334 key); 332 335 return false; 333 336 } … … 348 351 349 352 if (!psMetadataAddItem(md, metadataItem, where)) { 350 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",351 metadataItem->name);353 psError(PS_ERR_UNKNOWN,false, 354 PS_ERRORTEXT_psMetadata_ADD_FAILED); 352 355 psFree(metadataItem); 353 356 return false; … … 368 371 369 372 370 if (md == NULL) { 371 psError(__func__, "Null metadata collection not allowed"); 372 return false; 373 } 373 PS_PTR_CHECK_NULL(md,NULL); 374 PS_PTR_CHECK_NULL(md->table,NULL); 375 PS_PTR_CHECK_NULL(md->list,NULL); 374 376 375 377 mdList = md->list; 376 if (mdList == NULL) {377 psError(__func__, "Null metadata list not allowed");378 return false;379 }380 381 378 mdTable = md->table; 382 if (mdTable == NULL) { 383 psError(__func__, "Null metadata table not allowed"); 384 return false; 385 } 379 386 380 // Select removal by key or index 387 381 if (key != NULL) { … … 390 384 entry = (psMetadataItem* ) psHashLookup(mdTable, key); 391 385 if (entry == NULL) { 392 psError(__func__, "Couldn't find metadata item. Name: %s", key); 386 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 387 PS_ERRORTEXT_psMetadata_FIND_FAILED, 388 key); 393 389 return false; 394 390 } … … 402 398 while (entryChild != NULL) { 403 399 if (!psListRemove(mdList, PS_LIST_UNKNOWN, entryChild)) { 404 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key); 400 psError(PS_ERR_UNKNOWN,false, 401 PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED, 402 key); 405 403 return false; 406 404 } … … 411 409 // Table entry has no children. Remove entry from metadata collection's list 412 410 if (!psListRemove(mdList, PS_LIST_UNKNOWN, entry)) { 413 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key); 411 psError(PS_ERR_UNKNOWN,false, 412 PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED, 413 key); 414 414 return false; 415 415 } … … 417 417 // Remove entry from metadata collection's table 418 418 if (!psHashRemove(mdTable, key)) { 419 psError(__func__, "Couldn't remove metadata item from table. Name: %s", key); 419 psError(PS_ERR_UNKNOWN,false, 420 PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, 421 key); 420 422 return false; 421 423 } … … 425 427 entry = psListGet(mdList, where); 426 428 if (entry == NULL) { 427 psError(__func__, "Couldn't find metadata item in list. Index: %d", where); 429 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 430 PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED, 431 where); 428 432 return false; 429 433 } … … 431 435 key = entry->name; 432 436 if (key == NULL) { 433 psError(__func__, "Null key name not allowed. Index: %d", where); 437 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 438 PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED, 439 where); 434 440 return false; 435 441 } … … 447 453 448 454 449 if (md == NULL) { 450 psError(__func__, "Null metadata collection not allowed"); 451 return NULL; 452 } 455 PS_PTR_CHECK_NULL(md,NULL); 456 PS_PTR_CHECK_NULL(md->table,NULL); 457 PS_PTR_CHECK_NULL(key,NULL); 453 458 454 459 mdTable = md->table; 455 if (mdTable == NULL) {456 psError(__func__, "Null metadata table not allowed");457 return NULL;458 }459 460 if (key == NULL) {461 psError(__func__, "Null key name not allowed");462 return NULL;463 }464 460 465 461 entry = (psMetadataItem* ) psHashLookup(mdTable, key); … … 473 469 psMetadataItem* psMetadataGet(psMetadata* restrict md, psS32 where) 474 470 { 471 psMetadataItem* entry = NULL; 472 473 PS_PTR_CHECK_NULL(md,NULL); 474 PS_PTR_CHECK_NULL(md->list,NULL); 475 476 entry = (psMetadataItem* ) psListGet(md->list, where); 477 if (entry == NULL) { 478 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 479 PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED, 480 where); 481 return NULL; 482 } 483 484 return entry; 485 } 486 487 psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where) 488 { 489 PS_PTR_CHECK_NULL(md,NULL); 490 PS_PTR_CHECK_NULL(md->list,NULL); 491 492 psListSetIterator(md->list, where); 493 494 return true; 495 } 496 497 psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which) 498 { 475 499 psList* mdList = NULL; 476 500 psMetadataItem* entry = NULL; 477 501 478 502 479 if (md == NULL) { 480 psError(__func__, "Null metadata collection not allowed"); 481 return NULL; 482 } 503 PS_PTR_CHECK_NULL(md,NULL); 504 PS_PTR_CHECK_NULL(md->list,NULL); 483 505 484 506 mdList = md->list; 485 if (mdList == NULL) {486 psError(__func__, "Null metadata list not allowed");487 return NULL;488 }489 490 entry = (psMetadataItem* ) psListGet(mdList, where);491 if (entry == NULL) {492 psError(__func__, "Couldn't find metadata item with given index. Index: %d", where);493 return NULL;494 }495 496 return entry;497 }498 499 psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)500 {501 psList* mdList = NULL;502 503 if (md == NULL) {504 psError(__func__, "Null metadata collection not allowed");505 return false;506 }507 508 mdList = md->list;509 if (mdList == NULL) {510 psError(__func__, "Null metadata list not allowed");511 return false;512 }513 514 psListSetIterator(mdList, where);515 516 return true;517 }518 519 psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)520 {521 psList* mdList = NULL;522 psMetadataItem* entry = NULL;523 524 525 if (md == NULL) {526 psError(__func__, "Null metadata collection not allowed");527 return NULL;528 }529 530 mdList = md->list;531 if (mdList == NULL) {532 psError(__func__, "Null metadata list not allowed");533 return NULL;534 }535 507 536 508 psListSetIterator(mdList, which); … … 559 531 560 532 561 if (md == NULL) { 562 psError(__func__, "Null metadata collection not allowed"); 563 return NULL; 564 } 533 PS_PTR_CHECK_NULL(md,NULL); 534 PS_PTR_CHECK_NULL(md->list,NULL); 565 535 566 536 mdList = md->list; 567 if (mdList == NULL) {568 psError(__func__, "Null metadata list not allowed");569 return NULL;570 }571 537 572 538 psListSetIterator(mdList, which); -
trunk/psLib/src/astronomy/psMetadataIO.c
r2204 r2273 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-1 0-27 00:57:30$11 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-04 01:04:57 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 29 29 #include "psMetadata.h" 30 30 #include "psMetadataIO.h" 31 #include "psConstants.h" 32 #include "psAstronomyErrors.h" 31 33 32 34 … … 38 40 #define FITS_ERROR(STRING,PS_ERROR) \ 39 41 fits_get_errstatus(status, fitsErr); \ 40 psError( __func__, STRING, PS_ERROR, fitsErr); \42 psError(PS_ERR_IO,true, STRING, PS_ERROR, fitsErr); \ 41 43 status = 0; \ 42 44 fits_close_file(fd, &status); \ 43 45 if(status){ \ 44 46 fits_get_errstatus(status, fitsErr); \ 45 psError( __func__, "Couldn't close FITS file. FITS error: %s", fitsErr); \47 psError(PS_ERR_IO,true, "Couldn't close FITS file. FITS error: %s", fitsErr); \ 46 48 } \ 47 49 status = 0; \ … … 281 283 default: 282 284 *status = 1; 283 psError(__func__, "Invalid type: %d", elemType); 285 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 286 PS_ERRORTEXT_psMetadataIO_TYPE_INVALID, 287 elemType); 284 288 } 285 289 … … 302 306 psMetadataType type; 303 307 304 if (fd == NULL) { 305 psError(__func__, "Null file descriptor not allowed"); 306 return; 307 } 308 309 if (format == NULL) { 310 psError(__func__, "Null format not allowed"); 311 return; 312 } 313 314 if (metadataItem == NULL) { 315 psError(__func__, "Null metadata not allowed"); 316 return; 317 } 308 PS_PTR_CHECK_NULL(fd,); 309 PS_PTR_CHECK_NULL(format,); 310 PS_PTR_CHECK_NULL(metadataItem,); 318 311 319 312 type = metadataItem->type; … … 336 329 break; 337 330 default: 338 psError(__func__, " Invalid psMetadataType to print: %d", type); 331 psError(PS_ERR_BAD_PARAMETER_TYPE,true, 332 PS_ERRORTEXT_psMetadata_METATYPE_INVALID, 333 (int)type); 339 334 } 340 335 } … … 358 353 fitsfile *fd = NULL; 359 354 360 if(fileName == NULL) { 361 psError(__func__, "Null fileName not allowed"); 362 return NULL; 363 } 355 PS_PTR_CHECK_NULL(fileName,NULL); 364 356 365 357 fits_open_file(&fd, fileName, READONLY, &status); … … 369 361 } 370 362 371 if (extName == NULL && extNum == 0) { 372 psError(__func__, "Null extName and extNum = 0 not allowed"); 373 return NULL; 374 } else if (extName && (extNum != -1) ) { 375 psError(__func__, "If extName specified, extNum arguments should be -1."); 363 if (extName == NULL && extNum < 1) { 364 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 365 PS_ERRORTEXT_psMetadataIO_EXTNUM_NOTPOSITIVE, 366 extNum); 376 367 return NULL; 377 368 } … … 435 426 case 'X': 436 427 default: 437 psError(__func__, "Invalid psMetadataType: %c", keyType); 428 psError(PS_ERR_IO, true, 429 PS_ERRORTEXT_psMetadataIO_FITS_METATYPE_INVALID, 430 keyType); 438 431 return output; 439 432 } 440 433 441 434 if (!success) { 442 psError(__func__, "Failed to add metadata item. Name: %s", keyName); 435 psError(PS_ERR_UNKNOWN, false, 436 PS_ERRORTEXT_psMetadataIO_ADD_FAILED, 437 keyName); 443 438 return output; 444 439 } … … 471 466 472 467 // Check for nulls 473 if(fileName == NULL) {474 psError(__func__, "Null fileName not allowed");475 return -1;476 } else if((fp=fopen(fileName, "r")) == NULL) {477 psError(__func__, "Couldn't open file. Name: %s",fileName);468 PS_PTR_CHECK_NULL(fileName,-1); 469 if((fp=fopen(fileName, "r")) == NULL) { 470 psError(PS_ERR_IO, true, 471 PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED, 472 fileName); 478 473 return -1; 479 474 } … … 486 481 // Create reusable line for continuous read 487 482 line = (char*)psAlloc(MAX_STRING_LENGTH*sizeof(char)); 488 if (line == NULL) {489 psAbort(__func__, "Failed to allocate reusable line");490 }491 483 492 484 // While loop to parse the file … … 504 496 if(repeatedChars(linePtr, '@') > 1) { 505 497 failedLines++; 506 psError(__func__, "More than one @ charecter not allowed. Line %d: %s", lineCount, line); 498 psError(PS_ERR_IO, true, 499 PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR, 500 '@', lineCount, fileName); 507 501 continue; 508 502 } else if(repeatedChars(linePtr, '*') > 1) { 509 503 failedLines++; 510 psError(__func__, "More than one * charecter not allowed. Line %d: %s", lineCount, line); 504 psError(PS_ERR_IO, true, 505 PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR, 506 '*', lineCount, fileName); 511 507 continue; 512 508 } else if(repeatedChars(linePtr, '~') > 0) { 513 509 failedLines++; 514 psError(__func__, "Illegal character. Character:~ Line %d: %s", lineCount, line); 510 psError(PS_ERR_IO, true, 511 PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR, 512 '~', lineCount, fileName); 515 513 continue; 516 514 } … … 521 519 failedLines++; 522 520 status = 0; 523 psError(__func__, "Null name not allowed. Line %d: %s", lineCount, line); 521 psError(PS_ERR_IO, true, 522 PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, 523 "name",lineCount, fileName); 524 524 continue; 525 525 } … … 530 530 failedLines++; 531 531 status = 0; 532 psError(__func__, "Null type not allowed. Line %d: %s", lineCount, line); 532 psError(PS_ERR_IO, true, 533 PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, 534 "type",lineCount, fileName); 533 535 continue; 534 536 } else if(!strncmp(strType, "*", 1)) { … … 551 553 } else { 552 554 failedLines++; 553 psError(__func__, "Invalid psMetadataType. Type: %s Line %d: %s", strType, lineCount, line); 555 psError(PS_ERR_IO, true, 556 PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID, 557 strType, lineCount, fileName); 554 558 continue; 555 559 } … … 565 569 failedLines++; 566 570 status = 0; 567 psError(__func__, "Null value not allowed. Line %d: %s", lineCount, line); 571 psError(PS_ERR_IO, true, 572 PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, 573 "value",lineCount, fileName); 568 574 continue; 569 575 } … … 575 581 failedLines++; 576 582 status = 0; 577 psError(__func__, "Failed to parse comment. Line %d: %s", lineCount, line); 583 psError(PS_ERR_IO, true, 584 PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, 585 "comment",lineCount, fileName); 578 586 continue; 579 587 } … … 589 597 } else { 590 598 failedLines++; 591 psError(__func__, "Overwrite for name not allowed. Name: %s. Line %d: %s", strName, 592 lineCount, line); 599 psError(PS_ERR_IO, true, 600 PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, 601 strName, lineCount, fileName); 593 602 continue; 594 603 } … … 608 617 status = 0; 609 618 failedLines++; 610 psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line); 619 psError(PS_ERR_IO, true, 620 PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, 621 strValue, strName, strType, lineCount, fileName); 611 622 continue; 612 623 } … … 619 630 status = 0; 620 631 failedLines++; 621 psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line); 632 psError(PS_ERR_IO, true, 633 PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, 634 strValue, strName, strType, lineCount, fileName); 622 635 continue; 623 636 } … … 631 644 status = 0; 632 645 failedLines++; 633 psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line); 646 psError(PS_ERR_IO, true, 647 PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, 648 strValue, strName, strType, lineCount, fileName); 634 649 continue; 635 650 } … … 645 660 status = 0; 646 661 failedLines++; 647 psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line); 662 psError(PS_ERR_IO, true, 663 PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, 664 strValue, strName, strType, lineCount, fileName); 648 665 continue; 649 666 } … … 651 668 default: 652 669 failedLines++; 653 psError(__func__, "Invalid psMetadataType. Type: %d Line %d: %s", mdType, lineCount, line); 670 psError(PS_ERR_IO, true, 671 PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID, 672 mdType, lineCount, fileName); 654 673 continue; 655 674 } // switch -
trunk/psLib/src/astronomy/psTime.c
r2204 r2273 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-1 0-27 00:57:30$13 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-11-04 01:04:57 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 31 #include "psMetadata.h" 32 32 #include "psMetadataIO.h" 33 33 #include "psConstants.h" 34 34 #include "psAstronomyErrors.h" 35 35 … … 151 151 char line[LINESIZE]; 152 152 psS32 j = 0; 153 psS32 maxLines = 100 ;153 psS32 maxLines = 1000; 154 154 psF64 *ptr = NULL; 155 155 psImage *table = NULL; … … 159 159 fd=fopen(fileName, "r"); 160 160 if(fd==NULL) { 161 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName); 161 psError(PS_ERR_IO,true, 162 PS_ERRORTEXT_psTime_FILE_NOT_FOUND, 163 fileName,"Tai-Utc"); 162 164 return NULL; 163 165 } … … 168 170 while(fgets(line, LINESIZE, fd) != NULL) { 169 171 if(j>=maxLines) { 170 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines); 172 psError(PS_ERR_IO,true, 173 PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS, 174 fileName,maxLines); 171 175 return NULL; 172 176 psFree(table); … … 201 205 fd=fopen(fileName, "r"); 202 206 if(fd==NULL) { 203 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName); 207 psError(PS_ERR_IO,true, 208 PS_ERRORTEXT_psTime_FILE_NOT_FOUND, 209 fileName,"Ser7"); 204 210 return NULL ; 205 211 } … … 218 224 219 225 if(j>=maxLines) { 220 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines); 226 psError(PS_ERR_IO,true, 227 PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS, 228 fileName,maxLines); 221 229 return NULL; 222 230 psFree(table); … … 240 248 } 241 249 242 /* Not yet used...243 static psImage* readEopcFile(char *fileName)244 {245 char line[LINESIZE];246 psS32 i = 0;247 psS32 j = 0;248 psS32 maxLines = 2500;249 psImage *table = NULL;250 FILE *fd = NULL;251 252 253 fd=fopen(fileName, "r");254 if(fd==NULL) {255 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);256 return NULL ;257 }258 259 // Table shouldn't be larger than 2500 rows. All columns are read.260 table = psImageAlloc(11, maxLines, PS_TYPE_F64);261 for(i=0; i<3; i++) {262 if((fgets(line, LINESIZE, fd) != NULL)) {263 psError(__func__, " : Line %d - Error reading %s", __LINE__, fileName);264 }265 }266 267 while(fgets(line, LINESIZE, fd) != NULL) {268 if(j>=maxLines) {269 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);270 return NULL;271 psFree(table);272 }273 psF64 *ptr = table->data.F64[j++];274 sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",275 ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);276 }277 278 *(psU32 *)&table->numRows = j;279 280 return table;281 }282 283 static psImage* readFinalsFile(char *fileName)284 {285 char line[LINESIZE];286 psS32 j = 0;287 psS32 maxLines = 15000;288 psImage *table = NULL;289 FILE *fd = NULL;290 291 292 fd=fopen(fileName, "r");293 if(fd==NULL) {294 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);295 return NULL ;296 }297 298 // Table shouldn't be larger than 15000 rows. Select columns are read.299 table = psImageAlloc(6, maxLines, PS_TYPE_F64);300 while(fgets(line, LINESIZE, fd) != NULL) {301 if(j>=maxLines) {302 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);303 return NULL;304 psFree(table);305 }306 307 psF64 *ptr = table->data.F64[j++];308 ptr = table->data.F64[j++];309 310 // Sometimes there are blank entries in this table, so check for a space to determine if there is no entry311 if(*(line+7) == ' ') { // MJD312 *ptr = 0.0;313 } else {314 *ptr = atof(line+7);315 }316 317 if(*(line+18) == ' ') { // Polar motion X318 *(ptr+1) = 0.0;319 } else {320 *(ptr+1) = atof(line+18);321 }322 323 if(*(line+27) == ' ') { // Polar motion X error324 *(ptr+2) = 0.0;325 } else {326 *(ptr+2) = atof(line+27);327 }328 329 if(*(line+37) == ' ') { // Polar motion Y330 *(ptr+3) = 0.0;331 } else {332 *(ptr+3) = atof(line+37);333 }334 335 if(*(line+46) == ' ') { // Polar motion Y error336 *(ptr+4) = 0.0;337 } else {338 *(ptr+4) = atof(line+46);339 }340 341 if(*(line+58) == ' ') { // UT1-UTC342 *(ptr+5) = 0.0;343 } else {344 *(ptr+5) = atof(line+58);345 }346 }347 348 *(psU32 *)&table->numRows = j;349 350 return table;351 }352 */353 250 354 251 static double lookupTaiUtcTable(const psTime *time) … … 389 286 hiIdx++; 390 287 if(hiIdx >= numRows) { 391 psError(__func__, " : Line %d - High index too big. Value: %d", __LINE__, hiIdx); 288 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 289 PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE, 290 jd, "TAI-UTC"); 392 291 return 0.0; 393 292 } … … 395 294 loIdx = hiIdx--; 396 295 if(loIdx < 0) { 397 psError(__func__, " : Line %d - Low index too small. Value: %d", __LINE__, loIdx); 296 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 297 PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE, 298 jd, "TAI-UTC"); 398 299 return 0.0; 399 300 } 400 301 302 // since rows of table can not have same jd, this check is probably not needed. 401 303 denom = table->data.F64[hiIdx][0]-table->data.F64[loIdx][0]; 402 304 if(fabs(denom) < FLT_EPSILON) { 403 psError(__func__, " : Line %d - Divide by zero error during interpolation", __LINE__); 305 psError(PS_ERR_UNKNOWN,true, 306 PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS 307 "Ser7"); 404 308 return 0.0; 405 309 } else { 406 407 310 // Interpolate three constants required to calculate TAI-UTC 408 311 const1 = table->data.F64[loIdx][1]+(table->data.F64[hiIdx][1]-table->data.F64[loIdx][1]) … … 445 348 mjdUtc = psTimeToMJD(time); 446 349 if(mjdUtc < table->data.F64[0][3]) { // MJD time before start of table 447 psError(__func__, " : Line %d - MJD too small. Value: %d", __LINE__, mjdUtc); 350 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 351 PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE, 352 mjdUtc, "Ser7"); 448 353 449 354 } else if(mjdUtc > table->data.F64[numRows-1][3]) { // MJD time after end of table 450 psError(__func__, " : Line %d - MJD too big. Value: %d", __LINE__, mjdUtc); 355 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 356 PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE, 357 mjdUtc, "Ser7"); 451 358 } else { // All other times..interpolate 452 359 while(mjdUtc > table->data.F64[hiIdx][3]) { 453 360 hiIdx++; 454 361 if(hiIdx >= numRows) { 455 psError(__func__, " : Line %d - High index too big. Value: %d", __LINE__, hiIdx); 362 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 363 PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE, 364 mjdUtc, "Ser7"); 456 365 return 0.0; 457 366 } … … 460 369 loIdx = hiIdx--; 461 370 if(loIdx < 0) { 462 psError(__func__, " : Line %d - Low index too small. Value: %d", __LINE__, loIdx); 371 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 372 PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE, 373 mjdUtc, "Ser7"); 463 374 } 464 375 465 376 denom = table->data.F64[hiIdx][3] - table->data.F64[loIdx][3]; 466 377 if(fabs(denom) < FLT_EPSILON) { 467 psError(__func__, " : Line %d - Divide by zero error during interpolation", __LINE__); 378 psError(PS_ERR_UNKNOWN,true, 379 PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS, 380 "Ser7"); 468 381 } else { 469 382 out = table->data.F64[loIdx][col]+(table->data.F64[hiIdx][col]-table->data.F64[loIdx][col]) … … 525 438 // Error checks 526 439 if(type!=PS_TIME_TAI && type!=PS_TIME_UTC) { 527 psError(__func__, " : Line %d - Incorrect type. Type: %d", __LINE__, type); 440 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 441 PS_ERRORTEXT_psTime_TYPE_UNKNOWN, 442 type); 528 443 return NULL; 529 444 } 530 445 531 446 outTime = (psTime*)psAlloc(sizeof(psTime)); 532 if(outTime == NULL) {533 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);534 }535 447 536 448 outTime->sec = 0; … … 551 463 552 464 if (gettimeofday(&now, (struct timezone *)0) == -1) { 553 psError(__func__, " : Line %d - Failed to get time", __LINE__); 465 psError(PS_ERR_OS_CALL_FAILED, true, 466 PS_ERRORTEXT_psTime_GET_TOD_FAILED); 554 467 return NULL; 555 468 } … … 573 486 574 487 // Error checks 575 if(time == NULL) { 576 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 577 return NULL; 578 } else if(time->usec >= 1e6) { 579 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 580 return NULL; 581 } else if(time->type == type) { 582 psError(__func__, " : Line %d - Time already in correct psTime type. Time type: %d", __LINE__, type); 583 return NULL; 488 PS_PTR_CHECK_NULL(time,NULL); 489 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 490 491 if (time->type == type) { // time already right type. That was easy! 492 return time; 584 493 } 585 494 586 495 delta = psTimeGetTAIDelta(time); 587 496 588 if (type == PS_TIME_UTC) {497 if (type == PS_TIME_UTC) { 589 498 time->sec = time->sec - delta; // User wants UTC time. Subtract leapseconds. 590 499 } else if(type == PS_TIME_TAI) { 591 500 time->sec = time->sec + delta; // User wants TAI time. Add leapseconds. 592 501 } else { 593 psError(__func__, " : Line %d - Invalid psTimeType: %d", __LINE__, type); 502 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 503 PS_ERRORTEXT_psTime_TYPE_UNKNOWN, 504 type); 594 505 } 595 506 … … 623 534 624 535 // Error checks 625 if(time == NULL) { 626 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 627 return 0; 628 } else if(time->usec >= 1e6) { 629 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 630 return 0; 631 } 536 PS_PTR_CHECK_NULL(time,NAN); 537 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 632 538 633 539 // Calculate TAI or UTC time based on type of time user passes … … 698 604 699 605 // Error checks 700 if(time == NULL) { 701 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 702 return 0.0; 703 } else if(time->usec >= 1e6) { 704 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 705 return 0.0; 706 } 606 PS_PTR_CHECK_NULL(time,NAN); 607 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 707 608 708 609 return lookupSer7Table(time, 6); … … 717 618 718 619 // Error checks 719 if(time == NULL) 720 { 721 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 722 return NULL; 723 } else if(time->usec >= 1e6) 724 { 725 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 726 return NULL; 727 } 620 PS_PTR_CHECK_NULL(time,NULL); 621 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 728 622 729 623 x = lookupSer7Table((psTime*)time, 4); … … 741 635 742 636 // Error checks 743 if(time == NULL) { 744 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 745 return 0.0; 746 } else if(time->usec >= 1e6) { 747 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 748 return 0.0; 749 } 637 PS_PTR_CHECK_NULL(time,NAN); 638 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 750 639 751 640 return lookupTaiUtcTable(time); … … 758 647 759 648 // Error checks 760 if(time1 == NULL) { 761 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 762 return 0; 763 } else if(time1->usec >= 1e6) { 764 psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time1->usec); 765 return 0; 766 } else if(time2 == NULL) { 767 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 768 return 0; 769 } else if(time2->usec >= 1e6) { 770 psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time2->usec); 771 return 0; 772 } 649 PS_PTR_CHECK_NULL(time1,0); 650 PS_PTR_CHECK_NULL(time2,0); 651 PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0); 652 PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0); 773 653 774 654 diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2)); … … 781 661 double jd = 0.0; 782 662 783 784 // Error checks 785 if(time == NULL) { 786 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 787 return 0.0; 788 } else if(time->usec >= 1e6) { 789 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 790 return 0.0; 791 } 663 // Error checks 664 PS_PTR_CHECK_NULL(time,NAN); 665 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 792 666 793 667 // Julian date conversion … … 807 681 808 682 // Error checks 809 if(time == NULL) { 810 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 811 return 0.0; 812 } else if(time->usec >= 1e6) { 813 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 814 return 0.0; 815 } 683 PS_PTR_CHECK_NULL(time,NAN); 684 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 816 685 817 686 // Modified Julian date conversion … … 835 704 836 705 // Error checks 837 if(time == NULL) { 838 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 839 return NULL; 840 } else if(time->usec >= 1e6) { 841 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 842 return NULL; 843 } 706 PS_PTR_CHECK_NULL(time,NULL); 707 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 844 708 845 709 tempString = psAlloc(MAX_TIME_STRING_LENGTH); … … 854 718 // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form 855 719 if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) { 856 psError(__func__, " : Line %d - Failed strftime conversion", __LINE__); 720 psError(PS_ERR_OS_CALL_FAILED, true, 721 PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED); 857 722 } 858 723 859 724 if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3dZ", tempString, ms) < 0) { 860 psError(__func__, " : Line %d - Failed snprintf conversion", __LINE__); 725 psError(PS_ERR_OS_CALL_FAILED, true, 726 PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED); 861 727 } 862 728 psFree(tempString); … … 869 735 struct timeval timevalTime; 870 736 871 872 // Error checks 873 if(time == NULL) 874 { 875 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 876 return timevalTime; 877 } else if(time->usec >= 1e6) 878 { 879 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 880 return timevalTime; 881 } 737 timevalTime.tv_sec = 0; 738 timevalTime.tv_usec = 0; 739 740 // Error checks 741 PS_PTR_CHECK_NULL(time,timevalTime); 742 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,timevalTime); 882 743 883 744 timevalTime.tv_sec = time->sec; … … 901 762 902 763 // Error checks 903 if(time == NULL) 904 { 905 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 906 return NULL; 907 } else if(time->usec >= 1e6) 908 { 909 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 910 return NULL; 911 } 764 PS_PTR_CHECK_NULL(time,NULL); 765 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 912 766 913 767 seconds = time->sec%60; … … 945 799 // Allocate output 946 800 tmTime = (struct tm*)psAlloc(sizeof(struct tm)); 947 if (tmTime == NULL)948 {949 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);950 }951 801 952 802 tmTime->tm_year = year - 1900; … … 982 832 983 833 // Error check 984 if(outTime->usec >= 1e6) { 985 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 986 } 834 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 987 835 988 836 return outTime; … … 1010 858 1011 859 // Error check 1012 if(outTime->usec >= 1e6) { 1013 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1014 } 860 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1015 861 1016 862 return outTime; … … 1020 866 { 1021 867 char tempString[MAX_TIME_STRING_LENGTH]; 1022 psS32 month;1023 psS32 day;1024 psS32 year;1025 psS32 hour;1026 psS32 minute;1027 psS32 second;1028 868 psS32 millisecond; 1029 869 struct tm tmTime; 1030 870 psTime *outTime = NULL; 1031 871 1032 1033 // Preserve input string by creating duplicate1034 strncpy(tempString, time, MAX_TIME_STRING_LENGTH);1035 1036 872 // Convert YYYY-MM-DDThh:mm:ss.sss in string form to tm time 1037 year = atoi(strtok(tempString, "-")); 1038 if (year < 0) { 1039 psError(__func__, "Years less than 0 not allowed. Value: %d", year); 1040 return outTime; 1041 } 1042 1043 month = atoi(strtok(NULL, "-")); 1044 if (month < 1 || month > 12) { 1045 psError(__func__, "Month must have a value from 1 to 12. Value: %d", month); 1046 return outTime; 1047 } 1048 1049 day = atoi(strtok(NULL, "T")); 1050 if (day < 1 || day > 31) { 1051 psError(__func__, "Day must have a value from 1 to 31. Value: %d", day); 1052 return outTime; 1053 } 1054 1055 hour = atoi(strtok(NULL, ":")); 1056 if (hour < 0 || hour > 23) { 1057 psError(__func__, "Hour must have a value from 0 to 23. Value: %d", hour); 1058 return outTime; 1059 } 1060 1061 minute = atoi(strtok(NULL, ":")); 1062 if (minute < 0 || minute > 59) { 1063 psError(__func__, "Minute must have a value from 0 to 59. Value: %d", minute); 1064 return outTime; 1065 } 1066 1067 second = atoi(strtok(NULL, ".")); 1068 if (second < 0 || second > 59) { 1069 psError(__func__, "Second must have a value from 0 to 59. Value: %d", second); 1070 return outTime; 1071 } 1072 1073 millisecond = atoi(strtok(NULL, "Z")); 1074 if (millisecond < 0 || millisecond > 1000) { 1075 psError(__func__, "Millisecond must have a value from 0 to 999. Value: %d", millisecond); 1076 return outTime; 1077 } 1078 1079 tmTime.tm_year = year - 1900; 1080 tmTime.tm_mon = month - 1; 1081 tmTime.tm_mday = day; 1082 tmTime.tm_hour = hour; 1083 tmTime.tm_min = minute; 1084 tmTime.tm_sec = second; 873 if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d", 874 &tmTime.tm_year,&tmTime.tm_mon,&tmTime.tm_mday, 875 &tmTime.tm_hour,&tmTime.tm_min,&tmTime.tm_sec,&millisecond) < 7) { 876 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 877 PS_ERRORTEXT_psTime_ISOTIME_MALFORMED, 878 time); 879 return NULL; 880 } 881 882 PS_INT_CHECK_NON_NEGATIVE(tmTime.tm_year, outTime); 883 PS_INT_CHECK_RANGE(tmTime.tm_mon,1,12,outTime); 884 PS_INT_CHECK_RANGE(tmTime.tm_mday,1,31,outTime); 885 PS_INT_CHECK_RANGE(tmTime.tm_hour,0,23,outTime); 886 PS_INT_CHECK_RANGE(tmTime.tm_min,0,59,outTime); 887 PS_INT_CHECK_RANGE(tmTime.tm_sec,0,59,outTime); 888 PS_INT_CHECK_RANGE(millisecond,0,999,outTime); 889 890 tmTime.tm_year -= 1900; 891 tmTime.tm_mon--; 1085 892 tmTime.tm_isdst = -1; 1086 893 … … 1089 896 outTime->usec = millisecond * 1000; 1090 897 898 return outTime; 899 } 900 901 psTime* psTimeFromTimeval(const struct timeval *time) 902 { 903 psTime *outTime = NULL; 904 905 1091 906 // Error check 1092 if(outTime->usec >= 1e6) { 1093 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1094 } 1095 1096 return outTime; 1097 } 1098 1099 psTime* psTimeFromTimeval(const struct timeval *time) 1100 { 1101 psTime *outTime = NULL; 1102 1103 1104 // Error check 1105 if(time == NULL) 1106 { 1107 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 1108 return NULL; 1109 } 907 PS_PTR_CHECK_NULL(time,NULL); 1110 908 1111 909 // Allocate psTime struct … … 1117 915 1118 916 // Error check 1119 if(outTime->usec >= 1e6) 1120 { 1121 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1122 } 917 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1123 918 1124 919 return outTime; … … 1138 933 1139 934 // Error check 1140 if(time == NULL) 1141 { 1142 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 1143 return NULL; 1144 } 935 PS_PTR_CHECK_NULL(time,NULL); 1145 936 1146 937 // Allocate psTime struct … … 1183 974 1184 975 // Error check 1185 if(outTime->usec >= 1e6) 1186 { 1187 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1188 } 976 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1189 977 1190 978 return outTime; … … 1199 987 1200 988 // Error checks 989 PS_PTR_CHECK_NULL(tai1,NULL); 990 PS_PTR_CHECK_NULL(tai2,NULL); 991 PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL); 992 PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL); 993 1201 994 if(tai1->type != tai2->type) { 1202 psError(__func__, " : Line %d - Argument types inconsistent for time addition", __LINE__); 1203 return NULL; 1204 } else if(tai1 == NULL) { 1205 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1206 return NULL; 1207 } else if(tai1->usec >= 1e6) { 1208 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1209 return NULL; 1210 } else if(tai2 == NULL) { 1211 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1212 return NULL; 1213 } else if(tai2->usec >= 1e6) { 1214 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); 995 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 996 PS_ERRORTEXT_psTime_TYPE_MISMATCH); 1215 997 return NULL; 1216 998 } … … 1233 1015 1234 1016 // Error check 1235 if(outTime->usec >= 1e6) { 1236 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1237 } 1017 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1238 1018 1239 1019 return outTime; … … 1248 1028 1249 1029 // Error checks 1030 PS_PTR_CHECK_NULL(tai1,NULL); 1031 PS_PTR_CHECK_NULL(tai2,NULL); 1032 PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL); 1033 PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL); 1250 1034 if(tai1->type != tai2->type) { 1251 psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__); 1252 return NULL; 1253 } else if(tai1 == NULL) { 1254 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1255 return NULL; 1256 } else if(tai1->usec >= 1e6) { 1257 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1258 return NULL; 1259 } else if(tai2 == NULL) { 1260 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1261 return NULL; 1262 } else if(tai2->usec >= 1e6) { 1263 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); 1035 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1036 PS_ERRORTEXT_psTime_TYPE_MISMATCH); 1264 1037 return NULL; 1265 1038 } … … 1294 1067 1295 1068 // Error checks 1069 // Error checks 1070 PS_PTR_CHECK_NULL(tai1,NULL); 1071 PS_PTR_CHECK_NULL(tai2,NULL); 1072 PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL); 1073 PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL); 1296 1074 if(tai1->type != tai2->type) { 1297 psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__); 1298 return NULL; 1299 } else if(tai1 == NULL) { 1300 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1301 return NULL; 1302 } else if(tai1->usec >= 1e6) { 1303 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1304 return NULL; 1305 } else if(tai2 == NULL) { 1306 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1307 return NULL; 1308 } else if(tai2->usec >= 1e6) { 1309 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); 1075 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1076 PS_ERRORTEXT_psTime_TYPE_MISMATCH); 1310 1077 return NULL; 1311 1078 }
Note:
See TracChangeset
for help on using the changeset viewer.
