IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11182


Ignore:
Timestamp:
Jan 19, 2007, 12:14:15 PM (19 years ago)
Author:
magnier
Message:

adding pmFPAfileBindFromArgs

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

Legend:

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

    r11144 r11182  
    261261    psMetadata *format = NULL;
    262262
    263     if (*found)
     263    if (found && *found)
    264264        return NULL;
    265265
     
    411411
    412412// search for argname on the config->argument list
     413// construct an FPA based on the files in this list (must represent a single FPA)
     414// built the association between the FPA elements (CHIP/CELL) and the files
     415// define the pmFPAfile filename and bind it to this FPA
     416// save the pmFPAfile on config->files
     417// return the pmFPAfile (a view to the one saved on config->files)
     418pmFPAfile *pmFPAfileBindFromArgs (bool *found, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname)
     419{
     420    PS_ASSERT_PTR_NON_NULL(input, NULL);
     421    PS_ASSERT_PTR_NON_NULL(config, NULL);
     422    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     423    PS_ASSERT_STRING_NON_EMPTY(argname, NULL);
     424
     425    bool status;
     426    psFits *fits = NULL;
     427    pmFPAfile *file = NULL;
     428    psMetadata *phu = NULL;
     429    psMetadata *format = NULL;
     430
     431    if (found && *found)
     432        return NULL;
     433
     434    // we search the argument data for the named fileset (argname)
     435    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     436    if (!status) {
     437        // this is not an error: this just means no matching argument was supplied
     438        return NULL;
     439    }
     440    if (infiles->n < 1) {
     441        psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments\n", infiles->n, argname);
     442        return NULL;
     443    }
     444
     445    // load the given filerule (from config->camera) and bind it to the fpa
     446    // the returned file is just a view to the entry on config->files
     447    file = pmFPAfileDefineInput (config, input->fpa, filename);
     448    if (!file) {
     449        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
     450        psFree(phu);
     451        return NULL;
     452    }
     453    // XXX temporary hack : force PSF input onto filename
     454    if (file->type == PM_FPA_FILE_PSF) {
     455        file->filerule = psStringCopy (infiles->data[0]);
     456        return file;
     457    }
     458
     459    // set derived values
     460    file->fileLevel = input->fileLevel;
     461    file->format = psMemIncrRefCounter(input->format);
     462
     463    // defin the rule to identify these files in the file->names data
     464    psFree (file->filerule);
     465    psFree (file->filextra);
     466    file->filerule = psStringCopy ("@FILES");
     467    file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
     468
     469    // examine the list of input files and validate their cameras
     470    // associated each filename with an element of the FPA
     471    // save the association on file->names
     472    for (int i = 0; i < infiles->n; i++) {
     473        psString realName = pmConfigConvertFilename (infiles->data[i], config);
     474        if (!realName) {
     475            psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *) infiles->data[i]);
     476            return NULL;
     477        }
     478        fits = psFitsOpen (realName, "r");
     479        if (!fits) {
     480            psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
     481            psFree (realName);
     482            return NULL;
     483        }
     484        phu = psFitsReadHeader (NULL, fits);
     485        if (!phu) {
     486            psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
     487            psFree (realName);
     488            psFitsClose (fits);
     489            return NULL;
     490        }
     491        if (!pmConfigValidateCameraFormat (format, phu)) {
     492            psError(PS_ERR_IO, false, "specified MASK %s does not match format of supplied INPUT\n", realName);
     493            psFree (realName);
     494            psFitsClose (fits);
     495            return NULL;
     496        }
     497        psFree(realName);
     498        psFitsClose (fits);
     499
     500        // set the view to the corresponding entry for this phu
     501        // XXX this will override the fpa->header, which I don't want to do.
     502        // XXX do I need to carry around the mask and weight headers???
     503        psAbort ("psModules", "pmFPAfileBindMaskFromArgs is not completed");
     504        pmFPAview *view = pmFPAAddSourceFromHeader (input->fpa, phu, format);
     505        if (!view) {
     506            psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
     507            psFree(phu);
     508            psFree (format);
     509            return NULL;
     510        }
     511
     512        // associate the filename with the FPA element
     513        char *name = pmFPAfileNameFromRule (file->filextra, file, view);
     514
     515        // save the name association in the pmFPAfile structure
     516        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
     517
     518        psFree (view);
     519        psFree (name);
     520        psFree (phu);
     521    }
     522    *found = true;
     523    return file;
     524}
     525
     526// search for argname on the config->argument list
    413527// construct an FPA based on the files in this list (each represents the same FPA)
    414528// built the association between the FPA elements (CHIP/CELL) and the files
     
    430544    psMetadata *format = NULL;
    431545
    432     if (*found)
     546    if (found && *found)
    433547        return NULL;
    434548
     
    536650    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    537651
    538     if (*found) {
    539         return NULL;
    540     }
     652    if (found && *found)
     653        return NULL;
    541654
    542655    // a camera config is needed (as source of file rule)
     
    613726    pmFPAfile *file = NULL;
    614727
    615     if (*found)
     728    if (found && *found)
    616729        return NULL;
    617730
  • trunk/psModules/src/camera/pmFPAfileDefine.h

    r10966 r11182  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2007-01-08 22:30:21 $
     9*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2007-01-19 22:14:15 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    3535// reference count is held by the config->files metadata.
    3636pmFPAfile *pmFPAfileDefineFromArgs (bool *found, pmConfig *config, const char *filename, const char *argname);
     37
     38// look for the given argname on the argument list; bind the associated files to the specified
     39// fpa.  these are, eg, mask or weight images.
     40// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
     41// reference count is held by the config->files metadata.
     42pmFPAfile *pmFPAfileBindFromArgs (bool *found, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname);
    3743
    3844// look for the given argname on the argument list.  find the give filename from the file rules
Note: See TracChangeset for help on using the changeset viewer.