Changeset 12687 for trunk/psModules/src/camera/pmFPAfileIO.c
- Timestamp:
- Mar 29, 2007, 1:00:15 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAfileIO.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileIO.c
r12603 r12687 133 133 // do we need to open this file? 134 134 if (level >= file->fileLevel) { 135 // we are allowed to open a file at a level which is not the fileLevel, but we need to136 // supply a view at the fileLevel for the file lookup functions below137 pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view);138 if (!pmFPAfileOpen (file, fileView, config)) {135 // we are allowed to open a file at a level which is not the fileLevel, but we need to 136 // supply a view at the fileLevel for the file lookup functions below 137 pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view); 138 if (!pmFPAfileOpen (file, fileView, config)) { 139 139 psError(PS_ERR_IO, false, "failed to open file %s (%s)", file->filename, file->name); 140 psFree (fileView);141 return false; 142 } 143 psFree (fileView);140 psFree (fileView); 141 return false; 142 } 143 psFree (fileView); 144 144 } 145 145 146 146 // We need to read it --- double-check it's open! 147 147 if (file->state == PM_FPA_STATE_CLOSED) { 148 psError(PS_ERR_IO, false, "failed to open file %s when attempting to read", file->name);149 return false;148 psError(PS_ERR_IO, false, "failed to open file %s when attempting to read", file->name); 149 return false; 150 150 } 151 151 … … 154 154 switch (file->type) { 155 155 case PM_FPA_FILE_IMAGE: 156 status = pmFPAviewReadFitsImage(view, file);157 break;156 status = pmFPAviewReadFitsImage(view, file); 157 break; 158 158 case PM_FPA_FILE_MASK: 159 status = pmFPAviewReadFitsMask(view, file);159 status = pmFPAviewReadFitsMask(view, file); 160 160 break; 161 161 case PM_FPA_FILE_WEIGHT: 162 status = pmFPAviewReadFitsWeight(view, file);162 status = pmFPAviewReadFitsWeight(view, file); 163 163 break; 164 164 case PM_FPA_FILE_HEADER: 165 status = pmFPAviewReadFitsHeaderSet(view, file);165 status = pmFPAviewReadFitsHeaderSet(view, file); 166 166 break; 167 167 case PM_FPA_FILE_FRINGE: 168 status = pmFPAviewReadFitsImage (view, file);169 if (status) {170 if (!pmFPAviewReadFitsTable(view, file, "FRINGE")) {171 psError(PS_ERR_UNKNOWN, false, "Unable to read fringe data from %s.\n", file->filename);172 return false;173 }174 }175 break;168 status = pmFPAviewReadFitsImage (view, file); 169 if (status) { 170 if (!pmFPAviewReadFitsTable(view, file, "FRINGE")) { 171 psError(PS_ERR_UNKNOWN, false, "Unable to read fringe data from %s.\n", file->filename); 172 return false; 173 } 174 } 175 break; 176 176 case PM_FPA_FILE_SX: 177 177 case PM_FPA_FILE_RAW: … … 182 182 break; 183 183 case PM_FPA_FILE_PSF: 184 status = pmFPAviewReadPSFmodel (view, file, config);184 status = pmFPAviewReadPSFmodel (view, file, config); 185 185 break; 186 186 case PM_FPA_FILE_JPEG: … … 192 192 } 193 193 if (!status) { 194 psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name);195 return false;194 psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name); 195 return false; 196 196 } 197 197 psTrace ("psModules.camera", 5, "read %s (%s)\n", file->filename, file->name); … … 318 318 // XXX do we need to test mosaicLevel? 319 319 if (level >= file->fileLevel) { 320 // we are allowed to open a file at a level which is not the fileLevel, but 321 // we need to supply view at the fileLevel for the file lookup functions below322 pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view);320 // we are allowed to open a file at a level which is not the fileLevel, but 321 // we need to supply view at the fileLevel for the file lookup functions below 322 pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view); 323 323 if (!pmFPAfileOpen (file, fileView, config)) { 324 324 psError(PS_ERR_IO, false, "failed to open %s (%s)", file->filename, file->name); 325 psFree (fileView);326 return false; 327 } 328 psFree (fileView);325 psFree (fileView); 326 return false; 327 } 328 psFree (fileView); 329 329 } 330 330 … … 344 344 break; 345 345 case PM_FPA_FILE_MASK: 346 status = pmFPAviewWriteFitsMask(view, file, config);346 status = pmFPAviewWriteFitsMask(view, file, config); 347 347 break; 348 348 case PM_FPA_FILE_WEIGHT: 349 status = pmFPAviewWriteFitsWeight(view, file, config);349 status = pmFPAviewWriteFitsWeight(view, file, config); 350 350 break; 351 351 case PM_FPA_FILE_HEADER: 352 psAbort ("no HEADER write functions defined");352 psAbort ("no HEADER write functions defined"); 353 353 break; 354 354 case PM_FPA_FILE_FRINGE: 355 status = pmFPAviewWriteFitsImage (view, file, config);356 if (status) {357 if (!pmFPAviewWriteFitsTable(view, file, "FRINGE")) {358 psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename);359 return false;360 }361 }355 status = pmFPAviewWriteFitsImage (view, file, config); 356 if (status) { 357 if (!pmFPAviewWriteFitsTable(view, file, "FRINGE")) { 358 psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename); 359 return false; 360 } 361 } 362 362 break; 363 363 case PM_FPA_FILE_SX: … … 386 386 } 387 387 if (!status) { 388 psError(PS_ERR_UNKNOWN, false, "failed to write %s (%s)\n", file->filename, file->name);389 return false;388 psError(PS_ERR_UNKNOWN, false, "failed to write %s (%s)\n", file->filename, file->name); 389 return false; 390 390 } 391 391 psTrace ("psModules.camera", 5, "wrote %s (fpa: %p)\n", file->filename, file->fpa); … … 452 452 } 453 453 if (!status) { 454 psError(PS_ERR_UNKNOWN, false, "failed to close %s (%s)\n", file->filename, file->name);455 return false;454 psError(PS_ERR_UNKNOWN, false, "failed to close %s (%s)\n", file->filename, file->name); 455 return false; 456 456 } 457 457 return true; … … 488 488 case PM_FPA_FILE_HEADER: 489 489 case PM_FPA_FILE_FRINGE: 490 status = pmFPAviewFreeData(view, file);490 status = pmFPAviewFreeData(view, file); 491 491 break; 492 492 case PM_FPA_FILE_SX: … … 495 495 case PM_FPA_FILE_CMP: 496 496 case PM_FPA_FILE_CMF: 497 psTrace ("psModules.camera", 5, "NOT freeing %s (%s) : save for further analysis\n", file->filename, file->name);497 psTrace ("psModules.camera", 5, "NOT freeing %s (%s) : save for further analysis\n", file->filename, file->name); 498 498 break; 499 499 case PM_FPA_FILE_PSF: 500 500 case PM_FPA_FILE_JPEG: 501 501 case PM_FPA_FILE_KAPA: 502 psTrace ("psModules.camera", 5, "nothing to free for %s (%s)\n", file->filename, file->name);502 psTrace ("psModules.camera", 5, "nothing to free for %s (%s)\n", file->filename, file->name); 503 503 break; 504 504 default: … … 507 507 } 508 508 if (!status) { 509 psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name);510 return false;509 psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name); 510 return false; 511 511 } 512 512 psTrace ("psModules.camera", 5, "freed %s (%s)\n", file->filename, file->name); … … 558 558 } 559 559 560 // indirect filenames: these come from a list on the command line or elsewhere 560 // indirect filenames: these come from a list on the command line or elsewhere 561 561 if (!strcasecmp (file->filename, "@FILES")) { 562 562 char *filesrc = pmFPAfileNameFromRule (file->filesrc, file, view); … … 626 626 627 627 switch (file->type) { 628 // open the FITS types:628 // open the FITS types: 629 629 case PM_FPA_FILE_IMAGE: 630 630 case PM_FPA_FILE_MASK: … … 641 641 file->state = PM_FPA_STATE_OPEN; 642 642 643 // if needed, set the optional EXTWORD field based on the camera value644 if (config && config->format) {645 psMetadata *fileMenu = psMetadataLookupMetadata (NULL, config->format, "FILE");646 if (!fileMenu) {647 psError (PS_ERR_IO, true, "FILE METADATA missing from camera format %s\n", config->formatName);648 return false;649 }650 char *extword = psMetadataLookupStr (&status, fileMenu, "EXTWORD");651 if (status) {652 psFitsSetExtnameWord (file->fits, extword);653 }654 }655 656 // In some cases, we need to read the PHU after we've opened the file. This happens for657 // the images supplied by the detrend database, which are only identified here (above).658 if (!pmFPAfileReadPHU (file, view, config)) {659 psError (PS_ERR_IO, true, "error reading PHU for %s (%s)\n", file->filename, file->name);660 return false;661 }662 break; 663 664 // defer opening TEXT types:643 // if needed, set the optional EXTWORD field based on the camera value 644 if (config && config->format) { 645 psMetadata *fileMenu = psMetadataLookupMetadata (NULL, config->format, "FILE"); 646 if (!fileMenu) { 647 psError (PS_ERR_IO, true, "FILE METADATA missing from camera format %s\n", config->formatName); 648 return false; 649 } 650 char *extword = psMetadataLookupStr (&status, fileMenu, "EXTWORD"); 651 if (status) { 652 psFitsSetExtnameWord (file->fits, extword); 653 } 654 } 655 656 // In some cases, we need to read the PHU after we've opened the file. This happens for 657 // the images supplied by the detrend database, which are only identified here (above). 658 if (!pmFPAfileReadPHU (file, view, config)) { 659 psError (PS_ERR_IO, true, "error reading PHU for %s (%s)\n", file->filename, file->name); 660 return false; 661 } 662 break; 663 664 // defer opening TEXT types: 665 665 case PM_FPA_FILE_SX: 666 666 case PM_FPA_FILE_OBJ: … … 692 692 switch (file->fileLevel) { 693 693 case PM_FPA_LEVEL_FPA: 694 if (file->fpa->hdu) return true;695 break;694 if (file->fpa->hdu) return true; 695 break; 696 696 case PM_FPA_LEVEL_CHIP: { 697 pmChip *chip = pmFPAviewThisChip(view, file->fpa);698 if (!chip) psAbort ("inconsistent file/fpa: fileLevel is CHIP, view is FPA");699 if (chip->hdu) return true;700 break;697 pmChip *chip = pmFPAviewThisChip(view, file->fpa); 698 if (!chip) psAbort ("inconsistent file/fpa: fileLevel is CHIP, view is FPA"); 699 if (chip->hdu) return true; 700 break; 701 701 } 702 702 case PM_FPA_LEVEL_CELL: { 703 pmCell *cell = pmFPAviewThisCell(view, file->fpa);704 if (!cell) psAbort ("inconsistent file/fpa: fileLevel is CELL, view is FPA");705 if (cell->hdu) return true;706 break;703 pmCell *cell = pmFPAviewThisCell(view, file->fpa); 704 if (!cell) psAbort ("inconsistent file/fpa: fileLevel is CELL, view is FPA"); 705 if (cell->hdu) return true; 706 break; 707 707 } 708 case PM_FPA_LEVEL_NONE: 709 // Might get here immediately after opening a file selected from the detrend database. 710 break; 708 711 default: 709 psAbort("fileLevel not correctly set");710 break;712 psAbort("fileLevel not correctly set"); 713 break; 711 714 } 712 715 … … 714 717 psMetadata *phu = psFitsReadHeader (NULL, file->fits); 715 718 if (!file->format) { 716 file->format = pmConfigCameraFormatFromHeader (config, phu);717 if (!file->format) {718 psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename);719 psFree(phu);720 return false;721 }719 file->format = pmConfigCameraFormatFromHeader (config, phu); 720 if (!file->format) { 721 psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename); 722 psFree(phu); 723 return false; 724 } 722 725 } else { 723 bool valid;724 if (!pmConfigValidateCameraFormat (&valid, file->format, phu)) {725 psError (PS_ERR_UNKNOWN, false, "Error in camera configuration\n");726 psFree (phu);727 return false;728 }729 if (!valid) {730 psError(PS_ERR_IO, false, "file %s is not from the required camera", file->filename);731 psFree (phu);732 return false;733 }726 bool valid; 727 if (!pmConfigValidateCameraFormat (&valid, file->format, phu)) { 728 psError (PS_ERR_UNKNOWN, false, "Error in camera configuration\n"); 729 psFree (phu); 730 return false; 731 } 732 if (!valid) { 733 psError(PS_ERR_IO, false, "file %s is not from the required camera", file->filename); 734 psFree (phu); 735 return false; 736 } 734 737 } 735 738 pmFPAview *thisView = pmFPAAddSourceFromHeader (file->fpa, phu, file->format); … … 740 743 } 741 744 742 // XXX this function is only called from pmFPAfileWrite 745 // XXX this function is only called from pmFPAfileWrite 743 746 bool pmFPAfileWritePHU(pmFPAfile *file, const pmFPAview *view, pmConfig *config) 744 747 { … … 752 755 case PM_FPA_FILE_WEIGHT: 753 756 case PM_FPA_FILE_FRINGE: 754 if (file->mode == PM_FPA_MODE_WRITE) {755 // Want to write out any potential blank756 // XXX why do we need to construct a new fpa?? 757 pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config); // FPA, ensuring it's ready to write a blank758 759 switch (file->fileLevel) {760 case PM_FPA_LEVEL_FPA:761 if (file->fpa->wrote_phu) break;762 status = pmFPAWrite(fpa, file->fits, NULL, true, false);763 file->fpa->wrote_phu = true;764 break;765 case PM_FPA_LEVEL_CHIP: {766 pmChip *chip = pmFPAviewThisChip(view, fpa);767 if (chip->wrote_phu) break;768 status = pmChipWrite(chip, file->fits, NULL, true, false);769 chip->wrote_phu = true;770 break;771 }772 case PM_FPA_LEVEL_CELL: {773 pmCell *cell = pmFPAviewThisCell(view, fpa);774 if (cell->wrote_phu) break;775 status = pmCellWrite(cell, file->fits, NULL, true);776 cell->wrote_phu = true;777 break;778 }779 default:780 psAbort("fileLevel not correctly set");781 break;782 }783 784 psFree(fpa);785 }757 if (file->mode == PM_FPA_MODE_WRITE) { 758 // Want to write out any potential blank 759 // XXX why do we need to construct a new fpa?? 760 pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config); // FPA, ensuring it's ready to write a blank 761 762 switch (file->fileLevel) { 763 case PM_FPA_LEVEL_FPA: 764 if (file->fpa->wrote_phu) break; 765 status = pmFPAWrite(fpa, file->fits, NULL, true, false); 766 file->fpa->wrote_phu = true; 767 break; 768 case PM_FPA_LEVEL_CHIP: { 769 pmChip *chip = pmFPAviewThisChip(view, fpa); 770 if (chip->wrote_phu) break; 771 status = pmChipWrite(chip, file->fits, NULL, true, false); 772 chip->wrote_phu = true; 773 break; 774 } 775 case PM_FPA_LEVEL_CELL: { 776 pmCell *cell = pmFPAviewThisCell(view, fpa); 777 if (cell->wrote_phu) break; 778 status = pmCellWrite(cell, file->fits, NULL, true); 779 cell->wrote_phu = true; 780 break; 781 } 782 default: 783 psAbort("fileLevel not correctly set"); 784 break; 785 } 786 787 psFree(fpa); 788 } 786 789 case PM_FPA_FILE_SX: 787 790 case PM_FPA_FILE_RAW: … … 792 795 case PM_FPA_FILE_JPEG: 793 796 case PM_FPA_FILE_KAPA: 794 break;797 break; 795 798 default: 796 799 fprintf (stderr, "warning: type mismatch\n"); … … 798 801 } 799 802 if (!status) { 800 psError(PS_ERR_UNKNOWN, false, "failed to write PHU for %s (%s)\n", file->filename, file->name);801 return false;803 psError(PS_ERR_UNKNOWN, false, "failed to write PHU for %s (%s)\n", file->filename, file->name); 804 return false; 802 805 } 803 806 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
