IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 18, 2006, 12:20:45 PM (20 years ago)
Author:
Paul Price
Message:

Updating to use psLib rel11. Main problem was that vector and array lengths ('n' element) are no longer set to equal the number of allocated values ('nalloc' element) when allocated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/stac/src/stacConfig.c

    r5743 r6887  
    2424    config->outnx = 0;
    2525    config->outny = 0;
    26     config->saturated = 65535.0;        // Saturation level
    27     config->bad = 0.0;                  // Bad level
     26    config->saturated = 65535.0;        // Saturation level
     27    config->bad = 0.0;                  // Bad level
    2828    config->reject = 2.5;
    2929    config->frac = 0.45;
     
    3939    // Free the vectors, if necessary
    4040    if (config->inputs) {
    41         psFree(config->inputs);
     41        psFree(config->inputs);
    4242    }
    4343    // Free everything
     
    4646
    4747
    48 stacConfig *stacParseConfig(int argc,   // Number of command-line arguments
    49                             char **argv // Command-line arguments
     48stacConfig *stacParseConfig(int argc,   // Number of command-line arguments
     49                            char **argv // Command-line arguments
    5050    )
    5151{
    5252    stacConfig *config = stacConfigAlloc(); // Configuration values
    53     const char *programName = argv[0];  // Program name
     53    const char *programName = argv[0];  // Program name
    5454
    5555    /* Variables for getopt */
     
    6161    while ((opt = getopt(argc, argv, "hvSg:r:o:s:b:k:n:f:G:p:a:")) != -1) {
    6262        switch (opt) {
    63           case 'h':
    64             help(programName);
    65             exit(EXIT_SUCCESS);
    66           case 'v':
     63          case 'h':
     64            help(programName);
     65            exit(EXIT_SUCCESS);
     66          case 'v':
    6767            config->verbose++;
    6868            break;
    69           case 'g':
    70             if (sscanf(optarg, "%f", &config->gain) != 1) {
    71                 help(programName);
    72                 exit(EXIT_FAILURE);
    73             }
    74             break;
    75           case 'r':
    76             if (sscanf(optarg, "%f", &config->readnoise) != 1) {
    77                 help(programName);
    78                 exit(EXIT_FAILURE);
    79             }
    80             break;
    81           case 'o':
     69          case 'g':
     70            if (sscanf(optarg, "%f", &config->gain) != 1) {
     71                help(programName);
     72                exit(EXIT_FAILURE);
     73            }
     74            break;
     75          case 'r':
     76            if (sscanf(optarg, "%f", &config->readnoise) != 1) {
     77                help(programName);
     78                exit(EXIT_FAILURE);
     79            }
     80            break;
     81          case 'o':
    8282            if ((sscanf(argv[optind-1], "%d", &config->outnx) != 1) ||
    8383                (sscanf(argv[optind++], "%d", &config->outny) != 1)) {
     
    8686                exit(EXIT_FAILURE);
    8787            }
    88             break;
    89           case 's':
    90             if (sscanf(optarg, "%f", &config->saturated) != 1) {
    91                 help(programName);
    92                 exit(EXIT_FAILURE);
    93             }
    94             break;
    95           case 'b':
    96             if (sscanf(optarg, "%f", &config->bad) != 1) {
    97                 help(programName);
    98                 exit(EXIT_FAILURE);
    99             }
    100             break;
    101           case 'p':
    102             if (argc < optind+1) {
    103                 help(programName);
    104                 exit(EXIT_FAILURE);
    105             }
    106             config->starFile = argv[optind-1];
    107             config->starMapFile = argv[optind++];
    108             // Note: incrementing optind, so I can read more than one parameter.
    109             break;
    110           case 'a':
    111             if (sscanf(optarg, "%f", &config->aper) != 1) {
    112                 help(programName);
    113                 exit(EXIT_FAILURE);
    114             }
    115             break;
    116           case 'k':
    117             if (sscanf(optarg, "%f", &config->reject) != 1) {
    118                 help(programName);
    119                 exit(EXIT_FAILURE);
    120             }
    121             break;
    122           case 'n':
    123             if (sscanf(optarg, "%d", &config->nReject) != 1) {
    124                 help(programName);
    125                 exit(EXIT_FAILURE);
    126             }
    127             break;
    128           case 'f':
    129             if (sscanf(optarg, "%f", &config->frac) != 1) {
    130                 help(programName);
    131                 exit(EXIT_FAILURE);
    132             }
    133             break;
    134           case 'G':
    135             if (sscanf(optarg, "%f", &config->grad) != 1) {
    136                 help(programName);
    137                 exit(EXIT_FAILURE);
    138             }
    139             break;
    140           case 'S':
    141             config->saveShifts = true;
    142             break;
    143           default:
    144             help(programName);
    145         }
     88            break;
     89          case 's':
     90            if (sscanf(optarg, "%f", &config->saturated) != 1) {
     91                help(programName);
     92                exit(EXIT_FAILURE);
     93            }
     94            break;
     95          case 'b':
     96            if (sscanf(optarg, "%f", &config->bad) != 1) {
     97                help(programName);
     98                exit(EXIT_FAILURE);
     99            }
     100            break;
     101          case 'p':
     102            if (argc < optind+1) {
     103                help(programName);
     104                exit(EXIT_FAILURE);
     105            }
     106            config->starFile = argv[optind-1];
     107            config->starMapFile = argv[optind++];
     108            // Note: incrementing optind, so I can read more than one parameter.
     109            break;
     110          case 'a':
     111            if (sscanf(optarg, "%f", &config->aper) != 1) {
     112                help(programName);
     113                exit(EXIT_FAILURE);
     114            }
     115            break;
     116          case 'k':
     117            if (sscanf(optarg, "%f", &config->reject) != 1) {
     118                help(programName);
     119                exit(EXIT_FAILURE);
     120            }
     121            break;
     122          case 'n':
     123            if (sscanf(optarg, "%d", &config->nReject) != 1) {
     124                help(programName);
     125                exit(EXIT_FAILURE);
     126            }
     127            break;
     128          case 'f':
     129            if (sscanf(optarg, "%f", &config->frac) != 1) {
     130                help(programName);
     131                exit(EXIT_FAILURE);
     132            }
     133            break;
     134          case 'G':
     135            if (sscanf(optarg, "%f", &config->grad) != 1) {
     136                help(programName);
     137                exit(EXIT_FAILURE);
     138            }
     139            break;
     140          case 'S':
     141            config->saveShifts = true;
     142            break;
     143          default:
     144            help(programName);
     145        }
    146146    }
    147147
     
    154154    }
    155155
    156     config->output = argv[0];           // Output file
     156    config->output = argv[0];           // Output file
    157157    // Get the input files
    158     config->inputs = psArrayAlloc(argc-1);
     158    config->inputs = psArrayAlloc(argc - 1);
     159    config->inputs->n = argc - 1;
    159160    for (int i = 1; i < argc; i++) {
    160         config->inputs->data[i-1] = psAlloc(strlen(argv[i]));
    161         strncpy(config->inputs->data[i-1], argv[i], strlen(argv[i]));
     161        config->inputs->data[i-1] = psAlloc(strlen(argv[i]));
     162        strncpy(config->inputs->data[i-1], argv[i], strlen(argv[i]));
    162163    }
    163164
     
    167168    psTrace("stac.config", 9, "%d inputs:\n",config->inputs->n);
    168169    for (int i = 0; i < config->inputs->n; i++) {
    169         psTrace("stac.config", 9, "\t%s\n", config->inputs->data[i]);
     170        psTrace("stac.config", 9, "\t%s\n", config->inputs->data[i]);
    170171    }
    171172    psTrace("stac.config", 9, "Output file is %s\n",config->output);
Note: See TracChangeset for help on using the changeset viewer.