IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 4, 2015, 5:42:47 PM (11 years ago)
Author:
eugene
Message:

libfits compressed I/O seems to be generally working

File:
1 edited

Legend:

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

    r38363 r38366  
    44
    55int test_compress (char *zcmptype);
     6int test_compress_single_full (char *zcmptype);
    67
    78int main (int argc, char **argv) {
     
    1011
    1112  diag ("libfits tablecomp.c tests");
     13
     14  test_compress_single_full ("GZIP_1");
     15  test_compress_single_full ("RICE_1");
    1216
    1317  test_compress (NULL);
    1418  test_compress ("NONE");
     19  test_compress ("NONE_2");
    1520  test_compress ("GZIP_1");
    1621  test_compress ("GZIP_2");
    17   // test_compress ("GZIP_1");
     22  test_compress ("RICE_1");
     23  test_compress ("RICE_ONE");
    1824
    1925  exit (0);
     
    3137  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
    3238
     39  ok (gfits_define_bintable_column (&header, "B", "VAL", "val", "none", 1.0, 0.0), "defined byte column");
    3340  ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
    3441  ok (gfits_define_bintable_column (&header, "J", "ID",  "ID", "none", 1.0, 0.0),  "defined int column");
     
    4047
    4148  int Nval = 1000;
     49  char  *VAL;  ALLOCATE (VAL, char,   Nval);
    4250  short *SEQ;  ALLOCATE (SEQ, short,  Nval);
    4351  int    *ID;  ALLOCATE (ID,  int,    Nval);
     
    4755  int i;
    4856  for (i = 0; i < Nval; i++) {
     57    VAL[i] = i + 32;
    4958    SEQ[i] = i;
    5059    ID[i] = 10000*i + 100*i;
     
    5463
    5564  // add the columns to the output array
     65  ok (gfits_set_bintable_column (&header, &ftable, "VAL", VAL, Nval), "set byte   table column");
    5666  ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
    5767  ok (gfits_set_bintable_column (&header, &ftable,  "ID",  ID, Nval), "set int    table column");
     
    8494  off_t Nrow;
    8595
     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");
    8697  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");
    8798  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");
     
    90101
    91102  // count mismatched values
     103  int Nvalue = 0;
    92104  int Nseq = 0;
    93105  int  Nid = 0;
     
    95107  int   Ny = 0;
    96108  for (i = 0; i < Nval; i++) {
     109    if (VAL[i] != VAL_t[i]) Nvalue++;
    97110    if (SEQ[i] != SEQ_t[i]) Nseq++;
    98111    if ( ID[i] !=  ID_t[i]) Nid++;
     
    101114  }
    102115
    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)");
    107121
    108122  gfits_free_header (&header);
     
    115129}
    116130
     131int 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.