IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7728


Ignore:
Timestamp:
Jun 28, 2006, 9:23:20 AM (20 years ago)
Author:
magnier
Message:

added pmFPAfileDefineSingleFromArgs (lame name)

Location:
trunk/psModules/src/camera
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r7679 r7728  
    3333    PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
    3434
    35 
    36 
    3735    bool status;
    3836    char *type;
     
    118116    }
    119117
    120     psMetadataAddPtr (config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
    121     psFree (file); // we free this copy of file, but 'files' still has a copy
    122 
    123     return (file); // the returned value is a view into the version on 'files'
     118    // XXX ppImage and similar require the added file to be unique
     119    // XXX ppFocus wants to override the selection with the new selection
     120    // XXX require programs like ppFocus to remove existing files by hand
     121    if (!psMetadataAddPtr (config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file)) {
     122        psError (PS_ERR_IO, false, "could not add %s to config files", name);
     123        return NULL;
     124    }
     125    psFree (file);
     126    return (file);
    124127}
    125128
     
    345348        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    346349        psFree(phu);
    347         psFree (fpa);
    348         psFree (format);
     350        psFree(fpa);
     351        psFree(format);
    349352        return NULL;
    350353    }
     
    411414}
    412415
     416// search for argname on the config->argument list
     417// construct an FPA based on the files in this list (each represents the same FPA)
     418// built the association between the FPA elements (CHIP/CELL) and the files
     419// define the pmFPAfile filenames and bind them to the FPAs
     420// save the pmFPAfiles on config->files
     421// return the pmFPAfiles (a view to the one saved on config->files)
     422pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, char *filename, char *argname, int entry)
     423{
     424    PS_ASSERT_PTR_NON_NULL(config, NULL);
     425    PS_ASSERT_PTR_NON_NULL(filename, NULL);
     426    PS_ASSERT_INT_POSITIVE(strlen(filename), NULL);
     427    PS_ASSERT_PTR_NON_NULL(argname, NULL);
     428    PS_ASSERT_INT_POSITIVE(strlen(argname), NULL);
     429
     430    bool status;
     431    pmFPA *fpa = NULL;
     432    psFits *fits = NULL;
     433    pmFPAfile *file = NULL;
     434    psMetadata *phu = NULL;
     435    psMetadata *format = NULL;
     436
     437    if (*found)
     438        return NULL;
     439
     440    // we search the argument data for the named fileset (argname)
     441    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     442    if (!status) {
     443        psTrace("pmFPAfile", 5, "Failed to find %s in argument list", argname);
     444        return NULL;
     445    }
     446    if (infiles->n <= entry) {
     447        psError(PS_ERR_IO, false, "only %d files in %s in argument, entry %d requested\n", infiles->n, argname, entry);
     448        return NULL;
     449    }
     450
     451    // examine the list of input files and validate their cameras
     452    // associated each filename with an element of the FPA
     453    // save the association on file->names
     454    fits = psFitsOpen (infiles->data[entry], "r");
     455    phu = psFitsReadHeader (NULL, fits);
     456    psFitsClose (fits);
     457
     458    // on first call to this function, config->camera is not set.
     459    // later calls will give an error if the cameras do not match
     460    format = pmConfigCameraFormatFromHeader (config, phu);
     461    if (!format) {
     462        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", infiles->data[0]);
     463        psFree(phu);
     464        return NULL;
     465    }
     466
     467    // build the template fpa, set up the basic view
     468    fpa = pmFPAConstruct (config->camera);
     469    if (!fpa) {
     470        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", infiles->data[0]);
     471        return NULL;
     472    }
     473
     474    // load the given filerule (from config->camera) and bind it to the fpa
     475    // the returned file is just a view to the entry on config->files
     476    // we need a variable name here... (but in filerule)
     477    file = pmFPAfileDefineInput (config, fpa, filename);
     478    if (!file) {
     479        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
     480        psFree(phu);
     481        psFree(fpa);
     482        psFree(format);
     483        return NULL;
     484    }
     485    file->format = format;
     486
     487    // adjust the rules to identify these files in the file->names data
     488    psFree (file->filerule);
     489    psFree (file->filextra);
     490    file->filerule = psStringCopy ("@FILES");
     491    file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
     492
     493    // find the matching fileLevel
     494    psMetadata *filemenu = psMetadataLookupPtr (&status, format, "FILE");
     495    if (!filemenu) {
     496        psError (PS_ERR_IO, true, "missing FILE in FORMAT");
     497        return NULL;
     498    }
     499    char *levelName = psMetadataLookupStr (&status, filemenu, "PHU");
     500    if (!levelName) {
     501        psError (PS_ERR_IO, true, "missing PHU in FILE in FORMAT");
     502        return NULL;
     503    }
     504    file->fileLevel = pmFPALevelFromName (levelName);
     505    if (file->fileLevel == PM_FPA_LEVEL_NONE) {
     506        psError (PS_ERR_IO, true, "unknown level");
     507        return NULL;
     508    }
     509
     510    // set the view to the corresponding entry for this phu
     511    pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
     512    if (!view) {
     513        psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
     514        psFree(phu);
     515        psFree (fpa);
     516        psFree (format);
     517        return NULL;
     518    }
     519
     520    // associate the filename with the FPA element
     521    char *name = pmFPAfileNameFromRule (file->filextra, file, view);
     522
     523    // save the name association in the pmFPAfile structure
     524    psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[entry]);
     525
     526    psFree (view);
     527    psFree (name);
     528    psFree (phu);
     529    psFree (fpa);
     530
     531    file->format = format;
     532    *found = true;
     533    return file;
     534}
     535
    413536// define the named pmFPAfile from the camera->config
    414537// only valid for pmFPAfile->mode = READ
     
    661784    file->fpa = pmFPAConstruct(file->camera);
    662785
    663     for (int i = 0; i < file->fpa->chips->n; i++) {
    664         pmChip *chip = file->fpa->chips->data[i];
    665         for (int j = 0; j < chip->cells->n; j++) {
    666             pmCell *cell = chip->cells->data[j];
    667             char *name = psMetadataLookupStr (NULL, cell->concepts, "CELL.NAME");
    668             fprintf (stderr, "cell %d,%d : %s\n", i, j, name);
    669         }
    670     }
    671 
    672786    return file;
    673787}
  • trunk/psModules/src/camera/pmFPAfileDefine.h

    r7623 r7728  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-06-21 23:11:24 $
     9*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-06-28 19:23:20 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    4747bool pmFPAfileDropInternal (psMetadata *files, char *name);
    4848
     49// look for the given argname on the argument list.  find the give filename from the file rules
     50pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, char *filename, char *argname, int entry);
    4951# endif
Note: See TracChangeset for help on using the changeset viewer.