IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7480


Ignore:
Timestamp:
Jun 9, 2006, 5:01:38 PM (20 years ago)
Author:
magnier
Message:

added pmFPAfile Free Data functions and support, added PM_FPA_MODE_REFERENCE

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

Legend:

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

    r7443 r7480  
    289289
    290290    if (file->state & PM_FPA_STATE_INACTIVE) {
    291         psTrace("pmFPAfile", 5, "skip open for %s, files is inactive", file->name);
     291        psTrace("pmFPAfile", 6, "skip open for %s, files is inactive", file->name);
    292292        return true;
    293293    }
     
    380380
    381381    if (file->state & PM_FPA_STATE_INACTIVE) {
    382         psTrace("pmFPAfile", 5, "skip read for %s, files is inactive", file->name);
     382        psTrace("pmFPAfile", 6, "skip read for %s, files is inactive", file->name);
    383383        return true;
    384384    }
    385385
    386386    if (file->mode != PM_FPA_MODE_READ) {
    387         psTrace("pmFPAfile", 5, "skip read for %s, mode is not READ", file->name);
     387        psTrace("pmFPAfile", 6, "skip read for %s, mode is not READ", file->name);
    388388        return true;
    389389    }
     
    402402    // do we need to read this file?
    403403    if (depth != file->dataDepth) {
    404         psTrace("pmFPAfile", 5, "skip reading of %s at this depth %s: dataDepth is %s",
     404        psTrace("pmFPAfile", 6, "skip reading of %s at this depth %s: dataDepth is %s",
    405405                file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    406406        return true;
     
    441441}
    442442
    443 bool pmFPAfileWrite(pmFPAfile *file, const pmFPAview *view)
     443bool pmFPAfileFreeData(pmFPAfile *file, const pmFPAview *view)
    444444{
    445445    PS_ASSERT_PTR_NON_NULL(file, false);
     
    447447
    448448    if (file->state & PM_FPA_STATE_INACTIVE) {
    449         psTrace("pmFPAfile", 5, "skip write for %s, files is inactive", file->name);
    450         return true;
    451     }
    452 
    453     if (file->mode != PM_FPA_MODE_WRITE) {
    454         psTrace("pmFPAfile", 5, "skip write for %s, mode is not WRITE", file->name);
     449        psTrace("pmFPAfile", 6, "skip free for %s, files is inactive", file->name);
    455450        return true;
    456451    }
     
    459454    pmFPAdepth depth = pmFPAviewDepth (view);
    460455
     456    // do we need to read this file?
     457    if (depth != file->dataDepth) {
     458        psTrace("pmFPAfile", 6, "skip free of %s at this depth %s: dataDepth is %s",
     459                file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
     460        return true;
     461    }
     462
     463    switch (file->type) {
     464    case PM_FPA_FILE_IMAGE:
     465        if (pmFPAviewFreeFitsImage (view, file)) {
     466            psTrace ("pmFPAfile", 5, "freed %s (type: %d)\n", file->filename, file->type);
     467        } else {
     468            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
     469            return false;
     470        }
     471        break;
     472
     473    case PM_FPA_FILE_SX:
     474    case PM_FPA_FILE_RAW:
     475    case PM_FPA_FILE_OBJ:
     476    case PM_FPA_FILE_CMP:
     477    case PM_FPA_FILE_CMF:
     478        // pmFPAviewFreeObjects (view, file);
     479        psTrace ("pmFPAfile", 5, "NOT freeing %s (type: %d)\n", file->filename, file->type);
     480        break;
     481
     482        // XXX not certain what I need to free here
     483    case PM_FPA_FILE_PSF:
     484    case PM_FPA_FILE_JPEG:
     485        break;
     486
     487    default:
     488        psError(PS_ERR_IO, true, "warning: type mismatch; saw type %d", file->type);
     489        return false;
     490    }
     491    return true;
     492}
     493
     494bool pmFPAfileWrite(pmFPAfile *file, const pmFPAview *view)
     495{
     496    PS_ASSERT_PTR_NON_NULL(file, false);
     497    PS_ASSERT_PTR_NON_NULL(view, false);
     498
     499    if (file->state & PM_FPA_STATE_INACTIVE) {
     500        psTrace("pmFPAfile", 6, "skip write for %s, files is inactive", file->name);
     501        return true;
     502    }
     503
     504    if (file->mode != PM_FPA_MODE_WRITE) {
     505        psTrace("pmFPAfile", 6, "skip write for %s, mode is not WRITE", file->name);
     506        return true;
     507    }
     508
     509    // get the current depth
     510    pmFPAdepth depth = pmFPAviewDepth (view);
     511
    461512    // do we need to write this file?
    462513    if (depth != file->dataDepth) {
    463         psTrace("pmFPAfile", 5, "skip writing of %s at this depth %s: dataDepth is %s",
     514        psTrace("pmFPAfile", 6, "skip writing of %s at this depth %s: dataDepth is %s",
    464515                file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    465516        return true;
     
    518569    // these are not error conditions; these are state tests
    519570    if (file->state & PM_FPA_STATE_INACTIVE) {
    520         psTrace("pmFPAfile", 5, "skip create for inactive file %s", file->name);
     571        psTrace("pmFPAfile", 6, "skip create for inactive file %s", file->name);
    521572        return true;
    522573    }
    523574    if (file->mode != PM_FPA_MODE_WRITE) {
    524         psTrace("pmFPAfile", 5, "skip create for non-write file %s", file->name);
     575        psTrace("pmFPAfile", 6, "skip create for non-write file %s", file->name);
    525576        return true;
    526577    }
     
    531582    // don't create the file if the src FPA is not defined
    532583    if (file->src == NULL) {
    533         psTrace("pmFPAfile", 5, "skip create for FPA without src FPA for %s", file->name);
     584        psTrace("pmFPAfile", 6, "skip create for FPA without src FPA for %s", file->name);
    534585        return true;
    535586    }
     
    537588    // do we need to write this file?
    538589    if (depth != file->dataDepth) {
    539         psTrace("pmFPAfile", 5, "skip creation of %s at this depth %s: dataDepth is %s",
     590        psTrace("pmFPAfile", 6, "skip creation of %s at this depth %s: dataDepth is %s",
    540591                file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    541592        return true;
     
    571622
    572623    if (file->state & PM_FPA_STATE_INACTIVE) {
    573         psTrace("pmFPAfile", 5, "skip close for %s, files is inactive", file->name);
     624        psTrace("pmFPAfile", 6, "skip close for %s, files is inactive", file->name);
    574625        return true;
    575626    }
     
    581632    pmFPAdepth depth = pmFPAviewDepth (view);
    582633    if (file->fileDepth != depth) {
    583         psTrace("pmFPAfile", 5, "skip closing of %s at this depth %s: dataDepth is %s",
     634        psTrace("pmFPAfile", 6, "skip closing of %s at this depth %s: dataDepth is %s",
    584635                file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    585636        return true;
     
    639690    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    640691    if (!status) {
    641         psError(PS_ERR_IO, true, "Failed to look up file %s", name);
     692        psTrace("pmFPAfile", 6, "%s is not a defined IO file", name);
    642693        return false;
    643694    }
     
    654705}
    655706
    656 // attempt open, read, write, or close pmFPAfiles in files
     707// attempt create, read, write, close, or free pmFPAfiles available in files
     708// files are automatically opened before they are read
    657709bool pmFPAfileIOChecks (psMetadata *files, const pmFPAview *view, pmFPAfilePlace place)
    658710{
     
    660712    PS_ASSERT_PTR_NON_NULL(view, false);
    661713
    662     // recipe override values (command-line options):
     714    bool status = true;
     715
     716    // attempt to perform all create, read, write
    663717    psMetadataItem *item = NULL;
    664718    psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL);
     
    670724            if (!pmFPAfileRead (file, view)) {
    671725                psError(PS_ERR_IO, false, "failed READ in FPA_BEFORE block for %s", file->name);
    672                 psFree(iter);
    673                 return false;
     726                status = false;
    674727            }
    675728            if (!pmFPAfileCreate(file, view)) {
    676729                psError(PS_ERR_IO, false, "failed CREATE in FPA_BEFORE block for %s", file->name);
    677                 psFree(iter);
    678                 return false;
     730                status = false;
    679731            }
    680732            break;
     
    682734            if (!pmFPAfileWrite (file, view)) {
    683735                psError(PS_ERR_IO, false, "failed WRITE in FPA_AFTER block for %s", file->name);
    684                 psFree(iter);
    685                 return false;
     736                status = false;
    686737            }
    687738            if (!pmFPAfileClose(file, view)) {
    688739                psError(PS_ERR_IO, false, "failed CLOSE in FPA_AFTER block for %s", file->name);
    689                 psFree(iter);
    690                 return false;
     740                status = false;
    691741            }
    692742            break;
     
    695745        }
    696746    }
     747
     748    // attempt to free data that is no longer needed
     749    psMetadataIteratorSet (iter, PS_LIST_HEAD);
     750    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
     751        pmFPAfile *file = item->data.V;
     752
     753        switch (place) {
     754        case PM_FPA_BEFORE:
     755            break;
     756        case PM_FPA_AFTER:
     757            if (!pmFPAfileFreeData(file, view)) {
     758                psError(PS_ERR_IO, false, "failed FREE in FPA_AFTER block for %s", file->name);
     759                status = false;
     760            }
     761            break;
     762        default:
     763            psAbort(PS_FILE_LINE, "You can't get here");
     764        }
     765    }
    697766    psFree (iter);
    698 
    699     return true;
     767    return status;
    700768}
    701769
     
    810878        status = pmCellRead (cell, fits, NULL);
    811879        return status;
     880    }
     881    psError(PS_ERR_UNKNOWN, true, "Returning false");
     882    return false;
     883
     884    // XXX pmReadoutRead, pmReadoutReadSegement disabled for now
     885    #if 0
     886
     887    if (view->readout >= cell->readouts->n) {
     888        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
     889                view->readout, cell->readouts->n);
     890        return false;
     891    }
     892    pmReadout *readout = cell->readouts->data[view->readout];
     893
     894    if (view->nRows == 0) {
     895        pmReadoutRead (readout, fits, NULL);
     896    } else {
     897        pmReadoutReadSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
     898    }
     899    return true;
     900    #endif
     901}
     902
     903// given an already-opened fits file, read the components corresponding
     904// to the specified view
     905bool pmFPAviewFreeFitsImage (const pmFPAview *view, pmFPAfile *file)
     906{
     907    PS_ASSERT_PTR_NON_NULL(view, false);
     908    PS_ASSERT_PTR_NON_NULL(file, false);
     909
     910    pmFPA *fpa = file->fpa;
     911
     912    if (view->chip == -1) {
     913        psTrace ("pmFPAfile", 5, "freeing fpa for %s\n", file->filename);
     914        psFree (fpa);
     915        file->fpa = NULL;
     916        return true;
     917    }
     918
     919    if (view->chip >= fpa->chips->n) {
     920        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %d", view->chip, fpa->chips->n);
     921        return false;
     922    }
     923    pmChip *chip = fpa->chips->data[view->chip];
     924
     925    if (view->cell == -1) {
     926        psTrace ("pmFPAfile", 5, "freeing chip %d for %s\n", view->chip, file->filename);
     927        psFree (chip);
     928        fpa->chips->data[view->chip] = NULL;
     929        return true;
     930    }
     931
     932    if (view->cell >= chip->cells->n) {
     933        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
     934        return false;
     935    }
     936    pmCell *cell = chip->cells->data[view->cell];
     937
     938    if (view->readout == -1) {
     939        psTrace ("pmFPAfile", 5, "freeing cell %d for %s\n", view->cell, file->filename);
     940        psFree (cell);
     941        chip->cells->data[view->cell] = NULL;
     942        return true;
    812943    }
    813944    psError(PS_ERR_UNKNOWN, true, "Returning false");
     
    12511382
    12521383        if (file->mode == mode) {
    1253             psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", value);
     1384            psMetadataAddStr (file->names, PS_LIST_TAIL, name, PS_META_NO_REPLACE, "", value);
    12541385        }
    12551386    }
  • trunk/psModules/src/camera/pmFPAfile.h

    r7017 r7480  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-05-01 01:55:43 $
     9*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-06-10 03:01:29 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    4343    PM_FPA_MODE_WRITE,
    4444    PM_FPA_MODE_INTERNAL,
     45    PM_FPA_MODE_REFERENCE,
    4546} pmFPAfileMode;
    4647
     
    112113bool pmFPAfileClose (pmFPAfile *file, const pmFPAview *view);
    113114
     115// free the data at this level
     116bool pmFPAfileFreeData(pmFPAfile *file, const pmFPAview *view);
     117
    114118// set the state of the specified pmFPAfile to active (state == true) or inactive
    115119// if name is NULL, set the state for all pmFPAfiles
     
    139143bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file);
    140144
     145// free the appropriate image containers
     146bool pmFPAviewFreeFitsImage (const pmFPAview *view, pmFPAfile *file);
     147
    141148// look for the given argname on the argument list.  find the give filename from the file rules
    142149pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname);
Note: See TracChangeset for help on using the changeset viewer.