IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2015, 2:28:50 PM (11 years ago)
Author:
eugene
Message:

add timing test; handle empty table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/test/tablecomp.c

    r38404 r38415  
    44
    55int test_compress (char *zcmptype);
     6int test_compress_empty (char *zcmptype);
    67int test_compress_fullrange (char *zcmptype);
    78int test_compress_single_full (char *zcmptype);
     
    1516  diag ("libfits tablecomp.c tests");
    1617
    17   // test_compress ("RICE_1");
    18   // test_compress_fullrange ("RICE_1");
    19 
    20 # if (1)
     18  // test_compress_empty ("GZIP_1");
     19  // exit (0);
     20
    2121  test_compress (NULL);
    2222  test_compress_fullrange (NULL);
     
    2626    test_compress (cmptype[i]);
    2727    test_compress_fullrange (cmptype[i]);
    28   }
    29 # endif
    30 
    31   // test_compress_single_full ("GZIP_1");
    32   // test_compress_single_full ("RICE_1");
    33 
    34   // test_compress (NULL);
    35   // test_compress ("NONE");
    36   // test_compress ("NONE_2");
    37   // test_compress ("GZIP_1");
    38   // test_compress ("GZIP_2");
    39   // test_compress ("RICE_1");
    40   // test_compress ("RICE_ONE");
    41   // test_compress ("AUTO");
    42 
    43   // test_compress_fullrange (NULL);
    44   // test_compress_fullrange ("NONE");
     28    test_compress_empty (cmptype[i]);
     29    ok (ohana_memcheck_func (TRUE), "no memory corruption");
     30  }
    4531
    4632  return exit_status();
     
    349335}
    350336
     337int test_compress_empty (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     338
     339  Header header;
     340  FTable ftable;
     341
     342  diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
     343  ok (gfits_init_header (&header), "inited the header");
     344  ok (gfits_init_table (&ftable), "inited the table");
     345
     346  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
     347
     348  ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte",   "none", 1.0, 0.0), "defined byte column");
     349  ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short",  "none", 1.0, 0.0), "defined short column");
     350  ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int",    "none", 1.0, 0.0),  "defined int column");
     351  ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long",   "none", 1.0, 0.0),  "defined long column");
     352  ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float",  "degree", 1.0, 0.0),   "defined float column");
     353  ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0),   "defined double column");
     354 
     355  // generate the output array that carries the data
     356  ok (gfits_create_table (&header, &ftable), "created the basic table");
     357
     358  int Nval = 0;
     359  char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
     360  short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
     361  int     *VAL_J;  ALLOCATE (VAL_J, int,     Nval);
     362  int64_t *VAL_K;  ALLOCATE (VAL_K, int64_t, Nval);
     363  float   *VAL_E;  ALLOCATE (VAL_E, float,   Nval);
     364  double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
     365 
     366  int i;
     367  for (i = 0; i < Nval; i++) {
     368    VAL_B[i] = (i % 255) - 128;
     369    VAL_I[i] = i;
     370    VAL_J[i] = 10000*i + 100*i;
     371    VAL_K[i] = 10000*i + 330*i;
     372    VAL_E[i] = 0.1*i;
     373    VAL_D[i] = 1.001*i;
     374  }     
     375
     376  // add the columns to the output array
     377  ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte   table column");
     378  ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short  table column");
     379  ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int    table column");
     380  ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long   table column");
     381  ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float  table column");
     382  ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column");
     383
     384  Header *outheader = &header;
     385  FTable *outtable = &ftable;
     386
     387  if (zcmptype) {
     388    Header cmpheader;
     389    FTable cmptable;
     390    cmptable.header = &cmpheader;
     391    ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
     392
     393    Header rawheader;
     394    FTable rawtable;
     395    rawtable.header = &rawheader;
     396    ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
     397   
     398    gfits_free_header (&cmpheader);
     399    gfits_free_table (&cmptable);
     400
     401    outheader = &rawheader;
     402    outtable  = &rawtable;
     403  }
     404
     405  char type[16];
     406  int Ncol;
     407  off_t Nrow;
     408
     409  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");
     410  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");
     411  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");
     412  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");
     413  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");
     414  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");
     415
     416  // count mismatched values
     417  int NVAL_B_bad = 0;
     418  int NVAL_I_bad = 0;
     419  int NVAL_J_bad = 0;
     420  int NVAL_K_bad = 0;
     421  int NVAL_E_bad = 0;
     422  int NVAL_D_bad = 0;
     423
     424  // for (i = 0; i < Nval; i++) {
     425  //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
     426  // }
     427
     428  for (i = 0; i < Nval; i++) {
     429    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
     430    if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++;
     431    if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++;
     432    if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++;
     433    if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++;
     434    if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++;
     435  }
     436
     437  ok (!NVAL_B_bad, "byte    values match (input vs output)");
     438  ok (!NVAL_I_bad, "short   values match (input vs output)");
     439  ok (!NVAL_J_bad, "int     values match (input vs output)");
     440  ok (!NVAL_K_bad, "int64_t values match (input vs output)");
     441  ok (!NVAL_E_bad, "float   values match (input vs output)");
     442  ok (!NVAL_D_bad, "double  values match (input vs output)");
     443
     444  gfits_free_header (&header);
     445  gfits_free_table (&ftable);
     446  if (zcmptype) {
     447    gfits_free_header (outheader);
     448    gfits_free_table (outtable);
     449  }
     450  return TRUE;
     451}
     452
     453
Note: See TracChangeset for help on using the changeset viewer.