IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8337 for trunk/ppStats/src


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:
6 added
9 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/.cvsignore

    r7903 r8337  
    22Makefile
    33Makefile.in
     4.libs
     5*.lo
     6*.la
    47ppStats
  • trunk/ppStats/src/Makefile.am

    r7993 r8337  
     1lib_LTLIBRARIES = libppStats.la
     2libppStats_la_CPPFLAGS = $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS) $(ppStats_CFLAGS)
     3
    14bin_PROGRAMS = ppStats
    25
    36ppStats_CFLAGS += $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
    47ppStats_LDFLAGS += $(PSMODULE_LIBS) $(PSLIB_LIBS) -Wl,-Bdynamic
     8ppStats_LDADD = libppStats.la
    59
    6 ppStats_SOURCES =               \
     10libppStats_la_SOURCES =         \
    711        ppStats.c               \
    812        ppStatsData.c           \
    913        ppStatsLoop.c           \
    10         ppStatsSetup.c
     14        ppStatsSetupFromRecipe.c
    1115
    12 noinst_HEADERS =                \
     16ppStats_SOURCES =               \
     17        ppStatsData.c           \
     18        ppStatsLoop.c           \
     19        ppStatsSetupFromArgs.c  \
     20        ppStatsStandAlone.c
     21
     22include_HEADERS =               \
     23        ppStats.h               \
    1324        ppStatsData.h           \
    14         ppStats.h
     25        ppStatsLoop.h           \
     26        ppStatsSetupFromRecipe.h
     27
     28noinst_HEADERS =                \
     29        ppStats.h               \
     30        ppStatsSetupFromArgs.h
    1531
    1632CLEANFILES = *~
  • trunk/ppStats/src/ppStats.c

    r7902 r8337  
    55#include "ppStats.h"
    66
    7 int main(int argc, char *argv[])
     7psMetadata *ppStats(psMetadata *out,    // Output metadata
     8                    pmFPA *fpa,         // FPA for which to get statistics
     9                    pmConfig *config    // Configuration
     10    )
    811{
     12    // Get the options, open the files
     13    ppStatsData *data = ppStatsSetupFromRecipe(NULL, config);
    914
    10     psLibInit(NULL);
    11     psTimerStart(TIMERNAME);
    12 
    13     // Parse the configuration and arguments
    14     pmConfig *config = pmConfigRead(&argc, argv);
    15 
    16     // Get the options, open the files
    17     ppStatsData *data = ppStatsSetup(config);
     15    if (data->fpa) {
     16        psFree(data->fpa);
     17    }
     18    data->fpa = psMemIncrRefCounter(fpa);
    1819
    1920    // Go through the FPA and do the hard work
    20     ppStatsLoop(data, config);
     21    out = ppStatsLoop(out, data, config);
    2122
    2223    psFree(data);
    23     psFree(config);
    24     pmConceptsDone();
    25     pmConfigDone();
    26     psLibFinalize();
    2724
    28     return EXIT_SUCCESS;
     25    return out;
    2926}
  • trunk/ppStats/src/ppStats.h

    r7988 r8337  
    33
    44#define RECIPENAME "PPSTATS"
    5 #define TIMERNAME "PPSTATS"
    65
    76#include <psmodules.h>
     7
    88#include "ppStatsData.h"
    9 
    10 // Set up the options and input/output files
    11 ppStatsData *ppStatsSetup(pmConfig *config // Configuration
    12     );
    13 
    14 // Loop over the input image and do all the hard work
    15 void ppStatsLoop(ppStatsData *data,     // The data
    16                  const pmConfig *config // Configuration
    17     );
     9#include "ppStatsSetupFromRecipe.h"
     10#include "ppStatsLoop.h"
    1811
    1912#endif
  • trunk/ppStats/src/ppStatsData.c

    r7910 r8337  
    88{
    99    // inName and region are not on the psLib memory system (they are from argv).
    10     psFree(data->inFPA);
    11     if (data->inFile) {
    12         psFitsClose(data->inFile);
    13         data->inFile = NULL;
    14     }
    15     if (data->outFile) {
    16         fclose(data->outFile);
    17         data->outFile = NULL;
     10    psFree(data->fpa);
     11    if (data->fits) {
     12        psFitsClose(data->fits);
     13        data->fits = NULL;
    1814    }
    1915    psFree(data->headers);
     
    3329    psMemSetDeallocator(data, (psFreeFunc)statsDataFree);
    3430
    35     data->inName = NULL;
    36     data->inFile = NULL;
    37     data->outName = NULL;
    38     data->outFile = NULL;
    39     data->inFPA = NULL;
     31    data->fpa = NULL;
     32    data->fits = NULL;
    4033
    4134    data->headers = psListAlloc(NULL);
  • trunk/ppStats/src/ppStatsData.h

    r7910 r8337  
    77typedef struct {
    88    // Inputs
    9     const char *inName;                 // Input FITS image file
    10     const char *outName;                // Output filename
    11     psFits *inFile;                     // Input file handle
    12     FILE *outFile;                      // Output file handle
    13     pmFPA *inFPA;                       // Input FPA
     9    psFits *fits;                       // Input file handle
     10    pmFPA *fpa;                         // FPA to analyse
    1411    // Stuff to output
    1512    psStats *stats;                     // Statistics to calculate
  • 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.