Changeset 1840 for trunk/psLib/src/image/psImageIO.c
- Timestamp:
- Sep 21, 2004, 12:30:19 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageIO.c (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageIO.c
r1440 r1840 1 2 1 /** @file psImageIO.c 3 2 * … … 8 7 * @author Robert DeSonia, MHPCC 9 8 * 10 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-0 8-09 23:34:58$9 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-09-21 22:30:19 $ 12 11 * 13 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 21 #include "psMemory.h" 23 22 23 #include "psImageErrors.h" 24 24 25 psImage* psImageReadSection(psImage* output, 25 26 int col, 26 27 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) 28 34 { 29 35 fitsfile *fptr = NULL; /* Pointer to the FITS file */ … … 42 48 43 49 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); 45 53 psFree(output); 46 54 return NULL; … … 51 59 if (fptr == NULL || status != 0) { 52 60 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); 54 65 psFree(output); 55 66 return NULL; … … 62 73 status = 0; 63 74 (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); 65 79 psFree(output); 66 80 return NULL; … … 71 85 status = 0; 72 86 (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); 74 91 psFree(output); 75 92 return NULL; … … 82 99 status = 0; 83 100 (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); 85 105 psFree(output); 86 106 return NULL; … … 92 112 status = 0; 93 113 (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); 95 118 psFree(output); 96 119 return NULL; … … 101 124 status = 0; 102 125 (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); 104 130 psFree(output); 105 131 return NULL; … … 111 137 status = 0; 112 138 (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); 114 143 psFree(output); 115 144 return NULL; … … 134 163 increment[1] = 1; 135 164 increment[2] = 1; 136 137 // turn off the BSCALE/BZERO processing in138 // CFITSIO139 // (void)fits_set_bscale(fptr,140 // 1.0,0.0,&status);141 165 142 166 switch (bitPix) { … … 178 202 break; 179 203 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); 181 208 psFree(output); 182 209 return NULL; 183 210 } 184 211 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) { 188 214 psFree(output); 189 215 (void)fits_get_errstatus(status, fitsErr); 190 216 status = 0; 191 217 (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); 193 222 return NULL; 194 223 } … … 199 228 } 200 229 201 bool psImageWriteSection(psImage* input, int col0, int row0, int z, char *extname, int extnum, 230 bool psImageWriteSection(psImage* input, 231 int col0, 232 int row0, 233 int z, 234 char *extname, 235 int extnum, 202 236 char *filename) 203 237 { … … 220 254 /* need a valid image to write */ 221 255 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); 223 259 return false; 224 260 } … … 263 299 datatype = TDOUBLE; 264 300 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 } 269 310 } 270 311 … … 275 316 if (fptr == NULL || status != 0) { 276 317 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); 278 322 return false; 279 323 } … … 285 329 status = 0; 286 330 (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); 289 335 return false; 290 336 } … … 296 342 status = 0; 297 343 (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); 300 348 return false; 301 349 } else if (numHDUs == extnum) { … … 305 353 status = 0; 306 354 (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); 308 359 return false; 309 360 } … … 318 369 if (fptr == NULL || status != 0) { 319 370 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); 321 375 return false; 322 376 } … … 333 387 status = 0; 334 388 (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); 336 393 return false; 337 394 } … … 347 404 status = 0; 348 405 (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); 351 410 return false; 352 411 } … … 366 425 status = 0; 367 426 (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); 369 431 return false; 370 432 }
Note:
See TracChangeset
for help on using the changeset viewer.
