IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 16, 2007, 4:34:39 PM (19 years ago)
Author:
Paul Price
Message:

Cleaning up pmFPAfileSuitableFPA a bit more, so that the sense is more evident.

File:
1 edited

Legend:

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

    r11801 r11864  
    2828    }
    2929
    30     // Need to change format
    31     pmFPA *fpa = pmFPAConstruct(file->camera);
     30    // May need to change format
     31    pmFPALevel level = pmFPAviewLevel(view); // Level for the view
     32    if (level == PM_FPA_LEVEL_NONE || level == PM_FPA_LEVEL_READOUT) {
     33        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     34                "This function shouldn't be called at the readout (or unknown) level.");
     35        return NULL;
     36    }
     37
     38    // Does the HDU of interest conform to the desired format?
     39    pmHDU *hdu = pmFPAviewThisHDU(view, file->fpa); // The HDU of interest
     40    if (hdu && hdu->format == file->format) {
     41        // No work required
     42        return psMemIncrRefCounter(file->fpa);
     43    }
     44
     45    // Otherwise, we have to generate a copy with the correct format
    3246
    3347    pmFPAview *phuView = pmFPAviewAlloc(0); // View corresponding to the PHU
     
    3549    pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level for the PHU
    3650    switch (phuLevel) {
    37     case PM_FPA_LEVEL_FPA:
     51      case PM_FPA_LEVEL_FPA:
    3852        phuView->chip = -1;
    3953        // Flow through
    40     case PM_FPA_LEVEL_CHIP:
     54      case PM_FPA_LEVEL_CHIP:
    4155        phuView->cell = -1;
    4256        // Flow through
    43     case PM_FPA_LEVEL_CELL:
     57      case PM_FPA_LEVEL_CELL:
    4458        phuView->readout = -1;
    4559        break;
    46     case PM_FPA_LEVEL_READOUT:
    47     case PM_FPA_LEVEL_NONE:
    48     default:
     60      case PM_FPA_LEVEL_READOUT:
     61      case PM_FPA_LEVEL_NONE:
     62      default:
    4963        psAbort("Should never get here: bad phu level.\n");
    5064    }
     
    5771    const char *fpaname = psMetadataLookupStr(&mdok, nameSource->concepts, "FPA.NAME"); // Name of FPA
    5872
    59     if (!pmFPAAddSourceFromView(fpa, fpaname, phuView, file->format)) {
     73    pmFPA *copy = pmFPAConstruct(file->camera);  // FPA to return
     74    if (!pmFPAAddSourceFromView(copy, fpaname, phuView, file->format)) {
    6075        psError(PS_ERR_UNKNOWN, false, "Unable to insert HDU into FPA for writing.\n");
    61         psFree(fpa);
     76        psFree(copy);
    6277        psFree(phuView);
    6378        return false;
     
    6580    psFree(phuView);
    6681
    67 
    68     switch (phuLevel) {
    69     case PM_FPA_LEVEL_FPA:
    70         if (!pmFPACopy(fpa, file->fpa)) {
     82    switch (level) {
     83      case PM_FPA_LEVEL_FPA:
     84        if (!pmFPACopy(copy, file->fpa)) {
    7185            psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for format conversion.\n");
    7286            return NULL;
    7387        }
    74         return fpa;
    75     case PM_FPA_LEVEL_CHIP: {
    76             pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest
    77             pmChip *srcChip = pmFPAviewThisChip(view, file->fpa); // Source chip
    78             if (!pmChipCopy(chip, srcChip)) {
    79                 psError(PS_ERR_UNKNOWN, false, "Unable to copy chip for format conversion.\n");
    80                 return false;
    81             }
    82             return fpa;
    83         }
    84     case PM_FPA_LEVEL_CELL: {
    85             pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest
    86             pmCell *srcCell = pmFPAviewThisCell(view, file->fpa); // Source cell
    87             if (!pmCellCopy(cell, srcCell)) {
    88                 psError(PS_ERR_UNKNOWN, false, "Unable to copy cell for format conversion.\n");
    89                 return false;
    90             }
    91             return fpa;
    92         }
    93     case PM_FPA_LEVEL_READOUT:
    94     case PM_FPA_LEVEL_NONE:
    95     default:
     88        return copy;
     89      case PM_FPA_LEVEL_CHIP: {
     90          pmChip *chip = pmFPAviewThisChip(view, copy); // Chip of interest
     91          pmChip *srcChip = pmFPAviewThisChip(view, file->fpa); // Source chip
     92          if (!pmChipCopy(chip, srcChip)) {
     93              psError(PS_ERR_UNKNOWN, false, "Unable to copy chip for format conversion.\n");
     94              return false;
     95          }
     96          return copy;
     97      }
     98      case PM_FPA_LEVEL_CELL: {
     99          pmCell *cell = pmFPAviewThisCell(view, copy); // Cell of interest
     100          pmCell *srcCell = pmFPAviewThisCell(view, file->fpa); // Source cell
     101          if (!pmCellCopy(cell, srcCell)) {
     102              psError(PS_ERR_UNKNOWN, false, "Unable to copy cell for format conversion.\n");
     103              return false;
     104          }
     105          return copy;
     106      }
     107      case PM_FPA_LEVEL_READOUT:
     108      case PM_FPA_LEVEL_NONE:
     109      default:
    96110        psAbort("Should never get here: bad phu level.\n");
    97111    }
     112
    98113    return NULL;
     114
    99115}
    100116
Note: See TracChangeset for help on using the changeset viewer.