Changeset 6840 for branches/rel10_ifa/psModules/src/astrom/pmFPAWrite.c
- Timestamp:
- Apr 11, 2006, 6:11:54 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmFPAWrite.c
r6734 r6840 77 77 } 78 78 79 80 81 82 #if 083 static bool writeHDU(psFits *fits, // FITS file to which to write84 pmHDU *hdu // Pixel data to write85 )86 {87 bool status = true; // Status of write, to return88 for (int i = 0; i < hdu->images->n; i++) {89 status &= psFitsWriteImage(fits, hdu->header, hdu->images->data[i], i);90 // XXX: Insert here the writing on mask and weight images91 }92 93 return status;94 }95 96 97 bool pmFPAWrite(psFits *fits, // FITS file to which to write98 pmFPA *fpa, // FPA to write99 psDB *db // Database to update100 )101 {102 bool status = true; // Status of writing, to return103 104 psTrace(__func__, 1, "Writing FPA...\n");105 106 psTrace(__func__, 7, "Outgesting FPA concepts...\n");107 pmConceptsWriteFPA(fpa, db);108 109 // Write the primary header110 if (fpa->phu) {111 status &= psFitsMoveExtNum(fits, 0, false);112 status &= psFitsWriteHeader(fpa->phu, fits);113 }114 115 psArray *chips = fpa->chips; // Array of component chips116 for (int i = 0; i < chips->n; i++) {117 pmChip *chip = chips->data[i]; // The component chip118 if (chip && chip->exists && chip->process) {119 psTrace(__func__, 1, "Writing out chip %d...\n", i);120 121 pmConceptsWriteChip(chip, db);122 123 psArray *cells = chip->cells; // Array of component cells124 for (int j = 0; j < cells->n; j++) {125 pmCell *cell = cells->data[j]; // The component cell126 if (cell && cell->exists && cell->process) {127 psTrace(__func__, 2, "Writing out cell, %d...\n", j);128 129 pmConceptsWriteCell(cell, db);130 131 if (cell->hdu && strlen(cell->hdu->extname) > 0) {132 status &= writeHDU(fits, cell->hdu);133 }134 }135 }136 137 if (chip->hdu && strlen(chip->hdu->extname) > 0) {138 status &= writeHDU(fits, chip->hdu);139 }140 }141 142 }143 144 if (fpa->hdu && strlen(fpa->hdu->extname) > 0) {145 status &= writeHDU(fits, fpa->hdu);146 }147 148 psTrace(__func__, 1, "Done writing FPA...\n");149 150 return status;151 }152 153 154 bool pmFPAWriteMask(pmFPA *fpa, // FPA containing mask to write155 psFits *fits // FITS file for image156 )157 {158 const psMetadata *camera = fpa->camera; // Camera configuration for FPA159 bool mdok = false; // Status of MD lookup160 161 // Get the required information from the camera configuration162 psMetadata *supps = psMetadataLookupMD(&mdok, camera, "SUPPLEMENTARY"); // Rules for supplementary data163 if (! mdok || ! supps) {164 psError(PS_ERR_IO, false, "Unable to find SUPPLEMENTARY in camera configuration!\n");165 return false;166 }167 psString sourceType = psMetadataLookupStr(&mdok, supps, "MASK.SOURCE"); // Type of source: EXT | FILE168 if (! mdok || strlen(sourceType) <= 0) {169 psError(PS_ERR_IO, false, "Unable to find MASK.SOURCE in SUPPLEMENTARY section of camera "170 "configuration!\n");171 return false;172 }173 psString name = psMetadataLookupStr(&mdok, supps, "MASK.NAME"); // Name of mask174 if (! mdok || strlen(sourceType) <= 0) {175 psError(PS_ERR_IO, false, "Unable to find MASK.NAME in SUPPLEMENTARY section of camera "176 "configuration!\n");177 return false;178 }179 180 // Go through the FPA to each cell/readout to get the mask181 p_pmHDU *hdu = fpa->hdu; // The HDU into which we will read the mask182 psArray *chips = fpa->chips; // Array of chips183 for (int chipNum = 0; chipNum < chips->n; chipNum++) {184 pmChip *chip = chips->data[chipNum]; // The current chip of interest185 if (chip->exists && chip->process) {186 if (chip->hdu) {187 hdu = chip->hdu;188 }189 psArray *cells = chip->cells; // Array of cells190 for (int cellNum = 0; cellNum < cells->n; cellNum++) {191 pmCell *cell = cells->data[cellNum]; // The current cell of interest192 if (cell->exists && cell->process) {193 if (cell->hdu) {194 hdu = cell->hdu;195 }196 197 // Now, need to find out where to write the pixels198 psFits *maskDest = psMemIncrRefCounter(fits); // Destination of mask image199 psMetadata *header = psMetadataAlloc(); // A dummy header, containing the extension name200 if (strcasecmp(sourceType, "FILE") == 0) {201 // Source is a file (with optional extension, e.g., "myMaskFile.fits:thisExt"202 psString extname = NULL; // Extension name203 psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename204 psFree(maskDest);205 maskDest = psFitsOpen(filename, "rw");206 if (extname) {207 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname);208 }209 psFree(filename);210 psFree(extname);211 } else if (strncasecmp(sourceType, "EXT", 3) == 0) {212 // Source is an extension in the original file213 psString extname = p_pmFPATranslateName(name, cell);214 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname);215 psFree(extname);216 }217 218 // We've arrived where the pixels are. Now we need to write them out.219 psArray *readouts = cell->readouts; // The array of readouts220 for (int readNum = 0; readNum < readouts->n; readNum++) {221 pmReadout *readout = readouts->data[readNum]; // The readout of interest222 if (! readout->mask) {223 psLogMsg(__func__, PS_LOG_WARN, "No mask to write out in %d,%d,%d\n",224 chipNum, cellNum, readNum);225 } else {226 // XXX: Need to add the extname to the existing header227 if (! psFitsWriteImage(maskDest, header, readout->mask, readNum)) {228 psError(PS_ERR_IO, false, "Unable to write mask plane %d in extension %s\n",229 readNum, hdu->extname);230 return false;231 }232 }233 } // Iterating over readouts234 psFree(header);235 psFree(maskDest);236 } // Valid cells237 } // Iterating over cells238 } // Valid chips239 } // Iterating over chips240 241 return true;242 }243 244 245 bool pmFPAWriteWeight(pmFPA *fpa, // FPA containing mask to write246 psFits *fits // FITS file for image247 )248 {249 const psMetadata *camera = fpa->camera; // Camera configuration for FPA250 bool mdok = false; // Status of MD lookup251 252 // Get the required information from the camera configuration253 psMetadata *supps = psMetadataLookupMD(&mdok, camera, "SUPPLEMENTARY"); // Rules for supplementary data254 if (! mdok || ! supps) {255 psError(PS_ERR_IO, false, "Unable to find SUPPLEMENTARY in camera configuration!\n");256 return false;257 }258 psString sourceType = psMetadataLookupStr(&mdok, supps, "WEIGHT.SOURCE"); // Type of source: EXT | FILE259 if (! mdok || strlen(sourceType) <= 0) {260 psError(PS_ERR_IO, false, "Unable to find WEIGHT.SOURCE in SUPPLEMENTARY section of camera "261 "configuration!\n");262 return false;263 }264 psString name = psMetadataLookupStr(&mdok, supps, "WEIGHT.NAME"); // Name of weight265 if (! mdok || strlen(sourceType) <= 0) {266 psError(PS_ERR_IO, false, "Unable to find WEIGHT.NAME in SUPPLEMENTARY section of camera "267 "configuration!\n");268 return false;269 }270 271 // Go through the FPA to each cell/readout to get the weight272 p_pmHDU *hdu = fpa->hdu; // The HDU into which we will read the weight273 psArray *chips = fpa->chips; // Array of chips274 for (int chipNum = 0; chipNum < chips->n; chipNum++) {275 pmChip *chip = chips->data[chipNum]; // The current chip of interest276 if (chip->exists && chip->process) {277 if (chip->hdu) {278 hdu = chip->hdu;279 }280 psArray *cells = chip->cells; // Array of cells281 for (int cellNum = 0; cellNum < cells->n; cellNum++) {282 pmCell *cell = cells->data[cellNum]; // The current cell of interest283 if (cell->exists && cell->process) {284 if (cell->hdu) {285 hdu = cell->hdu;286 }287 288 // Now, need to find out where to write the pixels289 psFits *weightDest = psMemIncrRefCounter(fits); // Destination of weight image290 psMetadata *header = psMetadataAlloc(); // A dummy header, containing the extension name291 if (strcasecmp(sourceType, "FILE") == 0) {292 // Source is a file (with optional extension, e.g., "myWeightFile.fits:thisExt"293 psString extname = NULL; // Extension name294 psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename295 296 psFree(weightDest);297 weightDest = psFitsOpen(filename, "rw");298 if (extname) {299 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname);300 }301 psFree(filename);302 psFree(extname);303 } else if (strncasecmp(sourceType, "EXT", 3) == 0) {304 // Source is an extension in the original file305 psString extname = p_pmFPATranslateName(name, cell);306 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname);307 psFree(extname);308 }309 310 // We've arrived where the pixels are. Now we need to write them out.311 psArray *readouts = cell->readouts; // The array of readouts312 for (int readNum = 0; readNum < readouts->n; readNum++) {313 pmReadout *readout = readouts->data[readNum]; // The readout of interest314 if (! readout->weight) {315 psLogMsg(__func__, PS_LOG_WARN, "No weight image to write out in %d,%d,%d\n",316 chipNum, cellNum, readNum);317 } else {318 if (! psFitsWriteImage(weightDest, header, readout->weight, readNum)) {319 psError(PS_ERR_IO, false, "Unable to write weight plane %d in extension %s\n",320 readNum, hdu->extname);321 return false;322 }323 }324 } // Iterating over readouts325 psFree(header);326 psFree(weightDest);327 } // Valid cells328 } // Iterating over cells329 } // Valid chips330 } // Iterating over chips331 332 return true;333 }334 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
