IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 17, 2005, 10:58:22 AM (22 years ago)
Author:
desonia
Message:

added test for psFitsReadTable.

Location:
trunk/psLib/test/fileUtils
Files:
2 edited

Legend:

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

    r2993 r3025  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2005-01-14 19:21:55 $
     8*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2005-01-17 20:58:22 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1919
    2020static bool makeMulti(void);  // implicitly tests psFitsSetExtName
     21static bool makeTable(void);
    2122const char* multiFilename = "multi.fits";
     23const char* tableFilename = "table.fits";
     24const int tableNumRows = 10;
    2225
    2326static psS32 tst_psFitsAlloc( void );
     
    2629static psS32 tst_psFitsReadHeader( void );
    2730static psS32 tst_psFitsReadHeaderSet( void );
     31static psS32 tst_psFitsReadTable( void );
    2832
    2933testDescription tests[] = {
     
    3539                              {tst_psFitsMoveExtNum, 803, "psFitsGetSize", 0, true},
    3640                              {tst_psFitsReadHeader, 804, "psFitsReadHeader", 0, false},
    37                               {tst_psFitsReadHeaderSet, 0, "psFitsReadHeaderSet", 0, false},
     41                              {tst_psFitsReadHeaderSet,805, "psFitsReadHeaderSet", 0, false},
     42                              {tst_psFitsReadTable,809, "psFitsReadTable", 0, false},
    3843                              {NULL}
    3944                          };
     
    110115}
    111116
     117bool makeTable(void)
     118{
     119
     120    if (access(tableFilename, F_OK) != 0) {
     121        psFits* fitsFile = psFitsAlloc(tableFilename);
     122
     123        if (fitsFile == NULL) {
     124            psError(PS_ERR_UNKNOWN, false,
     125                    "Could not create 'table' FITS file.");
     126            return false;
     127        }
     128
     129        // make the PHU an image (per FITS standard, it must be)
     130        psImage* image = psImageAlloc(16,16,PS_TYPE_F32);
     131
     132        if (! psFitsWriteImage(fitsFile,NULL,image,1) ) {
     133            psError(PS_ERR_UNKNOWN, false,
     134                    "Could not write PHU image.");
     135            return false;
     136        }
     137
     138        psFree(image);
     139
     140        // build a table structure
     141        psArray* table = psArrayAlloc(tableNumRows);
     142        table->n = 0;
     143        for (int row = 0; row < tableNumRows; row++) {
     144            psMetadata* header = psMetadataAlloc();
     145
     146            psMetadataAdd(header,PS_LIST_TAIL, "MYINT",
     147                          PS_TYPE_S32, PS_META_PRIMITIVE,
     148                          "psS32 Item", (psS32)row);
     149
     150            psMetadataAdd(header,PS_LIST_TAIL, "MYFLT",
     151                          PS_TYPE_F32, PS_META_PRIMITIVE,
     152                          "psF32 Item", (float)(1.0f/(float)(1+row)));
     153
     154            psMetadataAdd(header,PS_LIST_TAIL, "MYDBL",
     155                          PS_TYPE_F64, PS_META_PRIMITIVE,
     156                          "psF64 Item", (double)(1.0/(double)(1+row)));
     157
     158            psMetadataAdd(header,PS_LIST_TAIL, "MYBOOL",
     159                          PS_TYPE_BOOL, PS_META_PRIMITIVE,
     160                          "psBool Item",
     161                          (row%2 == 0));
     162
     163            psArrayAdd(table,0,header);
     164        }
     165
     166        psFitsWriteTable(fitsFile, NULL, table, "table-1");
     167
     168        psFree(table);
     169        psFree(fitsFile);
     170    }
     171
     172    return true;
     173}
     174
    112175psS32 tst_psFitsAlloc( void )
    113176{
     
    176239    psFits* fits = psFitsAlloc(multiFilename);
    177240
     241    if (fits == NULL) {
     242        psError(PS_ERR_UNKNOWN, false,
     243                "psFitsAlloc returned NULL on existing file.");
     244        return 1;
     245    }
     246
    178247    int numHDUs = psFitsGetSize(fits);
    179248
     
    290359
    291360    psFits* fits = psFitsAlloc(multiFilename);
     361
     362    if (fits == NULL) {
     363        psError(PS_ERR_UNKNOWN, false,
     364                "psFitsAlloc returned NULL on existing file.");
     365        return 1;
     366    }
    292367
    293368    int numHDUs = psFitsGetSize(fits);
     
    489564    psFits* fits = psFitsAlloc(multiFilename);
    490565
     566    if (fits == NULL) {
     567        psError(PS_ERR_UNKNOWN, false,
     568                "psFitsAlloc returned NULL on existing file.");
     569        return 1;
     570    }
     571
    491572    int numHDUs = psFitsGetSize(fits);
    492573
     
    594675    psFits* fits = psFitsAlloc(multiFilename);
    595676
     677    if (fits == NULL) {
     678        psError(PS_ERR_UNKNOWN, false,
     679                "psFitsAlloc returned NULL on existing file.");
     680        return 1;
     681    }
     682
    596683    int numHDUs = psFitsGetSize(fits);
    597684
     
    701788    return 0;
    702789}
     790
     791static psS32 tst_psFitsReadTable( void )
     792{
     793
     794
     795    if (! makeTable() ) {
     796        return 1;
     797    }
     798
     799    psFits* fits = psFitsAlloc(tableFilename);
     800
     801    if (fits == NULL) {
     802        psError(PS_ERR_UNKNOWN, false,
     803                "psFitsAlloc returned NULL on existing file.");
     804        return 1;
     805    }
     806
     807    psFitsMoveExtNum(fits,1,false);
     808
     809    psArray* table = psFitsReadTable(fits);
     810
     811    if (table == NULL) {
     812        psError(PS_ERR_UNKNOWN, false,
     813                "psFitsReadTable returned NULL unexpectedly.");
     814        return 2;
     815    }
     816
     817    if (table->n != tableNumRows) {
     818        psError(PS_ERR_UNKNOWN, false,
     819                "Expected %d rows, but read %d.",
     820                tableNumRows, table->n);
     821        return 3;
     822    }
     823
     824
     825    for (int row = 0; row < table->n; row++) {
     826        psMetadata* rowData = table->data[row];
     827
     828        psS32 intItem = psMetadataLookupS32(rowData, "MYINT",NULL);
     829        psF32 fltItem = psMetadataLookupF32(rowData, "MYFLT",NULL);
     830        psF64 dblItem = psMetadataLookupF64(rowData, "MYDBL",NULL);
     831        psBool boolItem = psMetadataLookupBool(rowData, "MYBOOL",NULL);
     832
     833        if (intItem != row) {
     834            psError(PS_ERR_UNKNOWN, true,
     835                    "Failed to retrieve psS32 metadata item from file.  Got %d vs %d",
     836                    intItem, row);
     837            return 20;
     838        }
     839
     840        if (fabsf(fltItem - 1.0f/(float)(1+row)) > FLT_EPSILON) {
     841            psError(PS_ERR_UNKNOWN, true,
     842                    "Failed to retrieve psF32 metadata item from file.  Got %f vs %f",
     843                    fltItem,1.0f/(float)(1+row));
     844            return 21;
     845        }
     846
     847        if (abs(dblItem - 1.0/(double)(1+row)) > DBL_EPSILON) {
     848            psError(PS_ERR_UNKNOWN, true,
     849                    "Failed to retrieve psF64 metadata item from file.  Got %g vs %g",
     850                    dblItem, 1.0/(double)(1+row));
     851            return 22;
     852        }
     853
     854        if (boolItem != (row%2 == 0)) {
     855            psError(PS_ERR_UNKNOWN, true,
     856                    "Failed to retrieve psBool metadata item from file.");
     857            return 23;
     858        }
     859
     860    }
     861
     862    psFree(table);
     863    psFree(fits);
     864
     865    psArray* nullTest = psFitsReadTable(NULL);
     866
     867    if (nullTest != NULL || psErrorGetStackSize() != 1) {
     868        psError(PS_ERR_UNKNOWN, true,
     869                "psFitsReadTable returned non-NULL when given NULL.");
     870        return 30;
     871    }
     872
     873    return 0;
     874}
  • trunk/psLib/test/fileUtils/verified/tst_psFits.stderr

    r2993 r3025  
    9191---> TESTPOINT PASSED (psImage{psFitsReadHeaderSet} | tst_psFits.c)
    9292
     93/***************************** TESTPOINT ******************************************\
     94*             TestFile: tst_psFits.c                                               *
     95*            TestPoint: psImage{psFitsReadTable}                                   *
     96*             TestType: Positive                                                   *
     97\**********************************************************************************/
     98
     99<DATE><TIME>|<HOST>|E|psFitsReadTable (psFits.c:<LINENO>)
     100    The input psFits object can not NULL.
     101
     102---> TESTPOINT PASSED (psImage{psFitsReadTable} | tst_psFits.c)
     103
Note: See TracChangeset for help on using the changeset viewer.