IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7889


Ignore:
Timestamp:
Jul 12, 2006, 4:24:06 PM (20 years ago)
Author:
Paul Price
Message:

Check the output file to see if it already defines the fringe regions.
If not, do it ourselves. Code just about done. No memory leaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppFringe/src/ppFringeLoop.c

    r7838 r7889  
    99    )
    1010{
    11     psFitsWriteBlank(data->outFile, NULL);
     11    psRandom *rng = NULL; // Random number generator
    1212
     13    // Set up output header
     14    const char *detId = psMetadataLookupStr(NULL, config->arguments, "-detid"); // Detector ID, for header
     15    const char *classId = psMetadataLookupStr(NULL, config->arguments, "-classid"); // Class ID, for header
     16    psMetadata *outHeader = psMetadataAlloc(); // Header for output
     17    if (detId && strlen(detId) > 0) {
     18        psMetadataAddStr(outHeader, PS_LIST_TAIL, "DETID", 0, "Detector ID for this image.", detId);
     19    }
     20    if (classId && strlen(classId) > 0) {
     21        psMetadataAddStr(outHeader, PS_LIST_TAIL, "CLASSID", 0, "Class ID for this image.", classId);
     22    }
     23
     24    // Get table of contents for the output FITS file
     25    psMetadata *contents = psFitsReadHeaderSet(NULL, data->outFile);
     26#if 0
     27    psMetadataPrint(stdout, contents, 0);
     28    exit(EXIT_FAILURE);
     29#endif
     30    if (!contents || contents->list->n == 0) {
     31        psFitsWriteBlank(data->outFile, NULL);
     32    }
     33
     34    // Iterate through the FPA
    1335    pmFPA *fpa = data->inFPA;           // The FPA of interest
    1436    psArray *chips = fpa->chips;        // Array of component chips
     
    5072            }
    5173
    52             // Create points to measure fringes
    53             pmFringeRegions *regions = pmFringeRegionsAlloc(data->numPoints, data->xWidth, data->yWidth,
    54                                                             data->xSmooth, data->ySmooth);
    55             if (!pmFringeRegionsCreatePoints(regions, readout->image)) {
    56                 psLogMsg(__func__, PS_LOG_WARN, "Unable to create fringe regions for chip %s cell %s --- "
     74            // Look for this chip/cell in the output file
     75            pmFringeRegions *regions = NULL; // Points at which to measure fringes
     76            bool preDefined = false;    // Are the regions defined in the output file?
     77            psString extname = NULL;
     78            psStringAppend(&extname, "%s_%s", chipName, cellName);
     79            if (contents && contents->list->n > 0) {
     80                bool mdok;              // Status of MD lookup
     81                psMetadata *header = psMetadataLookupMD(&mdok, contents, extname); // Header
     82                if (mdok && header) {
     83                    regions = pmFringeRegionsReadFits(NULL, data->outFile, extname);
     84                    if (regions) {
     85                        preDefined = true;
     86                    } else {
     87                        psLogMsg(__func__, PS_LOG_WARN, "Unable to read fringe regions for chip %s cell %s "
     88                                 " --- will generate new regions.\n", chipName, cellName);
     89                    }
     90                }
     91            }
     92
     93            // Otherwise, generate one ourselves
     94            if (!regions) {
     95                if (!rng) {
     96                    rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     97                }
     98                // Create points to measure fringes
     99                regions = pmFringeRegionsAlloc(data->numPoints, data->xWidth, data->yWidth,
     100                                               data->xSmooth, data->ySmooth);
     101                if (!pmFringeRegionsCreatePoints(regions, readout->image, rng)) {
     102                    psLogMsg(__func__, PS_LOG_WARN, "Unable to create fringe regions for chip %s cell %s --- "
     103                             "ignored.\n", chipName, cellName);
     104                    psFree(extname);
     105                    psFree(regions);
     106                    pmCellFreeData(cell);
     107                    continue;
     108                }
     109            }
     110
     111            // Measure fringes
     112            pmFringeStats *fringeStats = pmFringeStatsMeasure(regions, readout, data->maskVal);
     113            psFree(regions);            // Drop reference
     114            if (!fringeStats) {
     115                psLogMsg(__func__, PS_LOG_WARN, "Unable to measure fringes for chip %s cell %s --- "
    57116                         "ignored.\n", chipName, cellName);
    58                 psFree(regions);
    59117                pmCellFreeData(cell);
    60118                continue;
    61119            }
    62120
    63             // Measure fringes
    64             pmFringeStats *fringeStats = pmFringeStatsMeasure(regions, readout, data->maskVal);
    65             if (!fringeStats) {
    66                 psLogMsg(__func__, PS_LOG_WARN, "Unable to measure fringes for chip %s cell %s --- "
     121            // Write fringe regions
     122            if (!preDefined &&
     123                !pmFringeRegionsWriteFits(data->outFile, NULL, fringeStats->regions, extname)) {
     124                psLogMsg(__func__, PS_LOG_WARN, "Unable to write fringe regions for chip %s cell %s --- "
    67125                         "ignored.\n", chipName, cellName);
    68                 psFree(regions);
     126                psFree(fringeStats);
     127                psFree(extname);
    69128                pmCellFreeData(cell);
    70129                continue;
    71130            }
    72131
     132            int version = 0;            // Version number
     133            if (preDefined) {
     134                // Find the lowest possible version number that isn't already taken
     135                psMetadata *header = NULL; // Header from the table of contents
     136                bool mdok = true;       // Status of MD lookup
     137                do {
     138                    version++;
     139                    psString checkName = NULL; // Extension name to check
     140                    psStringAppend(&checkName, "%s:%d", extname, version);
     141                    header = psMetadataLookupMD(&mdok, contents, checkName);
     142                    psFree(checkName);
     143                } while (mdok && header);
     144            }
     145
    73146            // Write fringe measurements
    74             psString extname = NULL;
    75             psStringAppend(&extname, "%s_%s", chipName, cellName);
    76             if (!pmFringeStatsWriteFits(data->outFile, fringeStats, extname)) {
     147            psStringAppend(&extname, ":%d", version);
     148            if (!pmFringeStatsWriteFits(data->outFile, outHeader, fringeStats, extname)) {
    77149                psLogMsg(__func__, PS_LOG_WARN, "Unable to write fringe measurements for chip %s cell %s --- "
    78150                         "ignored.\n", chipName, cellName);
    79                 psFree(regions);
    80151                psFree(fringeStats);
     152                psFree(extname);
    81153                pmCellFreeData(cell);
    82154                continue;
    83155            }
    84156
    85             psFree(regions);
    86157            psFree(fringeStats);
     158            psFree(extname);
    87159            pmCellFreeData(cell);
    88160        }
     
    90162    }
    91163    pmFPAFreeData(fpa);
     164
     165    psFree(rng);
     166    psFree(contents);
     167    psFree(outHeader);
     168
     169    return;
    92170}
Note: See TracChangeset for help on using the changeset viewer.