Changeset 5511 for trunk/psLib/test/fits/tst_psFits.c
- Timestamp:
- Nov 14, 2005, 12:18:38 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/fits/tst_psFits.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/fits/tst_psFits.c
r5168 r5511 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2005- 09-28 20:02:49$8 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-11-14 22:18:38 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 41 41 static psS32 testImageWrite(void); 42 42 43 static psS32 tst_psFits Alloc( void );43 static psS32 tst_psFitsOpen( void ); 44 44 static psS32 tst_psFitsMoveExtName( void ); // also tests psFitsGetExtName 45 45 static psS32 tst_psFitsMoveExtNum( void ); // also tests psFitsGetExtNum, psFitsGetSize … … 53 53 54 54 testDescription tests[] = { 55 {tst_psFits Alloc, 801, "psFitsAlloc", 0, false},55 {tst_psFitsOpen, 801, "psFitsOpen", 0, false}, 56 56 {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false}, 57 57 {tst_psFitsMoveExtName, 802, "psFitsGetExtName", 0, true}, … … 80 80 bool makeMulti(void) 81 81 { 82 83 remove 84 (multiFilename); 85 86 psFits* fitsFile = psFitsAlloc(multiFilename); 82 psFits* fitsFile = psFitsOpen(multiFilename,"w"); 87 83 88 84 if (fitsFile == NULL) { … … 145 141 bool makeTable(void) 146 142 { 147 148 remove 149 (tableFilename); 150 151 psFits* fitsFile = psFitsAlloc(tableFilename); 143 psFits* fitsFile = psFitsOpen(tableFilename,"w"); 152 144 153 145 if (fitsFile == NULL) { … … 223 215 } 224 216 225 psS32 tst_psFits Alloc( void )217 psS32 tst_psFitsOpen( void ) 226 218 { 227 219 … … 230 222 } 231 223 232 psFits* fitsFile = psFits Alloc(multiFilename);224 psFits* fitsFile = psFitsOpen(multiFilename,"r"); 233 225 234 226 if (fitsFile == NULL) { 235 227 psError(PS_ERR_UNKNOWN, false, 236 "psFits Allocreturned NULL on existing file.");228 "psFitsOpen returned NULL on existing file."); 237 229 return 1; 238 230 } … … 241 233 if (extNum != 0) { 242 234 psError(PS_ERR_UNKNOWN, false, 243 "psFits Allocwas not queued to the PHU, but to extension #%d.",235 "psFitsOpen was not queued to the PHU, but to extension #%d.", 244 236 extNum); 245 237 return 2; 246 238 } 247 239 248 psF ree(fitsFile);240 psFitsClose(fitsFile); 249 241 250 242 // make sure the file doesn't already exist. … … 258 250 } 259 251 260 fitsFile = psFits Alloc("new.fits");252 fitsFile = psFitsOpen("new.fits","w"); 261 253 262 254 if (fitsFile == NULL) { 263 255 psError(PS_ERR_UNKNOWN, false, 264 "psFits Alloc returned NULL on existing file.");256 "psFitsOpen returned NULL on w mode."); 265 257 return 4; 266 258 } 267 259 268 psFree(fitsFile); 269 270 // now, if psFitsAlloc actually created the file, I shouldn't error in removing it. 260 // write something to the file, otherwise CFITSIO will complain on close 261 psImage* img = psImageAlloc(16,16,PS_TYPE_F32); 262 psFitsWriteImage(fitsFile,NULL,img,1); 263 264 psFree(fitsFile); // psFree should be equivalent to psFitsClose 265 266 // now, if psFitsOpen actually created the file, I shouldn't error in removing it. 271 267 if (remove 272 268 ("new.fits") != 0) { 273 269 psError(PS_ERR_UNKNOWN, false, 274 "psFits Allocseemed to not have created a new file.");270 "psFitsOpen seemed to not have created a new file."); 275 271 return 5; 272 } 273 274 fitsFile = psFitsOpen("new.fits","w+"); 275 276 if (fitsFile == NULL) { 277 psError(PS_ERR_UNKNOWN, false, 278 "psFitsOpen returned NULL on w+ mode."); 279 return 6; 280 } 281 282 // write something to the file, otherwise CFITSIO will complain on close 283 psFitsWriteImage(fitsFile,NULL,img,1); 284 285 psFitsClose(fitsFile); 286 287 // now, if psFitsOpen actually created the file, I shouldn't error in removing it. 288 if (remove 289 ("new.fits") != 0) { 290 psError(PS_ERR_UNKNOWN, false, 291 "psFitsOpen seemed to not have created a new file."); 292 return 7; 293 } 294 295 fitsFile = psFitsOpen("new.fits","a"); 296 297 if (fitsFile == NULL) { 298 psError(PS_ERR_UNKNOWN, false, 299 "psFitsOpen returned NULL on a mode."); 300 return 8; 301 } 302 303 // write something to the file, otherwise CFITSIO will complain on close 304 psFitsWriteImage(fitsFile,NULL,img,1); 305 306 psFitsClose(fitsFile); 307 308 fitsFile = psFitsOpen("new.fits","a+"); 309 310 if (fitsFile == NULL) { 311 psError(PS_ERR_UNKNOWN, false, 312 "psFitsOpen returned NULL on a+ mode."); 313 return 9; 314 } 315 316 psFitsClose(fitsFile); 317 318 // now, if psFitsOpen actually created the file, I shouldn't error in removing it. 319 if (remove 320 ("new.fits") != 0) { 321 psError(PS_ERR_UNKNOWN, false, 322 "psFitsOpen seemed to not have created a new file."); 323 return 10; 276 324 } 277 325 278 326 // Attempt to allocate with NULL filename 279 327 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 280 fitsFile = psFits Alloc(NULL);328 fitsFile = psFitsOpen(NULL,"r"); 281 329 if(fitsFile != NULL) { 282 psError(PS_ERR_UNKNOWN,true,"psFitsAlloc did not return NULL for NULL input"); 283 return 5; 284 } 330 psError(PS_ERR_UNKNOWN,true,"psFitsOpen did not return NULL for NULL input"); 331 return 11; 332 } 333 334 // Attempt to use an invalid mode 335 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 336 fitsFile = psFitsOpen("new.fits","b+"); 337 if(fitsFile != NULL) { 338 psError(PS_ERR_UNKNOWN,true,"psFitsOpen did not return NULL for NULL input"); 339 return 12; 340 } 341 342 psFree(img); 285 343 286 344 return 0; … … 294 352 } 295 353 296 psFits* fits = psFits Alloc(multiFilename);354 psFits* fits = psFitsOpen(multiFilename,"r"); 297 355 298 356 if (fits == NULL) { 299 357 psError(PS_ERR_UNKNOWN, false, 300 "psFits Allocreturned NULL on existing file.");358 "psFitsOpen returned NULL on existing file."); 301 359 return 1; 302 360 } … … 422 480 } 423 481 424 psFits* fits = psFits Alloc(multiFilename);482 psFits* fits = psFitsOpen(multiFilename,"r"); 425 483 426 484 if (fits == NULL) { 427 485 psError(PS_ERR_UNKNOWN, false, 428 "psFits Allocreturned NULL on existing file.");486 "psFitsOpen returned NULL on existing file."); 429 487 return 1; 430 488 } … … 613 671 } 614 672 615 psF ree(fits);673 psFitsClose(fits); 616 674 617 675 // Attempt to get ext name from null fits file … … 631 689 } 632 690 633 psFits* fits = psFits Alloc(multiFilename);691 psFits* fits = psFitsOpen(multiFilename,"r"); 634 692 635 693 if (fits == NULL) { 636 694 psError(PS_ERR_UNKNOWN, false, 637 "psFits Allocreturned NULL on existing file.");695 "psFitsOpen returned NULL on existing file."); 638 696 return 1; 639 697 } … … 741 799 } 742 800 743 psFits* fits = psFits Alloc(multiFilename);801 psFits* fits = psFitsOpen(multiFilename,"r"); 744 802 745 803 if (fits == NULL) { 746 804 psError(PS_ERR_UNKNOWN, false, 747 "psFits Allocreturned NULL on existing file.");805 "psFitsOpen returned NULL on existing file."); 748 806 return 1; 749 807 } … … 852 910 // set2 should have been freed by psFitsReadHeaderSet upon an error. 853 911 854 psF ree(fits);912 psFitsClose(fits); 855 913 856 914 return 0; … … 865 923 } 866 924 867 psFits* fits = psFits Alloc(tableFilename);925 psFits* fits = psFitsOpen(tableFilename,"r"); 868 926 869 927 if (fits == NULL) { 870 928 psError(PS_ERR_UNKNOWN, false, 871 "psFits Allocreturned NULL on existing file.");929 "psFitsOpen returned NULL on existing file."); 872 930 return 1; 873 931 } … … 977 1035 } 978 1036 979 psFits* fits = psFits Alloc(tableFilename);1037 psFits* fits = psFitsOpen(tableFilename,"r"); 980 1038 981 1039 if (fits == NULL) { 982 1040 psError(PS_ERR_UNKNOWN, false, 983 "psFits Allocreturned NULL on existing file.");1041 "psFitsOpen returned NULL on existing file."); 984 1042 return 1; 985 1043 } … … 1079 1137 } 1080 1138 1081 psFits* fits = psFits Alloc(tableFilename);1139 psFits* fits = psFitsOpen(tableFilename,"r"); 1082 1140 1083 1141 if (fits == NULL) { 1084 1142 psError(PS_ERR_UNKNOWN, false, 1085 "psFits Allocreturned NULL on existing file.");1143 "psFitsOpen returned NULL on existing file."); 1086 1144 return 1; 1087 1145 } … … 1206 1264 } 1207 1265 1208 psFits* fits = psFits Alloc(tableFilename);1266 psFits* fits = psFitsOpen(tableFilename,"rw"); 1209 1267 1210 1268 if (fits == NULL) { 1211 1269 psError(PS_ERR_UNKNOWN, false, 1212 "psFits Allocreturned NULL on existing file.");1270 "psFitsOpen returned NULL on existing file."); 1213 1271 return 2; 1214 1272 } … … 1332 1390 psFree(err); 1333 1391 psFree(md); 1334 psF ree(fits);1392 psFitsClose(fits); 1335 1393 1336 1394 return 0; … … 1374 1432 psImageClip(img3,32.0,32.0,120.0,120.0); \ 1375 1433 img4 = psImageCopy(img4,img3,PS_TYPE_##TYP); \ 1376 remove(filename); \ 1377 psFits* fits = psFitsAlloc(filename); \ 1434 psFits* fits = psFitsOpen(filename, "w"); \ 1378 1435 psRegion region = {0,0,0,0}; \ 1379 1436 if (! psFitsWriteImage(fits, NULL, img, 2)) { \ … … 1398 1455 psFree(img3); \ 1399 1456 img3 = NULL; \ 1400 fits = psFits Alloc(filename); \1457 fits = psFitsOpen(filename,"r"); \ 1401 1458 psRegion reg = {readM0, readM, readN0, readN}; \ 1402 1459 img = psFitsReadImage(img, fits, reg, 0); \ … … 1536 1593 GENIMAGE(img2,m,n,F32,row+2*col); 1537 1594 mkdir("tmpImages",0777); 1538 remove 1539 ("tmpImages/writeTest.fits"); 1540 psRegion region = { 1541 0,0,0,0 1542 }; 1543 psFits* fits = psFitsAlloc("tmpImages/writeTest.fits"); 1595 psRegion region = {0,0,0,0}; 1596 psFits* fits = psFitsOpen("tmpImages/writeTest.fits","w"); 1544 1597 1545 1598 if (! psFitsWriteImage(fits, NULL, img,1)) { … … 1555 1608 1556 1609 // Did it really overwrite the pixel values? Let's read it in and see. 1557 psF ree(fits);1558 fits = psFits Alloc("tmpImages/writeTest.fits");1610 psFitsClose(fits); 1611 fits = psFitsOpen("tmpImages/writeTest.fits","r"); 1559 1612 img = psFitsReadImage(NULL, fits, region, 0); 1560 1613 if (img == NULL) { … … 1597 1650 1598 1651 psMetadata* header = psMetadataAlloc(); 1599 psFits* fitsFile = psFits Alloc(multiFilename);1652 psFits* fitsFile = psFitsOpen(multiFilename,"a+"); 1600 1653 1601 1654 // Test psFitsReadWrite generates files from psFitsWriteImage which calls psFitsWriteHeader
Note:
See TracChangeset
for help on using the changeset viewer.
