IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 11, 2006, 6:11:54 PM (20 years ago)
Author:
Paul Price
Message:

Removing old code that was #ifdef-ed out

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmFPAWrite.c

    r6734 r6840  
    7777}
    7878
    79 
    80 
    81 
    82 #if 0
    83 static bool writeHDU(psFits *fits,      // FITS file to which to write
    84                      pmHDU *hdu         // Pixel data to write
    85                     )
    86 {
    87     bool status = true;                 // Status of write, to return
    88     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 images
    91     }
    92 
    93     return status;
    94 }
    95 
    96 
    97 bool pmFPAWrite(psFits *fits,           // FITS file to which to write
    98                 pmFPA *fpa,             // FPA to write
    99                 psDB *db                // Database to update
    100                )
    101 {
    102     bool status = true;                 // Status of writing, to return
    103 
    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 header
    110     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 chips
    116     for (int i = 0; i < chips->n; i++) {
    117         pmChip *chip = chips->data[i];  // The component chip
    118         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 cells
    124             for (int j = 0; j < cells->n; j++) {
    125                 pmCell *cell = cells->data[j]; // The component cell
    126                 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 write
    155                     psFits *fits        // FITS file for image
    156                    )
    157 {
    158     const psMetadata *camera = fpa->camera; // Camera configuration for FPA
    159     bool mdok = false;                  // Status of MD lookup
    160 
    161     // Get the required information from the camera configuration
    162     psMetadata *supps = psMetadataLookupMD(&mdok, camera, "SUPPLEMENTARY"); // Rules for supplementary data
    163     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 | FILE
    168     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 mask
    174     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 mask
    181     p_pmHDU *hdu = fpa->hdu;            // The HDU into which we will read the mask
    182     psArray *chips = fpa->chips;        // Array of chips
    183     for (int chipNum = 0; chipNum < chips->n; chipNum++) {
    184         pmChip *chip = chips->data[chipNum]; // The current chip of interest
    185         if (chip->exists && chip->process) {
    186             if (chip->hdu) {
    187                 hdu = chip->hdu;
    188             }
    189             psArray *cells = chip->cells;       // Array of cells
    190             for (int cellNum = 0; cellNum < cells->n; cellNum++) {
    191                 pmCell *cell = cells->data[cellNum]; // The current cell of interest
    192                 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 pixels
    198                     psFits *maskDest = psMemIncrRefCounter(fits); // Destination of mask image
    199                     psMetadata *header = psMetadataAlloc(); // A dummy header, containing the extension name
    200                     if (strcasecmp(sourceType, "FILE") == 0) {
    201                         // Source is a file (with optional extension, e.g., "myMaskFile.fits:thisExt"
    202                         psString extname = NULL; // Extension name
    203                         psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename
    204                         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 file
    213                         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 readouts
    220                     for (int readNum = 0; readNum < readouts->n; readNum++) {
    221                         pmReadout *readout = readouts->data[readNum]; // The readout of interest
    222                         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 header
    227                             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 readouts
    234                     psFree(header);
    235                     psFree(maskDest);
    236                 } // Valid cells
    237             } // Iterating over cells
    238         } // Valid chips
    239     } // Iterating over chips
    240 
    241     return true;
    242 }
    243 
    244 
    245 bool pmFPAWriteWeight(pmFPA *fpa,       // FPA containing mask to write
    246                       psFits *fits      // FITS file for image
    247                      )
    248 {
    249     const psMetadata *camera = fpa->camera; // Camera configuration for FPA
    250     bool mdok = false;                  // Status of MD lookup
    251 
    252     // Get the required information from the camera configuration
    253     psMetadata *supps = psMetadataLookupMD(&mdok, camera, "SUPPLEMENTARY"); // Rules for supplementary data
    254     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 | FILE
    259     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 weight
    265     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 weight
    272     p_pmHDU *hdu = fpa->hdu;            // The HDU into which we will read the weight
    273     psArray *chips = fpa->chips;        // Array of chips
    274     for (int chipNum = 0; chipNum < chips->n; chipNum++) {
    275         pmChip *chip = chips->data[chipNum]; // The current chip of interest
    276         if (chip->exists && chip->process) {
    277             if (chip->hdu) {
    278                 hdu = chip->hdu;
    279             }
    280             psArray *cells = chip->cells;       // Array of cells
    281             for (int cellNum = 0; cellNum < cells->n; cellNum++) {
    282                 pmCell *cell = cells->data[cellNum]; // The current cell of interest
    283                 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 pixels
    289                     psFits *weightDest = psMemIncrRefCounter(fits); // Destination of weight image
    290                     psMetadata *header = psMetadataAlloc(); // A dummy header, containing the extension name
    291                     if (strcasecmp(sourceType, "FILE") == 0) {
    292                         // Source is a file (with optional extension, e.g., "myWeightFile.fits:thisExt"
    293                         psString extname = NULL; // Extension name
    294                         psString filename = p_pmFPATranslateFileExt(&extname, name, cell); // The filename
    295 
    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 file
    305                         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 readouts
    312                     for (int readNum = 0; readNum < readouts->n; readNum++) {
    313                         pmReadout *readout = readouts->data[readNum]; // The readout of interest
    314                         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 readouts
    325                     psFree(header);
    326                     psFree(weightDest);
    327                 } // Valid cells
    328             } // Iterating over cells
    329         } // Valid chips
    330     } // Iterating over chips
    331 
    332     return true;
    333 }
    334 #endif
Note: See TracChangeset for help on using the changeset viewer.