IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 27, 2006, 4:31:17 PM (20 years ago)
Author:
eugene
Message:

substantial work on the pmFPAfile,view concepts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotParseCamera.c

    r6571 r6715  
    11# include "psphot.h"
    2 
    3 # define METADATA_ADD_DEFAULT(CONFIG, TYPE, NAME, VALUE, COMMENT)\
    4     { psMetadataItem *ITEM; \
    5       ITEM = psMetadataLookup (CONFIG, NAME); \
    6       if (ITEM == NULL) { \
    7         psMetadataAdd##TYPE (CONFIG, PS_LIST_TAIL, NAME, 0, COMMENT, VALUE); \
    8       } }
    92
    103bool psphotParseCamera (pmConfig *config) {
    114
     5    bool status;
     6    psFits *fits = NULL;
     7    psMetadata *phu = NULL;
     8    psMetadata *format = NULL;
     9
    1210    // psphot is supplied with a list of input images (may be only one image)
    13     psArray *infiles = psMetadataLookupPtr(NULL, config->arguments, "INPUT");
     11    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, "INPUT");
     12    if (!status) psAbort (__func__, "missing INPUT entry");
    1413    if (infiles->n < 1) psAbort (__func__, "empty input list");
    1514
    1615    // if no camera has been specified, use the first image as a template for the rest.
    1716    if (config->camera == NULL) {
    18         psFits *fits = psFitsOpen (infiles->data[0], "r");
    19         psMetadata *phu = psFitsReadHeader (NULL, fits);
    20         config->camera = pmConfigCameraFromHeader (config->site, phu);
     17        fits = psFitsOpen (infiles->data[0], "r");
     18        phu = psFitsReadHeader (NULL, fits);
     19        format = pmConfigCameraFormatFromHeader (config, phu);
    2120        psFitsClose (fits);
    22         psFree (phu);
    2321    }
    2422    // There's no point in continuing if we can't recognize what we've got
     
    2826    }
    2927
    30     // XXX place the "data" element on the pmConfig structure?
     28    // files
    3129    config->files = psMetadataAlloc ();
    3230
    3331    // build the template fpa, set up the basic view
    34     pmFPA *input = pmFPAConstruct (camera);
     32    // XXX : 216 leaks in pmFPAConstruct / psFree (input)
     33    pmFPA *input = pmFPAConstruct (config->camera);
    3534
    3635    // assign the I/O files (potentially) needed by psphot
    37     pmFPAfile *file = pmFPAfileDefine (config->files, camera, input, "PSPHOT.INPUT");
     36    // the output file is just a view to the file on config->files
     37    pmFPAfile *file = pmFPAfileDefine (config->files, format, input, "PSPHOT.INPUT");
     38    if (!file) {
     39        exit(EXIT_FAILURE);
     40    }
    3841
    39     pmFPAview *view = pmFPAviewAlloc (input, config->camera, 0);
    4042    for (int i = 0; i < infiles->n; i++) {
    41         // XXX save the phu from above?
    42         psFits *fits = psFitsOpen (infiles->data[i], "r");
    43         psMetadata *phu = psFitsReadHeader (NULL, fits);
    44         pmConfigValidateCamera (config->camera, phu);
     43        if (phu == NULL) {
     44            fits = psFitsOpen (infiles->data[i], "r");
     45            phu = psFitsReadHeader (NULL, fits);
     46            pmConfigValidateCameraFormat (format, phu);
     47            psFitsClose (fits);
     48        }
    4549
    4650        // set the view to the corresponding entry for this phu
    47         // XXX should I save the phu data at the appropriate location in the fpa?
    48         pmFPAsetView (view, phu);
     51        pmFPAview *view = pmFPAAddSource (input, phu, format);
    4952
    5053        // XXX is this the correct psMD to save the filename?
    51         name = pmFPAviewNameFromRule (file->filextra, view);
     54        char *name = pmFPAfileNameFromRule (file->filextra, file, view);
    5255        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
     56
     57        psFree (view);
     58        psFree (name);
     59        psFree (phu);
     60        phu = NULL;
    5361    }
    54     pmFPAfileDefine (config->files, camera, input, "PSPHOT.OUTPUT");
    55     pmFPAfileDefine (config->files, camera, input, "PSPHOT.RESID");
    56     pmFPAfileDefine (config->files, camera, input, "PSPHOT.PSF_INPUT");
    57     pmFPAfileDefine (config->files, camera, input, "PSPHOT.PSF_OUTPUT");
     62
     63    pmFPAfileDefine (config->files, format, input, "PSPHOT.OUTPUT");
     64
     65    // pmFPAfileDefine (config->files, format, input, "PSPHOT.RESID");
     66    // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_INPUT");
     67    // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_OUTPUT");
    5868
    5969    // build the template fpa, set up the basic view
    6070    // supply the backgnd with a different camera?
    61     pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.BACKSUB");
    62     pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.BACKGND");
    63     pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.BACKMDL");
    64     pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.PSF_SAMPLE");
     71    // allow alternate format?
     72    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKSUB");
     73    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKGND");
     74    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKMDL");
     75    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.PSF_SAMPLE");
     76
     77    // psphot is supplied with the output name
     78    char *output = psMetadataLookupPtr(&status, config->arguments, "OUTPUT");
     79    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
     80    if (!status) psAbort (__func__, "missing OUTPUT entry");
     81    psMetadataAddStr (file->names, PS_LIST_TAIL, "OUTPUT", 0, "", output);
    6582
    6683    // recipe override values (command-line options):
    67     psMetadata *options = psMetadataLookupPtr (status, config->arguments, "PSPHOT.OPTIONS");
    68     psMetadata *recipe = psMetadataLookupPtr (status, config->recipes, "PSPHOT");
     84    psMetadata *options = psMetadataLookupPtr (&status, config->arguments, "PSPHOT.OPTIONS");
     85    psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
    6986    psMetadataIterator *iter = psMetadataIteratorAlloc (options, PS_LIST_HEAD, NULL);
    70     while ((psMetadataItem *item = psMetadataGetAndIncrement (iter)) != NULL) {
     87    psMetadataItem *item = NULL;
     88    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    7189        psMetadataAddItem (recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
    7290    }
     
    7492
    7593    // set default recipe values here
    76     // XXX this needs re-thinking...
    77     METADATA_ADD_DEFAULT (recipe, Str, "FITMODE",     "NONE", "");
    78     METADATA_ADD_DEFAULT (recipe, Str, "PHOTCODE",    "NONE", "");
    79     METADATA_ADD_DEFAULT (recipe, Str, "BREAK_POINT", "NONE", "");
     94    psMetadataAddStr (recipe, PS_LIST_TAIL, "FITMODE", PS_META_NO_REPLACE, "default fitting mode", "NONE");
     95    psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_NO_REPLACE, "default photcode", "NONE");
     96    psMetadataAddStr (recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_NO_REPLACE, "default break point", "NONE");
    8097
    8198    // Chip selection: if we are using a single chip, select it for each FPA
    8299    // Chip numbers to work on: -chip 1,2,3,5,8,10
     100    # if (0)
    83101    char *chips = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS");
    84102    if (chips != NULL) {
     
    102120        }
    103121    }
     122    # endif
     123
     124    psFree (input);
     125    psFree (format);
     126
    104127    psTrace(__func__, 1, "Done with psphotParseCamera...\n");
    105128    return true;
Note: See TracChangeset for help on using the changeset viewer.