Changeset 5564 for trunk/archive/scripts/src/phase2/pmFPAWrite.c
- Timestamp:
- Nov 21, 2005, 5:00:14 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/archive/scripts/src/phase2/pmFPAWrite.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/pmFPAWrite.c
r5371 r5564 5 5 #include "pmFPA.h" 6 6 #include "pmFPAConceptsSet.h" 7 #include "pmFPARead.h" 7 8 8 9 static bool writeHDU(psFits *fits, // FITS file to which to write 9 p mPixelData *pixelData// Pixel data to write10 p_pmHDU *hdu // Pixel data to write 10 11 ) 11 12 { 12 13 bool status = true; // Status of write, to return 13 for (int i = 0; i < pixelData->images->n; i++) {14 status &= psFitsWriteImage(fits, pixelData->header, pixelData->images->data[i], i);14 for (int i = 0; i < hdu->images->n; i++) { 15 status &= psFitsWriteImage(fits, hdu->header, hdu->images->data[i], i); 15 16 // XXX: Insert here the writing on mask and weight images 16 17 } … … 47 48 pmCellOutgestConcepts(cell, db); 48 49 49 if (cell-> data && strlen(cell->data->extname) > 0) {50 status &= writeHDU(fits, cell-> data);50 if (cell->hdu && strlen(cell->hdu->extname) > 0) { 51 status &= writeHDU(fits, cell->hdu); 51 52 } 52 53 } 53 54 } 54 55 55 if (chip-> data && strlen(chip->data->extname) > 0) {56 status &= writeHDU(fits, chip-> data);56 if (chip->hdu && strlen(chip->hdu->extname) > 0) { 57 status &= writeHDU(fits, chip->hdu); 57 58 } 58 59 } … … 60 61 } 61 62 62 if (fpa-> data && strlen(fpa->data->extname) > 0) {63 status &= writeHDU(fits, fpa-> data);63 if (fpa->hdu && strlen(fpa->hdu->extname) > 0) { 64 status &= writeHDU(fits, fpa->hdu); 64 65 } 65 66 66 67 return status; 67 68 } 69 70 71 bool pmFPAWriteMask(pmFPA *fpa, // FPA containing mask to write 72 psFits *fits // FITS file for image 73 ) 74 { 75 const psMetadata *camera = fpa->camera; // Camera configuration for FPA 76 bool mdok = false; // Status of MD lookup 77 78 // Get the required information from the camera configuration 79 psMetadata *supps = psMetadataLookupMD(&mdok, camera, "SUPPLEMENTARY"); // Rules for supplementary data 80 if (! mdok || ! supps) { 81 psError(PS_ERR_IO, false, "Unable to find SUPPLEMENTARY in camera configuration!\n"); 82 return false; 83 } 84 psString sourceType = psMetadataLookupString(&mdok, supps, "MASK.SOURCE"); // Type of source: EXT | FILE 85 if (! mdok || strlen(sourceType) <= 0) { 86 psError(PS_ERR_IO, false, "Unable to find MASK.SOURCE in SUPPLEMENTARY section of camera " 87 "configuration!\n"); 88 return false; 89 } 90 psString name = psMetadataLookupString(&mdok, supps, "MASK.NAME"); // Name of mask 91 if (! mdok || strlen(sourceType) <= 0) { 92 psError(PS_ERR_IO, false, "Unable to find MASK.NAME in SUPPLEMENTARY section of camera " 93 "configuration!\n"); 94 return false; 95 } 96 97 // Go through the FPA to each cell/readout to get the mask 98 p_pmHDU *hdu = fpa->hdu; // The HDU into which we will read the mask 99 psArray *chips = fpa->chips; // Array of chips 100 for (int chipNum = 0; chipNum < chips->n; chipNum++) { 101 pmChip *chip = chips->data[chipNum]; // The current chip of interest 102 if (chip->valid) { 103 if (chip->hdu) { 104 hdu = chip->hdu; 105 } 106 psArray *cells = chip->cells; // Array of cells 107 for (int cellNum = 0; cellNum < cells->n; cellNum++) { 108 pmCell *cell = cells->data[cellNum]; // The current cell of interest 109 if (cell->valid) { 110 if (cell->hdu) { 111 hdu = cell->hdu; 112 } 113 114 // Now, need to find out where to write the pixels 115 psFits *maskDest = psMemIncrRefCounter(fits); // Destination of mask image 116 psMetadata *header = psMetadataAlloc(); // A dummy header, containing the extension name 117 if (strcasecmp(sourceType, "FILE") == 0) { 118 // Source is a file (with optional extension, e.g., "myMaskFile.fits:thisExt" 119 psString filenameExt = p_pmFPATranslateName(name, cell); 120 char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn 121 psString filename = NULL; // The filename 122 psString extname = NULL;// The extenstion name 123 if (colon) { 124 filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon)); 125 if (strlen(colon) > 1) { 126 extname = psStringCopy(colon + 1); 127 } 128 } else { 129 filename = psMemIncrRefCounter(filenameExt); 130 } 131 132 psFree(maskDest); 133 maskDest = psFitsAlloc(filename); 134 if (extname) { 135 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname); 136 } 137 psFree(filename); 138 psFree(extname); 139 psFree(filenameExt); 140 } else if (strncasecmp(sourceType, "EXT", 3) == 0) { 141 // Source is an extension in the original file 142 psString extname = p_pmFPATranslateName(name, cell); 143 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname); 144 psFree(extname); 145 } 146 147 // We've arrived where the pixels are. Now we need to write them out. 148 psArray *readouts = cell->readouts; // The array of readouts 149 for (int readNum = 0; readNum < readouts->n; readNum++) { 150 pmReadout *readout = readouts->data[readNum]; // The readout of interest 151 if (! readout->mask) { 152 psLogMsg(__func__, PS_LOG_WARN, "No mask to write out in %d,%d,%d\n", 153 chipNum, cellNum, readNum); 154 } else { 155 // XXX: Need to add the extname to the existing header 156 if (! psFitsWriteImage(maskDest, header, readout->mask, readNum)) { 157 psError(PS_ERR_IO, false, "Unable to write mask plane %d in extension %s\n", 158 readNum, hdu->extname); 159 return false; 160 } 161 } 162 } // Iterating over readouts 163 psFree(header); 164 psFree(maskDest); 165 } // Valid cells 166 } // Iterating over cells 167 } // Valid chips 168 } // Iterating over chips 169 170 return true; 171 } 172 173 174 bool pmFPAWriteWeight(pmFPA *fpa, // FPA containing mask to write 175 psFits *fits // FITS file for image 176 ) 177 { 178 const psMetadata *camera = fpa->camera; // Camera configuration for FPA 179 bool mdok = false; // Status of MD lookup 180 181 // Get the required information from the camera configuration 182 psMetadata *supps = psMetadataLookupMD(&mdok, camera, "SUPPLEMENTARY"); // Rules for supplementary data 183 if (! mdok || ! supps) { 184 psError(PS_ERR_IO, false, "Unable to find SUPPLEMENTARY in camera configuration!\n"); 185 return false; 186 } 187 psString sourceType = psMetadataLookupString(&mdok, supps, "WEIGHT.SOURCE"); // Type of source: EXT | FILE 188 if (! mdok || strlen(sourceType) <= 0) { 189 psError(PS_ERR_IO, false, "Unable to find WEIGHT.SOURCE in SUPPLEMENTARY section of camera " 190 "configuration!\n"); 191 return false; 192 } 193 psString name = psMetadataLookupString(&mdok, supps, "WEIGHT.NAME"); // Name of weight 194 if (! mdok || strlen(sourceType) <= 0) { 195 psError(PS_ERR_IO, false, "Unable to find WEIGHT.NAME in SUPPLEMENTARY section of camera " 196 "configuration!\n"); 197 return false; 198 } 199 200 // Go through the FPA to each cell/readout to get the weight 201 p_pmHDU *hdu = fpa->hdu; // The HDU into which we will read the weight 202 psArray *chips = fpa->chips; // Array of chips 203 for (int chipNum = 0; chipNum < chips->n; chipNum++) { 204 pmChip *chip = chips->data[chipNum]; // The current chip of interest 205 if (chip->valid) { 206 if (chip->hdu) { 207 hdu = chip->hdu; 208 } 209 psArray *cells = chip->cells; // Array of cells 210 for (int cellNum = 0; cellNum < cells->n; cellNum++) { 211 pmCell *cell = cells->data[cellNum]; // The current cell of interest 212 if (cell->valid) { 213 if (cell->hdu) { 214 hdu = cell->hdu; 215 } 216 217 // Now, need to find out where to write the pixels 218 psFits *weightDest = psMemIncrRefCounter(fits); // Destination of weight image 219 psMetadata *header = psMetadataAlloc(); // A dummy header, containing the extension name 220 if (strcasecmp(sourceType, "FILE") == 0) { 221 // Source is a file (with optional extension, e.g., "myWeightFile.fits:thisExt" 222 psString filenameExt = p_pmFPATranslateName(name, cell); 223 char *colon = strchr(filenameExt, ':'); // Pointer to a colon in the filename-extn 224 psString filename = NULL; // The filename 225 psString extname = NULL;// The extenstion name 226 if (colon) { 227 filename = psStringNCopy(filenameExt, strlen(filenameExt) - strlen(colon)); 228 if (strlen(colon) > 1) { 229 extname = psStringCopy(colon + 1); 230 } 231 } else { 232 filename = psMemIncrRefCounter(filenameExt); 233 } 234 235 psFree(weightDest); 236 weightDest = psFitsAlloc(filename); 237 if (extname) { 238 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname); 239 } 240 psFree(filename); 241 psFree(extname); 242 psFree(filenameExt); 243 } else if (strncasecmp(sourceType, "EXT", 3) == 0) { 244 // Source is an extension in the original file 245 psString extname = p_pmFPATranslateName(name, cell); 246 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", 0, "Extension name", extname); 247 psFree(extname); 248 } 249 250 // We've arrived where the pixels are. Now we need to write them out. 251 psArray *readouts = cell->readouts; // The array of readouts 252 for (int readNum = 0; readNum < readouts->n; readNum++) { 253 pmReadout *readout = readouts->data[readNum]; // The readout of interest 254 if (! readout->weight) { 255 psLogMsg(__func__, PS_LOG_WARN, "No weight image to write out in %d,%d,%d\n", 256 chipNum, cellNum, readNum); 257 } else { 258 if (! psFitsWriteImage(weightDest, header, readout->weight, readNum)) { 259 psError(PS_ERR_IO, false, "Unable to write weight plane %d in extension %s\n", 260 readNum, hdu->extname); 261 return false; 262 } 263 } 264 } // Iterating over readouts 265 psFree(header); 266 psFree(weightDest); 267 } // Valid cells 268 } // Iterating over cells 269 } // Valid chips 270 } // Iterating over chips 271 272 return true; 273 }
Note:
See TracChangeset
for help on using the changeset viewer.
