IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6827


Ignore:
Timestamp:
Apr 10, 2006, 10:22:42 AM (20 years ago)
Author:
magnier
Message:

adding concepts to copy from fpa to fpa

Location:
branches/rel10_ifa/psModules/src/astrom
Files:
2 edited

Legend:

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

    r6821 r6827  
    77#include "pmFPAview.h"
    88#include "pmFPAfile.h"
     9#include "pmFPACopy.h"
    910#include "pmFPARead.h"
    1011#include "pmFPAWrite.h"
     
    1819
    1920    psFree (file->fpa);
     21    psFree (file->readout);
    2022    psFree (file->names);
    2123
     
    4648
    4749    file->phu = NULL;
     50    file->readout = NULL;
    4851    file->header = NULL;
    4952
     
    9497
    9598    pmFPAfile *file = pmFPAfileAlloc ();
     99
     100    // save the name of this pmFPAfile
     101    file->name = psStringCopy (name);
     102
    96103    file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE"));
    97104    file->filextra = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.XTRA"));
     
    213220
    214221    if (file->mode == PM_FPA_MODE_NONE) {
     222        return false;
     223    }
     224    if (file->mode == PM_FPA_MODE_INTERNAL) {
    215225        return false;
    216226    }
     
    350360        pmFPAviewWriteObjects (view, file);
    351361        psTrace ("pmFPAfile", 5, "wrote object %s (fpa: %p)\n", file->filename, file->fpa);
     362        break;
     363
     364    default:
     365        fprintf (stderr, "warning: type mismatch\n");
     366        return false;
     367    }
     368    return true;
     369}
     370
     371// create the data elements (headers, images) appropriate for this view
     372bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view)
     373{
     374    if (file->mode != PM_FPA_MODE_WRITE)
     375        return false;
     376
     377    // get the current depth
     378    pmFPAdepth depth = pmFPAviewDepth (view);
     379
     380    // do we need to write this file?
     381    if (depth != file->dataDepth)
     382        return false;
     383
     384    // XXX is this a sufficient check to avoid creating elements?
     385    if (file->src == NULL)
     386        return false;
     387
     388    switch (file->type) {
     389    case PM_FPA_FILE_IMAGE:
     390        /* create a PHU for thie file, if it does not exist */
     391        pmFPAfileCopyView (file->src, file->fpa, view);
     392        psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->filename, file->fpa);
     393        break;
     394
     395    case PM_FPA_FILE_SX:
     396    case PM_FPA_FILE_RAW:
     397    case PM_FPA_FILE_OBJ:
     398    case PM_FPA_FILE_CMP:
     399    case PM_FPA_FILE_CMF:
    352400        break;
    353401
     
    409457        if (place == PM_FPA_BEFORE) {
    410458            pmFPAfileRead (file, view);
     459            pmFPAfileCreate (file, view);
    411460        } else {
    412461            pmFPAfileWrite (file, view);
     
    418467}
    419468
     469// create a file with the given name, assign it type "INTERNAL", and supply it with an image
     470// of the requested dimensions. (image only, mask and weight are ignored)
     471pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type)
     472{
     473    pmReadout *readout = pmReadoutAlloc (NULL);
     474    readout->image = psImageAlloc (Nx, Ny, type);
     475
     476    // I want an image from the
     477    pmFPAfile *file = pmFPAfileAlloc();
     478    file->mode = PM_FPA_MODE_INTERNAL;
     479
     480    file->readout = readout;
     481    psMetadataAddPtr (files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
     482    psFree (file);
     483    // we free this copy of file, but 'files' still has a copy
     484
     485    return (readout);
     486}
     487
     488bool pmFPAfileDropInternal (psMetadata *files, char *name)
     489{
     490    bool status;
     491
     492    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
     493    if (file == NULL)
     494        return false;
     495
     496    if (file->mode != PM_FPA_MODE_INTERNAL)
     497        return false;
     498
     499    psMetadataRemoveKey (files, name);
     500    return true;
     501}
     502
    420503// select the readout from the named pmFPAfile; if the named file does not exist,
    421 // create an image of the requested dimensions (save this image and file?)
    422 psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type)
     504pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name)
    423505{
    424506    bool status;
    425     psImage *image = NULL;
    426 
    427     // I want an image from the
     507
    428508    pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    429     if (file == NULL) {
    430         // use Nx or Ny == 0 to avoid creating an image
    431         if (Nx*Ny <= 0) {
    432             return NULL;
    433         }
    434         image = psImageAlloc (Nx, Ny, type);
    435         return (image);
    436     }
    437 
    438     // make an fpa consistent with this view
    439     // save the image in the fpa
    440     // save the fpa in the file
    441 
    442     // inconsistent result: return NULL
     509    if (file == NULL)
     510        return NULL;
     511
     512    // internal files have the readout as a separate element:
     513    if (file->mode == PM_FPA_MODE_INTERNAL) {
     514        return file->readout;
     515    }
     516
    443517    pmReadout *readout = pmFPAviewThisReadout (view, file->fpa);
    444     if (readout == NULL) {
    445         return NULL;
    446     }
    447 
    448     // resize the existing readout??? this is wrong...
    449     // need to allocate it if it does not exist...
    450     image = psImageRecycle (readout->image, Nx, Ny, type);
    451     psMemIncrRefCounter (image);
    452     return (image);
     518    return readout;
    453519}
    454520
     
    649715}
    650716
     717// XXX this this function through, then finish
     718# if 0
    651719// look for the given name on the argument list.
    652720// returns the file (a view to the one saved on config->files)
     
    734802    return file;
    735803}
     804# endif
    736805
    737806// look for the given name on the argument list.
     
    884953}
    885954
     955// given an already-opened fits file, write the components corresponding
     956// to the specified view
     957bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view)
     958{
     959    // XXX how to we transmit the required binning factor?
     960    // pmFPAWrite takes care of all PHUs as needed
     961    if (view->chip == -1) {
     962        pmFPACopy (out, in);
     963        return true;
     964    }
     965    if (view->chip >= in->chips->n) {
     966        return false;
     967    }
     968    pmChip *inChip = in->chips->data[view->chip];
     969    pmChip *outChip = out->chips->data[view->chip];
     970
     971    if (view->cell == -1) {
     972        pmChipCopy (outChip, inChip);
     973        return true;
     974    }
     975    if (view->cell >= inChip->cells->n) {
     976        return false;
     977    }
     978    pmCell *inCell = inChip->cells->data[view->cell];
     979    pmCell *outCell = outChip->cells->data[view->cell];
     980
     981    if (view->readout == -1) {
     982        pmCellCopy (outCell, inCell);
     983        return true;
     984    }
     985    return false;
     986
     987    // XXX disable readout write for now
     988    # if (0)
     989
     990        if (view->readout >= cell->readouts->n) {
     991            return false;
     992        }
     993    pmReadout *readout = cell->readouts->data[view->readout];
     994
     995    if (view->nRows == 0) {
     996        pmReadoutWrite (readout, fits, NULL, NULL);
     997    } else {
     998        pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
     999    }
     1000    return true;
     1001    # endif
     1002}
     1003
     1004// need to distinguish between a "copy structure" and a "copy data"
     1005// need to allow for binning when performing the "copy structure"
  • branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h

    r6819 r6827  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.1.2.9 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-04-08 20:13:03 $
     9*  @version $Revision: 1.1.2.10 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-04-10 20:22:42 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    4040    PM_FPA_MODE_READ,
    4141    PM_FPA_MODE_WRITE,
     42    PM_FPA_MODE_INTERNAL,
    4243} pmFPAfileMode;
    4344
     
    4950typedef struct
    5051{
    51     pmFPAdepth fileDepth;
    52     pmFPAdepth dataDepth;
     52    pmFPAfileMode mode;   // is this file read, written, or only used internally?
     53    pmFPAfileType type;   // what type of data is read from / written to disk?
     54    pmFPAfileState state;  // have we opened the file, etc?
    5355
    54     psMetadata *phu;
    55     psMetadata *header;
     56    pmFPAdepth fileDepth;  // what depth in the FPA hierarchy represents a unique file?
     57    pmFPAdepth dataDepth;  // at what depth do we read/write the data segment?
    5658
    57     pmFPA *fpa;
    58     psFits *fits;
    59     psMetadata *names;
     59    pmFPA *fpa;    // for I/O files, we carry a pointer to the complete fpa
     60    psFits *fits;   // for I/O files of fits type (IMAGE, CMP, CMF), we carry a file handle
    6061
    61     char *filerule;
    62     char *filextra;
    63     char *extrule;
    64     char *extxtra;
     62    psMetadata *phu;   // pointer (view) to the current phu header
     63    psMetadata *header;   // pointer (view) to the current hdu header
    6564
    66     char *filename;
    67     char *extname;
     65    pmReadout *readout;   // for internal files, we only carry a single readout
    6866
    69     pmFPAfileType type;
    70     pmFPAfileMode mode;
    71     pmFPAfileState state;
     67    psMetadata *names;   // filenames supplied by the cmdline or detdb are saved here
     68
     69    char *filerule;   // rule for constructing a filename when needed
     70    char *filextra;   // additional information used to define filenames (context dependent)
     71    char *extrule;   // rule for constructing an extension name when needed
     72    char *extxtra;   // additional information used to define extension names (context dependent)
     73
     74    char *name;    // the name of the rule (useful for debugging / tracing)
     75    char *filename;   // the current name of an active file
     76    char *extname;   // the current name of an active file extension
     77
     78    // the following elements are used for WRITE-mode IMAGE-type pmFPAfiles to inform
     79    // the creation of a new image based on an existing image
     80    pmFPA *src;    // if an output FPA, inherit from this FPA
     81    int xBin;    // desired binning in x direction
     82    int yBin;    // desired binning in y direction
    7283}
    7384pmFPAfile;
     
    8192// load the pmFPAfile information from the camera configuration data, constructing the needed fpa structure
    8293// XXX deprecate this function?
    83 pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name);
     94// pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name);
    8495
    8596// open the real file corresponding to the given pmFPAfile appropriate to the current view
     
    8899// read from the real file corresponding to the given pmFPAfile for the current view
    89100bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view);
     101
     102bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view);
    90103
    91104// write to the real file corresponding to the given pmFPAfile for the current view
     
    100113// return an image corresponding to the current readout, from the specified file.  if the pmFPAfile does not
    101114// exist, construct the image using the given size and type (save it in a pmFPAfile??)
    102 psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type);
     115// psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type);
     116
     117// select the readout from the named pmFPAfile; if the named file does not exist,
     118pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name);
     119
     120// create a file with the given name, assign it type "INTERNAL", and supply it with an image
     121// of the requested dimensions. (image only, mask and weight are ignored)
     122pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type);
     123
     124// delete the INTERNAL file of the given name (if it exists)
     125bool pmFPAfileDropInternal (psMetadata *files, char *name);
    103126
    104127// read an image into the current view
     
    120143char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view);
    121144
     145bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view);
     146
    122147# endif
Note: See TracChangeset for help on using the changeset viewer.