IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6821


Ignore:
Timestamp:
Apr 9, 2006, 8:46:12 AM (20 years ago)
Author:
magnier
Message:

adding FileSetFromArgs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c

    r6819 r6821  
    650650
    651651// look for the given name on the argument list.
     652// returns the file (a view to the one saved on config->files)
     653// in this case, each file should correspond to the same view
     654// (except at the readout level), of multiple FPAs
     655// XXX think this through a bit more:
     656//  - do we create multiple input fpas, or assign the same files to the single fpa?
     657//  - do we save the multiple pmFPAfiles in the config->files psMD?
     658//  - do we save the multiple filenames in the file->names psMD?
     659//  - if we have a single FPA and multiple names, we need a method to
     660//    turn on a specific name for the I/O actions.  probably true if we
     661//    have multiple FPAs as well.
     662pmFPAfile *pmFPAfileSetFromArgs (bool *found, pmConfig *config, char *filename, char *argname)
     663{
     664    bool status;
     665    pmFPA *fpa = NULL;
     666    psFits *fits = NULL;
     667    pmFPAfile *file = NULL;
     668    psMetadata *phu = NULL;
     669    psMetadata *format = NULL;
     670
     671    if (*found)
     672        return NULL;
     673
     674    // we search the argument data for the named fileset (argname)
     675    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     676    if (!status)
     677        return NULL;
     678    if (infiles->n < 1)
     679        return NULL;
     680
     681    // determine the current format from the header
     682    // if no camera has been specified, use the first image as a template for the rest.
     683    fits = psFitsOpen (infiles->data[0], "r");
     684    phu = psFitsReadHeader (NULL, fits);
     685    format = pmConfigCameraFormatFromHeader (config, phu);
     686    psFitsClose (fits);
     687
     688    // build the template fpa, set up the basic view
     689    fpa = pmFPAConstruct (config->camera);
     690
     691    // load the given filerule (from config->camera) and associate it with the fpa
     692    // the output file is just a view to the file on config->files
     693    file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
     694    if (!file) {
     695        psErrorStackPrint(stderr, "file %s not defined\n", filename);
     696        psFree (fpa);
     697        psFree (format);
     698        return NULL;
     699    }
     700
     701    // this file is (by virtue of being supplied in the argument list) coming from the fileset
     702    psFree (file->filerule);
     703    psFree (file->filextra);
     704
     705    // adjust the rules to identify these files in the file->names data
     706    file->filerule = psStringCopy ("@FILES");
     707    // XXX this rule does not work in general
     708    file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
     709
     710    // examine the list of input files and validate their cameras
     711    for (int i = 0; i < infiles->n; i++) {
     712        if (i > 0) {
     713            fits = psFitsOpen (infiles->data[i], "r");
     714            phu = psFitsReadHeader (NULL, fits);
     715            pmConfigValidateCameraFormat (format, phu);
     716            psFitsClose (fits);
     717        }
     718
     719        // set the view to the corresponding entry for this phu
     720        pmFPAview *view = pmFPAAddSource (fpa, phu, format);
     721
     722        // XXX is this the correct psMD to save the filename?
     723        char *name = pmFPAfileNameFromRule (file->filextra, file, view);
     724        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
     725
     726        psFree (view);
     727        psFree (name);
     728        psFree (phu);
     729    }
     730    psFree (fpa);
     731    psFree (format);
     732    *found = true;
     733
     734    return file;
     735}
     736
     737// look for the given name on the argument list.
    652738pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input)
    653739{
Note: See TracChangeset for help on using the changeset viewer.