IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7717


Ignore:
Timestamp:
Jun 27, 2006, 7:12:19 PM (20 years ago)
Author:
Paul Price
Message:

Changes to pmHDU and pmFPAWrite to (hopefully) fix for the last time
this horrible problem of when we write that annoying blank PHU. When
we want to write something out, there are four usage cases for the
pm{FPA,Chip,Cell}Write functions:

(1) Write the blank PHU only: blank=true, recurse=false;
(2) Write an image HDU only: blank=false, recurse=false;
(3) Write an entire file: blank=true, recurse=true; and
(4) Write only image HDUs within the file: blank=false, recurse=true.

So here, the "blank" boolean indicates whether we should write a
"blank" HDU (which consists of a header only, i.e., no pixels) when we
come across it. "recurse" is self-explanatory.

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

Legend:

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

    r7643 r7717  
    522522    // Case 1: PHU=FPA and EXTENSIONS=NONE.  We need to parse the single list of chip:cell:cellType entries.
    523523    if (strcasecmp(phuType, "FPA") == 0 && strcasecmp(extType, "NONE") == 0) {
     524        phdu->blankPHU = false;
    524525        const char *contents = psMetadataLookupStr(&mdok, format, "CONTENTS"); // The contents of the file
    525526        if (!mdok || !contents || strlen(contents) == 0) {
     
    529530            return NULL;
    530531        }
    531 
    532532        if (processContents(fpa, NULL, NULL, phdu, PM_FPA_LEVEL_FPA, contents, format) < 0) {
    533533            psError(PS_ERR_IO, false, "Error setting CONTENTS");
     
    563563    // chip/cell directly from that.
    564564    if (strcasecmp(extType, "NONE") == 0) {
     565        phdu->blankPHU = false;
    565566        pmChip *chip = NULL;        // The chip of interest
    566567        pmCell *cell = NULL;        // The cell of interest
     
    650651    // Case 3: EXTENSIONS=CHIP or EXTENSIONS=CELL.  We have extensions that we iterate through.  The CONTENTS
    651652    // is a list of extensions.
     653    phdu->blankPHU = true;
    652654    pmChip *chip = NULL;                // The chip of interest
    653655    pmCell *cell = NULL;                // The cell of interest
  • trunk/psModules/src/camera/pmFPACopy.c

    r7624 r7717  
    3232}
    3333
    34 static pmHDU *findPHU(const pmCell *cell// The cell for which to find the PHU
    35                      )
     34static pmHDU *findBlankPHU(const pmCell *cell// The cell for which to find the PHU
     35                          )
    3636{
    3737    assert(cell);
    3838
    39     if (cell->hdu && cell->hdu->phu) {
     39    if (cell->hdu && cell->hdu->blankPHU) {
    4040        return cell->hdu;
    4141    }
    4242    pmChip *chip = cell->parent;        // The parent chip
    43     if (chip->hdu && chip->hdu->phu) {
     43    if (chip->hdu && chip->hdu->blankPHU) {
    4444        return chip->hdu;
    4545    }
    4646    pmFPA *fpa = chip->parent;  // The parent FPA
    47     if (fpa->hdu && fpa->hdu->phu) {
     47    if (fpa->hdu && fpa->hdu->blankPHU) {
    4848        return fpa->hdu;
    4949    }
     
    261261    }
    262262    // Copy the PHU over as well, if required
    263     pmHDU *targetPHU = findPHU(target); // The target PHU
     263    pmHDU *targetPHU = findBlankPHU(target); // The target PHU
    264264    if (targetPHU && targetPHU != targetHDU && !targetPHU->header) {
    265         pmHDU *sourcePHU = findPHU(source); // The source PHU
     265        pmHDU *sourcePHU = findBlankPHU(source); // The source PHU
    266266        targetPHU->header = psMetadataCopy(targetPHU->header, sourcePHU->header);
    267267    }
  • trunk/psModules/src/camera/pmFPAWrite.c

    r7618 r7717  
    11#include <stdio.h>
    22#include <strings.h>
    3 #include "pslib.h"
     3#include <pslib.h>
    44
    55#include "pmFPA.h"
     
    7373
    7474    // We can simply update an existing HDU
    75     if (((hdu->phu || strcasecmp(hdu->extname, "PHU") == 0) && !psFitsMoveExtNum(fits, 0, false)) ||
    76             !psFitsMoveExtName(fits, hdu->extname)) {
    77         psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname);
     75    if (hdu->blankPHU && !psFitsMoveExtNum(fits, 0, false)) {
     76        psError(PS_ERR_IO, false, "Unable to move to PHU\n");
    7877        return false;
    7978    }
     
    8786                 psFits *fits,          // FITS file to which to write
    8887                 psDB *db,              // Database handle for "concepts" update
    89                  bool pixels            // Write the pixels, or only the PHU header?
     88                 bool blank             // Write a blank PHU?
    9089                )
    9190{
     
    9897    }
    9998
    100     bool success = true;                // Success of writing
    101     if ((!pixels && hdu->phu && !hdu->images) || // Data-less PHU
    102             (pixels && (hdu->images || (!hdu->images && pmHDUGenerateForCell(cell) && hdu->images)))) { // Data
    103         success &= pmConceptsWriteCell(cell, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA |
    104                                        PM_CONCEPT_SOURCE_DEFAULTS, false, NULL);
    105         success &= pmHDUWrite(hdu, fits);
    106     }
    107 
    108     if (!success) {
    109         psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
    110         return false;
    111     }
    112 
     99    // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not
     100    // generate the HDU, but only copies the structure.
     101    if (!hdu->blankPHU && !hdu->images) {
     102        if (!pmHDUGenerateForCell(cell) || !hdu->images) {
     103            psAbort(__func__, "Unable to generate HDU for cell --- likely programming error.\n");
     104        }
     105    }
     106
     107    // We only write out a blank PHU if it's specifically requested.
     108    bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank PHU?
     109    bool writeImage = !hdu->blankPHU && hdu->images; // Write an image?
     110
     111    if (writeBlank || writeImage) {
     112        pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA |
     113                                 PM_CONCEPT_SOURCE_DEFAULTS;
     114        if (!pmConceptsWriteCell(cell, source, false, NULL)) {
     115            psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n");
     116            return false;
     117        }
     118        if (!pmHDUWrite(hdu, fits)) {
     119            psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n");
     120            return false;
     121        }
     122    }
    113123    // No lower levels to which to recurse
    114124
    115     return success;
     125    return true;
    116126}
    117127
     
    120130                 psFits *fits,          // FITS file to which to write
    121131                 psDB *db,              // Database handle for "concepts" update
    122                  bool pixels,           // Write the pixels, or only the PHU header?
     132                 bool blank,            // Write a blank PHU?
    123133                 bool recurse           // Recurse to lower levels?
    124134                )
     
    129139    pmHDU *hdu = chip->hdu;             // The HDU
    130140
    131     // XXXX this makes no sense to me at all:
    132     // an image made up of only cells would not have
    133     // any entries at this level, and could not be written out!!!
    134 
    135     // if we have data at this level, try to write it out
     141    // If we have data at this level, try to write it out
    136142    if (hdu) {
    137         // generate the HDU if needed
    138         if (pixels && !hdu->images) {
    139             if (!pmHDUGenerateForChip(chip))
    140                 psAbort ("pmFPAWrite", "error generating HDU");
    141             if (!hdu->images)
    142                 psAbort ("pmChipWrite", "programming error: failure generating HDU");
    143         }
    144 
    145         // chip->hdu represents a blank data segment
    146         bool blankSegment = !pixels && hdu->phu && !hdu->images;
    147 
    148         // chip->hdu represents an image data segment
    149         bool imageSegment = pixels && hdu->images;
    150 
    151         if (blankSegment || imageSegment) {
    152             pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS;
     143        // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not
     144        // generate the HDU, but only copies the structure.
     145        if (!blank && !hdu->blankPHU && !hdu->images) {
     146            if (!pmHDUGenerateForChip(chip) || !hdu->images) {
     147                psAbort (__func__, "Unable to generate HDU for chip --- likely programming error.\n");
     148            }
     149        }
     150
     151        // We only write out a blank PHU if it's specifically requested.
     152        bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank HDU?
     153        bool writeImage = !hdu->blankPHU && hdu->images; // Write an image?
     154
     155        if (writeBlank || writeImage) {
     156            pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA |
     157                                     PM_CONCEPT_SOURCE_DEFAULTS;
    153158            if (!pmConceptsWriteChip(chip, source, false, true, NULL)) {
    154                 psError(PS_ERR_IO, false, "Unable to write Concepts for Chip.\n");
     159                psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n");
    155160                return false;
    156161            }
    157162            if (!pmHDUWrite(hdu, fits)) {
    158                 psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
    159                 return false;
    160             }
    161         }
    162     }
    163 
    164     // XXX are we allowed to recurse if we have already written data at this level?
     163                psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n");
     164                return false;
     165            }
     166        }
     167    }
     168
     169    // Recurse to lower level if specifically requested.
    165170    if (recurse) {
    166171        psArray *cells = chip->cells;       // Array of cells
    167172        for (int i = 0; i < cells->n; i++) {
    168173            pmCell *cell = cells->data[i];  // The cell of interest
    169             if (!pmCellWrite(cell, fits, db, pixels)) {
     174            if (!pmCellWrite(cell, fits, db, blank)) {
    170175                psError(PS_ERR_IO, false, "Unable to write Chip.\n");
    171176                return false;
     
    182187                psFits *fits,           // FITS file to which to write
    183188                psDB *db,               // Database handle for "concepts" update
    184                 bool pixels,            // Write the pixels, or only the PHU header?
     189                bool blank,             // Write a blank PHU?
    185190                bool recurse            // Recurse to lower levels?
    186191               )
     
    191196    pmHDU *hdu = fpa->hdu;              // The HDU
    192197
    193     // XXXX this makes no sense to me at all:
    194     // an image made up of only chips or cells would not have
    195     // any entries at this level, and could not be written out!!!
    196 
    197     // if we have data at this level, try to write it out
     198    // If we have data at this level, try to write it out
    198199    if (hdu) {
    199 
    200         // XXXXXXXXX this was extremely unclear.  the conditions MUST be written more explicitly
    201         // so someone else has a chance to understand it without massive reverse engineering!!!!
    202 
    203         // generate the HDU if needed
    204         if (pixels && !hdu->images) {
    205             if (!pmHDUGenerateForFPA(fpa))
    206                 psAbort ("pmFPAWrite", "error generating HDU");
    207             if (!hdu->images)
    208                 psAbort ("pmFPAWrite", "programming error: failure generating HDU");
    209         }
    210 
    211         // fpa->hdu represents a blank data segment
    212         bool blankSegment = !pixels && hdu->phu && !hdu->images;
    213 
    214         // fpa->hdu represents an image data segment
    215         bool imageSegment = pixels && hdu->images;
    216 
    217         // if neither of these conditions is true, we probably need to recurse down to the next level and try again
    218         if (blankSegment || imageSegment) {
    219             pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS;
     200        // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not
     201        // generate the HDU, but only copies the structure.
     202        if (!blank && !hdu->blankPHU && !hdu->images) {
     203            if (!pmHDUGenerateForFPA(fpa)) {
     204                psAbort("pmFPAWrite", "error generating HDU");
     205            }
     206            if (!hdu->images) {
     207                psAbort("pmFPAWrite", "programming error: failure generating HDU");
     208            }
     209        }
     210
     211        // We only write out a blank PHU if it's specifically requested.
     212        bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank PHU?
     213        bool writeImage = !hdu->blankPHU && hdu->images; // Write an image?
     214
     215        if (writeBlank || writeImage) {
     216            pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA |
     217                                     PM_CONCEPT_SOURCE_DEFAULTS;
    220218            if (!pmConceptsWriteFPA(fpa, source, true, NULL)) {
    221                 psError(PS_ERR_IO, false, "Unable to write Concepts for FPA.\n");
     219                psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n");
    222220                return false;
    223221            }
     
    229227    }
    230228
    231     // XXX what are the rules on when we allow recursion?
     229    // Recurse to lower levels if requested
    232230    if (recurse) {
    233231        psArray *chips = fpa->chips;        // Array of chips
    234232        for (int i = 0; i < chips->n; i++) {
    235233            pmChip *chip = chips->data[i];  // The chip of interest
    236             if (!pmChipWrite(chip, fits, db, pixels, true)) {
     234            if (!pmChipWrite(chip, fits, db, blank, true)) {
    237235                psError(PS_ERR_IO, false, "Unable to write FPA.\n");
    238236                return false;
     
    242240
    243241    return true;
    244 
    245     // summary:
    246     // pmHDUWrite writes out the PHU header or the header + pixels
    247     // we need to generate the HDU (why?)
    248     // we call pmHDUWrite if:
    249     // - the fpa->hdu represents a blank data segment (header w/ no pixels)
    250     // - the fpa->hdu represents an image data segment (header w/ pixels)
    251 }
     242}
  • trunk/psModules/src/camera/pmFPAview.c

    r7589 r7717  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-17 01:50:43 $
     5 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-28 05:12:19 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    253253    if (view->chip < 0) {
    254254        hdu = pmHDUFromFPA (fpa);
    255         if (hdu->phu)
     255        if (hdu->blankPHU)
    256256            return hdu;
    257257        return NULL;
     
    260260        chip = pmFPAviewThisChip (view, fpa);
    261261        hdu  = pmHDUFromChip (chip);
    262         if (hdu->phu)
     262        if (hdu->blankPHU)
    263263            return hdu;
    264264        new.chip = -1;
     
    269269        cell = pmFPAviewThisCell (view, fpa);
    270270        hdu  = pmHDUFromCell (cell);
    271         if (hdu->phu)
     271        if (hdu->blankPHU)
    272272            return hdu;
    273273        new.cell = -1;
  • trunk/psModules/src/camera/pmHDU.c

    r7604 r7717  
    1515{
    1616    // Deal with the PHU case
    17     if (strcasecmp(hdu->extname, "PHU") == 0 || hdu->phu) {
    18         if (! psFitsMoveExtNum(fits, 0, false)) {
     17    if (hdu->blankPHU) {
     18        if (!psFitsMoveExtNum(fits, 0, false)) {
    1919            psError(PS_ERR_IO, false, "Unable to move to primary header!\n");
    2020            return false;
    2121        }
    22         hdu->phu = true;
    23         return true;
    24     }
    25 
    26     if (! psFitsMoveExtName(fits, hdu->extname)) {
     22        return true;
     23    }
     24
     25    if (!psFitsMoveExtName(fits, hdu->extname)) {
    2726        psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname);
    2827        return false;
    29     }
    30     // Now, just in case for some reason the PHU has an extension name that we've moved to....
    31     if (psFitsGetExtNum(fits) == 0) {
    32         hdu->phu = true;
    33     } else {
    34         hdu->phu = false;
    3528    }
    3629
     
    6154
    6255    if (!extname || strlen(extname) == 0) {
    63         hdu->phu = true;
    64         hdu->extname = psStringCopy("PHU");
     56        hdu->blankPHU = true;
     57        hdu->extname = NULL;
    6558    } else {
    66         if (strcasecmp(extname, "PHU") == 0) {
    67             hdu->phu = true;
    68         } else {
    69             hdu->phu = false;
    70         }
     59        hdu->blankPHU = false;
    7160        hdu->extname = psStringCopy(extname);
    7261    }
  • trunk/psModules/src/camera/pmHDU.h

    r7017 r7717  
    66{
    77    psString extname;                   // The extension name
    8     bool phu;                           // Is this the FITS Primary Header Unit
     8    bool blankPHU;                      // Is this a blank FITS Primary Header Unit, i.e., no data?
    99    psMetadata *format;                 // The camera format
    1010    psMetadata *header;                 // The FITS header, or NULL if primary for FITS; or section info
  • trunk/psModules/src/camera/pmHDUUtils.c

    r7609 r7717  
    9494    PS_ASSERT_PTR_NON_NULL(hdu,);
    9595
    96     if (hdu->phu) {
    97         psTrace(__func__, level, "HDU: %s (PHU)\n", hdu->extname);
     96    if (hdu->blankPHU) {
     97        psTrace(__func__, level, "HDU: (PHU)\n");
    9898    } else {
    9999        psTrace(__func__, level, "HDU: %s\n", hdu->extname);
Note: See TracChangeset for help on using the changeset viewer.