Changeset 777
- Timestamp:
- May 25, 2004, 10:28:46 AM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
image/psImage.c (modified) (3 diffs)
-
image/psImage.h (modified) (2 diffs)
-
mathtypes/psImage.c (modified) (3 diffs)
-
mathtypes/psImage.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r746 r777 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-05-2 0 01:49:47$11 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-05-25 20:28:46 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 /* INCLUDE FILES */ 19 19 /******************************************************************************/ 20 #include <string.h> 21 #include <fitsio.h> 22 20 23 #include "psMemory.h" 21 24 #include "psError.h" 22 25 #include "psImage.h" 23 26 24 #include <string.h>25 27 26 28 /*****************************************************************************/ … … 355 357 int numRows, int z, char* extname, int extnum, char* filename) 356 358 { 357 358 return NULL; 359 } 359 fitsfile *fptr=NULL; /*Pointer to the FITS file*/ 360 int status=0; /*CFITSIO file vars*/ 361 int nAxis=0; 362 int anynull=0; 363 int bitPix=0; /*Pixel type*/ 364 long nAxes[3]; 365 long firstPixel[3]; /* lower-left corner of image subset */ 366 long lastPixel[3]; /* upper-right corner of image subset */ 367 long increment[3]; /* increment for image subset */ 368 char fitsErr[80] = ""; /*CFITSIO error message string */ 369 int hduType = IMAGE_HDU; 370 371 /* Open the FITS file */ 372 (void)fits_open_file(&fptr, filename, READONLY, &status); 373 if (fptr == NULL || status != 0) { 374 fits_get_errstatus(status,fitsErr); 375 psError(__func__,"Could not open file '%s'. FITS error:%s", 376 filename, fitsErr); 377 psImageFree(output); 378 return NULL; 379 } 380 381 /* find the specified extension */ 382 if (extname != NULL) { 383 if (fits_movnam_hdu(fptr, hduType, extname, 0,&status) != 0) { 384 fits_get_errstatus(status, fitsErr); 385 status = 0; 386 (void)fits_close_file(fptr, &status); 387 psError(__func__,"Could not index to '%s' HDU for file %s. FITSIO ERROR:%s", 388 extname, filename, fitsErr); 389 psImageFree(output); 390 return NULL; 391 } 392 } else { 393 if (fits_movabs_hdu(fptr, extnum, &hduType, &status) != 0) { 394 fits_get_errstatus(status, fitsErr); 395 status = 0; 396 (void)fits_close_file(fptr, &status); 397 psError(__func__,"Could not index to HDU #%d for file %s. FITSIO ERROR:%s", 398 extnum, filename, fitsErr); 399 psImageFree(output); 400 return NULL; 401 } 402 } 403 404 /* Get the data type 'bitPix' from the FITS image */ 405 if (fits_get_img_type(fptr, &bitPix, &status) != 0) { 406 fits_get_errstatus(status, fitsErr); 407 status = 0; 408 (void)fits_close_file(fptr, &status); 409 psError("Could not determine image data type of '%s'. FITSIO ERROR:%s", 410 filename, fitsErr); 411 psImageFree(output); 412 return NULL; 413 } 414 415 /* Get the dimensions 'nAxis' from the FITS image */ 416 if (fits_get_img_dim(fptr, &nAxis, &status) != 0) { 417 (void)fits_get_errstatus(status, fitsErr); 418 status = 0; 419 (void)fits_close_file(fptr, &status); 420 psError("Could not determine dimensions of '%s'. FITSIO Error: %s", 421 filename,fitsErr); 422 psImageFree(output); 423 return NULL; 424 } 425 426 /* Validate the number of axis */ 427 if ( (nAxis < 2) || (nAxis > 3) ) { 428 status=0; 429 (void)fits_close_file(fptr, &status); 430 psError("Dimensions of '%s' are not supported (NAXIS=%i).", 431 filename, nAxis); 432 psImageFree(output); 433 return NULL; 434 } 435 436 /* Get the Image size from the FITS file */ 437 if ( fits_get_img_size(fptr, nAxis, nAxes, &status) != 0) { 438 (void)fits_get_errstatus(status, fitsErr); 439 status = 0; 440 (void)fits_close_file(fptr, &status); 441 psError("Could not determine image size of '%s'. FITSIO Error:%s", 442 filename,fitsErr); 443 psImageFree(output); 444 return NULL; 445 } 446 447 if (numCols < 1) { 448 numCols += nAxes[0]; 449 } 450 if (numRows < 1) { 451 numRows += nAxes[1]; 452 } 453 454 firstPixel[0] = col+1; 455 firstPixel[1] = row+1; 456 firstPixel[2] = z+1; 457 458 lastPixel[0] = firstPixel[0] + numCols - 1; 459 lastPixel[1] = firstPixel[1] + numRows - 1; 460 lastPixel[2] = z+1; 461 462 increment[0] = 1; 463 increment[1] = 1; 464 increment[2] = 1; 465 466 // turn off the BSCALE/BZERO processing in CFITSIO 467 (void)fits_set_bscale(fptr, 1.0,0.0,&status); 468 469 switch (bitPix) { 470 case BYTE_IMG: 471 psImageRealloc(output,numCols,numRows,PS_TYPE_U8); 472 (void)fits_read_subset(fptr, TBYTE, firstPixel, lastPixel, increment, 473 NULL, output->data.v, &anynull, &status); 474 break; 475 case SHORT_IMG: 476 psImageRealloc(output,numCols,numRows,PS_TYPE_S16); 477 (void)fits_read_subset(fptr, TSHORT, firstPixel, lastPixel, increment, 478 NULL, output->data.v, &anynull, &status); 479 break; 480 case LONG_IMG: 481 psImageRealloc(output,numCols,numRows,PS_TYPE_S32); 482 (void)fits_read_subset(fptr, TINT, firstPixel, lastPixel, increment, 483 NULL, output->data.v, &anynull, &status); 484 break; 485 case FLOAT_IMG: 486 psImageRealloc(output,numCols,numRows,PS_TYPE_F32); 487 (void)fits_read_subset(fptr, TFLOAT, firstPixel, lastPixel, increment, 488 NULL, output->data.v, &anynull, &status); 489 break; 490 case DOUBLE_IMG: 491 psImageRealloc(output,numCols,numRows,PS_TYPE_F64); 492 (void)fits_read_subset(fptr, TDOUBLE, firstPixel, lastPixel, increment, 493 NULL, output->data.v, &anynull, &status); 494 break; 495 default: 496 psError(__func__,"Unsupported bitpix value (%d) in FITS file %s.", 497 bitPix,filename); 498 psImageFree(output); 499 return NULL; 500 } 501 502 return output; 503 } 504 505 506 int psImageWriteSection(psImage* input, int col0,int row0,int z, 507 char* extname, int extnum, char* filename) 508 { 509 510 return 0; 511 } -
trunk/psLib/src/image/psImage.h
r746 r777 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-05-2 0 01:49:47$11 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-05-25 20:28:46 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 207 207 * only used if extname is NULL 208 208 */ 209 FILE* file 210 /**< the file descriptor of the FITS file */ 211 ); 212 213 /** Read an image or subimage from a FITS file specified by a filename. 214 * 215 * return psImage* NULL if an error, otherwise same as input psImage 216 */ 217 int psImageWriteSection( 218 psImage* input, 219 /**< the psImage to write */ 220 int col0, 221 /**< the column index of the origin to start writing */ 222 int row0, 223 /**< the row index of the origin to start writing */ 224 int z, 225 /**< the z index to start writing */ 226 char* extname, 227 /**< the image extension to write (this should match the EXTNAME keyword in 228 * the extension If NULL, the extnum parameter is to be used instead 229 */ 230 int extnum, 231 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is 232 * only used if extname is NULL. 233 */ 234 char* filename 235 /**< the filename of the FITS image file to write */ 236 ); 237 238 /** Read an image or subimage from a FITS file from a file descriptor. 239 * 240 * return psImage* NULL if an error, otherwise same as input psImage 241 */ 242 int psImageFWriteSection( 243 psImage* input, 244 /**< the psImage to write */ 245 int col0, 246 /**< the column index of the origin to start writing */ 247 int row0, 248 /**< the row index of the origin to start writing */ 249 int z, 250 /**< the z index to start writing */ 251 char* extname, 252 /**< the image extension to write (this should match the EXTNAME keyword in 253 * the extension If NULL, the extnum parameter is to be used instead 254 */ 255 int extnum, 256 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is 257 * only used if extname is NULL. 258 */ 209 259 FILE* f 210 260 /**< the file descriptor of the FITS file */ 211 261 ); 212 262 213 /** Read an image or subimage from a FITS file specified by a filename.214 *215 * return psImage* NULL if an error, otherwise same as input psImage216 */217 psImage* psImageWriteSection(218 psImage* input,219 /**< the psImage to write */220 int col0,221 /**< the column index of the origin to start writing */222 int row0,223 /**< the row index of the origin to start writing */224 int z,225 /**< the z index to start writing */226 char* extname,227 /**< the image extension to write (this should match the EXTNAME keyword in228 * the extension If NULL, the extnum parameter is to be used instead229 */230 int extnum,231 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is232 * only used if extname is NULL.233 */234 char* filename235 /**< the filename of the FITS image file to write */236 );237 238 /** Read an image or subimage from a FITS file from a file descriptor.239 *240 * return psImage* NULL if an error, otherwise same as input psImage241 */242 psImage* psImageFWriteSection(243 psImage* input,244 /**< the psImage to write */245 int col0,246 /**< the column index of the origin to start writing */247 int row0,248 /**< the row index of the origin to start writing */249 int z,250 /**< the z index to start writing */251 char* extname,252 /**< the image extension to write (this should match the EXTNAME keyword in253 * the extension If NULL, the extnum parameter is to be used instead254 */255 int extnum,256 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is257 * only used if extname is NULL.258 */259 FILE* f260 /**< the file descriptor of the FITS file */261 );262 263 263 #endif -
trunk/psLib/src/mathtypes/psImage.c
r746 r777 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-05-2 0 01:49:47$11 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-05-25 20:28:46 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 /* INCLUDE FILES */ 19 19 /******************************************************************************/ 20 #include <string.h> 21 #include <fitsio.h> 22 20 23 #include "psMemory.h" 21 24 #include "psError.h" 22 25 #include "psImage.h" 23 26 24 #include <string.h>25 27 26 28 /*****************************************************************************/ … … 355 357 int numRows, int z, char* extname, int extnum, char* filename) 356 358 { 357 358 return NULL; 359 } 359 fitsfile *fptr=NULL; /*Pointer to the FITS file*/ 360 int status=0; /*CFITSIO file vars*/ 361 int nAxis=0; 362 int anynull=0; 363 int bitPix=0; /*Pixel type*/ 364 long nAxes[3]; 365 long firstPixel[3]; /* lower-left corner of image subset */ 366 long lastPixel[3]; /* upper-right corner of image subset */ 367 long increment[3]; /* increment for image subset */ 368 char fitsErr[80] = ""; /*CFITSIO error message string */ 369 int hduType = IMAGE_HDU; 370 371 /* Open the FITS file */ 372 (void)fits_open_file(&fptr, filename, READONLY, &status); 373 if (fptr == NULL || status != 0) { 374 fits_get_errstatus(status,fitsErr); 375 psError(__func__,"Could not open file '%s'. FITS error:%s", 376 filename, fitsErr); 377 psImageFree(output); 378 return NULL; 379 } 380 381 /* find the specified extension */ 382 if (extname != NULL) { 383 if (fits_movnam_hdu(fptr, hduType, extname, 0,&status) != 0) { 384 fits_get_errstatus(status, fitsErr); 385 status = 0; 386 (void)fits_close_file(fptr, &status); 387 psError(__func__,"Could not index to '%s' HDU for file %s. FITSIO ERROR:%s", 388 extname, filename, fitsErr); 389 psImageFree(output); 390 return NULL; 391 } 392 } else { 393 if (fits_movabs_hdu(fptr, extnum, &hduType, &status) != 0) { 394 fits_get_errstatus(status, fitsErr); 395 status = 0; 396 (void)fits_close_file(fptr, &status); 397 psError(__func__,"Could not index to HDU #%d for file %s. FITSIO ERROR:%s", 398 extnum, filename, fitsErr); 399 psImageFree(output); 400 return NULL; 401 } 402 } 403 404 /* Get the data type 'bitPix' from the FITS image */ 405 if (fits_get_img_type(fptr, &bitPix, &status) != 0) { 406 fits_get_errstatus(status, fitsErr); 407 status = 0; 408 (void)fits_close_file(fptr, &status); 409 psError("Could not determine image data type of '%s'. FITSIO ERROR:%s", 410 filename, fitsErr); 411 psImageFree(output); 412 return NULL; 413 } 414 415 /* Get the dimensions 'nAxis' from the FITS image */ 416 if (fits_get_img_dim(fptr, &nAxis, &status) != 0) { 417 (void)fits_get_errstatus(status, fitsErr); 418 status = 0; 419 (void)fits_close_file(fptr, &status); 420 psError("Could not determine dimensions of '%s'. FITSIO Error: %s", 421 filename,fitsErr); 422 psImageFree(output); 423 return NULL; 424 } 425 426 /* Validate the number of axis */ 427 if ( (nAxis < 2) || (nAxis > 3) ) { 428 status=0; 429 (void)fits_close_file(fptr, &status); 430 psError("Dimensions of '%s' are not supported (NAXIS=%i).", 431 filename, nAxis); 432 psImageFree(output); 433 return NULL; 434 } 435 436 /* Get the Image size from the FITS file */ 437 if ( fits_get_img_size(fptr, nAxis, nAxes, &status) != 0) { 438 (void)fits_get_errstatus(status, fitsErr); 439 status = 0; 440 (void)fits_close_file(fptr, &status); 441 psError("Could not determine image size of '%s'. FITSIO Error:%s", 442 filename,fitsErr); 443 psImageFree(output); 444 return NULL; 445 } 446 447 if (numCols < 1) { 448 numCols += nAxes[0]; 449 } 450 if (numRows < 1) { 451 numRows += nAxes[1]; 452 } 453 454 firstPixel[0] = col+1; 455 firstPixel[1] = row+1; 456 firstPixel[2] = z+1; 457 458 lastPixel[0] = firstPixel[0] + numCols - 1; 459 lastPixel[1] = firstPixel[1] + numRows - 1; 460 lastPixel[2] = z+1; 461 462 increment[0] = 1; 463 increment[1] = 1; 464 increment[2] = 1; 465 466 // turn off the BSCALE/BZERO processing in CFITSIO 467 (void)fits_set_bscale(fptr, 1.0,0.0,&status); 468 469 switch (bitPix) { 470 case BYTE_IMG: 471 psImageRealloc(output,numCols,numRows,PS_TYPE_U8); 472 (void)fits_read_subset(fptr, TBYTE, firstPixel, lastPixel, increment, 473 NULL, output->data.v, &anynull, &status); 474 break; 475 case SHORT_IMG: 476 psImageRealloc(output,numCols,numRows,PS_TYPE_S16); 477 (void)fits_read_subset(fptr, TSHORT, firstPixel, lastPixel, increment, 478 NULL, output->data.v, &anynull, &status); 479 break; 480 case LONG_IMG: 481 psImageRealloc(output,numCols,numRows,PS_TYPE_S32); 482 (void)fits_read_subset(fptr, TINT, firstPixel, lastPixel, increment, 483 NULL, output->data.v, &anynull, &status); 484 break; 485 case FLOAT_IMG: 486 psImageRealloc(output,numCols,numRows,PS_TYPE_F32); 487 (void)fits_read_subset(fptr, TFLOAT, firstPixel, lastPixel, increment, 488 NULL, output->data.v, &anynull, &status); 489 break; 490 case DOUBLE_IMG: 491 psImageRealloc(output,numCols,numRows,PS_TYPE_F64); 492 (void)fits_read_subset(fptr, TDOUBLE, firstPixel, lastPixel, increment, 493 NULL, output->data.v, &anynull, &status); 494 break; 495 default: 496 psError(__func__,"Unsupported bitpix value (%d) in FITS file %s.", 497 bitPix,filename); 498 psImageFree(output); 499 return NULL; 500 } 501 502 return output; 503 } 504 505 506 int psImageWriteSection(psImage* input, int col0,int row0,int z, 507 char* extname, int extnum, char* filename) 508 { 509 510 return 0; 511 } -
trunk/psLib/src/mathtypes/psImage.h
r746 r777 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-05-2 0 01:49:47$11 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-05-25 20:28:46 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 207 207 * only used if extname is NULL 208 208 */ 209 FILE* file 210 /**< the file descriptor of the FITS file */ 211 ); 212 213 /** Read an image or subimage from a FITS file specified by a filename. 214 * 215 * return psImage* NULL if an error, otherwise same as input psImage 216 */ 217 int psImageWriteSection( 218 psImage* input, 219 /**< the psImage to write */ 220 int col0, 221 /**< the column index of the origin to start writing */ 222 int row0, 223 /**< the row index of the origin to start writing */ 224 int z, 225 /**< the z index to start writing */ 226 char* extname, 227 /**< the image extension to write (this should match the EXTNAME keyword in 228 * the extension If NULL, the extnum parameter is to be used instead 229 */ 230 int extnum, 231 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is 232 * only used if extname is NULL. 233 */ 234 char* filename 235 /**< the filename of the FITS image file to write */ 236 ); 237 238 /** Read an image or subimage from a FITS file from a file descriptor. 239 * 240 * return psImage* NULL if an error, otherwise same as input psImage 241 */ 242 int psImageFWriteSection( 243 psImage* input, 244 /**< the psImage to write */ 245 int col0, 246 /**< the column index of the origin to start writing */ 247 int row0, 248 /**< the row index of the origin to start writing */ 249 int z, 250 /**< the z index to start writing */ 251 char* extname, 252 /**< the image extension to write (this should match the EXTNAME keyword in 253 * the extension If NULL, the extnum parameter is to be used instead 254 */ 255 int extnum, 256 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is 257 * only used if extname is NULL. 258 */ 209 259 FILE* f 210 260 /**< the file descriptor of the FITS file */ 211 261 ); 212 262 213 /** Read an image or subimage from a FITS file specified by a filename.214 *215 * return psImage* NULL if an error, otherwise same as input psImage216 */217 psImage* psImageWriteSection(218 psImage* input,219 /**< the psImage to write */220 int col0,221 /**< the column index of the origin to start writing */222 int row0,223 /**< the row index of the origin to start writing */224 int z,225 /**< the z index to start writing */226 char* extname,227 /**< the image extension to write (this should match the EXTNAME keyword in228 * the extension If NULL, the extnum parameter is to be used instead229 */230 int extnum,231 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is232 * only used if extname is NULL.233 */234 char* filename235 /**< the filename of the FITS image file to write */236 );237 238 /** Read an image or subimage from a FITS file from a file descriptor.239 *240 * return psImage* NULL if an error, otherwise same as input psImage241 */242 psImage* psImageFWriteSection(243 psImage* input,244 /**< the psImage to write */245 int col0,246 /**< the column index of the origin to start writing */247 int row0,248 /**< the row index of the origin to start writing */249 int z,250 /**< the z index to start writing */251 char* extname,252 /**< the image extension to write (this should match the EXTNAME keyword in253 * the extension If NULL, the extnum parameter is to be used instead254 */255 int extnum,256 /**< the image extension to write (0=PHU, 1=first extension, etc.) This is257 * only used if extname is NULL.258 */259 FILE* f260 /**< the file descriptor of the FITS file */261 );262 263 263 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
