IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2006, 5:27:13 PM (20 years ago)
Author:
eugene
Message:

major revisions to use the new pmFPAfile,view I/O handling

File:
1 edited

Legend:

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

    r6379 r6571  
    88      } }
    99
    10 // 2006.02.07 : no leaks!
    11 ppFile *psphotParseCamera (ppConfig *config) {
     10bool psphotParseCamera (pmConfig *config) {
    1211
    13     ppFile *input = ppFileAlloc ();
     12    // psphot is supplied with a list of input images (may be only one image)
     13    psArray *infiles = psMetadataLookupPtr(NULL, config->arguments, "INPUT");
     14    if (infiles->n < 1) psAbort (__func__, "empty input list");
    1415
    15     input->filename = psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE");
    16     psMemCopy (input->filename); // keep for external use
    17 
    18     // Open the input image
    19     psLogMsg("psphot", PS_LOG_INFO, "Opening input image: %s\n", input->filename);
    20     input->fits = psFitsOpen (input->filename, "r"); // File handle for FITS file
    21     if (! input->fits) {
    22         psErrorStackPrint(stderr, "Can't open input image: %s\n", input->filename);
    23         exit(EXIT_FAILURE);
     16    // if no camera has been specified, use the first image as a template for the rest.
     17    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);
     21        psFitsClose (fits);
     22        psFree (phu);
    2423    }
    25     input->phu = psFitsReadHeader(NULL, input->fits); // FITS header
    26 
    27     // Get camera configuration from header if not already defined
     24    // There's no point in continuing if we can't recognize what we've got
    2825    if (! config->camera) {
    29         config->camera = pmConfigCameraFromHeader(config->site, input->phu);
    30         if (! config->camera) {
    31              // There's no point in continuing if we can't recognize what we've got
    32             psErrorStackPrint(stderr, "Can't find camera configuration!\n");
    33             exit(EXIT_FAILURE);
    34         }
    35    } else if (! pmConfigValidateCamera(config->camera, input->phu)) {
    36        // There's no point in continuing if what we've got doesn't match what we've been told
    37         psError(PS_ERR_IO, true, "%s does not seem to be from the specified camera.\n",
    38                 input->filename);
    39         exit(EXIT_FAILURE);
     26        psErrorStackPrint(stderr, "Can't find camera configuration!\n");
     27        exit(EXIT_FAILURE);
    4028    }
    4129
    42     // Determine the correct recipe to use (from camera or from user)
    43     // if config->recipe is not NULL, it is a user-supplied recipe
    44     if (!config->recipe) {
    45         config->recipe = pmConfigRecipeFromCamera(config->camera, PSPHOT_RECIPE);
    46         if (config->recipe == NULL) {
    47             psErrorStackPrint(stderr, "Can't find recipe configuration!\n");
    48             exit(EXIT_FAILURE);
    49         }
     30    // XXX place the "data" element on the pmConfig structure?
     31    config->files = psMetadataAlloc ();
     32
     33    // build the template fpa, set up the basic view
     34    pmFPA *input = pmFPAConstruct (camera);
     35
     36    // assign the I/O files (potentially) needed by psphot
     37    pmFPAfile *file = pmFPAfileDefine (config->files, camera, input, "PSPHOT.INPUT");
     38
     39    pmFPAview *view = pmFPAviewAlloc (input, config->camera, 0);
     40    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);
     45
     46        // 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);
     49
     50        // XXX is this the correct psMD to save the filename?
     51        name = pmFPAviewNameFromRule (file->filextra, view);
     52        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    5053    }
     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");
     58
     59    // build the template fpa, set up the basic view
     60    // 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");
    5165
    5266    // recipe override values (command-line options):
    53     psMetadataItem *item = NULL;
    54     psMetadataIterator *iter = psMetadataIteratorAlloc (config->options, PS_LIST_HEAD, NULL);
    55     while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    56         psMetadataAddItem (config->recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
     67    psMetadata *options = psMetadataLookupPtr (status, config->arguments, "PSPHOT.OPTIONS");
     68    psMetadata *recipe = psMetadataLookupPtr (status, config->recipes, "PSPHOT");
     69    psMetadataIterator *iter = psMetadataIteratorAlloc (options, PS_LIST_HEAD, NULL);
     70    while ((psMetadataItem *item = psMetadataGetAndIncrement (iter)) != NULL) {
     71        psMetadataAddItem (recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
    5772    }
    5873    psFree (iter);
    5974
    6075    // set default recipe values here
    61     METADATA_ADD_DEFAULT (config->recipe, Str, "FITMODE", "NONE", "");
    62     METADATA_ADD_DEFAULT (config->recipe, Str, "PHOTCODE", "NONE", "");
    63     METADATA_ADD_DEFAULT (config->recipe, Str, "BREAK_POINT", "NONE", "");
    64     METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_FORMAT", "CMP", "");
    65     METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_MODE", "SPLIT", "");
     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", "");
    6680
    6781    // Chip selection: if we are using a single chip, select it for each FPA
     
    88102        }
    89103    }
    90 
    91     // Construct cameras in preparation for reading
    92     input->fpa = pmFPAConstruct(config->camera);
    93 
    94104    psTrace(__func__, 1, "Done with psphotParseCamera...\n");
    95     return input;
     105    return true;
    96106}
Note: See TracChangeset for help on using the changeset viewer.