IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28580


Ignore:
Timestamp:
Jul 1, 2010, 3:10:20 PM (16 years ago)
Author:
Paul Price
Message:

Better way of checking for empty tables --- doesn't always make sense.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFitsTable.c

    r28511 r28580  
    6969}
    7070
    71 
    72 // Check the FITS file in preparation for reading a table
    73 static bool readTableCheck(const psFits *fits // FITS file
    74                            )
     71// Check if the FITS file is an empty table
     72static bool emptyTableCheck(const psFits *fits // FITS file
     73                            )
    7574{
    7675    PS_ASSERT_FITS_NON_NULL(fits, false);
     
    8180    }
    8281
    83     // check that we are positioned on a table HDU
    8482    int status = 0;                     // CFITSIO status
    8583    int hdutype;                        // Type of HDU
    8684    fits_get_hdu_type(fits->fd, &hdutype, &status);
    87     if (psFitsError(status, true, "Could not determine the HDU type.")) {
     85    if (status) {
     86        psFitsError(status, true, "Could not determine the HDU type.");
    8887        return false;
    8988    }
     
    9998            return false;
    10099        }
    101     } else if (hdutype != ASCII_TBL && hdutype != BINARY_TBL) {
    102         psError(PS_ERR_BAD_FITS, true, _("Current FITS HDU is not a table."));
     100        return true;
     101    }
     102
     103    return false;
     104}
     105
     106// Check the FITS file in preparation for reading a table
     107static bool readTableCheck(const psFits *fits // FITS file
     108                           )
     109{
     110    PS_ASSERT_FITS_NON_NULL(fits, false);
     111
     112    if (psFitsGetExtNum(fits) == 0 && !psFitsMoveExtNum(fits, 1, false)) {
     113        psError(PS_ERR_IO, false, "Unable to move to first extension to read table.");
     114        return false;
     115    }
     116
     117    // check that we are positioned on a table HDU
     118    int status = 0;                     // CFITSIO status
     119    int hdutype;                        // Type of HDU
     120    fits_get_hdu_type(fits->fd, &hdutype, &status);
     121    if (status) {
     122        psFitsError(status, true, "Could not determine the HDU type.");
     123        return false;
     124    }
     125    if (hdutype != ASCII_TBL && hdutype != BINARY_TBL) {
    103126        return false;
    104127    }
     
    114137
    115138    if (!readTableCheck(fits)) {
     139        if (emptyTableCheck(fits)) {
     140            return psMetadataAlloc();
     141        }
     142        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
    116143        return NULL;
    117144    }
     
    123150    fits_get_num_rows(fits->fd, &numRows, &status);
    124151    fits_get_num_cols(fits->fd, &numCols, &status);
    125     if (status != 0) {
     152    if (status) {
    126153        psFitsError(status, true, "Failed to determine the size of the current HDU table.");
    127154        return NULL;
     
    236263
    237264    if (!readTableCheck(fits)) {
     265        if (emptyTableCheck(fits)) {
     266            return psArrayAlloc(0);
     267        }
     268        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
    238269        return NULL;
    239270    }
     
    283314
    284315    if (!readTableCheck(fits)) {
     316        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
    285317        return NULL;
    286318    }
     
    327359
    328360    if (!readTableCheck(fits)) {
     361        if (emptyTableCheck(fits)) {
     362            return psArrayAlloc(0);
     363        }
     364        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
    329365        return NULL;
    330366    }
     
    736772
    737773    if (!readTableCheck(fits)) {
     774        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
    738775        return NULL;
    739776    }
     
    785822
    786823    if (!readTableCheck(fits)) {
     824        if (emptyTableCheck(fits)) {
     825            return psMetadataAlloc();
     826        }
     827        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
    787828        return NULL;
    788829    }
     
    794835    fits_get_num_rows(fits->fd, &numRows, &status);
    795836    fits_get_num_cols(fits->fd, &numCols, &status);
    796     if (psFitsError(status, true, "Failed to determine the size of the current HDU table.")) {
     837    if (status) {
     838        psFitsError(status, true, "Failed to determine the size of the current HDU table.");
    797839        return NULL;
    798840    }
     
    800842    int hdutype;                        // Type of HDU: need to distinguish ASCII and binary tables
    801843    fits_get_hdu_type(fits->fd, &hdutype, &status);
    802     if (psFitsError(status, true, "Could not determine the HDU type.")) {
     844    if (status) {
     845        psFitsError(status, true, "Could not determine the HDU type.");
    803846        return false;
    804847    }
     
    818861        long repeat;                     // Number of repeats
    819862        fits_get_eqcoltype(fits->fd, col, &cfitsioType, &repeat, NULL, &status);
    820         if (psFitsError(status, true, "Could not determine the column data for %s", name)) {
     863        if (status) {
     864            psFitsError(status, true, "Could not determine the column data for %s", name);
    821865            psFree(table);
    822866            return false;
     
    837881            }
    838882            fits_read_col_str(fits->fd, col, 1, 1, numRows, "", (char**)array->data, NULL, &status);
    839             if (psFitsError(status, true, "Failed to read column %s", name)) {
     883            if (status) {
     884                psFitsError(status, true, "Failed to read column %s", name);
    840885                psFree(array);
    841886                psFree(table);
     
    854899            fits_read_col(fits->fd, cfitsioType, col, 1, 1, numRows, NULL,
    855900                          vector->data.U8, NULL, &status);
    856             if (psFitsError(status, true, "Failed to read column %s", name)) {
     901            if (status) {
     902                psFitsError(status, true, "Failed to read column %s", name);
    857903                psFree(vector);
    858904                psFree(table);
     
    9651011    psFree(names);
    9661012    psFree(types);
    967     if (psFitsError(status, true, "Unable to create FITS table with %d columns and %ld rows",
    968                     numCols, numRows)) {
     1013    if (status) {
     1014        psFitsError(status, true, "Unable to create FITS table with %d columns and %ld rows",
     1015                    numCols, numRows);
    9691016        psFree(columns);
    9701017        return false;
     
    10181065        }
    10191066        // Check error status from writing column
    1020         if (psFitsError(status, true, "Unable to write column %ld of FITS table", col)) {
     1067        if (status) {
     1068            psFitsError(status, true, "Unable to write column %ld of FITS table", col);
    10211069            psFree(columns);
    10221070            return false;
     
    10291077    // hurt.
    10301078    ffrdef(fits->fd, &status);
    1031     if (psFitsError(status, true, "Could not re-scan HDU.")) {
     1079    if (status) {
     1080        psFitsError(status, true, "Could not re-scan HDU.");
    10321081        return false;
    10331082    }
Note: See TracChangeset for help on using the changeset viewer.