IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

adding concepts to copy from fpa to fpa

File:
1 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"
Note: See TracChangeset for help on using the changeset viewer.