IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8999 for trunk/ppNorm/src


Ignore:
Timestamp:
Sep 26, 2006, 3:41:46 PM (20 years ago)
Author:
Paul Price
Message:

Input and output files are now optional.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppNorm/src/ppNormCalc.c

    r8785 r8999  
    77#include <psmodules.h>
    88
     9void helpAndDie(const char *programName)
     10{
     11    printf("Calculate normalisation for flat fields.\n\n"
     12           "Usage: %s [IN.mdc [OUT.mdc]]\n\n"
     13           "where IN.mdc is a metadata config file containing the background\n"
     14           "      value for each component of each exposure;\n"
     15           "and   OUT.mdc is a metadata config file containing the output\n"
     16           "      normalisation factors.\n"
     17           "\n", programName);
     18    exit(EXIT_FAILURE);
     19}
     20
    921
    1022int main(int argc, char *argv[])
     
    1426    psFree(config);
    1527
    16     if (argc != 2) {
    17         printf("Calculate normalisation for flat fields.\n\n"
    18                "Usage: %s IN.mdc\n\n"
    19                "where IN.mdc is a metadata config file containing the background\n"
    20                "value for each component of each exposure.\n\n", argv[0]);
    21         exit(EXIT_FAILURE);
     28    if (argc > 3 ||
     29        psArgumentGet(argc, argv, "-h") ||
     30        psArgumentGet(argc, argv, "-help") ||
     31        psArgumentGet(argc, argv, "--help") ||
     32        psArgumentGet(argc, argv, "-?")) {
     33        helpAndDie(argv[0]);
     34    }
     35
     36    FILE *inFile = stdin;               // Input file stream
     37    FILE *outFile = stdout;             // Output file stream
     38
     39    if (argc >= 2) {
     40        inFile = fopen(argv[1], "r");
     41        if (!inFile) {
     42            psError(PS_ERR_IO, true, "Unable to open input file: %s\n\n", argv[1]);
     43            helpAndDie(argv[0]);
     44        }
     45    }
     46    if (argc == 3) {
     47        outFile = fopen(argv[2], "w");
     48        if (!outFile) {
     49            psError(PS_ERR_IO, true, "Unable to open output file: %s\n\n", argv[2]);
     50            helpAndDie(argv[0]);
     51        }
     52    }
     53
     54    psString inputMDC = psSlurpFile(inFile); // Input metadata config stuff
     55    if (argc >= 2) {
     56        fclose(inFile);
    2257    }
    2358
    2459    psU32 badLines = 0;                   // Number of bad lines
    25     psMetadata *exposures = psMetadataConfigRead(NULL, &badLines, argv[1], false); // Exposure statistics
     60    psMetadata *exposures = psMetadataConfigParse(NULL, &badLines, inputMDC, false); // Exposure statistics
    2661    if (badLines > 0) {
    27         psLogMsg("ppNormCalc", PS_LOG_WARN, "%d bad lines found when reading %s\n", badLines, argv[1]);
     62        psWarning("%d bad lines found when reading input\n", badLines);
    2863    }
    2964
     
    97132    psFree(compsIter);
    98133    psString outputString = psMetadataConfigFormat(outputMD);
    99     printf("%s", outputString);
     134    fprintf(outFile, "%s", outputString);
    100135    psFree(outputString);
    101136    psFree(outputMD);
     137    if (argc == 3) {
     138        fclose(outFile);
     139    }
    102140
    103141    // Clean up
Note: See TracChangeset for help on using the changeset viewer.