IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 21, 2004, 12:30:19 PM (22 years ago)
Author:
desonia
Message:

Changed the image code to the new psErrorMsg error handling specification.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImageIO.c

    r1440 r1840  
    1 
    21/** @file  psImageIO.c
    32 *
     
    87 *  @author Robert DeSonia, MHPCC
    98 *
    10  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-08-09 23:34:58 $
     9 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-09-21 22:30:19 $
    1211 *
    1312 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2221#include "psMemory.h"
    2322
     23#include "psImageErrors.h"
     24
    2425psImage* psImageReadSection(psImage* output,
    2526                            int col,
    2627                            int row,
    27                             int numCols, int numRows, int z, char *extname, int extnum, char *filename)
     28                            int numCols,
     29                            int numRows,
     30                            int z,
     31                            char *extname,
     32                            int extnum,
     33                            char *filename)
    2834{
    2935    fitsfile *fptr = NULL;      /* Pointer to the FITS file */
     
    4248
    4349    if (filename == NULL) {
    44         psError(__func__, "Must specify filename; it can not be NULL.");
     50        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     51                   PS_ERR_BAD_PARAMETER_NULL, true,
     52                   PS_ERRORTEXT_psImageIO_FILENAME_NULL);
    4553        psFree(output);
    4654        return NULL;
     
    5159    if (fptr == NULL || status != 0) {
    5260        fits_get_errstatus(status, fitsErr);
    53         psError(__func__, "Could not open file '%s'. (%s)", filename, fitsErr);
     61        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     62                   PS_ERR_BAD_PARAMETER_VALUE, true,
     63                   PS_ERRORTEXT_psImageIO_FILENAME_INVALID,
     64                   filename, fitsErr);
    5465        psFree(output);
    5566        return NULL;
     
    6273            status = 0;
    6374            (void)fits_close_file(fptr, &status);
    64             psError(__func__, "Could not index to '%s' HDU for file %s. (%s)", extname, filename, fitsErr);
     75            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     76                       PS_ERR_LOCATION_INVALID, true,
     77                       PS_ERRORTEXT_psImageIO_EXTNAME_INVALID,
     78                       extname, filename, fitsErr);
    6579            psFree(output);
    6680            return NULL;
     
    7185            status = 0;
    7286            (void)fits_close_file(fptr, &status);
    73             psError(__func__, "Could not index to HDU #%d for file %s. (%s)", extnum, filename, fitsErr);
     87            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     88                       PS_ERR_LOCATION_INVALID, true,
     89                       PS_ERRORTEXT_psImageIO_EXTNUM_INVALID,
     90                       extnum, filename, fitsErr);
    7491            psFree(output);
    7592            return NULL;
     
    8299        status = 0;
    83100        (void)fits_close_file(fptr, &status);
    84         psError("Could not determine image data type of '%s'. (%s)", filename, fitsErr);
     101        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     102                   PS_ERR_IO, true,
     103                   PS_ERRORTEXT_psImageIO_DATATYPE_UNKNOWN,
     104                   filename, fitsErr);
    85105        psFree(output);
    86106        return NULL;
     
    92112        status = 0;
    93113        (void)fits_close_file(fptr, &status);
    94         psError("Could not determine dimensions of '%s'. (%s)", filename, fitsErr);
     114        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     115                   PS_ERR_IO, true,
     116                   PS_ERRORTEXT_psImageIO_IMAGE_DIM_UNKNOWN,
     117                   filename, fitsErr);
    95118        psFree(output);
    96119        return NULL;
     
    101124        status = 0;
    102125        (void)fits_close_file(fptr, &status);
    103         psError("Dimensions of '%s' are not supported (NAXIS=%i).", filename, nAxis);
     126        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     127                   PS_ERR_IO, true,
     128                   PS_ERRORTEXT_psImageIO_IMAGE_DIMENSION_UNSUPPORTED,
     129                   nAxis);
    104130        psFree(output);
    105131        return NULL;
     
    111137        status = 0;
    112138        (void)fits_close_file(fptr, &status);
    113         psError("Could not determine image size of '%s'. (%s)", filename, fitsErr);
     139        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     140                   PS_ERR_IO, true,
     141                   PS_ERRORTEXT_psImageIO_IMAGE_SIZE_UNKNOWN,
     142                   filename, fitsErr);
    114143        psFree(output);
    115144        return NULL;
     
    134163    increment[1] = 1;
    135164    increment[2] = 1;
    136 
    137     // turn off the BSCALE/BZERO processing in
    138     // CFITSIO
    139     // (void)fits_set_bscale(fptr,
    140     // 1.0,0.0,&status);
    141165
    142166    switch (bitPix) {
     
    178202        break;
    179203    default:
    180         psError(__func__, "Unsupported bitpix value (%d) in FITS file %s.", bitPix, filename);
     204        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     205                   PS_ERR_IO, true,
     206                   PS_ERRORTEXT_psImageIO_FITS_TYPE_UNSUPPORTED,
     207                   bitPix, filename);
    181208        psFree(output);
    182209        return NULL;
    183210    }
    184211    output = psImageRecycle(output, numCols, numRows, datatype);
    185     if (fits_read_subset
    186             (fptr, fitsDatatype, firstPixel,
    187              lastPixel, increment, NULL, output->data.V[0], &anynull, &status) != 0) {
     212    if (fits_read_subset(fptr, fitsDatatype, firstPixel, lastPixel, increment,
     213                         NULL, output->data.V[0], &anynull, &status) != 0) {
    188214        psFree(output);
    189215        (void)fits_get_errstatus(status, fitsErr);
    190216        status = 0;
    191217        (void)fits_close_file(fptr, &status);
    192         psError(__func__, "Failed to read image [%s]", filename, fitsErr);
     218        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
     219                   PS_ERR_IO, true,
     220                   PS_ERRORTEXT_psImageIO_READ_FAILED,
     221                   filename, fitsErr);
    193222        return NULL;
    194223    }
     
    199228}
    200229
    201 bool psImageWriteSection(psImage* input, int col0, int row0, int z, char *extname, int extnum,
     230bool psImageWriteSection(psImage* input,
     231                         int col0,
     232                         int row0,
     233                         int z,
     234                         char *extname,
     235                         int extnum,
    202236                         char *filename)
    203237{
     
    220254    /* need a valid image to write */
    221255    if (input == NULL) {
    222         psError(__func__, "Can not write %s.  Input psImage is NULL.", filename);
     256        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     257                   PS_ERR_BAD_PARAMETER_NULL, true,
     258                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    223259        return false;
    224260    }
     
    263299        datatype = TDOUBLE;
    264300        break;
    265     default:
    266         psError(__func__,
    267                 "psImage datatype (%d) not supported.  File %s not written.", input->type.type, filename);
    268         return false;
     301    default: {
     302            char* typeStr;
     303            PS_TYPE_NAME(typeStr,input->type.type);
     304            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     305                       PS_ERR_BAD_PARAMETER_TYPE, true,
     306                       PS_ERRORTEXT_psImageIO_TYPE_UNSUPPORTED,
     307                       typeStr);
     308            return false;
     309        }
    269310    }
    270311
     
    275316        if (fptr == NULL || status != 0) {
    276317            fits_get_errstatus(status, fitsErr);
    277             psError(__func__, "Could not open file '%s'. FITS error:%s", filename, fitsErr);
     318            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     319                       PS_ERR_BAD_PARAMETER_VALUE, true,
     320                       PS_ERRORTEXT_psImageIO_FILENAME_INVALID,
     321                       filename, fitsErr);
    278322            return false;
    279323        }
     
    285329                status = 0;
    286330                (void)fits_close_file(fptr, &status);
    287                 psError(__func__,
    288                         "Could not index to '%s' HDU for file %s. (%s)", extname, filename, fitsErr);
     331                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     332                           PS_ERR_LOCATION_INVALID, true,
     333                           PS_ERRORTEXT_psImageIO_EXTNAME_INVALID,
     334                           extname, filename, fitsErr);
    289335                return false;
    290336            }
     
    296342                status = 0;
    297343                (void)fits_close_file(fptr, &status);
    298                 psError(__func__,
    299                         "extnum (%d) must not exceed number of HDUs (%d) by more than one.", extnum, numHDUs);
     344                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     345                           PS_ERR_LOCATION_INVALID, true,
     346                           PS_ERRORTEXT_psImageIO_WRITE_EXTNUM_INVALID,
     347                           extnum, numHDUs);
    300348                return false;
    301349            } else if (numHDUs == extnum) {
     
    305353                status = 0;
    306354                (void)fits_close_file(fptr, &status);
    307                 psError(__func__, "Could not index to HDU #%d for file %s. (%s)", extnum, filename, fitsErr);
     355                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     356                           PS_ERR_LOCATION_INVALID, true,
     357                           PS_ERRORTEXT_psImageIO_EXTNUM_INVALID,
     358                           extnum, filename, fitsErr);
    308359                return false;
    309360            }
     
    318369        if (fptr == NULL || status != 0) {
    319370            fits_get_errstatus(status, fitsErr);
    320             psError(__func__, "Could not create file '%s'. (%s)", filename, fitsErr);
     371            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     372                       PS_ERR_IO, true,
     373                       PS_ERRORTEXT_psImageIO_FILENAME_CREATE_FAILED,
     374                       filename, fitsErr);
    321375            return false;
    322376        }
     
    333387            status = 0;
    334388            (void)fits_close_file(fptr, &status);
    335             psError(__func__, "Could not create image HDU in FITS file '%s'. %s", filename, fitsErr);
     389            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     390                       PS_ERR_IO, true,
     391                       PS_ERRORTEXT_psImageIO_CREATE_HDU_FAILED,
     392                       filename, fitsErr);
    336393            return false;
    337394        }
     
    347404                status = 0;
    348405                (void)fits_close_file(fptr, &status);
    349                 psError(__func__,
    350                         "Could not create EXTNAME keyword in FITS file '%s'. (%s)", filename, fitsErr);
     406                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     407                           PS_ERR_IO, true,
     408                           PS_ERRORTEXT_psImageIO_CREATE_EXTENSION_FAILED,
     409                           filename, fitsErr);
    351410                return false;
    352411            }
     
    366425        status = 0;
    367426        (void)fits_close_file(fptr, &status);
    368         psError(__func__, "Could not write image data to '%s'. (%s)", filename, fitsErr);
     427        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
     428                   PS_ERR_IO, true,
     429                   PS_ERRORTEXT_psImageIO_WRITE_FAILED,
     430                   filename, fitsErr);
    369431        return false;
    370432    }
Note: See TracChangeset for help on using the changeset viewer.