IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 14, 2006, 4:55:08 PM (20 years ago)
Author:
Paul Price
Message:

Making ppStats into a library, so we can incorporate it into ppImage, etc. There's still an executable which provides a wrapper to the functionality. Nothing tested yet following the change.

Location:
trunk/ppStats
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStats

    • Property svn:ignore
      •  

        old new  
        1010install-sh
        1111missing
         12config.guess
         13config.sub
         14libtool
         15ltmain.sh
         16ppStats.pc
  • trunk/ppStats/src

    • Property svn:ignore
      •  

        old new  
        22Makefile
        33Makefile.in
         4.libs
         5*.lo
         6*.la
        47ppStats
  • trunk/ppStats/src/ppStatsLoop.c

    r8195 r8337  
    55
    66#include "ppStats.h"
     7#include "ppStatsLoop.h"
    78
    89
     
    4748
    4849
    49 void ppStatsLoop(ppStatsData *data,     // The data
    50                  const pmConfig *config // Configuration
     50psMetadata *ppStatsLoop(psMetadata *fpaResults, // Metadata to hold the FPA results
     51                        ppStatsData *data, // The data
     52                        const pmConfig *config // Configuration
    5153    )
    5254{
    53     psMetadata *fpaResults = psMetadataAlloc(); // Metadata to hold the FPA results
     55    PS_ASSERT_PTR_NON_NULL(data, NULL);
     56    pmFPA *fpa = data->fpa;             // FPA to analyse
     57    psFits *fits = data->fits;          // FITS file handle
     58    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
     59
     60    if (!fpaResults) {
     61        fpaResults = psMetadataAlloc();
     62    }
     63
     64    bool mdok;                          // Status of MD lookup
    5465
    5566    // Iterators for the headers and concepts
     
    5869
    5970    // Iterate through the FPA
    60     pmFPA *fpa = data->inFPA;           // The FPA of interest
    6171    if (psListLength(data->headers) > 0 && fpa->hdu) {
    62         pmFPAReadHeader(fpa, data->inFile);
     72        if (fits) {
     73            pmFPAReadHeader(fpa, fits);
     74        }
    6375        pmHDU *hdu = fpa->hdu;          // HDU for headers
    6476        getMetadata(fpaResults, hdu->header, headersIter);
    6577    }
    6678    if (psListLength(data->concepts) > 0) {
    67         pmFPAReadHeader(fpa, data->inFile);
     79        if (fits) {
     80            pmFPAReadHeader(fpa, fits);
     81        }
    6882        pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_ALL, false, config->database);
    6983        getMetadata(fpaResults, fpa->concepts, conceptsIter);
     
    8296        }
    8397
    84         psMetadata *chipResults = psMetadataAlloc(); // Metadata to hold the chip-level results
     98        psMetadata *chipResults = psMetadataLookupMD(&mdok, fpaResults, chipName); // Chip-level results
     99        if (!mdok || !chipResults) {
     100            chipResults = psMetadataAlloc();
     101        }
    85102
    86103        if (psListLength(data->headers) > 0 && chip->hdu) {
    87             if (!pmChipReadHeader(chip, data->inFile)) {
     104            if (fits && !pmChipReadHeader(chip, fits)) {
    88105                continue;
    89106            }
     
    92109        }
    93110        if (psListLength(data->concepts) > 0) {
    94             if (!pmChipReadHeader(chip, data->inFile)) {
     111            if (fits && !pmChipReadHeader(chip, fits)) {
    95112                continue;
    96113            }
     
    112129            }
    113130
    114             psMetadata *cellResults = psMetadataAlloc(); // Metadata to hold the cell-level results
     131            psMetadata *cellResults = psMetadataLookupMD(&mdok, chipResults, cellName); // Cell-level results
     132            if (!mdok || !cellResults) {
     133                cellResults = psMetadataAlloc();
     134            }
    115135
    116136            if (psListLength(data->headers) > 0 && cell->hdu) {
    117                 if (!pmCellReadHeader(cell, data->inFile)) {
     137                if (fits && !pmCellReadHeader(cell, fits)) {
    118138                    continue;
    119139                }
     
    122142            }
    123143            if (psListLength(data->concepts) > 0) {
    124                 if (!pmCellReadHeader(cell, data->inFile)) {
     144                if (fits && !pmCellReadHeader(cell, fits)) {
    125145                    continue;
    126146                }
     
    143163            }
    144164
    145             if (!pmCellRead(cell, data->inFile, config->database)) {
     165            if (fits && !pmCellRead(cell, fits, config->database)) {
    146166                psLogMsg(__func__, PS_LOG_WARN, "Unable to read chip %s cell %s\n", chipName, cellName);
    147167                pmCellFreeData(cell);
     
    229249
    230250            // Add the cell results to the chip
    231             psMetadataAdd(chipResults, PS_LIST_TAIL, cellName, PS_DATA_METADATA,
    232                           "Results for cell", cellResults);
    233 
    234             psFree(cellResults);
    235             pmCellFreeData(cell);
    236         }
    237         pmChipFreeData(chip);
    238         if (psListLength(chipResults->list) > 0) {
     251            if (psListLength(cellResults->list) > 0 && !psMetadataLookup(chipResults, cellName)) {
     252                psMetadataAdd(chipResults, PS_LIST_TAIL, cellName, PS_DATA_METADATA,
     253                              "Results for cell", cellResults);
     254                psFree(cellResults);
     255            }
     256
     257            if (fits) {
     258                pmCellFreeData(cell);
     259            }
     260        }
     261        if (fits) {
     262            pmChipFreeData(chip);
     263        }
     264
     265        if (psListLength(chipResults->list) > 0 && !psMetadataLookup(fpaResults, chipName)) {
    239266            psMetadataAdd(fpaResults, PS_LIST_TAIL, chipName, PS_DATA_METADATA,
    240267                          "Results for chip", chipResults);
    241         }
    242         psFree(chipResults);
    243     }
    244     pmFPAFreeData(fpa);
     268            psFree(chipResults);
     269        }
     270    }
     271    if (fits) {
     272        pmFPAFreeData(fpa);
     273    }
     274
    245275    psFree(headersIter);
    246276    psFree(conceptsIter);
    247277
    248     if (psListLength(fpaResults->list) == 0) {
    249         psError(PS_ERR_UNKNOWN, true, "No output.\n");
    250         return;
    251     }
    252 
    253     psString output = psMetadataConfigFormat(fpaResults);
    254     psFree(fpaResults);
    255     if (!output) {
    256         psError(PS_ERR_UNKNOWN, false, "Unable to generate configuration file with result.\n");
    257         return;
    258     }
    259     fprintf(data->outFile, "%s", output);
    260     psFree(output);
    261 
    262     return;
     278    return fpaResults;
    263279}
Note: See TracChangeset for help on using the changeset viewer.