- Timestamp:
- Jun 4, 2015, 5:42:47 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
r38363 r38366 4 4 5 5 int test_compress (char *zcmptype); 6 int test_compress_single_full (char *zcmptype); 6 7 7 8 int main (int argc, char **argv) { … … 10 11 11 12 diag ("libfits tablecomp.c tests"); 13 14 test_compress_single_full ("GZIP_1"); 15 test_compress_single_full ("RICE_1"); 12 16 13 17 test_compress (NULL); 14 18 test_compress ("NONE"); 19 test_compress ("NONE_2"); 15 20 test_compress ("GZIP_1"); 16 21 test_compress ("GZIP_2"); 17 // test_compress ("GZIP_1"); 22 test_compress ("RICE_1"); 23 test_compress ("RICE_ONE"); 18 24 19 25 exit (0); … … 31 37 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 32 38 39 ok (gfits_define_bintable_column (&header, "B", "VAL", "val", "none", 1.0, 0.0), "defined byte column"); 33 40 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 34 41 ok (gfits_define_bintable_column (&header, "J", "ID", "ID", "none", 1.0, 0.0), "defined int column"); … … 40 47 41 48 int Nval = 1000; 49 char *VAL; ALLOCATE (VAL, char, Nval); 42 50 short *SEQ; ALLOCATE (SEQ, short, Nval); 43 51 int *ID; ALLOCATE (ID, int, Nval); … … 47 55 int i; 48 56 for (i = 0; i < Nval; i++) { 57 VAL[i] = i + 32; 49 58 SEQ[i] = i; 50 59 ID[i] = 10000*i + 100*i; … … 54 63 55 64 // add the columns to the output array 65 ok (gfits_set_bintable_column (&header, &ftable, "VAL", VAL, Nval), "set byte table column"); 56 66 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 57 67 ok (gfits_set_bintable_column (&header, &ftable, "ID", ID, Nval), "set int table column"); … … 84 94 off_t Nrow; 85 95 96 char *VAL_t = gfits_get_bintable_column_data (outheader, outtable, "VAL", type, &Nrow, &Ncol); ok (!strcmp (type, "byte"), "read byte table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 86 97 short *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"), "read short table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 87 98 int *ID_t = gfits_get_bintable_column_data (outheader, outtable, "ID", type, &Nrow, &Ncol); ok (!strcmp (type, "int"), "read int table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); … … 90 101 91 102 // count mismatched values 103 int Nvalue = 0; 92 104 int Nseq = 0; 93 105 int Nid = 0; … … 95 107 int Ny = 0; 96 108 for (i = 0; i < Nval; i++) { 109 if (VAL[i] != VAL_t[i]) Nvalue++; 97 110 if (SEQ[i] != SEQ_t[i]) Nseq++; 98 111 if ( ID[i] != ID_t[i]) Nid++; … … 101 114 } 102 115 103 ok (!Nseq, "short values match (input vs output)"); 104 ok (!Nid, "int values match (input vs output)"); 105 ok (!Nx, "float values match (input vs output)"); 106 ok (!Ny, "double values match (input vs output)"); 116 ok (!Nvalue, "byte values match (input vs output)"); 117 ok (!Nseq, "short values match (input vs output)"); 118 ok (!Nid, "int values match (input vs output)"); 119 ok (!Nx, "float values match (input vs output)"); 120 ok (!Ny, "double values match (input vs output)"); 107 121 108 122 gfits_free_header (&header); … … 115 129 } 116 130 131 int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 132 133 Header header; 134 FTable ftable; 135 136 diag ("--- starting test_compress with zcmptype %s ---", zcmptype); 137 ok (gfits_init_header (&header), "inited the header"); 138 ok (gfits_init_table (&ftable), "inited the table"); 139 140 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 141 142 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 143 144 // generate the output array that carries the data 145 ok (gfits_create_table (&header, &ftable), "created the basic table"); 146 147 int Nval = 1000; 148 short *SEQ; ALLOCATE (SEQ, short, Nval); 149 150 int i; 151 for (i = 0; i < Nval; i++) { 152 SEQ[i] = i; 153 } 154 155 // add the columns to the output array 156 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 157 158 Header *outheader = &header; 159 FTable *outtable = &ftable; 160 161 if (zcmptype) { 162 Header cmpheader; 163 FTable cmptable; 164 cmptable.header = &cmpheader; 165 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table"); 166 167 Header rawheader; 168 FTable rawtable; 169 rawtable.header = &rawheader; 170 ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table"); 171 172 gfits_free_header (&cmpheader); 173 gfits_free_table (&cmptable); 174 175 outheader = &rawheader; 176 outtable = &rawtable; 177 } 178 179 char type[16]; 180 int Ncol; 181 off_t Nrow; 182 183 short *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"), "read short table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 184 185 // count mismatched values 186 int Nseq = 0; 187 for (i = 0; i < Nval; i++) { 188 if (SEQ[i] != SEQ_t[i]) Nseq++; 189 } 190 191 ok (!Nseq, "short values match (input vs output)"); 192 193 gfits_free_header (&header); 194 gfits_free_table (&ftable); 195 if (zcmptype) { 196 gfits_free_header (outheader); 197 gfits_free_table (outtable); 198 } 199 return TRUE; 200 } 201
Note:
See TracChangeset
for help on using the changeset viewer.
