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/shiftSize.c

    r5743 r6887  
    1717{
    1818    fprintf (stderr, "shiftSize: Calculate size for output combined image\n"
    19              "Usage: %s [-h] [-v] IN1 IN2...\n"
    20              "where\n"
    21              "\t-h           Help (this info)\n"
    22              "\t-v           Increase verbosity level\n"
    23              "\tIN1, IN2...  Input images, which have associated .map files.\n",
    24              name
    25         );
     19             "Usage: %s [-h] [-v] IN1 IN2...\n"
     20             "where\n"
     21             "\t-h           Help (this info)\n"
     22             "\t-v           Increase verbosity level\n"
     23             "\tIN1, IN2...  Input images, which have associated .map files.\n",
     24             name
     25        );
    2626}
    2727
     
    4141
    4242
    43     int verbose = 0;                    // Verbosity level
     43    int verbose = 0;                    // Verbosity level
    4444
    4545    // Parse command line
    46     const char *programName = argv[0];  // Program name
     46    const char *programName = argv[0];  // Program name
    4747    /* Variables for getopt */
    4848    int opt;   /* Option, from getopt */
     
    5353    while ((opt = getopt(argc, argv, "hv")) != -1) {
    5454        switch (opt) {
    55           case 'h':
    56             help(programName);
    57             exit(EXIT_SUCCESS);
    58           case 'v':
     55          case 'h':
     56            help(programName);
     57            exit(EXIT_SUCCESS);
     58          case 'v':
    5959            verbose++;
    6060            break;
    61           default:
    62             help(programName);
    63         }
     61          default:
     62            help(programName);
     63        }
    6464    }
    6565
     
    7373
    7474    psArray *inputs = psArrayAlloc(argc); // Input filenames
     75    inputs->n = argc;
    7576    for (int i = 0; i < argc; i++) {
    76         inputs->data[i] = psAlloc(strlen(argv[i]));
    77         strncpy(inputs->data[i], argv[i], strlen(argv[i]));
     77        inputs->data[i] = psAlloc(strlen(argv[i]));
     78        strncpy(inputs->data[i], argv[i], strlen(argv[i]));
     79        psTrace("stac.size", 8, "Input file: %s\n", inputs->data[i]);
    7880    }
    7981
    8082    // Read input files
    81     psArray *images = stacReadImages(NULL, inputs);
     83    psVector *xSize = psVectorAlloc(inputs->n, PS_TYPE_S32);
     84    psVector *ySize = psVectorAlloc(inputs->n, PS_TYPE_S32);
     85    xSize->n = inputs->n;
     86    ySize->n = inputs->n;
     87    for (int i = 0; i < inputs->n; i++) {
     88        const char *filename = inputs->data[i]; // Name of FITS file
     89        psFits *file = psFitsOpen(filename, "r"); // FITS file handle
     90        psMetadata *header = psFitsReadHeader(NULL, file); // FITS header
     91        psFitsClose(file);
     92        bool mdok = true;               // Status of MD lookup
     93        xSize->data.S32[i] = psMetadataLookupS32(&mdok, header, "NAXIS1");
     94        if (!mdok) {
     95            psError(PS_ERR_IO, true, "Unable to find NAXIS1 in %s\n", filename);
     96            exit(EXIT_FAILURE);
     97        }
     98        ySize->data.S32[i] = psMetadataLookupS32(&mdok, header, "NAXIS2");
     99        if (!mdok) {
     100            psError(PS_ERR_IO, true, "Unable to find NAXIS2 in %s\n", filename);
     101            exit(EXIT_FAILURE);
     102        }
     103        psFree(header);
     104    }
    82105
    83106    // Read maps
     
    85108
    86109    // Get size
    87     int outnx, outny;                   // Size of combined image
    88     float xMapDiff, yMapDiff;           // Difference to apply to maps
    89     stacSize(&outnx, &outny, &xMapDiff, &yMapDiff, images, maps);
     110    int outnx, outny;                   // Size of combined image
     111    float xMapDiff, yMapDiff;           // Difference to apply to maps
     112    stacSize(&outnx, &outny, &xMapDiff, &yMapDiff, xSize, ySize, maps);
     113    psFree(xSize);
     114    psFree(ySize);
    90115
    91116    printf("%d %d\n", outnx, outny);
     
    95120
    96121    psFree(inputs);
    97     psFree(images);
    98122    psFree(maps);
    99123
Note: See TracChangeset for help on using the changeset viewer.