IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.