IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13993


Ignore:
Timestamp:
Jul 2, 2007, 10:35:53 AM (19 years ago)
Author:
eugene
Message:

reorg to make consistent with other programs: ppStats is the program, ppStatsFPA is the library call; ppStats.h contains everything, ppStatsInternal.h is used by the ppStats functions

Location:
trunk/ppStats/src
Files:
2 added
7 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStats/src/Makefile.am

    r13923 r13993  
     1
    12lib_LTLIBRARIES = libppStats.la
    23libppStats_la_CPPFLAGS = $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS)
     
    89ppStats_LDADD   = libppStats.la
    910
     11ppStats_SOURCES =               \
     12        ppStats.c               
     13
    1014libppStats_la_SOURCES =                 \
    11         ppStats.c                       \
     15        ppStatsFPA.c                    \
    1216        ppStatsData.c                   \
    1317        ppStatsFringe.c                 \
    1418        ppStatsLoop.c                   \
    1519        ppStatsSetupFromRecipe.c        \
    16         ppStatsVersion.c
    17 
    18 ppStats_SOURCES =               \
    19         ppStatsData.c           \
    20         ppStatsLoop.c           \
    21         ppStatsSetupFromArgs.c  \
    22         ppStatsStandAlone.c     \
     20        ppStatsSetupFromArgs.c          \
    2321        ppStatsVersion.c
    2422
    2523include_HEADERS =                       \
    26         ppStats.h                       \
    27         ppStatsData.h                   \
    28         ppStatsFringe.h                 \
    29         ppStatsLoop.h                   \
    30         ppStatsSetupFromRecipe.h        \
    31         ppStatsVersion.h
     24        ppStats.h
    3225
    3326noinst_HEADERS =                \
    34         ppStats.h               \
    35         ppStatsSetupFromArgs.h
     27        ppStatsInternal.h
    3628
    3729CLEANFILES = *~
  • trunk/ppStats/src/ppStats.c

    r13677 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
     1# include "ppStatsInternal.h"
    42
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
     3int main(int argc, char **argv) {
    84
    9 #include "ppStats.h"
     5    psExit status = PS_EXIT_SUCCESS;
    106
    11 psMetadata *ppStats(psMetadata *out,
    12                     pmFPA *fpa,         // FPA for which to get statistics
    13                     pmFPAview *view,    // View for analysis
    14                     psMaskType maskVal, // Value to mask
    15                     pmConfig *config    // Configuration
    16     )
    17 {
    18     PS_ASSERT_PTR_NON_NULL(fpa, NULL)
    19     PS_ASSERT_PTR_NON_NULL(view, NULL);
    20     PS_ASSERT_PTR_NON_NULL(config, NULL);
     7    psLibInit(NULL);
     8    psTimerStart("PPSTATS");
    219
    22     ppStatsData *data = ppStatsDataAlloc(); // All the input data
     10    // Parse the configuration and arguments
     11    pmConfig *config = pmConfigRead(&argc, argv, PPSTATS_RECIPE);
     12    if (!config) {
     13        psErrorStackPrint(stderr, "Unable to read configuration.\n");
     14        exit(PS_EXIT_CONFIG_ERROR);
     15    }
    2316
    2417    // Get the options, open the files
    25     if (!ppStatsSetupFromRecipe(data, config)) {
    26         psError(PS_ERR_UNKNOWN, false, "Unable to get ppStats options from recipe.");
    27         psFree(data);
    28         return NULL;
     18    ppStatsData *data = ppStatsSetupFromArgs(&argc, argv, config);
     19    if (!data) {
     20        psErrorStackPrint(stderr, "Unable to parse command-line arguments.\n");
     21        exit(PS_EXIT_CONFIG_ERROR);
    2922    }
    3023
    31     // Override recipe mask value if one is provided
    32     if (maskVal != 0) {
    33         data->maskVal = maskVal;
     24    // Output filename is optional
     25    const char *outName = NULL;         // Output file name
     26    FILE *outFile = stdout;             // Output file
     27    if (argc == 2) {
     28        outName = argv[1];
     29        psString resolved = pmConfigConvertFilename(outName, config, true); // Resolved filename
     30
     31        if (resolved && strlen(resolved) > 0) {
     32            outFile = fopen(resolved, "w");
     33            if (!outFile) {
     34                psLogMsg("ppStats", PS_LOG_ERROR, "Unable to open output file %s\n", resolved);
     35                psFree(resolved);
     36                // XXX this could be a system or config error, but not a data error
     37                status = PS_EXIT_CONFIG_ERROR;
     38                goto die;
     39            }
     40        } else {
     41            psErrorStackPrint(stderr, "Unable to open output file %s.\n", resolved);
     42            exit(PS_EXIT_CONFIG_ERROR);
     43        }
     44        psFree(resolved);
    3445    }
    3546
    36     if (data->fpa) {
    37         psFree(data->fpa);
     47    // Go through the FPA and do the hard work
     48    psMetadata *results = ppStatsLoop(&status, data, config);
     49    if (status != PS_EXIT_SUCCESS) {
     50        psErrorStackPrint(stderr, "Error in stats loop.\n");
     51        exit (status);
    3852    }
    39     data->fpa = psMemIncrRefCounter(fpa);
    40 
    41     if (data->view) {
    42         psFree(data->view);
    43     }
    44     data->view = psMemIncrRefCounter(view);
    45 
    46     // Go through the FPA and do the hard work
    47     psExit status;                      // Status of statistics loop
    48     psMetadata *result = ppStatsLoop(&status, data, config);
    49     if (status != PS_EXIT_SUCCESS) {
    50         psError (PS_ERR_UNKNOWN, false, "Not able to measure FPA statistics.\n");
    51         psFree(result);
    52         psFree(data);
    53         return (NULL);
     53    if (psListLength(results->list) == 0) {
     54        psErrorStackPrint(stderr, "No output.\n");
     55        exit (status);
    5456    }
    5557
    56     if (out != NULL) {
    57         psMetadataCopy (out, result);
    58         psFree(result);
    59         psFree(data);
    60         return out;
     58    if (data->fileLevel) {
     59        const char *level = pmFPALevelToName(pmFPAPHULevel(config->format)); // Level for file
     60        psMetadataAddStr(results, PS_LIST_HEAD, "FILE.LEVEL", 0, "File level", level);
    6161    }
    6262
     63    // Format and print the output
     64    psString output = psMetadataConfigFormat(results);
     65    if (!output) {
     66        psErrorStackPrint(stderr, "Unable to generate configuration file with result.\n");
     67        psFree(results);
     68        exit(PS_EXIT_CONFIG_ERROR);
     69    }
     70    fprintf(outFile, "%s", output);
     71    psFree(output);
     72
     73    // Clean up
     74    psFree(results);
     75    if (outName) {
     76        fclose(outFile);
     77    }
     78
     79    // Common code for the death.
     80die:
     81    if (status) {
     82        psErrorStackPrint (stderr, "failure in %s", __func__);
     83    }
    6384    psFree(data);
    64     return result;
     85    psFree(config);
     86    pmConceptsDone();
     87    pmConfigDone();
     88    psLibFinalize();
     89
     90    return status;
    6591}
  • trunk/ppStats/src/ppStats.h

    r13923 r13993  
     1
    12#ifndef PP_STATS_H
    23#define PP_STATS_H
     
    45#define PPSTATS_RECIPE "PPSTATS"
    56
    6 #include <psmodules.h>
     7typedef struct {
     8    // Inputs
     9    psFits *fits;                       // Input file handle
     10    pmFPA *fpa;                         // FPA to analyse
     11    pmFPAview *view;                    // View to analyse
     12    // Stuff to output
     13    psStats *stats;                     // Statistics to calculate
     14    bool doStats;                       // Do statistics?
     15    bool fileLevel;                     // Output file level?
     16    psList *headers;                    // Headers to read
     17    psList *concepts;                   // Concepts to read
     18    psList *summary;                    // Summary statistics to calculate
     19    // Options for input data
     20    float sample;                       // Fraction of cell to sample for statistics
     21    psMaskType maskVal;                 // Mask value for images
     22    psList *chips;                      // Chips to look at
     23    psList *cells;                      // Cells to look at
     24} ppStatsData;
    725
    8 #include "ppStatsData.h"
    9 #include "ppStatsSetupFromRecipe.h"
    10 #include "ppStatsLoop.h"
    11 #include "ppStatsVersion.h"
    12 #include "ppStatsFringe.h"
     26// Allocator
     27ppStatsData *ppStatsDataAlloc(void);
    1328
    14 // Perform the ppStats steps
    15 psMetadata *ppStats(psMetadata *out,
    16                     pmFPA *fpa,         // FPA for which to get statistics
    17                     pmFPAview *view,    // View for analysis
    18                     psMaskType maskVal, // Value to mask
    19                     pmConfig *config    // Configuration
     29/// Perform the ppStats steps on the given FPA (optionally for specified view)
     30psMetadata *ppStatsFPA(psMetadata *out,
     31                       pmFPA *fpa,         // FPA for which to get statistics
     32                       pmFPAview *view,    // View for analysis
     33                       psMaskType maskVal, // Value to mask
     34                       pmConfig *config    // Configuration
    2035    );
    2136
     37/// Supplement the statistics with the fringe solution
     38bool ppStatsFringe(psMetadata *stats,     ///< Statistics metadata to supplement
     39                   const pmChip *chip,    ///< The chip containing the solution
     40                   const char *root,      ///< Name of output entry
     41                   const char *fringeName ///< Name of the solution in the chip->analysis
     42    );
     43
     44
     45/// Loop over the input image and do all the hard work
     46psMetadata *ppStatsLoop(psExit *result,
     47                        ppStatsData *data, // The data
     48                        const pmConfig *config // Configuration
     49    );
     50
     51/// Set up the options and input/output files
     52ppStatsData *ppStatsSetupFromArgs(int *argc, char *argv[], // Command-line arguments
     53                                  pmConfig *config // Configuration
     54    );
     55
     56bool ppStatsSetupFromRecipe(ppStatsData *data, // Data for running ppStats
     57                            pmConfig *config // Configuration
     58    );
     59
     60
     61/// Return short version information
     62psString ppStatsVersion(void);
     63
     64/// Return long version information
     65psString ppStatsVersionLong(void);
     66
    2267#endif
  • trunk/ppStats/src/ppStatsData.c

    r13602 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 
    8 #include "ppStatsData.h"
     1#include "ppStatsInternal.h"
    92
    103static void statsDataFree(ppStatsData *data // Data to free
  • trunk/ppStats/src/ppStatsFringe.c

    r13971 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <string.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 
    9 #include "ppStatsFringe.h"
     1#include "ppStatsInternal.h"
    102
    113bool ppStatsFringe(psMetadata *stats, const pmChip *chip, const char *root, const char *fringeName)
  • trunk/ppStats/src/ppStatsLoop.c

    r13797 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <assert.h>
    7 #include <string.h>
    8 #include <pslib.h>
    9 #include <psmodules.h>
    10 
    11 #include "ppStats.h"
    12 #include "ppStatsLoop.h"
    13 
     1#include "ppStatsInternal.h"
    142
    153static void getMetadata(psMetadata *target, // Target for metadata
  • trunk/ppStats/src/ppStatsSetupFromArgs.c

    r13658 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <string.h>
    9 
    10 #include "ppStats.h"
    11 #include "ppStatsData.h"
    12 #include "ppStatsSetupFromArgs.h"
     1#include "ppStatsInternal.h"
    132
    143// This file is for setting up the required inputs from the command-line
  • trunk/ppStats/src/ppStatsSetupFromRecipe.c

    r13658 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <string.h>
    9 
    10 #include "ppStats.h"
    11 #include "ppStatsData.h"
    12 #include "ppStatsSetupFromRecipe.h"
     1#include "ppStatsInternal.h"
    132
    143// Strings in a recipe may be defined multiply (with MULTI) or listed on a single line
  • trunk/ppStats/src/ppStatsVersion.c

    r10292 r13993  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
    4 
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include "ppStatsVersion.h"
     1#include "ppStatsInternal.h"
    92
    103static const char *cvsTag = "$Name: not supported by cvs2svn $";// CVS tag name
Note: See TracChangeset for help on using the changeset viewer.