IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 14, 2005, 12:18:38 PM (21 years ago)
Author:
desonia
Message:

Overhauled the Fits functions to match latest SDRS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/fits/tst_psFits.c

    r5168 r5511  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.11 $ $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 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4141static psS32 testImageWrite(void);
    4242
    43 static psS32 tst_psFitsAlloc( void );
     43static psS32 tst_psFitsOpen( void );
    4444static psS32 tst_psFitsMoveExtName( void ); // also tests psFitsGetExtName
    4545static psS32 tst_psFitsMoveExtNum( void );  // also tests psFitsGetExtNum, psFitsGetSize
     
    5353
    5454testDescription tests[] = {
    55                               {tst_psFitsAlloc, 801, "psFitsAlloc", 0, false},
     55                              {tst_psFitsOpen, 801, "psFitsOpen", 0, false},
    5656                              {tst_psFitsMoveExtName, 802, "psFitsMoveExtName", 0, false},
    5757                              {tst_psFitsMoveExtName, 802, "psFitsGetExtName", 0, true},
     
    8080bool makeMulti(void)
    8181{
    82 
    83     remove
    84         (multiFilename);
    85 
    86     psFits* fitsFile = psFitsAlloc(multiFilename);
     82    psFits* fitsFile = psFitsOpen(multiFilename,"w");
    8783
    8884    if (fitsFile == NULL) {
     
    145141bool makeTable(void)
    146142{
    147 
    148     remove
    149         (tableFilename);
    150 
    151     psFits* fitsFile = psFitsAlloc(tableFilename);
     143    psFits* fitsFile = psFitsOpen(tableFilename,"w");
    152144
    153145    if (fitsFile == NULL) {
     
    223215}
    224216
    225 psS32 tst_psFitsAlloc( void )
     217psS32 tst_psFitsOpen( void )
    226218{
    227219
     
    230222    }
    231223
    232     psFits* fitsFile = psFitsAlloc(multiFilename);
     224    psFits* fitsFile = psFitsOpen(multiFilename,"r");
    233225
    234226    if (fitsFile == NULL) {
    235227        psError(PS_ERR_UNKNOWN, false,
    236                 "psFitsAlloc returned NULL on existing file.");
     228                "psFitsOpen returned NULL on existing file.");
    237229        return 1;
    238230    }
     
    241233    if (extNum != 0) {
    242234        psError(PS_ERR_UNKNOWN, false,
    243                 "psFitsAlloc was not queued to the PHU, but to extension #%d.",
     235                "psFitsOpen was not queued to the PHU, but to extension #%d.",
    244236                extNum);
    245237        return 2;
    246238    }
    247239
    248     psFree(fitsFile);
     240    psFitsClose(fitsFile);
    249241
    250242    // make sure the file doesn't already exist.
     
    258250    }
    259251
    260     fitsFile = psFitsAlloc("new.fits");
     252    fitsFile = psFitsOpen("new.fits","w");
    261253
    262254    if (fitsFile == NULL) {
    263255        psError(PS_ERR_UNKNOWN, false,
    264                 "psFitsAlloc returned NULL on existing file.");
     256                "psFitsOpen returned NULL on w mode.");
    265257        return 4;
    266258    }
    267259
    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.
    271267    if (remove
    272268            ("new.fits") != 0) {
    273269        psError(PS_ERR_UNKNOWN, false,
    274                 "psFitsAlloc seemed to not have created a new file.");
     270                "psFitsOpen seemed to not have created a new file.");
    275271        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;
    276324    }
    277325
    278326    // Attempt to allocate with NULL filename
    279327    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");
    280     fitsFile = psFitsAlloc(NULL);
     328    fitsFile = psFitsOpen(NULL,"r");
    281329    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);
    285343
    286344    return 0;
     
    294352    }
    295353
    296     psFits* fits = psFitsAlloc(multiFilename);
     354    psFits* fits = psFitsOpen(multiFilename,"r");
    297355
    298356    if (fits == NULL) {
    299357        psError(PS_ERR_UNKNOWN, false,
    300                 "psFitsAlloc returned NULL on existing file.");
     358                "psFitsOpen returned NULL on existing file.");
    301359        return 1;
    302360    }
     
    422480    }
    423481
    424     psFits* fits = psFitsAlloc(multiFilename);
     482    psFits* fits = psFitsOpen(multiFilename,"r");
    425483
    426484    if (fits == NULL) {
    427485        psError(PS_ERR_UNKNOWN, false,
    428                 "psFitsAlloc returned NULL on existing file.");
     486                "psFitsOpen returned NULL on existing file.");
    429487        return 1;
    430488    }
     
    613671    }
    614672
    615     psFree(fits);
     673    psFitsClose(fits);
    616674
    617675    // Attempt to get ext name from null fits file
     
    631689    }
    632690
    633     psFits* fits = psFitsAlloc(multiFilename);
     691    psFits* fits = psFitsOpen(multiFilename,"r");
    634692
    635693    if (fits == NULL) {
    636694        psError(PS_ERR_UNKNOWN, false,
    637                 "psFitsAlloc returned NULL on existing file.");
     695                "psFitsOpen returned NULL on existing file.");
    638696        return 1;
    639697    }
     
    741799    }
    742800
    743     psFits* fits = psFitsAlloc(multiFilename);
     801    psFits* fits = psFitsOpen(multiFilename,"r");
    744802
    745803    if (fits == NULL) {
    746804        psError(PS_ERR_UNKNOWN, false,
    747                 "psFitsAlloc returned NULL on existing file.");
     805                "psFitsOpen returned NULL on existing file.");
    748806        return 1;
    749807    }
     
    852910    // set2 should have been freed by psFitsReadHeaderSet upon an error.
    853911
    854     psFree(fits);
     912    psFitsClose(fits);
    855913
    856914    return 0;
     
    865923    }
    866924
    867     psFits* fits = psFitsAlloc(tableFilename);
     925    psFits* fits = psFitsOpen(tableFilename,"r");
    868926
    869927    if (fits == NULL) {
    870928        psError(PS_ERR_UNKNOWN, false,
    871                 "psFitsAlloc returned NULL on existing file.");
     929                "psFitsOpen returned NULL on existing file.");
    872930        return 1;
    873931    }
     
    9771035    }
    9781036
    979     psFits* fits = psFitsAlloc(tableFilename);
     1037    psFits* fits = psFitsOpen(tableFilename,"r");
    9801038
    9811039    if (fits == NULL) {
    9821040        psError(PS_ERR_UNKNOWN, false,
    983                 "psFitsAlloc returned NULL on existing file.");
     1041                "psFitsOpen returned NULL on existing file.");
    9841042        return 1;
    9851043    }
     
    10791137    }
    10801138
    1081     psFits* fits = psFitsAlloc(tableFilename);
     1139    psFits* fits = psFitsOpen(tableFilename,"r");
    10821140
    10831141    if (fits == NULL) {
    10841142        psError(PS_ERR_UNKNOWN, false,
    1085                 "psFitsAlloc returned NULL on existing file.");
     1143                "psFitsOpen returned NULL on existing file.");
    10861144        return 1;
    10871145    }
     
    12061264    }
    12071265
    1208     psFits* fits = psFitsAlloc(tableFilename);
     1266    psFits* fits = psFitsOpen(tableFilename,"rw");
    12091267
    12101268    if (fits == NULL) {
    12111269        psError(PS_ERR_UNKNOWN, false,
    1212                 "psFitsAlloc returned NULL on existing file.");
     1270                "psFitsOpen returned NULL on existing file.");
    12131271        return 2;
    12141272    }
     
    13321390    psFree(err);
    13331391    psFree(md);
    1334     psFree(fits);
     1392    psFitsClose(fits);
    13351393
    13361394    return 0;
     
    13741432        psImageClip(img3,32.0,32.0,120.0,120.0); \
    13751433        img4 = psImageCopy(img4,img3,PS_TYPE_##TYP); \
    1376         remove(filename); \
    1377         psFits* fits = psFitsAlloc(filename); \
     1434        psFits* fits = psFitsOpen(filename, "w"); \
    13781435        psRegion region = {0,0,0,0}; \
    13791436        if (! psFitsWriteImage(fits, NULL, img, 2)) { \
     
    13981455        psFree(img3); \
    13991456        img3 = NULL; \
    1400         fits = psFitsAlloc(filename); \
     1457        fits = psFitsOpen(filename,"r"); \
    14011458        psRegion reg = {readM0, readM, readN0, readN}; \
    14021459        img = psFitsReadImage(img, fits, reg, 0); \
     
    15361593    GENIMAGE(img2,m,n,F32,row+2*col);
    15371594    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");
    15441597
    15451598    if (! psFitsWriteImage(fits, NULL, img,1)) {
     
    15551608
    15561609    // Did it really overwrite the pixel values?  Let's read it in and see.
    1557     psFree(fits);
    1558     fits = psFitsAlloc("tmpImages/writeTest.fits");
     1610    psFitsClose(fits);
     1611    fits = psFitsOpen("tmpImages/writeTest.fits","r");
    15591612    img = psFitsReadImage(NULL, fits, region, 0);
    15601613    if (img == NULL) {
     
    15971650
    15981651    psMetadata* header   = psMetadataAlloc();
    1599     psFits*     fitsFile = psFitsAlloc(multiFilename);
     1652    psFits*     fitsFile = psFitsOpen(multiFilename,"a+");
    16001653
    16011654    // Test psFitsReadWrite generates files from psFitsWriteImage which calls psFitsWriteHeader
Note: See TracChangeset for help on using the changeset viewer.