IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2007, 1:00:15 PM (19 years ago)
Author:
Paul Price
Message:

Was getting an abort when opening a file given from the detrend database. Added an 'out' for when the fileLevel is NONE. Not entirely happy with this solution --- maybe it will break something else?

File:
1 edited

Legend:

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

    r12603 r12687  
    133133    // do we need to open this file?
    134134    if (level >= file->fileLevel) {
    135         // we are allowed to open a file at a level which is not the fileLevel, but we need to
    136         // supply a view at the fileLevel for the file lookup functions below
    137         pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view);
    138         if (!pmFPAfileOpen (file, fileView, config)) {
     135        // we are allowed to open a file at a level which is not the fileLevel, but we need to
     136        // supply a view at the fileLevel for the file lookup functions below
     137        pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view);
     138        if (!pmFPAfileOpen (file, fileView, config)) {
    139139            psError(PS_ERR_IO, false, "failed to open file %s (%s)", file->filename, file->name);
    140             psFree (fileView);
    141             return false;
    142         }
    143         psFree (fileView);
     140            psFree (fileView);
     141            return false;
     142        }
     143        psFree (fileView);
    144144    }
    145145
    146146    // We need to read it --- double-check it's open!
    147147    if (file->state == PM_FPA_STATE_CLOSED) {
    148         psError(PS_ERR_IO, false, "failed to open file %s when attempting to read", file->name);
    149         return false;
     148        psError(PS_ERR_IO, false, "failed to open file %s when attempting to read", file->name);
     149        return false;
    150150    }
    151151
     
    154154    switch (file->type) {
    155155      case PM_FPA_FILE_IMAGE:
    156         status = pmFPAviewReadFitsImage(view, file);
    157         break;
     156        status = pmFPAviewReadFitsImage(view, file);
     157        break;
    158158      case PM_FPA_FILE_MASK:
    159         status = pmFPAviewReadFitsMask(view, file);
     159        status = pmFPAviewReadFitsMask(view, file);
    160160        break;
    161161      case PM_FPA_FILE_WEIGHT:
    162         status = pmFPAviewReadFitsWeight(view, file);
     162        status = pmFPAviewReadFitsWeight(view, file);
    163163        break;
    164164      case PM_FPA_FILE_HEADER:
    165         status = pmFPAviewReadFitsHeaderSet(view, file);
     165        status = pmFPAviewReadFitsHeaderSet(view, file);
    166166        break;
    167167      case PM_FPA_FILE_FRINGE:
    168         status = pmFPAviewReadFitsImage (view, file);
    169         if (status) {
    170             if (!pmFPAviewReadFitsTable(view, file, "FRINGE")) {
    171                 psError(PS_ERR_UNKNOWN, false, "Unable to read fringe data from %s.\n", file->filename);
    172                 return false;
    173             }
    174         }
    175         break;
     168        status = pmFPAviewReadFitsImage (view, file);
     169        if (status) {
     170            if (!pmFPAviewReadFitsTable(view, file, "FRINGE")) {
     171                psError(PS_ERR_UNKNOWN, false, "Unable to read fringe data from %s.\n", file->filename);
     172                return false;
     173            }
     174        }
     175        break;
    176176      case PM_FPA_FILE_SX:
    177177      case PM_FPA_FILE_RAW:
     
    182182        break;
    183183      case PM_FPA_FILE_PSF:
    184         status = pmFPAviewReadPSFmodel (view, file, config);
     184        status = pmFPAviewReadPSFmodel (view, file, config);
    185185        break;
    186186      case PM_FPA_FILE_JPEG:
     
    192192    }
    193193    if (!status) {
    194         psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name);
    195         return false;
     194        psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name);
     195        return false;
    196196    }
    197197    psTrace ("psModules.camera", 5, "read %s (%s)\n", file->filename, file->name);
     
    318318    // XXX do we need to test mosaicLevel?
    319319    if (level >= file->fileLevel) {
    320         // we are allowed to open a file at a level which is not the fileLevel, but
    321         // we need to supply view at the fileLevel for the file lookup functions below
    322         pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view);
     320        // we are allowed to open a file at a level which is not the fileLevel, but
     321        // we need to supply view at the fileLevel for the file lookup functions below
     322        pmFPAview *fileView = pmFPAviewForLevel (file->fileLevel, view);
    323323        if (!pmFPAfileOpen (file, fileView, config)) {
    324324            psError(PS_ERR_IO, false, "failed to open %s (%s)", file->filename, file->name);
    325             psFree (fileView);
    326             return false;
    327         }
    328         psFree (fileView);
     325            psFree (fileView);
     326            return false;
     327        }
     328        psFree (fileView);
    329329    }
    330330
     
    344344        break;
    345345      case PM_FPA_FILE_MASK:
    346         status = pmFPAviewWriteFitsMask(view, file, config);
     346        status = pmFPAviewWriteFitsMask(view, file, config);
    347347        break;
    348348      case PM_FPA_FILE_WEIGHT:
    349         status = pmFPAviewWriteFitsWeight(view, file, config);
     349        status = pmFPAviewWriteFitsWeight(view, file, config);
    350350        break;
    351351      case PM_FPA_FILE_HEADER:
    352         psAbort ("no HEADER write functions defined");
     352        psAbort ("no HEADER write functions defined");
    353353        break;
    354354      case PM_FPA_FILE_FRINGE:
    355         status = pmFPAviewWriteFitsImage (view, file, config);
    356         if (status) {
    357             if (!pmFPAviewWriteFitsTable(view, file, "FRINGE")) {
    358                 psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename);
    359                 return false;
    360             }
    361         }
     355        status = pmFPAviewWriteFitsImage (view, file, config);
     356        if (status) {
     357            if (!pmFPAviewWriteFitsTable(view, file, "FRINGE")) {
     358                psError(PS_ERR_UNKNOWN, false, "Unable to write fringe data from %s.\n", file->filename);
     359                return false;
     360            }
     361        }
    362362        break;
    363363      case PM_FPA_FILE_SX:
     
    386386    }
    387387    if (!status) {
    388         psError(PS_ERR_UNKNOWN, false, "failed to write %s (%s)\n", file->filename, file->name);
    389         return false;
     388        psError(PS_ERR_UNKNOWN, false, "failed to write %s (%s)\n", file->filename, file->name);
     389        return false;
    390390    }
    391391    psTrace ("psModules.camera", 5, "wrote %s (fpa: %p)\n", file->filename, file->fpa);
     
    452452    }
    453453    if (!status) {
    454         psError(PS_ERR_UNKNOWN, false, "failed to close %s (%s)\n", file->filename, file->name);
    455         return false;
     454        psError(PS_ERR_UNKNOWN, false, "failed to close %s (%s)\n", file->filename, file->name);
     455        return false;
    456456    }
    457457    return true;
     
    488488      case PM_FPA_FILE_HEADER:
    489489      case PM_FPA_FILE_FRINGE:
    490         status = pmFPAviewFreeData(view, file);
     490        status = pmFPAviewFreeData(view, file);
    491491        break;
    492492      case PM_FPA_FILE_SX:
     
    495495      case PM_FPA_FILE_CMP:
    496496      case PM_FPA_FILE_CMF:
    497         psTrace ("psModules.camera", 5, "NOT freeing %s (%s) : save for further analysis\n", file->filename, file->name);
     497        psTrace ("psModules.camera", 5, "NOT freeing %s (%s) : save for further analysis\n", file->filename, file->name);
    498498        break;
    499499      case PM_FPA_FILE_PSF:
    500500      case PM_FPA_FILE_JPEG:
    501501      case PM_FPA_FILE_KAPA:
    502         psTrace ("psModules.camera", 5, "nothing to free for %s (%s)\n", file->filename, file->name);
     502        psTrace ("psModules.camera", 5, "nothing to free for %s (%s)\n", file->filename, file->name);
    503503        break;
    504504      default:
     
    507507    }
    508508    if (!status) {
    509         psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name);
    510         return false;
     509        psError(PS_ERR_UNKNOWN, false, "failed to read %s (%s)\n", file->filename, file->name);
     510        return false;
    511511    }
    512512    psTrace ("psModules.camera", 5, "freed %s (%s)\n", file->filename, file->name);
     
    558558    }
    559559
    560     // indirect filenames: these come from a list on the command line or elsewhere 
     560    // indirect filenames: these come from a list on the command line or elsewhere
    561561    if (!strcasecmp (file->filename, "@FILES")) {
    562562        char *filesrc = pmFPAfileNameFromRule (file->filesrc, file, view);
     
    626626
    627627    switch (file->type) {
    628         // open the FITS types:
     628        // open the FITS types:
    629629      case PM_FPA_FILE_IMAGE:
    630630      case PM_FPA_FILE_MASK:
     
    641641        file->state = PM_FPA_STATE_OPEN;
    642642
    643         // if needed, set the optional EXTWORD field based on the camera value
    644         if (config && config->format) {
    645             psMetadata *fileMenu = psMetadataLookupMetadata (NULL, config->format, "FILE");
    646             if (!fileMenu) {
    647                 psError (PS_ERR_IO, true, "FILE METADATA missing from camera format %s\n", config->formatName);
    648                 return false;
    649             }
    650             char *extword = psMetadataLookupStr (&status, fileMenu, "EXTWORD");
    651             if (status) {
    652                 psFitsSetExtnameWord (file->fits, extword);
    653             }
    654         }
    655 
    656         // In some cases, we need to read the PHU after we've opened the file.  This happens for
    657         // the images supplied by the detrend database, which are only identified here (above).
    658         if (!pmFPAfileReadPHU (file, view, config)) {
    659             psError (PS_ERR_IO, true, "error reading PHU for %s (%s)\n", file->filename, file->name);
    660             return false;
    661         }
    662         break;
    663 
    664         // defer opening TEXT types:
     643        // if needed, set the optional EXTWORD field based on the camera value
     644        if (config && config->format) {
     645            psMetadata *fileMenu = psMetadataLookupMetadata (NULL, config->format, "FILE");
     646            if (!fileMenu) {
     647                psError (PS_ERR_IO, true, "FILE METADATA missing from camera format %s\n", config->formatName);
     648                return false;
     649            }
     650            char *extword = psMetadataLookupStr (&status, fileMenu, "EXTWORD");
     651            if (status) {
     652                psFitsSetExtnameWord (file->fits, extword);
     653            }
     654        }
     655
     656        // In some cases, we need to read the PHU after we've opened the file.  This happens for
     657        // the images supplied by the detrend database, which are only identified here (above).
     658        if (!pmFPAfileReadPHU (file, view, config)) {
     659            psError (PS_ERR_IO, true, "error reading PHU for %s (%s)\n", file->filename, file->name);
     660            return false;
     661        }
     662        break;
     663
     664        // defer opening TEXT types:
    665665      case PM_FPA_FILE_SX:
    666666      case PM_FPA_FILE_OBJ:
     
    692692    switch (file->fileLevel) {
    693693      case PM_FPA_LEVEL_FPA:
    694         if (file->fpa->hdu) return true;
    695         break;
     694        if (file->fpa->hdu) return true;
     695        break;
    696696      case PM_FPA_LEVEL_CHIP: {
    697           pmChip *chip = pmFPAviewThisChip(view, file->fpa);
    698           if (!chip) psAbort ("inconsistent file/fpa: fileLevel is CHIP, view is FPA");
    699           if (chip->hdu) return true;
    700           break;
     697          pmChip *chip = pmFPAviewThisChip(view, file->fpa);
     698          if (!chip) psAbort ("inconsistent file/fpa: fileLevel is CHIP, view is FPA");
     699          if (chip->hdu) return true;
     700          break;
    701701      }
    702702      case PM_FPA_LEVEL_CELL: {
    703           pmCell *cell = pmFPAviewThisCell(view, file->fpa);
    704           if (!cell) psAbort ("inconsistent file/fpa: fileLevel is CELL, view is FPA");
    705           if (cell->hdu) return true;
    706           break;
     703          pmCell *cell = pmFPAviewThisCell(view, file->fpa);
     704          if (!cell) psAbort ("inconsistent file/fpa: fileLevel is CELL, view is FPA");
     705          if (cell->hdu) return true;
     706          break;
    707707      }
     708      case PM_FPA_LEVEL_NONE:
     709        // Might get here immediately after opening a file selected from the detrend database.
     710        break;
    708711      default:
    709         psAbort("fileLevel not correctly set");
    710         break;
     712        psAbort("fileLevel not correctly set");
     713        break;
    711714    }
    712715
     
    714717    psMetadata *phu = psFitsReadHeader (NULL, file->fits);
    715718    if (!file->format) {
    716         file->format = pmConfigCameraFormatFromHeader (config, phu);
    717         if (!file->format) {
    718             psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename);
    719             psFree(phu);
    720             return false;
    721         }
     719        file->format = pmConfigCameraFormatFromHeader (config, phu);
     720        if (!file->format) {
     721            psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename);
     722            psFree(phu);
     723            return false;
     724        }
    722725    } else {
    723         bool valid;
    724         if (!pmConfigValidateCameraFormat (&valid, file->format, phu)) {
    725             psError (PS_ERR_UNKNOWN, false, "Error in camera configuration\n");
    726             psFree (phu);
    727             return false;
    728         }
    729         if (!valid) {
    730             psError(PS_ERR_IO, false, "file %s is not from the required camera", file->filename);
    731             psFree (phu);
    732             return false;
    733         }
     726        bool valid;
     727        if (!pmConfigValidateCameraFormat (&valid, file->format, phu)) {
     728            psError (PS_ERR_UNKNOWN, false, "Error in camera configuration\n");
     729            psFree (phu);
     730            return false;
     731        }
     732        if (!valid) {
     733            psError(PS_ERR_IO, false, "file %s is not from the required camera", file->filename);
     734            psFree (phu);
     735            return false;
     736        }
    734737    }
    735738    pmFPAview *thisView = pmFPAAddSourceFromHeader (file->fpa, phu, file->format);
     
    740743}
    741744
    742 // XXX this function is only called from pmFPAfileWrite 
     745// XXX this function is only called from pmFPAfileWrite
    743746bool pmFPAfileWritePHU(pmFPAfile *file, const pmFPAview *view, pmConfig *config)
    744747{
     
    752755      case PM_FPA_FILE_WEIGHT:
    753756      case PM_FPA_FILE_FRINGE:
    754         if (file->mode == PM_FPA_MODE_WRITE) {
    755             // Want to write out any potential blank
    756             // XXX why do we need to construct a new fpa??
    757             pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config); // FPA, ensuring it's ready to write a blank
    758 
    759             switch (file->fileLevel) {
    760               case PM_FPA_LEVEL_FPA:
    761                 if (file->fpa->wrote_phu) break;
    762                 status = pmFPAWrite(fpa, file->fits, NULL, true, false);
    763                 file->fpa->wrote_phu = true;
    764                 break;
    765               case PM_FPA_LEVEL_CHIP: {
    766                   pmChip *chip = pmFPAviewThisChip(view, fpa);
    767                   if (chip->wrote_phu) break;
    768                   status = pmChipWrite(chip, file->fits, NULL, true, false);
    769                   chip->wrote_phu = true;
    770                   break;
    771               }
    772               case PM_FPA_LEVEL_CELL: {
    773                   pmCell *cell = pmFPAviewThisCell(view, fpa);
    774                   if (cell->wrote_phu) break;
    775                   status = pmCellWrite(cell, file->fits, NULL, true);
    776                   cell->wrote_phu = true;
    777                   break;
    778               }
    779               default:
    780                 psAbort("fileLevel not correctly set");
    781                 break;
    782             }
    783 
    784             psFree(fpa);
    785         }
     757        if (file->mode == PM_FPA_MODE_WRITE) {
     758            // Want to write out any potential blank
     759            // XXX why do we need to construct a new fpa??
     760            pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config); // FPA, ensuring it's ready to write a blank
     761
     762            switch (file->fileLevel) {
     763              case PM_FPA_LEVEL_FPA:
     764                if (file->fpa->wrote_phu) break;
     765                status = pmFPAWrite(fpa, file->fits, NULL, true, false);
     766                file->fpa->wrote_phu = true;
     767                break;
     768              case PM_FPA_LEVEL_CHIP: {
     769                  pmChip *chip = pmFPAviewThisChip(view, fpa);
     770                  if (chip->wrote_phu) break;
     771                  status = pmChipWrite(chip, file->fits, NULL, true, false);
     772                  chip->wrote_phu = true;
     773                  break;
     774              }
     775              case PM_FPA_LEVEL_CELL: {
     776                  pmCell *cell = pmFPAviewThisCell(view, fpa);
     777                  if (cell->wrote_phu) break;
     778                  status = pmCellWrite(cell, file->fits, NULL, true);
     779                  cell->wrote_phu = true;
     780                  break;
     781              }
     782              default:
     783                psAbort("fileLevel not correctly set");
     784                break;
     785            }
     786
     787            psFree(fpa);
     788        }
    786789      case PM_FPA_FILE_SX:
    787790      case PM_FPA_FILE_RAW:
     
    792795      case PM_FPA_FILE_JPEG:
    793796      case PM_FPA_FILE_KAPA:
    794         break;
     797        break;
    795798      default:
    796799        fprintf (stderr, "warning: type mismatch\n");
     
    798801    }
    799802    if (!status) {
    800         psError(PS_ERR_UNKNOWN, false, "failed to write PHU for %s (%s)\n", file->filename, file->name);
    801         return false;
     803        psError(PS_ERR_UNKNOWN, false, "failed to write PHU for %s (%s)\n", file->filename, file->name);
     804        return false;
    802805    }
    803806    return true;
Note: See TracChangeset for help on using the changeset viewer.