IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 13, 2006, 12:15:55 PM (19 years ago)
Author:
Paul Price
Message:

Adding FRINGE type to pmFPAfile, which reads from/writes to FITS tables at the cell level.

File:
1 edited

Legend:

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

    r9654 r9950  
    3030#include "pmDetrendDB.h"
    3131
     32// Open a file that contains an image
     33static bool openImage(pmFPAfile *file,  // File to open
     34                      const pmFPAview *view, // View pointing to open level
     35                      const char *mode,  // Open mode (for psFitsOpen)
     36                      pmConfig *config  // Configuration
     37                     )
     38{
     39    file->fits = psFitsOpen (file->filename, mode);
     40    if (file->fits == NULL) {
     41        psError(PS_ERR_IO, false, "error opening file %s\n", file->filename);
     42        return false;
     43    }
     44    file->state = PM_FPA_STATE_OPEN;
     45
     46    // In some cases, I need to call pmFPAAddSourceFromHeader after I've opened the file,
     47    // specifically if I have not called this function on startup.  This happens for the
     48    // images supplied by the detrend database, which are only identified here (above).
     49    // this is never true for the output images, which are constructed later
     50
     51    if (file->mode == PM_FPA_MODE_READ) {
     52        bool addSource = false;
     53        switch (file->fileLevel) {
     54        case PM_FPA_LEVEL_FPA:
     55            addSource = !file->fpa->hdu;
     56            break;
     57        case PM_FPA_LEVEL_CHIP: {
     58                pmChip *chip = pmFPAviewThisChip(view, file->fpa);
     59                if (!chip) {
     60                    psError (PS_ERR_IO, true, "inconsistent file/fpa: fileLevel is CHIP, view is FPA");
     61                    return false;
     62                }
     63                addSource = !chip->hdu;
     64                break;
     65            }
     66        case PM_FPA_LEVEL_CELL: {
     67                pmCell *cell = pmFPAviewThisCell(view, file->fpa);
     68                if (!cell) {
     69                    psError (PS_ERR_IO, true, "inconsistent file/fpa: fileLevel is CELL, view is FPA");
     70                    return false;
     71                }
     72                addSource = !cell->hdu;
     73                break;
     74            }
     75        default:
     76            psAbort ("pmFPAfileIO", "fileLevel not correctly set");
     77            break;
     78        }
     79
     80        if (addSource) {
     81            psMetadata *phu = psFitsReadHeader (NULL, file->fits);
     82            if (!file->format) {
     83                file->format = pmConfigCameraFormatFromHeader (config, phu);
     84                if (!file->format) {
     85                    psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename);
     86                    psFree(phu);
     87                    return NULL;
     88                }
     89            } else {
     90                pmConfigValidateCameraFormat (file->format, phu);
     91            }
     92            pmFPAview *thisView = pmFPAAddSourceFromHeader (file->fpa, phu, file->format);
     93            psFree (thisView);
     94            psFree (phu);
     95            // XXX we can check the output view to be sure it corresponds to our current view
     96        }
     97    }
     98    if (file->mode == PM_FPA_MODE_WRITE) {
     99        switch (file->fileLevel) {
     100        case PM_FPA_LEVEL_FPA:
     101            pmFPAWrite (file->fpa, file->fits, NULL, true, false);
     102            break;
     103        case PM_FPA_LEVEL_CHIP: {
     104                pmChip *chip = pmFPAviewThisChip(view, file->fpa);
     105                pmChipWrite (chip, file->fits, NULL, true, false);
     106                break;
     107            }
     108        case PM_FPA_LEVEL_CELL: {
     109                pmCell *cell = pmFPAviewThisCell(view, file->fpa);
     110                pmCellWrite(cell, file->fits, NULL, true);
     111                break;
     112            }
     113        default:
     114            psAbort ("pmFPAfileIO", "fileLevel not correctly set");
     115            break;
     116        }
     117    }
     118
     119    return true;
     120
     121}
     122
     123
    32124// open file (if not already opened)
    33125bool pmFPAfileOpen (pmFPAfile *file, const pmFPAview *view, pmConfig *config)
     
    133225        // open the FITS types:
    134226    case PM_FPA_FILE_IMAGE:
     227    case PM_FPA_FILE_FRINGE:
    135228        psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
    136         file->fits = psFitsOpen (file->filename, mode);
    137         if (file->fits == NULL) {
    138             psError(PS_ERR_IO, false, "error opening file %s\n", file->filename);
    139             return false;
    140         }
    141         file->state = PM_FPA_STATE_OPEN;
    142 
    143         // In some cases, I need to call pmFPAAddSourceFromHeader after I've opened the file,
    144         // specifically if I have not called this function on startup.  This happens for the
    145         // images supplied by the detrend database, which are only identified here (above).
    146         // this is never true for the output images, which are constructed later
    147 
    148         if (file->mode == PM_FPA_MODE_READ) {
    149             pmChip *chip;
    150             pmCell *cell;
    151             bool addSource = false;
    152             switch (file->fileLevel) {
    153             case PM_FPA_LEVEL_FPA:
    154                 addSource = !file->fpa->hdu;
    155                 break;
    156             case PM_FPA_LEVEL_CHIP:
    157                 chip = pmFPAviewThisChip(view, file->fpa);
    158                 if (!chip) {
    159                     psError (PS_ERR_IO, true, "inconsistent file/fpa: fileLevel is CHIP, view is FPA");
    160                     return false;
    161                 }
    162                 addSource = !chip->hdu;
    163                 break;
    164             case PM_FPA_LEVEL_CELL:
    165                 cell = pmFPAviewThisCell(view, file->fpa);
    166                 if (!cell) {
    167                     psError (PS_ERR_IO, true, "inconsistent file/fpa: fileLevel is CELL, view is FPA");
    168                     return false;
    169                 }
    170                 addSource = !cell->hdu;
    171                 break;
    172             default:
    173                 psAbort ("pmFPAfileIO", "fileLevel not correctly set");
    174                 break;
    175             }
    176 
    177             if (addSource) {
    178                 psMetadata *phu = psFitsReadHeader (NULL, file->fits);
    179                 if (!file->format) {
    180                     file->format = pmConfigCameraFormatFromHeader (config, phu);
    181                     if (!file->format) {
    182                         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename);
    183                         psFree(phu);
    184                         return NULL;
    185                     }
    186                 } else {
    187                     pmConfigValidateCameraFormat (file->format, phu);
    188                 }
    189                 pmFPAview *thisView = pmFPAAddSourceFromHeader (file->fpa, phu, file->format);
    190                 psFree (thisView);
    191                 psFree (phu);
    192                 // XXX we can check the output view to be sure it corresponds to our current view
    193             }
    194         }
    195         if (file->mode == PM_FPA_MODE_WRITE) {
    196             switch (file->fileLevel) {
    197             case PM_FPA_LEVEL_FPA:
    198                 pmFPAWrite (file->fpa, file->fits, NULL, true, false);
    199                 break;
    200             case PM_FPA_LEVEL_CHIP: {
    201                     pmChip *chip = pmFPAviewThisChip(view, file->fpa);
    202                     pmChipWrite (chip, file->fits, NULL, true, false);
    203                     break;
    204                 }
    205             case PM_FPA_LEVEL_CELL: {
    206                     pmCell *cell = pmFPAviewThisCell(view, file->fpa);
    207                     pmCellWrite(cell, file->fits, NULL, true);
    208                     break;
    209                 }
    210             default:
    211                 psAbort ("pmFPAfileIO", "fileLevel not correctly set");
    212                 break;
    213             }
    214         }
    215         break;
    216 
     229        if (!openImage(file, view, mode, config)) {
     230            psError(PS_ERR_UNKNOWN, false, "Unable to open image %s (type %d)\n", file->filename, file->type);
     231            return false;
     232        }
     233        break;
    217234        // open the FITS object files
    218235    case PM_FPA_FILE_CMF:
     
    294311    switch (file->type) {
    295312    case PM_FPA_FILE_IMAGE:
    296         if (pmFPAviewReadFitsImage (view, file)) {
    297             psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
    298         } else {
     313        if (!pmFPAviewReadFitsImage (view, file)) {
    299314            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
    300315            return false;
    301316        }
     317        psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
     318        break;
     319    case PM_FPA_FILE_FRINGE:
     320        if (!pmFPAviewReadFitsImage (view, file)) {
     321            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
     322            return false;
     323        }
     324        psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
     325
     326        if (!pmFPAviewReadFitsTable(view, file, "FRINGE")) {
     327            psError(PS_ERR_UNKNOWN, false, "Unable to read fringe data from %s.\n", file->filename);
     328            return false;
     329        }
     330
    302331        break;
    303332
     
    365394        }
    366395        break;
     396    case PM_FPA_FILE_FRINGE:
     397        if (!pmFPAviewFreeFitsTable(view, file, "FRINGE")) {
     398            psError(PS_ERR_UNKNOWN, false, "Unable to free fringe data.\n");
     399            return false;
     400        }
     401        break;
    367402
    368403    case PM_FPA_FILE_SX:
     
    436471        pmFPAviewWriteFitsImage (view, file);
    437472        psTrace ("pmFPAfile", 5, "wrote image %s (fpa: %p)\n", file->filename, file->fpa);
     473        break;
     474    case PM_FPA_FILE_FRINGE:
     475        pmFPAviewWriteFitsImage (view, file);
     476        psTrace ("pmFPAfile", 5, "wrote table %s (fpa: %p)\n", file->filename, file->fpa);
     477        pmFPAviewWriteFitsTable(view, file, "FRINGE");
     478        psTrace ("pmFPAfile", 5, "wrote fringe table %s (fpa: %p)\n", file->filename, file->fpa);
    438479        break;
    439480
     
    513554    switch (file->type) {
    514555    case PM_FPA_FILE_IMAGE:
    515 
     556    case PM_FPA_FILE_FRINGE:
    516557        // create FPA structure component based on view
    517558        pmFPAAddSourceFromView (file->fpa, view, file->format);
     
    567608        // check the FITS types
    568609    case PM_FPA_FILE_IMAGE:
     610    case PM_FPA_FILE_FRINGE:
    569611    case PM_FPA_FILE_CMF:
    570612        psFitsClose (file->fits);
Note: See TracChangeset for help on using the changeset viewer.