IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17634


Ignore:
Timestamp:
May 12, 2008, 11:41:55 AM (18 years ago)
Author:
Paul Price
Message:

Adding additional notes in header file that the returned pmFPAfile is a view only (the caller should not free it). Cleaning up erroneous frees of the pmFPAfile when an error is hit.

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

Legend:

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

    r17489 r17634  
    8787    }
    8888
    89     pmFPAfile *file = pmFPAfileAlloc ();
     89    pmFPAfile *file = pmFPAfileAlloc();
    9090
    9191    // save the name of this pmFPAfile
    92     file->name = psStringCopy (name);
     92    file->name = psStringCopy(name);
    9393
    9494    file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE"));
    9595
    96     type = psMetadataLookupStr (&status, data, "FILE.TYPE");
     96    type = psMetadataLookupStr(&status, data, "FILE.TYPE");
    9797    file->type = pmFPAfileTypeFromString(type);
    9898    if (file->type == PM_FPA_FILE_NONE) {
    9999        psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
     100        psFree(file);
    100101        return NULL;
    101102    }
     
    107108    if (file->dataLevel == PM_FPA_LEVEL_NONE) {
    108109        psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
     110        psFree(file);
    109111        return NULL;
    110112    }
     
    125127    // XXX ppFocus wants to override the selection with the new selection
    126128    // XXX require programs like ppFocus to remove existing files by hand
    127     if (!psMetadataAddPtr (config->files, PS_LIST_TAIL, name,
    128                            PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {
    129         psError (PS_ERR_IO, false, "could not add %s to config files", name);
    130         return NULL;
    131     }
    132     psFree (file);
    133     return (file);
     129    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, name,
     130                          PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", file)) {
     131        psError(PS_ERR_IO, false, "could not add %s to config files", name);
     132        return NULL;
     133    }
     134    psFree(file);
     135    return file;
    134136}
    135137
     
    242244    if (fitsType && strcasecmp(fitsType, "NONE") != 0) {
    243245
    244         // load the FITSTYPE scheme for this file
    245         psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule
     246        // load the FITSTYPE scheme for this file
     247        psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule
    246248        if (!scheme) {
    247             // XXX change to a config error?
     249            // XXX change to a config error?
    248250            psWarning("Unable to find %s in FITS in camera configuration --- will use defaults.", fitsType);
    249251            goto FITS_OPTIONS_DONE;
     
    375377    // place the resulting file in the config system
    376378    psMetadataAddPtr (config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
    377     psFree (file); // we free this copy of file, but 'files' still has a copy
    378     return (file); // the returned value is a view into the version on 'files'
     379    psFree(file);                      // we free this copy of file, but 'files' still has a copy
     380    return file;                        // the returned value is a view into the version on 'files'
    379381}
    380382
     
    429431
    430432    // use success to identify valid exit conditions (as opposed to 'argument not supplied')
    431     if (success) *success = false;
     433    if (success) {
     434        *success = false;
     435    }
    432436
    433437    // we search the argument data for the named fileset (argname)
    434438    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
    435439    if (!status) {
    436         if (success) *success = true;
     440        if (success) {
     441            *success = true;
     442        }
    437443        return NULL;
    438444    }
     
    467473    // determine the current format from the header
    468474    // determine camera if not specified already
    469     format = pmConfigCameraFormatFromHeader (config, phu, true);
     475    format = pmConfigCameraFormatFromHeader(config, phu, true);
    470476    if (!format) {
    471477        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
     
    476482
    477483    // build the template fpa, set up the basic view
    478     fpa = pmFPAConstruct (config->camera);
     484    fpa = pmFPAConstruct(config->camera);
    479485    if (!fpa) {
    480486        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
     
    486492    // load the given filerule (from config->camera) and bind it to the fpa
    487493    // the returned file is just a view to the entry on config->files
    488     file = pmFPAfileDefineInput (config, fpa, filename);
     494    file = pmFPAfileDefineInput(config, fpa, filename);
    489495    if (!file) {
    490496        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
     
    500506    // adjust the rules to identify these files in the file->names data
    501507    psFree (file->filerule);
    502     file->filerule = psStringCopy ("@FILES");
    503     file->filesrc = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
     508    file->filerule = psStringCopy("@FILES");
     509    file->filesrc = psStringCopy("{CHIP.NAME}.{CELL.NAME}");
    504510
    505511    file->fileLevel = pmFPAPHULevel(format);
     
    509515        psFree(fpa);
    510516        psFree(format);
    511         psFree(file);
    512517        return NULL;
    513518    }
     
    528533            if (!fits) {
    529534                psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
    530                 psFree (realName);
     535                psFree(realName);
    531536                return NULL;
    532537            }
     
    534539            if (!phu) {
    535540                psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
    536                 psFree (realName);
    537                 psFitsClose (fits);
     541                psFree(realName);
     542                psFitsClose(fits);
    538543                return NULL;
    539544            }
    540545            bool valid = false;
    541546            if (!pmConfigValidateCameraFormat (&valid, format, phu)) {
    542                 psError (PS_ERR_UNKNOWN, false, "Error in config scripts\n");
    543                 psFree (realName);
    544                 psFitsClose (fits);
     547                psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
     548                psFree(realName);
     549                psFitsClose(fits);
    545550                return NULL;
    546551            }
    547552            if (!valid) {
    548553                psError(PS_ERR_IO, false, "file %s is not from the required camera", realName);
    549                 psFree (realName);
    550                 psFitsClose (fits);
     554                psFree(realName);
     555                psFitsClose(fits);
    551556                return NULL;
    552557            }
    553558            psFree(realName);
    554             psFitsClose (fits);
     559            psFitsClose(fits);
    555560        }
    556561
     
    560565            psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
    561566            psFree(phu);
    562             psFree (fpa);
    563             psFree (format);
     567            psFree(fpa);
     568            psFree(format);
    564569            return NULL;
    565570        }
    566571
    567572        // associate the filename with the FPA element
    568         char *name = pmFPAfileNameFromRule (file->filesrc, file, view);
     573        char *name = pmFPAfileNameFromRule(file->filesrc, file, view);
    569574
    570575        // save the name association in the pmFPAfile structure
    571         psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    572 
    573         psFree (view);
    574         psFree (name);
    575         psFree (phu);
    576     }
    577     psFree (fpa);
    578     if (success) *success = true;
     576        psMetadataAddStr(file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
     577
     578        psFree(view);
     579        psFree(name);
     580        psFree(phu);
     581    }
     582    psFree(fpa);
     583    if (success) {
     584        *success = true;
     585    }
    579586
    580587    return file;
     
    600607
    601608    // use success to identify valid exit conditions (as opposed to 'argument not supplied')
    602     if (success) *success = false;
     609    if (success) {
     610        *success = false;
     611    }
    603612
    604613    // we search the argument data for the named fileset (argname)
     
    606615    if (!status) {
    607616        // this is not an error: this just means no matching argument was supplied
    608         if (success) *success = true;
     617        if (success) {
     618            *success = true;
     619        }
    609620        return NULL;
    610621    }
     
    647658        if (!fits) {
    648659            psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
    649             psFree (realName);
     660            psFree(realName);
    650661            return NULL;
    651662        }
     
    653664        if (!phu) {
    654665            psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
    655             psFree (realName);
    656             psFitsClose (fits);
     666            psFree(realName);
     667            psFitsClose(fits);
    657668            return NULL;
    658669        }
     
    665676                psFree(realName);
    666677                psFitsClose(fits);
    667                 psFree(file);
    668678                return NULL;
    669679            }
     
    673683                psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
    674684                psFree(realName);
    675                 psFree(file);
    676685                psFitsClose(fits);
    677686                return NULL;
     
    681690                        realName);
    682691                psFree(realName);
    683                 psFree(file);
    684692                psFitsClose(fits);
    685693                return NULL;
     
    704712        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    705713
    706         psFree (view);
    707         psFree (name);
    708         psFree (phu);
     714        psFree(view);
     715        psFree(name);
     716        psFree(phu);
    709717    }
    710718    psFree(file->format);
     
    712720    file->formatName = psStringCopy(config->formatName);
    713721
    714     if (success) *success = true;
     722    if (success) {
     723        *success = true;
     724    }
    715725    return file;
    716726}
     
    736746    psMetadata *format = NULL;
    737747
    738     if (success) *success = false;
     748    if (success) {
     749        *success = false;
     750    }
    739751
    740752    // we search the argument data for the named fileset (argname)
     
    742754    if (!status) {
    743755        psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname);
    744         if (success) *success = true;
     756        if (success) {
     757            *success = true;
     758        }
    745759        return NULL;
    746760    }
    747761    if (infiles->n <= entry) {
    748         psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n", infiles->n, argname, entry);
     762        psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n",
     763                infiles->n, argname, entry);
    749764        return NULL;
    750765    }
     
    802817        psFree(phu);
    803818        psFree(fpa);
    804         psFree(file);
    805819        psFree(format);
    806820        return NULL;
     
    813827        psFree(phu);
    814828        psFree(fpa);
    815         psFree(file);
    816829        psFree(format);
    817830        return NULL;
     
    830843    psFree(format);
    831844
    832     if (success) *success = true;
     845    if (success) {
     846        *success = true;
     847    }
    833848    return file;
    834849}
     
    841856    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    842857
    843     if (success) *success = false;
     858    if (success) {
     859        *success = false;
     860    }
    844861
    845862    // a camera config is needed (as source of file rule)
     
    858875    // load the given filerule (from config->camera) and bind it to the fpa
    859876    // the returned file is just a view to the entry on config->files
    860     pmFPAfile *file = pmFPAfileDefineInput (config, fpa, filename);
     877    pmFPAfile *file = pmFPAfileDefineInput(config, fpa, filename);
    861878    psFree (fpa);
    862879    if (!file) {
     
    866883
    867884    // image names may not come from file->names
    868     if (!strcasecmp (file->filerule, "@FILES")) {
     885    if (!strcasecmp(file->filerule, "@FILES")) {
    869886        psError(PS_ERR_IO, true, "supplied filerule uses illegal value @FILES");
    870887        // XXX remove the file from config->files
    871         psFree(file);
    872888        return NULL;
    873889    }
    874890
    875891    // image names may come from the detrend database
    876     if (!strcasecmp (file->filerule, "@DETDB")) {
     892    if (!strcasecmp(file->filerule, "@DETDB")) {
    877893        psTrace ("pmFPAfile", 5, "requiring use of detrend database source\n");
    878894        // don't free the file here: it is left on config->files
    879895        // to be used optionally by pmFPAfileDefineFromDetDB (or others)
    880         if (success) *success = true;
     896        if (success) {
     897            *success = true;
     898        }
    881899        return NULL;
    882900    }
     
    884902    // Prepend the global path to the file rule
    885903    // this function is implicitly an INPUT operation: do not create the file
    886     psString tmpName = pmConfigConvertFilename (file->filerule, config, false);
     904    psString tmpName = pmConfigConvertFilename(file->filerule, config, false);
    887905    psFree (file->filerule);
    888906    file->filerule = tmpName;
    889907
    890     if (success) *success = true;
     908    if (success) {
     909        *success = true;
     910    }
    891911
    892912    return file;
     
    911931    pmFPAfile *file = NULL;
    912932
    913     if (success) *success = false;
     933    if (success) {
     934        *success = false;
     935    }
    914936
    915937    // a camera config is needed (as source of file rule)
     
    937959        if (!file) {
    938960            psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    939             psFree (fpa);
     961            psFree(fpa);
    940962            return NULL;
    941963        }
     
    10541076    psFree (options);
    10551077
    1056     if (success) *success = true;
     1078    if (success) {
     1079        *success = true;
     1080    }
    10571081    return file;
    10581082}
     
    12021226        if (!pmConceptsCopyFPA(file->fpa, src, true, false)) {
    12031227            psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
    1204             psFree(file);
    12051228            return NULL;
    12061229        }
     
    12541277        if (!pmConceptsCopyFPA(file->fpa, src, false, false)) {
    12551278            psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from source to new FPA");
    1256             psFree(file);
    12571279            return NULL;
    12581280        }
     
    12941316    bool status = false;
    12951317
    1296     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
     1318    pmFPAfile *file = psMetadataLookupPtr(&status, files, name);
    12971319    if (!status) {
    12981320        psTrace("psModules.camera", 6, "Internal File %s not in file list", name);
     
    13091331
    13101332    psTrace("psModules.camera", 6, "dropping Internal FPA File %s", name);
    1311     psMetadataRemoveKey (files, name);
     1333    psMetadataRemoveKey(files, name);
    13121334    return true;
    13131335}
  • trunk/psModules/src/camera/pmFPAfileDefine.h

    r15931 r17634  
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-12-27 02:08:19 $
     6 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2008-05-12 21:41:55 $
    88 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
    99 */
     
    3939
    4040/// Define the FPA file using the provided camera and format names.
     41///
     42/// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
     43/// reference count is held by the config->files metadata.
    4144pmFPAfile *pmFPAfileDefineOutputForFormat(const pmConfig *config, // Configuration
    4245                                          pmFPA *fpa, // Optional FPA to bind
     
    7881
    7982/// Same as pmFPAfileDefineFromFPA, except it uses an FPA file instead of an FPA
     83///
     84/// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does
     85/// not have to (and should not!) free the result.
    8086pmFPAfile *pmFPAfileDefineFromFile(const pmConfig *config, // Configuration
    8187                                   pmFPAfile *src, // Source file for this file
     
    122128// create a file with the given name, assign it type "INTERNAL", and supply it with an image
    123129// of the requested dimensions. (image only, mask and weight are ignored)
    124 pmReadout *pmFPAfileDefineInternal (psMetadata *files, const char *name, int Nx, int Ny, int type);
     130///
     131/// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does
     132/// not have to (and should not!) free the result.
     133pmReadout *pmFPAfileDefineInternal(psMetadata *files, const char *name, int Nx, int Ny, int type);
    125134
    126135// delete the INTERNAL file of the given name (if it exists)
    127 bool pmFPAfileDropInternal (psMetadata *files, const char *name);
     136bool pmFPAfileDropInternal(psMetadata *files, const char *name);
    128137
    129138// look for the given argname on the argument list.  find the give filename from the file rules
     
    131140// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
    132141// reference count is held by the config->files metadata.
    133 pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, const char *filename,
    134         const char *argname, int entry);
     142pmFPAfile *pmFPAfileDefineSingleFromArgs(bool *found, pmConfig *config, const char *filename,
     143                                         const char *argname, int entry);
    135144
    136145// Select or construct the requested readout.  If the named entry does not exist, generate it based
     
    139148// pmFPAfile is being used internally.
    140149pmReadout *pmFPAGenerateReadout(const pmConfig *config, // configuration information
    141                                 const pmFPAview *view, // select background for this entry
    142                                 const char *name, // name of internal/external file
    143                                 const pmFPA *fpa, // use this fpa to generate
    144                                 const psImageBinning *binning);
     150                                const pmFPAview *view, // select background for this entry
     151                                const char *name, // name of internal/external file
     152                                const pmFPA *fpa, // use this fpa to generate
     153                                const psImageBinning *binning);
    145154
    146155/// @}
Note: See TracChangeset for help on using the changeset viewer.