Changeset 3025 for trunk/psLib/test/fileUtils
- Timestamp:
- Jan 17, 2005, 10:58:22 AM (22 years ago)
- Location:
- trunk/psLib/test/fileUtils
- Files:
-
- 2 edited
-
tst_psFits.c (modified) (10 diffs)
-
verified/tst_psFits.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/fileUtils/tst_psFits.c
r2993 r3025 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-01-1 4 19:21:55$8 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-01-17 20:58:22 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 20 20 static bool makeMulti(void); // implicitly tests psFitsSetExtName 21 static bool makeTable(void); 21 22 const char* multiFilename = "multi.fits"; 23 const char* tableFilename = "table.fits"; 24 const int tableNumRows = 10; 22 25 23 26 static psS32 tst_psFitsAlloc( void ); … … 26 29 static psS32 tst_psFitsReadHeader( void ); 27 30 static psS32 tst_psFitsReadHeaderSet( void ); 31 static psS32 tst_psFitsReadTable( void ); 28 32 29 33 testDescription tests[] = { … … 35 39 {tst_psFitsMoveExtNum, 803, "psFitsGetSize", 0, true}, 36 40 {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}, 38 43 {NULL} 39 44 }; … … 110 115 } 111 116 117 bool 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 112 175 psS32 tst_psFitsAlloc( void ) 113 176 { … … 176 239 psFits* fits = psFitsAlloc(multiFilename); 177 240 241 if (fits == NULL) { 242 psError(PS_ERR_UNKNOWN, false, 243 "psFitsAlloc returned NULL on existing file."); 244 return 1; 245 } 246 178 247 int numHDUs = psFitsGetSize(fits); 179 248 … … 290 359 291 360 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 } 292 367 293 368 int numHDUs = psFitsGetSize(fits); … … 489 564 psFits* fits = psFitsAlloc(multiFilename); 490 565 566 if (fits == NULL) { 567 psError(PS_ERR_UNKNOWN, false, 568 "psFitsAlloc returned NULL on existing file."); 569 return 1; 570 } 571 491 572 int numHDUs = psFitsGetSize(fits); 492 573 … … 594 675 psFits* fits = psFitsAlloc(multiFilename); 595 676 677 if (fits == NULL) { 678 psError(PS_ERR_UNKNOWN, false, 679 "psFitsAlloc returned NULL on existing file."); 680 return 1; 681 } 682 596 683 int numHDUs = psFitsGetSize(fits); 597 684 … … 701 788 return 0; 702 789 } 790 791 static 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 91 91 ---> TESTPOINT PASSED (psImage{psFitsReadHeaderSet} | tst_psFits.c) 92 92 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.
