Changeset 7253 for trunk/psModules/src/concepts/pmConceptsStandard.c
- Timestamp:
- May 31, 2006, 12:47:32 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/concepts/pmConceptsStandard.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/concepts/pmConceptsStandard.c
r7017 r7253 288 288 } 289 289 290 // Work out how the time is represented 291 bool usaTime = false; // Is the time specified in USA (MM-DD-YYYY) order? 292 bool backwardsTime = false; // Is the time specified in backwards (DD-MM-YYYY) order? 293 bool pre2000Time = false; // Is the time specified pre-2000 (where the year only has two digits) 294 bool mjdTime = false; // Is the time specified a MJD? 295 bool jdTime = false; // Is the time specified a JD? 296 290 297 // Get format 291 298 psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS"); 292 if (!mdok || !formats) { 293 psError(PS_ERR_IO, false, "Unable to find FORMATS in camera configuration.\n"); 294 return NULL; 295 } 296 297 psString timeFormat = psMetadataLookupStr(&mdok, formats, "CELL.TIME"); 298 if (!mdok || strlen(timeFormat) == 0) { 299 psError(PS_ERR_IO, false, "Unable to find CELL.TIME in FORMATS.\n"); 300 return NULL; 299 if (mdok && formats) { 300 psString timeFormat = psMetadataLookupStr(&mdok, formats, "CELL.TIME"); 301 if (mdok && timeFormat && strlen(timeFormat) > 0) { 302 // Parse the time format 303 psList *timeFormats = psStringSplit(timeFormat, " ,;", false); // List of the format options 304 psListIterator *timeFormatsIter = psListIteratorAlloc(timeFormats, PS_LIST_HEAD, false); // Iter 305 while ((timeFormat = psListGetAndIncrement(timeFormatsIter))) { 306 if (strcasecmp(timeFormat, "USA") == 0) { 307 usaTime = true; 308 backwardsTime = false; 309 jdTime = false; 310 mjdTime = false; 311 } else if (strcasecmp(timeFormat, "BACKWARDS") == 0) { 312 backwardsTime = true; 313 usaTime = false; 314 jdTime = false; 315 mjdTime = false; 316 } else if (strcasecmp(timeFormat, "PRE2000") == 0) { 317 pre2000Time = true; 318 } else if (strcasecmp(timeFormat, "MJD") == 0) { 319 mjdTime = true; 320 jdTime = false; 321 backwardsTime = false; 322 usaTime = false; 323 } else if (strcasecmp(timeFormat, "JD") == 0) { 324 jdTime = true; 325 mjdTime = false; 326 backwardsTime = false; 327 usaTime = false; 328 } else { 329 psLogMsg(__func__, PS_LOG_WARN, "Unrecognised FORMATS option for CELL.TIME: %s --- " 330 "ignored.\n", timeFormat); 331 } 332 } 333 psFree(timeFormatsIter); 334 psFree(timeFormats); 335 } 301 336 } 302 337 … … 315 350 psString dateString = dateItem->data.V; // The string with the date 316 351 int day = 0, month = 0, year = 0; 317 if (sscanf(dateString, "%d-%d-%d", & day, &month, &year) != 3 &&318 sscanf(dateString, "%d/%d/%d", & day, &month, &year) != 3) {352 if (sscanf(dateString, "%d-%d-%d", &year, &month, &day) != 3 && 353 sscanf(dateString, "%d/%d/%d", &year, &month, &day) != 3) { 319 354 psError(PS_ERR_IO, true, "Unable to read date: %s\n", dateString); 320 355 return NULL; 321 356 } 322 if (strstr(timeFormat, "BACKWARDS")) { 357 if (backwardsTime) { 358 // Need to switch days and years 323 359 int temp = day; 324 360 day = year; 325 361 year = temp; 326 362 } 327 if (strstr(timeFormat, "PRE2000") || year < 2000) { 363 if (usaTime) { 364 // Need to switch everything around.... Yanks! 365 int temp = day; 366 day = month; 367 month = year; 368 year = temp; 369 } 370 if (pre2000Time || year < 2000) { 328 371 year += 2000; 329 372 } 330 331 373 psString timeString = NULL; // The string with the time 332 374 if (timeItem->type == PS_DATA_STRING) { … … 362 404 case PS_DATA_STRING: { 363 405 psString timeString = concept->data.V; // String with the time 364 if (strcasecmp(timeFormat, "ISO") == 0) { 365 // timeString contains an ISO time 366 time = psTimeFromISO(timeString, timeSys); 367 } else if (strcasecmp(timeFormat, "JD") == 0) { 406 if (jdTime) { 368 407 double timeValue = strtod (timeString, NULL); 369 408 time = psTimeFromJD(timeValue); 370 } else if ( strcasecmp(timeFormat, "MJD") == 0) {409 } else if (mjdTime) { 371 410 double timeValue = strtod (timeString, NULL); 372 411 time = psTimeFromMJD(timeValue); 373 412 } else { 374 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%s) --- trying " 375 "ISO\n", timeString); 413 // It's ISO 376 414 time = psTimeFromISO(timeString, timeSys); 377 415 } // Interpreting the time string … … 380 418 case PS_TYPE_F32: { 381 419 double timeValue = (double)concept->data.F32; 382 if ( strcasecmp(timeFormat, "JD") == 0) {420 if (jdTime) { 383 421 time = psTimeFromJD(timeValue); 384 } else if ( strcasecmp(timeFormat, "MJD") == 0) {422 } else if (mjdTime) { 385 423 time = psTimeFromMJD(timeValue); 386 424 } else { 387 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying " 388 "JD\n", timeValue); 425 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n", timeValue); 389 426 time = psTimeFromJD(timeValue); 390 427 } … … 393 430 case PS_TYPE_F64: { 394 431 double timeValue = (double)concept->data.F64; 395 if ( strcasecmp(timeFormat, "JD") == 0) {432 if (jdTime) { 396 433 time = psTimeFromJD(timeValue); 397 } else if ( strcasecmp(timeFormat, "MJD") == 0) {434 } else if (mjdTime) { 398 435 time = psTimeFromMJD(timeValue); 399 436 } else { 400 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying " 401 "JD\n", timeValue); 437 psError(PS_ERR_IO, true, "Not sure how to parse CELL.TIME (%f) --- trying JD\n", timeValue); 402 438 time = psTimeFromJD(timeValue); 403 439 } … … 557 593 { 558 594 psTime *time = concept->data.V; // The time 559 psMetadata *formats = psMetadataLookupMD(NULL, cameraFormat, "FORMATS"); 560 psString format = psMetadataLookupStr(NULL, formats, "CELL.TIME"); 561 562 if (strlen(format) == 0 || strcasecmp(format, "ISO") == 0) { 563 psString dateTimeString = psTimeToISO(time); // String representation 564 psMetadataItem *item = psMetadataItemAllocStr(concept->name, concept->comment, dateTimeString); 565 psFree(dateTimeString); 566 return item; 567 } 568 if (strstr(format, "SEPARATE")) { 595 596 // Work out the format 597 bool separateTime = false; // Are the date and time stored separately? 598 bool pre2000Time = false; // Is the year in pre-2000 format (two digits only)? 599 bool backwardsTime = false; // Is the date stored backwards (DD-MM-YYYY)? 600 bool usaTime = false; // Is the date stored in USA order (MM-DD-YYYY)? 601 bool jdTime = false; // Is the date stored as a JD? 602 bool mjdTime = false; // Is the date stored as a MJD? 603 604 bool mdok = true; // Status of MD lookup 605 psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS"); // The formats 606 if (mdok && formats) { 607 psString format = psMetadataLookupStr(&mdok, formats, "CELL.TIME"); // The formats for CELL.TIME 608 if (mdok && format && strlen(format) > 0) { 609 psList *formatList = psStringSplit(format, " ,;", false); // List of formats specified 610 psListIterator *formatListIter = psListIteratorAlloc(formatList, PS_LIST_HEAD, false); // Iterator 611 while ((format = psListGetAndIncrement(formatListIter))) { 612 if (strcasecmp(format, "SEPARATE") == 0) { 613 separateTime = true; 614 } else if (strcasecmp(format, "PRE2000") == 0) { 615 pre2000Time = true; 616 } else if (strcasecmp(format, "BACKWARDS") == 0) { 617 backwardsTime = true; 618 usaTime = false; 619 mjdTime = false; 620 jdTime = false; 621 } else if (strcasecmp(format, "USA") == 0) { 622 usaTime = true; 623 backwardsTime = false; 624 jdTime = false; 625 mjdTime = false; 626 } else if (strcasecmp(format, "JD") == 0) { 627 jdTime = true; 628 usaTime = false; 629 backwardsTime = false; 630 mjdTime = false; 631 separateTime = false; 632 } else if (strcasecmp(format, "MJD") == 0) { 633 mjdTime = true; 634 usaTime = false; 635 backwardsTime = false; 636 jdTime = false; 637 separateTime = false; 638 } else { 639 psLogMsg(__func__, PS_LOG_WARN, "Unrecognised FORMATS option for CELL.TIME: %s --- " 640 "ignored.\n", format); 641 } 642 } 643 } 644 } 645 646 if (separateTime) { 569 647 // We're working with two separate headers --- construct a list with the date and time separately 570 648 psString dateTimeString = psTimeToISO(time); // String representation … … 576 654 // Need to format the strings.... 577 655 // XXX: Couldn't be bothered doing these right now 578 if ( strstr(format, "PRE2000")) {656 if (pre2000Time) { 579 657 psError(PS_ERR_IO, true, "Don't you realise it's the twenty-first century?\n"); 580 658 return NULL; 581 659 } 582 if ( strstr(format, "BACKWARDS")) {660 if (backwardsTime) { 583 661 psError(PS_ERR_IO, true, "You want it BACKWARDS? Not right now, thanks.\n"); 662 return NULL; 663 } 664 if (usaTime) { 665 psError(PS_ERR_IO, true, "USA? No OK --- yet.\n"); 584 666 return NULL; 585 667 } … … 601 683 return item; 602 684 } 603 if (strcasecmp(format, "MJD") == 0) { 685 if (jdTime) { 686 double jd = psTimeToMJD(time); 687 return psMetadataItemAllocF64(concept->name, concept->comment, jd); 688 } 689 if (mjdTime) { 604 690 double mjd = psTimeToMJD(time); 605 691 return psMetadataItemAllocF64(concept->name, concept->comment, mjd); 606 692 } 607 if (strcasecmp(format, "JD") == 0) { 608 double jd = psTimeToMJD(time); 609 return psMetadataItemAllocF64("CELL.TIME", "JD of observation", jd); 610 } 611 612 psError(PS_ERR_IO, true, "Not sure how to format concept CELL.TIME\n"); 613 return NULL; 693 694 // If we've gotten this far, so it's straight ISO. 695 psString dateTimeString = psTimeToISO(time); // String representation 696 psMetadataItem *item = psMetadataItemAllocStr(concept->name, concept->comment, dateTimeString); 697 psFree(dateTimeString); 698 return item; 614 699 } 615 700
Note:
See TracChangeset
for help on using the changeset viewer.
