- Timestamp:
- Jun 5, 2015, 7:58:50 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c
r38366 r38399 4 4 5 5 int test_compress (char *zcmptype); 6 int test_compress_fullrange (char *zcmptype); 6 7 int test_compress_single_full (char *zcmptype); 7 8 9 char *cmptype[] = {"NONE", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", "AUTO", NULL}; 10 8 11 int main (int argc, char **argv) { 9 12 10 plan_tests ( 64);13 plan_tests (286); 11 14 12 15 diag ("libfits tablecomp.c tests"); 13 16 14 test_compress_single_full ("GZIP_1");15 test_compress_single_full ("RICE_1");16 17 17 test_compress (NULL); 18 test_compress ("NONE"); 19 test_compress ("NONE_2"); 20 test_compress ("GZIP_1"); 21 test_compress ("GZIP_2"); 22 test_compress ("RICE_1"); 23 test_compress ("RICE_ONE"); 24 25 exit (0); 18 test_compress_fullrange (NULL); 19 20 int i; 21 for (i = 0; cmptype[i]; i++) { 22 test_compress (cmptype[i]); 23 test_compress_fullrange (cmptype[i]); 24 } 25 26 // test_compress_single_full ("GZIP_1"); 27 // test_compress_single_full ("RICE_1"); 28 29 // test_compress (NULL); 30 // test_compress ("NONE"); 31 // test_compress ("NONE_2"); 32 // test_compress ("GZIP_1"); 33 // test_compress ("GZIP_2"); 34 // test_compress ("RICE_1"); 35 // test_compress ("RICE_ONE"); 36 // test_compress ("AUTO"); 37 38 // test_compress_fullrange (NULL); 39 // test_compress_fullrange ("NONE"); 40 41 return exit_status(); 26 42 } 27 43 … … 37 53 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 38 54 39 ok (gfits_define_bintable_column (&header, "B", "VAL", "val", "none", 1.0, 0.0), "defined byte column"); 40 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 41 ok (gfits_define_bintable_column (&header, "J", "ID", "ID", "none", 1.0, 0.0), "defined int column"); 42 ok (gfits_define_bintable_column (&header, "E", "X", "x", "degree", 1.0, 0.0), "defined float column"); 43 ok (gfits_define_bintable_column (&header, "D", "Y", "y", "degree", 1.0, 0.0), "defined double column"); 55 ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte", "none", 1.0, 0.0), "defined byte column"); 56 ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short", "none", 1.0, 0.0), "defined short column"); 57 ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int", "none", 1.0, 0.0), "defined int column"); 58 ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long", "none", 1.0, 0.0), "defined long column"); 59 ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float", "degree", 1.0, 0.0), "defined float column"); 60 ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0), "defined double column"); 44 61 45 62 // generate the output array that carries the data … … 47 64 48 65 int Nval = 1000; 49 char *VAL; ALLOCATE (VAL, char, Nval); 50 short *SEQ; ALLOCATE (SEQ, short, Nval); 51 int *ID; ALLOCATE (ID, int, Nval); 52 float *X; ALLOCATE (X, float, Nval); 53 double *Y; ALLOCATE (Y, double, Nval); 66 char *VAL_B; ALLOCATE (VAL_B, char, Nval); 67 short *VAL_I; ALLOCATE (VAL_I, short, Nval); 68 int *VAL_J; ALLOCATE (VAL_J, int, Nval); 69 int64_t *VAL_K; ALLOCATE (VAL_K, int64_t, Nval); 70 float *VAL_E; ALLOCATE (VAL_E, float, Nval); 71 double *VAL_D; ALLOCATE (VAL_D, double, Nval); 54 72 55 73 int i; 56 74 for (i = 0; i < Nval; i++) { 57 VAL[i] = i + 32; 58 SEQ[i] = i; 59 ID[i] = 10000*i + 100*i; 60 X[i] = 0.1*i; 61 Y[i] = 1.001*i; 75 VAL_B[i] = (i % 255) - 128; 76 VAL_I[i] = i; 77 VAL_J[i] = 10000*i + 100*i; 78 VAL_K[i] = 10000*i + 330*i; 79 VAL_E[i] = 0.1*i; 80 VAL_D[i] = 1.001*i; 62 81 } 63 82 64 83 // add the columns to the output array 65 ok (gfits_set_bintable_column (&header, &ftable, "VAL", VAL, Nval), "set byte table column"); 66 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 67 ok (gfits_set_bintable_column (&header, &ftable, "ID", ID, Nval), "set int table column"); 68 ok (gfits_set_bintable_column (&header, &ftable, "X", X, Nval), "set float table column"); 69 ok (gfits_set_bintable_column (&header, &ftable, "Y", Y, Nval), "set double table column"); 84 ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte table column"); 85 ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short table column"); 86 ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int table column"); 87 ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long table column"); 88 ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float table column"); 89 ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column"); 70 90 71 91 Header *outheader = &header; … … 94 114 off_t Nrow; 95 115 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"); 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"); 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"); 99 float *X_t = gfits_get_bintable_column_data (outheader, outtable, "X", type, &Nrow, &Ncol); ok (!strcmp (type, "float"), "read float table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 100 double *Y_t = gfits_get_bintable_column_data (outheader, outtable, "Y", type, &Nrow, &Ncol); ok (!strcmp (type, "double"), "read double table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 116 char *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", 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"); 117 short *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", 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"); 118 int *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", 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"); 119 int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 120 float *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"), "read float table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 121 double *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"), "read double table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 101 122 102 123 // count mismatched values 103 int Nvalue = 0; 104 int Nseq = 0; 105 int Nid = 0; 106 int Nx = 0; 107 int Ny = 0; 108 for (i = 0; i < Nval; i++) { 109 if (VAL[i] != VAL_t[i]) Nvalue++; 110 if (SEQ[i] != SEQ_t[i]) Nseq++; 111 if ( ID[i] != ID_t[i]) Nid++; 112 if ( X[i] != X_t[i]) Nx++; 113 if ( Y[i] != Y_t[i]) Ny++; 114 } 115 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)"); 124 int NVAL_B_bad = 0; 125 int NVAL_I_bad = 0; 126 int NVAL_J_bad = 0; 127 int NVAL_K_bad = 0; 128 int NVAL_E_bad = 0; 129 int NVAL_D_bad = 0; 130 131 // for (i = 0; i < Nval; i++) { 132 // fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]); 133 // } 134 135 for (i = 0; i < Nval; i++) { 136 if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++; 137 if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++; 138 if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++; 139 if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++; 140 if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++; 141 if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++; 142 } 143 144 ok (!NVAL_B_bad, "byte values match (input vs output)"); 145 ok (!NVAL_I_bad, "short values match (input vs output)"); 146 ok (!NVAL_J_bad, "int values match (input vs output)"); 147 ok (!NVAL_K_bad, "int64_t values match (input vs output)"); 148 ok (!NVAL_E_bad, "float values match (input vs output)"); 149 ok (!NVAL_D_bad, "double values match (input vs output)"); 121 150 122 151 gfits_free_header (&header); … … 129 158 } 130 159 131 int test_compress_ single_full(char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"160 int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 132 161 133 162 Header header; … … 140 169 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 141 170 142 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 171 ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte", "none", 1.0, 0.0), "defined byte column"); 172 ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short", "none", 1.0, 0.0), "defined short column"); 173 ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int", "none", 1.0, 0.0), "defined int column"); 174 ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long", "none", 1.0, 0.0), "defined long column"); 175 ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float", "degree", 1.0, 0.0), "defined float column"); 176 ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0), "defined double column"); 143 177 144 178 // generate the output array that carries the data … … 146 180 147 181 int Nval = 1000; 148 short *SEQ; ALLOCATE (SEQ, short, Nval); 149 182 char *VAL_B; ALLOCATE (VAL_B, char, Nval); 183 short *VAL_I; ALLOCATE (VAL_I, short, Nval); 184 int *VAL_J; ALLOCATE (VAL_J, int, Nval); 185 int64_t *VAL_K; ALLOCATE (VAL_K, int64_t, Nval); 186 float *VAL_E; ALLOCATE (VAL_E, float, Nval); 187 double *VAL_D; ALLOCATE (VAL_D, double, Nval); 188 189 long A = time(NULL); 190 srand48(A); 191 150 192 int i; 151 193 for (i = 0; i < Nval; i++) { 152 SEQ[i] = i; 194 VAL_B[i] = 0xff & lrand48(); 195 VAL_I[i] = 0xffff & lrand48(); 196 VAL_J[i] = 0xffffffff & lrand48(); 197 VAL_K[i] = (((int64_t)lrand48()) << 32) + (int64_t)lrand48(); 198 VAL_E[i] = FLT_MAX * (2.0*drand48() - 1.0); 199 VAL_D[i] = DBL_MAX * (2.0*drand48() - 1.0); 153 200 } 154 201 155 202 // add the columns to the output array 156 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 203 ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte table column"); 204 ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short table column"); 205 ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int table column"); 206 ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long table column"); 207 ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float table column"); 208 ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column"); 157 209 158 210 Header *outheader = &header; … … 163 215 FTable cmptable; 164 216 cmptable.header = &cmpheader; 165 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");217 ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table"); 166 218 167 219 Header rawheader; … … 181 233 off_t Nrow; 182 234 235 char *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", 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"); 236 short *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", 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"); 237 int *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", 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"); 238 int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 239 float *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"), "read float table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 240 double *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"), "read double table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols"); 241 242 // count mismatched values 243 int NVAL_B_bad = 0; 244 int NVAL_I_bad = 0; 245 int NVAL_J_bad = 0; 246 int NVAL_K_bad = 0; 247 int NVAL_E_bad = 0; 248 int NVAL_D_bad = 0; 249 250 for (i = 0; i < Nval; i++) { 251 if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++; 252 if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++; 253 if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++; 254 if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++; 255 if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++; 256 if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++; 257 } 258 259 ok (!NVAL_B_bad, "byte values match (input vs output)"); 260 ok (!NVAL_I_bad, "short values match (input vs output)"); 261 ok (!NVAL_J_bad, "int values match (input vs output)"); 262 ok (!NVAL_K_bad, "int64_t values match (input vs output)"); 263 ok (!NVAL_E_bad, "float values match (input vs output)"); 264 ok (!NVAL_D_bad, "double values match (input vs output)"); 265 266 gfits_free_header (&header); 267 gfits_free_table (&ftable); 268 if (zcmptype) { 269 gfits_free_header (outheader); 270 gfits_free_table (outtable); 271 } 272 return TRUE; 273 } 274 275 int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE" 276 277 Header header; 278 FTable ftable; 279 280 diag ("--- starting test_compress with zcmptype %s ---", zcmptype); 281 ok (gfits_init_header (&header), "inited the header"); 282 ok (gfits_init_table (&ftable), "inited the table"); 283 284 ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header"); 285 286 ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column"); 287 288 // generate the output array that carries the data 289 ok (gfits_create_table (&header, &ftable), "created the basic table"); 290 291 int Nval = 1000; 292 short *SEQ; ALLOCATE (SEQ, short, Nval); 293 294 int i; 295 for (i = 0; i < Nval; i++) { 296 SEQ[i] = i; 297 } 298 299 // add the columns to the output array 300 ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short table column"); 301 302 Header *outheader = &header; 303 FTable *outtable = &ftable; 304 305 if (zcmptype) { 306 Header cmpheader; 307 FTable cmptable; 308 cmptable.header = &cmpheader; 309 ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table"); 310 311 Header rawheader; 312 FTable rawtable; 313 rawtable.header = &rawheader; 314 ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table"); 315 316 gfits_free_header (&cmpheader); 317 gfits_free_table (&cmptable); 318 319 outheader = &rawheader; 320 outtable = &rawtable; 321 } 322 323 char type[16]; 324 int Ncol; 325 off_t Nrow; 326 183 327 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 328
Note:
See TracChangeset
for help on using the changeset viewer.
