Changeset 6834
- Timestamp:
- Apr 11, 2006, 4:12:24 PM (20 years ago)
- Location:
- branches/rel10_ifa/psModules/src/astrom
- Files:
-
- 4 edited
-
pmFPAConstruct.c (modified) (7 diffs)
-
pmFPAConstruct.h (modified) (1 diff)
-
pmFPAfile.c (modified) (3 diffs)
-
pmHDU.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c
r6815 r6834 324 324 } 325 325 326 static pmFPALevel hduLevel(psMetadata *format // The camera format configuration 327 ) 328 { 329 bool mdok = true; // Status of MD lookup 330 psMetadata *file = psMetadataLookupMD(&mdok, format, "FILE"); // File information 331 if (!mdok || !file) { 332 psError(PS_ERR_IO, true, "Unable to find FILE information in camera format configuration.\n"); 333 return PM_FPA_LEVEL_NONE; 334 } 335 const char *extType = psMetadataLookupStr(&mdok, file, "EXTENSIONS"); 336 if (!mdok || !extType || strlen(extType) == 0) { 337 psError(PS_ERR_IO, true, "Unable to find EXTENSIONS in the FILE information in the camera format" 338 " configuration.\n"); 339 return PM_FPA_LEVEL_NONE; 340 } 341 342 // Where do we stick in the HDUs? 343 pmFPALevel level = PM_FPA_LEVEL_NONE; // Level for HDU insertion 344 if (strcasecmp(extType, "CHIP") == 0) { 345 level = PM_FPA_LEVEL_CHIP; 346 } else if (strcasecmp(extType, "CELL") == 0) { 347 level = PM_FPA_LEVEL_CELL; 348 } else if (strcasecmp(extType, "NONE") != 0) { 349 psError(PS_ERR_IO, true, "EXTENSIONS is not CHIP or CELL or NONE.\n"); 350 } 351 352 return level; 353 } 354 326 355 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 327 356 // Public functions … … 362 391 } 363 392 393 bool pmFPAAddSourceFromView(pmFPA *fpa, // The FPA 394 pmFPAview *phuView, // The view, corresponding to the PHU 395 psMetadata *format // Format of file 396 ) 397 { 398 assert(fpa); 399 assert(phuView); 400 assert(format); 401 402 // Where does the PHU go? 403 bool mdok = true; // Status of MD lookup 404 psMetadata *fileInfo = psMetadataLookupMD(&mdok, format, "FILE"); // File information from the format 405 if (!mdok || !fileInfo) { 406 psError(PS_ERR_IO, false, "Unable to find FILE information in the camera format configuration.\n"); 407 return false; 408 } 409 const char *phuType = psMetadataLookupStr(&mdok, fileInfo, "PHU"); // What is the PHU? 410 if (!mdok || strlen(phuType) == 0) { 411 psError(PS_ERR_IO, false, "Unable to find PHU in the FILE information of the camera format.\n"); 412 return false; 413 } 414 415 // Generate the PHU 416 pmHDU *phdu = pmHDUAlloc("PHU"); // The primary header data unit 417 phdu->format = psMemIncrRefCounter(format); 418 419 // Put in the PHU 420 pmChip *chip = NULL; // The chip that corresponds to the PHU 421 pmCell *cell = NULL; // The cell that corresponds to the PHU 422 if (strcasecmp(phuType, "FPA") == 0) { 423 fpa->hdu = phdu; 424 } else { 425 psArray *chips = fpa->chips; // Array of chips 426 if (phuView->chip < 0 || phuView->chip > chips->n) { 427 psError(PS_ERR_IO, true, "PHU specified by the camera format requires specification of a " 428 "particular chip, which cannot be determined from the view (%d).\n", phuView->chip); 429 psFree(phdu); 430 return false; 431 } 432 chip = chips->data[phuView->chip]; 433 if (strcasecmp(phuType, "CHIP") == 0) { 434 chip->hdu = phdu; 435 } else if (strcasecmp(phuType, "CELL") == 0) { 436 psArray *cells = chip->cells; // Array of cells 437 if (phuView->cell < 0 || phuView->cell > cells->n) { 438 psError(PS_ERR_IO, true, "PHU specified by the camera format requires specification of a " 439 "particular cell, which cannot be determined from the view (%d).\n", phuView->cell); 440 psFree(phdu); 441 return false; 442 } 443 cell->hdu = phdu; 444 } else { 445 psError(PS_ERR_IO, true, "PHU in the camera configuration format is not FPA, CHIP or CELL.\n"); 446 psFree(phdu); 447 return false; 448 } 449 } 450 451 // Put in the extensions 452 pmFPALevel level = hduLevel(format);// The level for the HDUs to go 453 if (level == PM_FPA_LEVEL_NONE) { 454 // No extensions --- we're done 455 return true; 456 } 457 psMetadata *contents = psMetadataLookupMD(&mdok, format, "CONTENTS"); // The contents of the FITS file 458 if (!mdok || !contents) { 459 psError(PS_ERR_IO, false, "Unable to find CONTENTS in the camera format configuration.\n"); 460 return false; 461 } 462 463 psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL); // Iterator 464 psMetadataItem *contentsItem = NULL;// Item from the contents iteration 465 while ((contentsItem = psMetadataGetAndIncrement(contentsIter))) { 466 if (contentsItem->type != PS_DATA_STRING) { 467 psLogMsg(__func__, PS_LOG_WARN, "Content item %s is not of type STR --- ignored.\n", 468 contentsItem->name); 469 continue; 470 } 471 pmHDU *hdu = pmHDUAlloc(contentsItem->name); // HDU to add 472 hdu->format = psMemIncrRefCounter(format); 473 const char *content = contentsItem->data.V; // The content data 474 processContents(fpa, chip, cell, hdu, level, content, format); 475 psFree(hdu); 476 } 477 psFree(contentsIter); 478 479 return true; 480 } 481 482 364 483 365 484 // Add an input file to the FPA 366 pmFPAview *pmFPAAddSource (pmFPA *fpa, // The FPA367 psMetadata *phu, // Primary header of file368 psMetadata *format // Format of file369 )485 pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA 486 psMetadata *phu, // Primary header of file 487 psMetadata *format // Format of file 488 ) 370 489 { 371 490 assert(fpa); … … 531 650 psFree(phdu); 532 651 533 // Where do we stick in the HDUs? 534 pmFPALevel hduLevel = PM_FPA_LEVEL_NONE; // Level for HDU insertion 535 if (strcasecmp(extType, "CHIP") == 0) { 536 hduLevel = PM_FPA_LEVEL_CHIP; 537 } else if (strcasecmp(extType, "CELL") == 0) { 538 hduLevel = PM_FPA_LEVEL_CELL; 539 } else { 540 psError(PS_ERR_IO, true, "EXTENSIONS is not CHIP or CELL or NONE.\n"); 541 psFree(view); 542 return NULL; 543 } 652 pmFPALevel level = hduLevel(format);// The level at which to plug in HDU 544 653 545 654 // Now go through the contents … … 556 665 hdu->format = psMemIncrRefCounter(format); 557 666 558 processContents(fpa, chip, cell, hdu, hduLevel, contentsItem->data.V, format);667 processContents(fpa, chip, cell, hdu, level, contentsItem->data.V, format); 559 668 psFree(hdu); 560 669 } … … 579 688 psTrace(__func__, 2, "---> NO PIXELS read in for extension %s\n", fpa->hdu->extname); 580 689 } 581 if (fpa->hdu->header && header) { 582 psTrace(__func__, 2, "---> Header:\n"); 583 psMetadataPrint(fpa->hdu->header, 8); 690 if (header) { 691 if (fpa->hdu->header) { 692 psTrace(__func__, 2, "---> Header:\n"); 693 psMetadataPrint(fpa->hdu->header, 8); 694 } else { 695 psTrace(__func__, 2, "---> NO HEADER read in for extension %s\n", fpa->hdu->extname); 696 } 584 697 } 585 698 } … … 595 708 if (chip->hdu) { 596 709 psTrace(__func__, 4, "---> Chip is extension %s.\n", chip->hdu->extname); 597 if (chip->hdu->header && header) { 598 psTrace(__func__, 4, "---> Header:\n"); 599 psMetadataPrint(chip->hdu->header, 8); 710 if (header) { 711 if (chip->hdu->header) { 712 psTrace(__func__, 4, "---> Header:\n"); 713 psMetadataPrint(chip->hdu->header, 8); 714 } else { 715 psTrace(__func__, 4, "---> NO HEADER read in for extension %s\n", chip->hdu->extname); 716 } 600 717 } 601 718 if (! chip->hdu->images) { … … 614 731 if (cell->hdu) { 615 732 psTrace(__func__, 6, "---> Cell is extension %s.\n", cell->hdu->extname); 616 if (cell->hdu->header && header) { 617 psTrace(__func__, 4, "---> Header:\n"); 618 psMetadataPrint(cell->hdu->header, 8); 733 if (header) { 734 if (cell->hdu->header) { 735 psTrace(__func__, 6, "---> Header:\n"); 736 psMetadataPrint(cell->hdu->header, 8); 737 } else { 738 psTrace(__func__, 6, "---> NO HEADER read in for extension %s\n", cell->hdu->extname); 739 } 619 740 } 620 741 if (! cell->hdu->images) { -
branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.h
r6734 r6834 10 10 ); 11 11 12 pmFPAview *pmFPAAddSource(pmFPA *fpa, // The FPA 13 psMetadata *phu, // Primary header of file 14 psMetadata *format // Format of file 15 ); 12 bool pmFPAAddSourceFromView(pmFPA *fpa, // The FPA 13 pmFPAview *phuView, // The view, corresponding to the PHU 14 psMetadata *format // Format of file 15 ); 16 17 pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA 18 psMetadata *phu, // Primary header of file 19 psMetadata *format // Format of file 20 ); 16 21 17 22 // Print out the FPA -
branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
r6827 r6834 698 698 699 699 // set the view to the corresponding entry for this phu 700 pmFPAview *view = pmFPAAddSource (fpa, phu, format);700 pmFPAview *view = pmFPAAddSourceFromHeader(fpa, phu, format); 701 701 702 702 // XXX is this the correct psMD to save the filename? … … 786 786 787 787 // set the view to the corresponding entry for this phu 788 pmFPAview *view = pmFPAAddSource (fpa, phu, format);788 pmFPAview *view = pmFPAAddSourceFromHeader(fpa, phu, format); 789 789 790 790 // XXX is this the correct psMD to save the filename? … … 879 879 880 880 // set the view to the corresponding entry for this phu 881 pmFPAview *view = pmFPAAddSource (file->fpa, phu, format);881 pmFPAview *view = pmFPAAddSourceFromHeader(file->fpa, phu, format); 882 882 883 883 // XXX is this the correct psMD to save the filename? -
branches/rel10_ifa/psModules/src/astrom/pmHDU.c
r6815 r6834 135 135 } 136 136 137 if (!hdu->images && !hdu->table && !hdu->header) { 138 psLogMsg(__func__, PS_LOG_WARN, "Nothing to write for HDU %s\n", hdu->extname); 139 return false; 140 } 141 137 142 // Preserve the extension name, if it's the PHU 138 143 char *extname = hdu->extname; // The name of the extension 139 if (strcasecmp(extname, "PHU") == 0 ) {144 if (strcasecmp(extname, "PHU") == 0 && hdu->header) { 140 145 bool mdok = true; // Status of MD lookup 141 146 extname = psMetadataLookupStr(&mdok, hdu->header, "EXTNAME"); 142 if (!mdok || strlen(extname) == 0) {147 if (!mdok || !extname || strlen(extname) == 0) { 143 148 extname = ""; 144 149 } … … 149 154 // Tell CFITSIO there's nothing there 150 155 psMetadataItem *naxis = psMetadataLookup(hdu->header, "NAXIS"); 151 naxis->data.S32 = 0; 156 if (naxis) { 157 naxis->data.S32 = 0; 158 } 152 159 153 160 if (!psFitsWriteHeader(hdu->header, fits)) {
Note:
See TracChangeset
for help on using the changeset viewer.
