Changeset 7227
- Timestamp:
- May 25, 2006, 5:24:49 PM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 4 edited
-
src/fits/psFitsHeader.c (modified) (5 diffs)
-
src/fits/psFitsHeader.h (modified) (2 diffs)
-
src/fits/psFitsImage.c (modified) (4 diffs)
-
test/fits/tst_psFits.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsHeader.c
r7226 r7227 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-05-26 0 2:48:47$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-05-26 03:24:49 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 218 218 } 219 219 220 bool psFitsWriteHeader(psMetadata* output, 221 psFits* fits) 222 { 223 220 221 // Do the work of writing out the header. 222 // Doesn't check to see if a new HDU needs to be created 223 bool p_psFitsWriteHeader(psMetadata *output, // Metadata that is to be output into the FITS file 224 psFits *fits // The FITS file handle 225 ) 226 { 224 227 if (!fits) { 225 228 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL); … … 230 233 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_METADATA_NULL); 231 234 return false; 232 }233 234 int status = 0; // Status of cfitsio calls235 236 // Check to see if there are any extant HDUs237 int hdus = psFitsGetSize(fits); // Number of HDUs238 if (hdus == 0) {239 // Need to create a dummy image HDU for the primary HDU240 fits_create_img(fits->fd, 16, 0, NULL, &status);241 if (status) {242 char fitsErr[MAX_STRING_LENGTH];243 (void)fits_get_errstatus(status, fitsErr);244 psError(PS_ERR_IO, true, "Unable to create primary header.\n%s\n", fitsErr);245 return false;246 }247 235 } 248 236 … … 250 238 psListIterator* iter = psListIteratorAlloc(output->list, PS_LIST_HEAD, true); // Iterator 251 239 psMetadataItem* item; // Item from iteration 240 int status = 0; // Status of cfitsio calls 252 241 while ((item = psListGetAndIncrement(iter))) { 253 242 // Check to see if the item should be ignored … … 325 314 } 326 315 316 bool psFitsWriteHeader(psMetadata* output, 317 psFits* fits) 318 { 319 if (!fits) { 320 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL); 321 return false; 322 } 323 324 if (!output) { 325 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_METADATA_NULL); 326 return false; 327 } 328 329 // Check to see if there are any extant HDUs 330 int hdus = psFitsGetSize(fits); // Number of HDUs 331 if (hdus == 0) { 332 // Need to create a dummy image HDU for the primary HDU 333 int status = 0; // Status of cfitsio 334 fits_create_img(fits->fd, 16, 0, NULL, &status); 335 if (status) { 336 char fitsErr[MAX_STRING_LENGTH]; 337 (void)fits_get_errstatus(status, fitsErr); 338 psError(PS_ERR_IO, true, "Unable to create primary header.\n%s\n", fitsErr); 339 return false; 340 } 341 } 342 343 return p_psFitsWriteHeader(output, fits); 344 } 345 327 346 bool psFitsHeaderValidate(psMetadata *header) 328 347 { -
trunk/psLib/src/fits/psFitsHeader.h
r7162 r7227 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-05-2 2 22:39:07$9 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-05-26 03:24:49 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 42 42 43 43 /** Writes the values of the metadata to the current HDU header. 44 * Doesn't check if the header has to be created, so not for general public use. 45 * 46 * @return bool if TRUE, the write was successful, otherwise FALSE. 47 */ 48 bool p_psFitsWriteHeader( 49 psMetadata* output, ///< the psMetadata data in which to write 50 psFits* fits ///< the psFits object 51 ); 52 53 /** Writes the values of the metadata to an HDU header. 44 54 * 45 55 * @return bool if TRUE, the write was successful, otherwise FALSE. -
trunk/psLib/src/fits/psFitsImage.c
r7224 r7227 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-05-26 0 0:48:20$9 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-05-26 03:24:49 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 296 296 { 297 297 298 if (fits == NULL) { 299 psError(PS_ERR_BAD_PARAMETER_NULL, true, 300 PS_ERRORTEXT_psFits_NULL); 301 return false; 302 } 303 304 if (input == NULL) { 305 psError(PS_ERR_BAD_PARAMETER_NULL, true, 306 PS_ERRORTEXT_psFits_IMAGE_NULL); 307 return false; 308 } 309 int numCols = input->numCols; 310 int numRows = input->numRows; 311 312 int status = 0; 298 if (!fits) { 299 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL); 300 return false; 301 } 302 303 if (!input) { 304 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_IMAGE_NULL); 305 return false; 306 } 307 308 int numCols = input->numCols; // Number of columns for image 309 int numRows = input->numRows; // Number of rows for image 310 int status = 0; // Status from cfitsio 313 311 314 312 // determine the FITS-equivalent parameters 315 int bitPix; 316 double bZero; 317 int dataType; 313 int bitPix; // Bits per pixel 314 double bZero; // Zero offset 315 int dataType; // cfitsio data type 318 316 if (! convertPsTypeToFits(input->type.type, &bitPix, &bZero, &dataType) ) { 319 317 return false; 320 318 } 321 319 322 int naxis = 3; 323 long naxes[3]; 324 320 int naxis = 3; // Number of axes 321 long naxes[3]; // Length of each axis 325 322 naxes[0] = numCols; 326 323 naxes[1] = numRows; … … 331 328 } 332 329 333 int chdu = psFitsGetExtNum(fits); // Current HDU number330 // Create the image HDU 334 331 int hdus = psFitsGetSize(fits); // Number of HDUs in file 335 if (! after) {336 if (chdu == 0) {337 // set status to signal fits_insert_img to insert a new primary HDU338 status = PREPEND_PRIMARY;339 } else if (hdus > 0) {340 // move back one to perform an insert after the previous HDU341 psFitsMoveExtNum(fits, -1, true);342 }343 }344 345 332 if (hdus == 0) { 346 status = 0;333 // We're creating the first image 347 334 fits_create_img(fits->fd, bitPix, naxis, naxes, &status); 348 335 } else { 336 if (!after) { 337 int chdu = psFitsGetExtNum(fits); // Current HDU number 338 if (chdu == 0) { 339 // We're creating a replacement primary HDU. 340 // Set status to signal fits_insert_img to insert a new primary HDU 341 status = PREPEND_PRIMARY; 342 } else { 343 // Move back one to perform an insert after the previous HDU 344 psFitsMoveExtNum(fits, -1, true); 345 } 346 } 347 // Insert after the current position 349 348 fits_insert_img(fits->fd, bitPix, naxis, naxes, &status); 349 } 350 351 if (header && !p_psFitsWriteHeader(header, fits)) { 352 psError(PS_ERR_IO, false, "Unable to write FITS header.\n"); 353 return false; 350 354 } 351 355 … … 361 365 } 362 366 363 if (header) {364 psFitsWriteHeader(header, fits);365 }366 367 if (input->parent == NULL) { // if no parent, assume that the image data is contiguous 367 368 fits_write_img(fits->fd, -
trunk/psLib/test/fits/tst_psFits.c
r6912 r7227 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-0 4-20 01:13:11$8 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-05-26 03:24:37 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 119 119 120 120 // set the pixels in the image 121 ps BinaryOp(image,image,"=",psScalarAlloc(lcv,PS_TYPE_F32));122 if (! psFitsWriteImage(fitsFile,header,image, 1,extname) ) {121 psImageInit(image, lcv); 122 if (! psFitsWriteImage(fitsFile,header,image,0,extname) ) { 123 123 psError(PS_ERR_UNKNOWN, false, 124 124 "Could not write image.");
Note:
See TracChangeset
for help on using the changeset viewer.
