IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 18, 2006, 1:43:28 PM (19 years ago)
Author:
Paul Price
Message:

Extensive changes to FPA reading/writing functions to support mask and weight map reading/writing. Actually, not so much changes as generalisations to the reading/writing functions. Moved the reading/writing functionality into file-static functions, which the higher level functions for reading/writing particular elements (image, mask, weight) call. Added additional pmFPAfile types for mask and weight, with supporting functionality to call the reading/writing functions.

File:
1 edited

Legend:

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

    r9950 r10081  
    6161}
    6262
    63 // given an already-opened fits file, read the components corresponding
    64 // to the specified view
    65 bool pmFPAviewReadFitsImage (const pmFPAview *view, pmFPAfile *file)
    66 {
    67     PS_ASSERT_PTR_NON_NULL(view, false);
    68     PS_ASSERT_PTR_NON_NULL(file, false);
    69 
    70     bool status;
    71     pmFPA *fpa = file->fpa;
    72     psFits *fits = file->fits;
    73 
    74     if (view->chip == -1) {
    75         status = pmFPARead (fpa, fits, NULL);
    76         return status;
     63
     64// given an already-opened fits file, read the components corresponding to the specified view
     65static bool fpaViewReadFitsImage(const pmFPAview *view, // FPA view, specifying the level of interest
     66                                 pmFPAfile *file, // FPA file of interest
     67                                 bool (*fpaReadFunc)(pmFPA*, psFits*, psDB*), // Function to read FPA
     68                                 bool (*chipReadFunc)(pmChip*, psFits*, psDB*), // Function to read chip
     69                                 bool (*cellReadFunc)(pmCell*, psFits*, psDB*) // Function to read cell
     70                                )
     71{
     72    assert(view);
     73    assert(file);
     74
     75    pmFPA *fpa = file->fpa;             // FPA of interest
     76    psFits *fits = file->fits;          // FITS file from which to read
     77
     78    if (view->chip == -1) {
     79        return fpaReadFunc(fpa, fits, NULL);
    7780    }
    7881
     
    8184        return false;
    8285    }
    83     pmChip *chip = fpa->chips->data[view->chip];
    84 
    85     if (view->cell == -1) {
    86         status = pmChipRead (chip, fits, NULL);
    87         return status;
     86    pmChip *chip = fpa->chips->data[view->chip]; // Chip of interest
     87
     88    if (view->cell == -1) {
     89        return chipReadFunc(chip, fits, NULL);
    8890    }
    8991
     
    9294        return false;
    9395    }
    94     pmCell *cell = chip->cells->data[view->cell];
     96    pmCell *cell = chip->cells->data[view->cell]; // Cell of interest
    9597
    9698    if (view->readout == -1) {
    97         status = pmCellRead (cell, fits, NULL);
    98         return status;
    99     }
    100     psError(PS_ERR_UNKNOWN, true, "Returning false");
     99        return cellReadFunc(cell, fits, NULL);
     100    }
     101    psError(PS_ERR_UNKNOWN, true, "Bad view: %d,%d", view->chip, view->cell);
    101102    return false;
    102103
     
    118119    return true;
    119120    #endif
     121}
     122
     123
     124bool pmFPAviewReadFitsImage(const pmFPAview *view, pmFPAfile *file)
     125{
     126    PS_ASSERT_PTR_NON_NULL(view, false);
     127    PS_ASSERT_PTR_NON_NULL(file, false);
     128    return fpaViewReadFitsImage(view, file, pmFPARead, pmChipRead, pmCellRead);
     129}
     130
     131bool pmFPAviewReadFitsMask(const pmFPAview *view, pmFPAfile *file)
     132{
     133    PS_ASSERT_PTR_NON_NULL(view, false);
     134    PS_ASSERT_PTR_NON_NULL(file, false);
     135    return fpaViewReadFitsImage(view, file, pmFPAReadMask, pmChipReadMask, pmCellReadMask);
     136}
     137
     138bool pmFPAviewReadFitsWeight(const pmFPAview *view, pmFPAfile *file)
     139{
     140    PS_ASSERT_PTR_NON_NULL(view, false);
     141    PS_ASSERT_PTR_NON_NULL(file, false);
     142    return fpaViewReadFitsImage(view, file, pmFPAReadWeight, pmChipReadWeight, pmCellReadWeight);
    120143}
    121144
     
    126149// out data in an inconsistent fashion
    127150// the calls below should recurse down the element to write out all components.
    128 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file)
    129 {
    130     PS_ASSERT_PTR_NON_NULL(view, false);
    131     PS_ASSERT_PTR_NON_NULL(file, false);
    132 
    133     pmFPA *fpa = file->fpa;
    134     psFits *fits = file->fits;
     151static bool fpaViewWriteFitsImage(const pmFPAview *view, // FPA view, specifying the level of interest
     152                                  pmFPAfile *file, // FPA file of interest
     153                                  bool (*fpaWriteFunc)(pmFPA*, psFits*, psDB*, bool, bool), // Func for FPA
     154                                  bool (*chipWriteFunc)(pmChip*, psFits*, psDB*, bool, bool), // Func for chip
     155                                  bool (*cellWriteFunc)(pmCell*, psFits*, psDB*, bool) // Func for cell
     156                                 )
     157{
     158    assert(view);
     159    assert(file);
     160
     161    pmFPA *fpa = file->fpa;             // FPA of interest
     162    psFits *fits = file->fits;          // FITS file
    135163
    136164    // pmFPAWrite takes care of all PHUs as needed
    137165    if (view->chip == -1) {
    138         pmFPAWrite(fpa, fits, NULL, false, true);
    139         return true;
     166        return fpaWriteFunc(fpa, fits, NULL, false, true);
    140167    }
    141168
     
    144171        return false;
    145172    }
    146     pmChip *chip = fpa->chips->data[view->chip];
    147 
    148     if (view->cell == -1) {
    149         pmChipWrite (chip, fits, NULL, false, true);
    150         return true;
     173    pmChip *chip = fpa->chips->data[view->chip]; // Chip of interest
     174
     175    if (view->cell == -1) {
     176        return chipWriteFunc(chip, fits, NULL, false, true);
    151177    }
    152178
     
    155181        return false;
    156182    }
    157     pmCell *cell = chip->cells->data[view->cell];
     183    pmCell *cell = chip->cells->data[view->cell]; // Cell of interest
    158184
    159185    if (view->readout == -1) {
    160         return pmCellWrite (cell, fits, NULL, false);
    161     }
    162     psError(PS_ERR_UNKNOWN, true, "Returning false");
     186        return cellWriteFunc(cell, fits, NULL, false);
     187    }
     188    psError(PS_ERR_UNKNOWN, true, "Bad view: %d,%d", view->chip, view->cell);
    163189    return false;
    164190
     
    182208}
    183209
    184 // this old code was used to write the blank by hand.
    185 // pmFPAWrite now takes care of this choice.
    186 # if 0
    187 // do we need to write out a PHU for this entry?
    188 if (file->phu == NULL)
    189     {
    190         pmHDU *hdu = pmFPAviewThisHDU (view, file->fpa);
    191         pmHDU *phu = pmFPAviewThisPHU (view, file->fpa);
    192         // if this hdu is the phu, the write function below will create the phu
    193         if (hdu != phu) {
    194             // we assume that the PHU is just a header
    195             // header may not be defined for constructed images; make a dummy one
    196             psMetadata *outhead = NULL;
    197             if (phu->header) {
    198                 outhead = psMetadataCopy (NULL, phu->header);
    199             } else {
    200                 outhead = psMetadataAlloc ();
    201             }
    202             psMetadataAdd (outhead, PS_LIST_TAIL, "EXTEND", PS_DATA_BOOL | PS_META_REPLACE, "this file has extensions", true);
    203             psFitsWriteBlank (file->fits, outhead, "");
    204             file->phu = phu->header;
    205             psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
    206             psFree (outhead);
    207         }
    208     }
    209 # endif
     210bool pmFPAviewWriteFitsImage(const pmFPAview *view, pmFPAfile *file)
     211{
     212    PS_ASSERT_PTR_NON_NULL(view, false);
     213    PS_ASSERT_PTR_NON_NULL(file, false);
     214    return fpaViewWriteFitsImage(view, file, pmFPAWrite, pmChipWrite, pmCellWrite);
     215}
     216
     217bool pmFPAviewWriteFitsMask(const pmFPAview *view, pmFPAfile *file)
     218{
     219    PS_ASSERT_PTR_NON_NULL(view, false);
     220    PS_ASSERT_PTR_NON_NULL(file, false);
     221    return fpaViewWriteFitsImage(view, file, pmFPAWriteMask, pmChipWriteMask, pmCellWriteMask);
     222}
     223
     224bool pmFPAviewWriteFitsWeight(const pmFPAview *view, pmFPAfile *file)
     225{
     226    PS_ASSERT_PTR_NON_NULL(view, false);
     227    PS_ASSERT_PTR_NON_NULL(file, false);
     228    return fpaViewWriteFitsImage(view, file, pmFPAWriteWeight, pmChipWriteWeight, pmCellWriteWeight);
     229}
    210230
    211231// given an already-opened fits file, read the components corresponding
    212232// to the specified view
    213 bool pmFPAviewFreeFitsImage (const pmFPAview *view, pmFPAfile *file)
     233bool pmFPAviewFreeData(const pmFPAview *view, pmFPAfile *file)
    214234{
    215235    PS_ASSERT_PTR_NON_NULL(view, false);
     
    270290}
    271291
     292#if 0
     293// Shouldn't need this --- when we want to free fringe data, we want to free the whole level, not just the
     294// table.
    272295
    273296// Free the table within a cell
     
    329352}
    330353
     354#endif
Note: See TracChangeset for help on using the changeset viewer.