Changeset 11255
- Timestamp:
- Jan 23, 2007, 5:11:19 PM (19 years ago)
- Location:
- trunk/psModules/src/camera
- Files:
-
- 10 edited
-
pmFPAConstruct.c (modified) (2 diffs)
-
pmFPAConstruct.h (modified) (2 diffs)
-
pmFPACopy.c (modified) (4 diffs)
-
pmFPAMosaic.c (modified) (1 diff)
-
pmFPAWrite.c (modified) (1 diff)
-
pmFPAfile.c (modified) (1 diff)
-
pmFPAfileDefine.c (modified) (4 diffs)
-
pmFPAfileFitsIO.c (modified) (2 diffs)
-
pmFPAfileFitsIO.h (modified) (2 diffs)
-
pmFPAfileIO.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAConstruct.c
r11237 r11255 766 766 767 767 pmFPAview *view = addSource(fpa, phuView, NULL, format, true); 768 bool status = (view == NULL);768 bool status = (view != NULL); 769 769 psFree(view); 770 770 return status; … … 895 895 896 896 } 897 898 899 pmFPALevel pmFPAPHULevel(const psMetadata *format) 900 { 901 PS_ASSERT_METADATA_NON_NULL(format, PM_FPA_LEVEL_NONE); 902 903 bool mdok; // Status of MD lookup 904 psMetadata *fileInfo = psMetadataLookupMetadata(&mdok, format, "FILE"); // Contents of FILE metadata 905 if (!mdok || !fileInfo) { 906 psError(PS_ERR_UNKNOWN, true, "Unable to find FILE in camera format configuration.\n"); 907 return PM_FPA_LEVEL_NONE; 908 } 909 const char *phu = psMetadataLookupStr(&mdok, fileInfo, "PHU"); // PHU level 910 if (!mdok || !phu || strlen(phu) == 0) { 911 psError(PS_ERR_UNKNOWN, true, "Unable to find PHU in FILE in camera format configuration.\n"); 912 return PM_FPA_LEVEL_NONE; 913 } 914 915 return pmFPALevelFromName(phu); 916 } 917 918 pmFPALevel pmFPAExtensionsLevel(const psMetadata *format) 919 { 920 PS_ASSERT_METADATA_NON_NULL(format, PM_FPA_LEVEL_NONE); 921 922 bool mdok; // Status of MD lookup 923 psMetadata *fileInfo = psMetadataLookupMetadata(&mdok, format, "FILE"); // Contents of FILE metadata 924 if (!mdok || !fileInfo) { 925 psError(PS_ERR_UNKNOWN, true, "Unable to find FILE in camera format configuration.\n"); 926 return PM_FPA_LEVEL_NONE; 927 } 928 929 const char *extensions = psMetadataLookupStr(&mdok, fileInfo, "EXTENSIONS"); // EXTENSIONS level 930 if (!mdok || !extensions || strlen(extensions) == 0) { 931 psError(PS_ERR_UNKNOWN, true, "Unable to find EXTENSIONS in FILE in camera format configuration.\n"); 932 return PM_FPA_LEVEL_NONE; 933 } 934 935 return pmFPALevelFromName(extensions); 936 } 937 -
trunk/psModules/src/camera/pmFPAConstruct.h
r11253 r11255 4 4 * @author Paul Price, IfA 5 5 * 6 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-01-24 0 2:54:14$6 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-01-24 03:11:19 $ 8 8 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 9 9 */ … … 61 61 bool concepts ///< Print concepts? 62 62 ); 63 64 /// Return the PHU level for an FPA, given the format 65 pmFPALevel pmFPAPHULevel(const psMetadata *format); 66 67 /// Return the Extensions level for an FPA, given the format 68 pmFPALevel pmFPAExtensionsLevel(const psMetadata *format); 69 63 70 /// @} 71 64 72 #endif -
trunk/psModules/src/camera/pmFPACopy.c
r10516 r11255 37 37 } 38 38 39 #if 0 39 40 // Find the blank (image-less) PHU, given a cell. 40 41 static pmHDU *findBlankPHU(const pmCell *cell // The cell for which to find the PHU … … 57 58 return NULL; 58 59 } 60 #endif 59 61 60 62 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 277 279 binItem->data.S32 *= yBin; 278 280 281 #if 0 279 282 // Copy any headers 280 283 pmHDU *targetHDU = pmHDUFromCell(target); // The target HDU … … 285 288 } 286 289 } 290 287 291 // Copy the PHU over as well, if required 288 292 pmHDU *targetPHU = findBlankPHU(target); // The target PHU 289 293 if (targetPHU && targetPHU != targetHDU && !targetPHU->header) { 290 pmHDU *sourcePHU = findBlankPHU(source); // The source PHU 291 if (sourcePHU->header) { 294 // pmHDU *sourcePHU = pmHDUGetHighest(source->parent->parent, source->parent, source); // A source HDU 295 pmHDU *sourcePHU = findBlankPHU(source); // The target PHU 296 if (sourcePHU && sourcePHU->header) { 292 297 targetPHU->header = psMetadataCopy(targetPHU->header, sourcePHU->header); 293 298 } 294 299 } 300 #endif 295 301 296 302 target->data_exists = true; -
trunk/psModules/src/camera/pmFPAMosaic.c
r10966 r11255 1200 1200 return false; 1201 1201 } 1202 targetHDU->header = psMetadataCopy(targetHDU->header, sourceHDU->header); 1202 1203 if (sourceHDU->header) { 1204 targetHDU->header = psMetadataCopy(targetHDU->header, sourceHDU->header); 1205 } else if (!targetHDU->header) { 1206 targetHDU->header = psMetadataAlloc(); 1207 } 1203 1208 1204 1209 if (!pmConfigConformHeader(targetHDU->header, targetHDU->format)) { -
trunk/psModules/src/camera/pmFPAWrite.c
r10966 r11255 38 38 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU.\n"); 39 39 return false; 40 } 41 if (!hdu->header) { 42 hdu->header = psMetadataAlloc(); 40 43 } 41 44 bool mdok; // Status of MD lookup -
trunk/psModules/src/camera/pmFPAfile.c
r11144 r11255 382 382 return PM_FPA_FILE_NONE; 383 383 } 384 -
trunk/psModules/src/camera/pmFPAfileDefine.c
r11242 r11255 106 106 } 107 107 108 // Check the various levels for file operations to make sure that they are suitable based on the format 109 static void adjustLevels(pmFPAfile *file, // File for which to adjust levels 110 const psMetadata *format // Format to use to adjust levels 111 ) 112 { 113 assert(file); 114 assert(format); 115 116 117 return; 118 } 119 108 120 // define a pmFPAfile, bind to the optional fpa if supplied 109 121 pmFPAfile *pmFPAfileDefineOutput(pmConfig *config, pmFPA *fpa, const char *name) … … 167 179 } 168 180 169 file->fileLevel = pmFPALevelFromName(psMetadataLookupStr(&status, data, "FILE.LEVEL")); 181 file->camera = psMemIncrRefCounter(config->camera); 182 const char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT"); 183 psMetadata *format = NULL; // Camera format to use 184 if (formatName && strcasecmp(formatName, "NONE") != 0) { 185 // select the format list from the selected camera 186 psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats 187 188 // select the desired format 189 format = psMetadataLookupMetadata(&status, formats, formatName); 190 if (!format) { 191 psError(PS_ERR_IO, false, "format %s for %s not defined", formatName, name); 192 psFree(file); 193 return NULL; 194 } 195 file->format = psMemIncrRefCounter(format); 196 #if 0 197 198 file->src = psMemIncrRefCounter(fpa); 199 file->fpa = pmFPAConstruct(file->camera); 200 #endif 201 202 } else { 203 format = config->format; 204 #if 0 205 206 file->fpa = psMemIncrRefCounter(fpa); 207 #endif 208 209 } 210 #if 1 211 file->fpa = psMemIncrRefCounter(fpa); 212 #endif 213 214 215 file->fileLevel = pmFPAPHULevel(format); 170 216 if (file->fileLevel == PM_FPA_LEVEL_NONE) { 171 psError(PS_ERR_IO, true, " FILE.LEVEL is not setfor %s\n", name);172 return NULL; 173 } 174 175 file->dataLevel = pmFPALevelFromName(psMetadataLookupStr (&status, data, "DATA.LEVEL"));217 psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", name); 218 return NULL; 219 } 220 221 file->dataLevel = pmFPALevelFromName(psMetadataLookupStr(&status, data, "DATA.LEVEL")); 176 222 if (file->dataLevel == PM_FPA_LEVEL_NONE) { 177 223 psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name); … … 182 228 file->freeLevel = file->dataLevel; 183 229 184 if (fpa != NULL) { 185 file->fpa = psMemIncrRefCounter(fpa); 186 } 187 188 #if 0 189 // for WRITE type of data, the output format needs to be determined 190 // this is only needed if the output file is not identical in structure to the input? 191 // for 192 char *formatLine = psMetadataLookupStr (&status, data, "FILE.FORMAT"); 193 if (formatLine && strcasecmp (formatLine, "NONE")) { 194 195 char *formatName = NULL; 196 197 psArray *words = psStringSplitArray (formatLine, ":", false); 198 if (!words || !words->n) { 199 psAbort("pmFPAfileDefine", "programming error: cannot be NULL or empty!"); 200 } 201 if (words->n == 1) { 202 // format selected in this camera 203 formatName = formatLine; 204 file->camera = psMemIncrRefCounter (config->camera); 205 } 206 if (words->n == 2) { 207 // select the requested camera 208 formatName = words->data[1]; 209 file->camera = pmConfigCameraByName(config, words->data[0]); 210 // XXX do we need to save the camera name? 211 if (!file->camera) { 212 psError(PS_ERR_IO, false, "camera %s not found\n", (char *)words->data[0]); 213 psFree(words); 214 return NULL; 215 } 216 } 217 218 // select the format list from the selected camera 219 psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats 220 221 // select the desired format 222 char *formatFile = psMetadataLookupStr (&status, formats, formatName); 223 if (!formatFile) { 224 psError(PS_ERR_IO, false, "format %s for %s not defined", formatName, name); 225 psFree (file); 226 psFree (words); 227 return NULL; 228 } 229 pmConfigFileRead(&file->format, formatFile, formatName); 230 psFree (words); 231 } 232 #endif 230 pmFPALevel extLevel = pmFPAExtensionsLevel(format); // Level for extensions 231 if (extLevel != PM_FPA_LEVEL_NONE) { 232 if (extLevel < file->dataLevel) { 233 psWarning("Level for extensions is higher than desired data level --- adjusting.\n"); 234 file->dataLevel = extLevel; 235 } 236 if (extLevel < file->freeLevel) { 237 psWarning("Level for extensions is higher than desired free level --- adjusting.\n"); 238 file->freeLevel = extLevel; 239 } 240 } 241 adjustLevels(file, format); 242 233 243 234 244 // add argument-supplied OUTPUT name to this file 235 245 char *outname = psMetadataLookupStr(&status, config->arguments, "OUTPUT"); 236 psMetadataAddStr (file->names, PS_LIST_TAIL, "OUTPUT", PS_META_NO_REPLACE, "", outname);246 psMetadataAddStr(file->names, PS_LIST_TAIL, "OUTPUT", PS_META_NO_REPLACE, "", outname); 237 247 238 248 // place the resulting file in the config system … … 241 251 return (file); // the returned value is a view into the version on 'files' 242 252 } 253 243 254 244 255 // search for argname on the config->argument list -
trunk/psModules/src/camera/pmFPAfileFitsIO.c
r10081 r11255 16 16 #include "pmFPAfile.h" 17 17 #include "pmFPAfileFitsIO.h" 18 #include "pmFPACopy.h" 19 20 pmFPA *pmFPAfileSuitableFPA(const pmFPAfile *file, const pmFPAview *view) 21 { 22 PS_ASSERT_PTR_NON_NULL(file, NULL); 23 PS_ASSERT_PTR_NON_NULL(view, NULL); 24 25 if (!file->format) { 26 return psMemIncrRefCounter(file->fpa); 27 } 28 29 // Need to change format 30 pmFPA *fpa = pmFPAConstruct(file->camera); 31 32 pmFPAview *phuView = pmFPAviewAlloc(0); // View corresponding to the PHU 33 *phuView = *view; // Copy contents 34 pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level for the PHU 35 switch (phuLevel) { 36 case PM_FPA_LEVEL_FPA: 37 phuView->chip = -1; 38 // Flow through 39 case PM_FPA_LEVEL_CHIP: 40 phuView->cell = -1; 41 // Flow through 42 case PM_FPA_LEVEL_CELL: 43 phuView->readout = -1; 44 break; 45 case PM_FPA_LEVEL_READOUT: 46 case PM_FPA_LEVEL_NONE: 47 default: 48 psAbort(PS_FILE_LINE, "Should never get here: bad phu level.\n"); 49 } 50 51 if (!pmFPAAddSourceFromView(fpa, phuView, file->format)) { 52 psError(PS_ERR_UNKNOWN, false, "Unable to insert HDU into FPA for writing.\n"); 53 psFree(fpa); 54 psFree(phuView); 55 return false; 56 } 57 psFree(phuView); 58 59 60 switch (phuLevel) { 61 case PM_FPA_LEVEL_FPA: 62 if (!pmFPACopy(fpa, file->fpa)) { 63 psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for format conversion.\n"); 64 return NULL; 65 } 66 return fpa; 67 case PM_FPA_LEVEL_CHIP: { 68 pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest 69 pmChip *srcChip = pmFPAviewThisChip(view, file->fpa); // Source chip 70 if (!pmChipCopy(chip, srcChip)) { 71 psError(PS_ERR_UNKNOWN, false, "Unable to copy chip for format conversion.\n"); 72 return false; 73 } 74 return fpa; 75 } 76 case PM_FPA_LEVEL_CELL: { 77 pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest 78 pmCell *srcCell = pmFPAviewThisCell(view, file->fpa); // Source cell 79 if (!pmCellCopy(cell, srcCell)) { 80 psError(PS_ERR_UNKNOWN, false, "Unable to copy cell for format conversion.\n"); 81 return false; 82 } 83 return fpa; 84 } 85 case PM_FPA_LEVEL_READOUT: 86 case PM_FPA_LEVEL_NONE: 87 default: 88 psAbort(PS_FILE_LINE, "Should never get here: bad phu level.\n"); 89 } 90 return NULL; 91 } 18 92 19 93 // given an already-opened fits file, read the table corresponding to the specified view … … 159 233 assert(file); 160 234 161 pmFPA *fpa = file->fpa; // FPA of interest162 235 psFits *fits = file->fits; // FITS file 163 164 // pmFPAWrite takes care of all PHUs as needed 165 if (view->chip == -1) { 166 return fpaWriteFunc(fpa, fits, NULL, false, true); 167 } 168 169 if (view->chip >= fpa->chips->n) { 170 psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n); 171 return false; 172 } 173 pmChip *chip = fpa->chips->data[view->chip]; // Chip of interest 174 175 if (view->cell == -1) { 176 return chipWriteFunc(chip, fits, NULL, false, true); 177 } 178 179 if (view->cell >= chip->cells->n) { 180 psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n); 181 return false; 182 } 183 pmCell *cell = chip->cells->data[view->cell]; // Cell of interest 184 185 if (view->readout == -1) { 186 return cellWriteFunc(cell, fits, NULL, false); 187 } 188 psError(PS_ERR_UNKNOWN, true, "Bad view: %d,%d", view->chip, view->cell); 236 PS_ASSERT_PTR_NON_NULL(fits, false); 237 238 pmFPA *fpa = pmFPAfileSuitableFPA(file, view); // FPA to write 239 240 switch (pmFPAviewLevel(view)) { 241 case PM_FPA_LEVEL_FPA: { 242 bool success = fpaWriteFunc(fpa, fits, NULL, false, true); 243 psFree(fpa); 244 return success; 245 } 246 case PM_FPA_LEVEL_CHIP: { 247 pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest 248 bool success = chipWriteFunc(chip, fits, NULL, false, true); 249 psFree(fpa); 250 return success; 251 } 252 case PM_FPA_LEVEL_CELL: { 253 pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest 254 bool success = cellWriteFunc(cell, fits, NULL, false); 255 psFree(fpa); 256 return success; 257 } 258 case PM_FPA_LEVEL_READOUT: 259 #if 0 // XXX disable readout write for now 260 261 { 262 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); // Readout of interest 263 if (changeFormat) 264 { 265 // No copy function defined for readouts! 266 psError(PS_ERR_UNKNOWN, false, "Unable to copy readout for format conversion on write.\n"); 267 return false; 268 } 269 if (view->nRows == 0) 270 { 271 return pmReadoutWrite(readout, fits, NULL, NULL); 272 } else 273 { 274 return pmReadoutWriteSegment(readout, fits, view->nRows, view->iRows, NULL, NULL); 275 } 276 } 277 #endif 278 case PM_FPA_LEVEL_NONE: 279 default: 280 psAbort(PS_FILE_LINE, "Should never reach here: invalid file level."); 281 } 282 189 283 return false; 190 191 // XXX disable readout write for now192 #if 0193 194 if (view->readout >= cell->readouts->n) {195 psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",196 view->readout, cell->readouts->n);197 return false;198 }199 pmReadout *readout = cell->readouts->data[view->readout];200 201 if (view->nRows == 0) {202 pmReadoutWrite (readout, fits, NULL, NULL);203 } else {204 pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);205 }206 return true;207 #endif208 284 } 209 285 -
trunk/psModules/src/camera/pmFPAfileFitsIO.h
r11253 r11255 5 5 * @author PAP, IfA 6 6 * 7 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-01-24 0 2:54:14$7 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-01-24 03:11:19 $ 9 9 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii 10 10 */ … … 61 61 const char *name ///< Name of table 62 62 ); 63 64 /// Produce a suitable FPA for writing, on the basis of the input FPAfile 65 /// 66 /// A format change is done is required. Otherwise the file->fpa is returned (incremented). 67 pmFPA *pmFPAfileSuitableFPA(const pmFPAfile *file,///< File containing the fpa 68 const pmFPAview *view ///< View at which to produce the fpa 69 ); 70 63 71 /// @} 72 64 73 # endif -
trunk/psModules/src/camera/pmFPAfileIO.c
r11242 r11255 108 108 } 109 109 if (file->mode == PM_FPA_MODE_WRITE) { 110 // Want to write out any potential blank 111 pmFPA *fpa = pmFPAfileSuitableFPA(file, view); 112 110 113 switch (file->fileLevel) { 111 114 case PM_FPA_LEVEL_FPA: 112 pmFPAWrite (file->fpa, file->fits, NULL, true, false);115 pmFPAWrite(fpa, file->fits, NULL, true, false); 113 116 break; 114 117 case PM_FPA_LEVEL_CHIP: { 115 pmChip *chip = pmFPAviewThisChip(view, f ile->fpa);116 pmChipWrite (chip, file->fits, NULL, true, false);118 pmChip *chip = pmFPAviewThisChip(view, fpa); 119 pmChipWrite(chip, file->fits, NULL, true, false); 117 120 break; 118 121 } 119 122 case PM_FPA_LEVEL_CELL: { 120 pmCell *cell = pmFPAviewThisCell(view, f ile->fpa);123 pmCell *cell = pmFPAviewThisCell(view, fpa); 121 124 pmCellWrite(cell, file->fits, NULL, true); 122 125 break; … … 126 129 break; 127 130 } 131 132 psFree(fpa); 128 133 } 129 134 … … 152 157 return true; 153 158 } 159 160 #if 0 161 // do we need to open this file? 162 if (level != file->fileLevel) { 163 psTrace("psModules.camera", 6, "skip open of %s at this level %s: fileLevel is %s", 164 file->name, pmFPALevelToName(level), pmFPALevelToName(file->fileLevel)); 165 return true; 166 } 167 #endif 154 168 155 169 if (file->mode == PM_FPA_MODE_NONE) { … … 755 769 switch (place) { 756 770 case PM_FPA_BEFORE: 771 #if 0 772 773 if (!pmFPAfileOpen(file, view, config)) { 774 psError(PS_ERR_IO, false, "failed OPEN in FPA_BEFORE block for %s", file->name); 775 goto failure; 776 } 777 #endif 757 778 if (!pmFPAfileRead (file, view, config)) { 758 779 psError(PS_ERR_IO, false, "failed READ in FPA_BEFORE block for %s", file->name);
Note:
See TracChangeset
for help on using the changeset viewer.
