Commit 39befd1b7e9a0938e44ba811763879311fe0dd52

Authored by knodlseder
1 parent 5a240000

complete binary table column test

Showing 1 changed file with 1338 additions and 541 deletions
test/test_GFits.cpp
... ... @@ -23,6 +23,10 @@
23 23 /***************************************************************************
24 24 * Verification routines *
25 25 ***************************************************************************/
  26 +int equal(double val, double ref, double eps)
  27 +{
  28 + return (fabs(val-ref) < eps) ? 1 : 0;
  29 +}
26 30 int fequal(double val, double ref)
27 31 {
28 32 return (fabs(val-ref) < 1.0e-5) ? 1 : 0;
... ... @@ -34,262 +38,6 @@ int dequal(double val, double ref)
34 38  
35 39  
36 40 /***************************************************************************
37   - * Test: Open *
38   - ***************************************************************************/
39   -void test_open(void)
40   -{
41   - cout << "Test GFits: Open FITS file: ";
42   - try {
43   - GFits fits;
44   - fits.open("test_GFits.fits");
45   - cout << endl << fits;
46   - }
47   - catch (exception &e) {
48   - cout << endl << "TEST ERROR: Unable to open FITS file." << endl;
49   - cout << e.what() << endl;
50   - throw;
51   - }
52   - cout << ". ok." << endl;
53   -}
54   -
55   -
56   -/***************************************************************************
57   - * Test: Columns *
58   - ***************************************************************************/
59   -void test_columns(void)
60   -{
61   - GFits fits;
62   - try {
63   - // Open FITS file
64   - fits.open("test_GFits.fits");
65   - }
66   - catch (exception &e) {
67   - cout << endl << "TEST ERROR: Unable to open test file." << endl;
68   - cout << e.what() << endl;
69   - throw;
70   - }
71   -
72   - //
73   - // Test single string column
74   - //
75   - cout << "Test GFits: String column handling: ";
76   - try {
77   - GFitsTableStrCol str = *((GFitsTableStrCol*)fits.hdu("BinTable")->column("TSTRING"));
78   - if (str.string(0) != "1" || str.string(1) != "2" || str.string(2) != "") {
79   - cout << endl << "TEST ERROR: Bad single TSTRING values read ("
80   - << str.string(0) << ", " << str.string(1) << ", " << str.string(2) << ")." << endl;
81   - throw;
82   - }
83   - else
84   - std::cout << ".";
85   - std::string nullval = "empty";
86   - str.set_nullval(nullval);
87   - if (str.string(2) != "empty") {
88   - cout << endl << "TEST ERROR: Bad single TSTRING NULL value read ("
89   - << str.string(2) << ")." << endl;
90   - throw;
91   - }
92   - else
93   - std::cout << ".";
94   - }
95   - catch (exception &e) {
96   - cout << endl << "TEST ERROR: Unable to handle single TSTRING column." << endl;
97   - cout << e.what() << endl;
98   - throw;
99   - }
100   - cout << ". ok." << endl;
101   -
102   - //
103   - // Test single short column
104   - //
105   - cout << "Test GFits: Short column handling: ";
106   - try {
107   - GFitsTableShtCol sht = *((GFitsTableShtCol*)fits.hdu("BinTable")->column("TSHORT"));
108   - if (sht.integer(0) != 1 || sht.real(0) != 1.0 || sht.string(0) != "1" ||
109   - sht.integer(1) != 2 || sht.real(1) != 2.0 || sht.string(1) != "2" ||
110   - sht.integer(2) != -3 || sht.real(2) != -3.0 || sht.string(2) != "-3") {
111   - cout << endl << "TEST ERROR: Bad single TSHORT values read." << endl;
112   - throw;
113   - }
114   - else
115   - std::cout << ".";
116   - }
117   - catch (exception &e) {
118   - cout << endl << "TEST ERROR: Unable to handle single TSHORT column." << endl;
119   - cout << e.what() << endl;
120   - throw;
121   - }
122   - cout << ". ok." << endl;
123   -
124   - //
125   - // Test single long column
126   - //
127   - cout << "Test GFits: Long column handling: ";
128   - try {
129   - GFitsTableLngCol lng = *((GFitsTableLngCol*)fits.hdu("BinTable")->column("TLONG"));
130   - if (lng.integer(0) != 10 || lng.real(0) != 10.0 || lng.string(0) != "10" ||
131   - lng.integer(1) != -20 || lng.real(1) != -20.0 || lng.string(1) != "-20" ||
132   - lng.integer(2) != 30 || lng.real(2) != 30.0 || lng.string(2) != "30") {
133   - cout << endl << "TEST ERROR: Bad single TLONG values read." << endl;
134   - throw;
135   - }
136   - else
137   - cout << ".";
138   - }
139   - catch (exception &e) {
140   - cout << endl << "TEST ERROR: Unable to handle single TLONG column." << endl;
141   - cout << e.what() << endl;
142   - throw;
143   - }
144   - cout << ". ok." << endl;
145   -
146   - //
147   - // Test single floating point column
148   - //
149   - std::cout << "Test GFits: Floating point column handling: ";
150   - try {
151   - GFitsTableFltCol flt = *((GFitsTableFltCol*)fits.hdu("BinTable")->column("TFLOAT"));
152   - if (!fequal(flt.real(0),1.0)) {
153   - cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
154   - << flt.real(0) << " != 1.0)." << endl;
155   - throw;
156   - }
157   - else
158   - std::cout << ".";
159   - if (!fequal(flt.real(1),-2.1)) {
160   - cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
161   - << flt.real(1) << " != -2.1)." << endl;
162   - throw;
163   - }
164   - else
165   - std::cout << ".";
166   - if (flt.integer(0) != 1) {
167   - cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
168   - << flt.integer(0) << " != 1)." << endl;
169   - throw;
170   - }
171   - else
172   - std::cout << ".";
173   - if (flt.integer(1) != -2) {
174   - cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
175   - << flt.integer(1) << " != -2)." << endl;
176   - throw;
177   - }
178   - else
179   - std::cout << ".";
180   - if (flt.string(0) != "1.000000e+00") {
181   - cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
182   - << flt.string(0) << " != 1.000000e+00)." << endl;
183   - throw;
184   - }
185   - else
186   - std::cout << ".";
187   - if (flt.string(1) != "-2.100000e+00") {
188   - cout << endl << "TEST ERROR: Bad single TFLOAT values read ("
189   - << flt.string(1) << " != -2.100000e+00)." << endl;
190   - throw;
191   - }
192   - else
193   - std::cout << ".";
194   - float nullval = -99.9;
195   - flt.set_nullval(&nullval);
196   - if (!fequal(flt.real(2),-99.9)) {
197   - cout << endl << "TEST ERROR: Bad single TFLOAT NULL value read ("
198   - << flt.real(2) << ")." << endl;
199   - throw;
200   - }
201   - else
202   - std::cout << ".";
203   - }
204   - catch (exception &e) {
205   - std::cout << std::endl << "TEST ERROR: Unable to handle single TFLOAT column." << std::endl;
206   - std::cout << e.what() << std::endl;
207   - throw;
208   - }
209   - try {
210   - GFitsTableFltCol flt = *((GFitsTableFltCol*)fits.hdu("BinTable2")->column("TFLOAT3"));
211   - if (!fequal(flt.real(0,0),0.0)) {
212   - cout << endl << "TEST ERROR: Bad TFLOAT (3) values read ("
213   - << flt.real(0,0) << " != 0.0)." << endl;
214   - throw;
215   - }
216   - }
217   - catch (exception &e) {
218   - cout << endl << "TEST ERROR: Unable to handle single TFLOAT column." << endl;
219   - cout << e.what() << endl;
220   - throw;
221   - }
222   - cout << ". ok." << endl;
223   -
224   - //
225   - // Test single double column
226   - //
227   - std::cout << "Test GFits: Double precision column handling: ";
228   - try {
229   - GFitsTableDblCol dbl = *((GFitsTableDblCol*)fits.hdu("BinTable")->column("TDOUBLE"));
230   - if (!dequal(dbl.real(0),11.1)) {
231   - cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
232   - << dbl.real(0) << " != 11.1)." << endl;
233   - throw;
234   - }
235   - else
236   - std::cout << ".";
237   - if (!dequal(dbl.real(2),22.2)) {
238   - cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
239   - << dbl.real(2) << " != 22.2)." << endl;
240   - throw;
241   - }
242   - else
243   - std::cout << ".";
244   - if (dbl.integer(0) != 11) {
245   - cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
246   - << dbl.integer(0) << " != 11)." << endl;
247   - throw;
248   - }
249   - else
250   - std::cout << ".";
251   - if (dbl.integer(2) != 22) {
252   - cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
253   - << dbl.integer(2) << " != 22)." << endl;
254   - throw;
255   - }
256   - else
257   - std::cout << ".";
258   - if (dbl.string(0) != "1.110000e+01") {
259   - cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
260   - << dbl.string(0) << " != 1.110000e+01)." << endl;
261   - throw;
262   - }
263   - else
264   - std::cout << ".";
265   - if (dbl.string(2) != "2.220000e+01") {
266   - cout << endl << "TEST ERROR: Bad single TDOUBLE values read ("
267   - << dbl.string(2) << " != 2.220000e+01)." << endl;
268   - throw;
269   - }
270   - else
271   - std::cout << ".";
272   - double nullval = -9999.9;
273   - dbl.set_nullval(&nullval);
274   - if (!dequal(dbl.real(1),-9999.9)) {
275   - cout << endl << "TEST ERROR: Bad single TDOUBLE NULL value read ("
276   - << dbl.real(1) << ")." << endl;
277   - throw;
278   - }
279   - else
280   - std::cout << ".";
281   - }
282   - catch (exception &e) {
283   - cout << endl << "TEST ERROR: Unable to handle single TDOUBLE column." << endl;
284   - cout << e.what() << endl;
285   - throw;
286   - }
287   - cout << ". ok." << endl;
288   -
289   -}
290   -
291   -
292   -/***************************************************************************
293 41 * Test: Creation *
294 42 ***************************************************************************/
295 43 void test_create(void)
... ... @@ -307,7 +55,6 @@ void test_create(void)
307 55 GFitsDblImage image;
308 56 GFitsHDU hdu(image);
309 57 fits.append_hdu(hdu);
310   - //cout << fits;
311 58 fits.save();
312 59 }
313 60 catch (exception &e) {
... ... @@ -335,7 +82,6 @@ void test_create(void)
335 82 }
336 83 GFitsHDU hdu(image);
337 84 fits.append_hdu(hdu);
338   - //cout << fits;
339 85 fits.save();
340 86 }
341 87 catch (exception &e) {
... ... @@ -390,12 +136,11 @@ void test_create(void)
390 136 cout << second << endl;
391 137 table.append_column(first);
392 138 table.append_column(second);
393   - cout << table;
  139 +// cout << table;
394 140  
395 141 // Create HDU and append to FILE file
396 142 GFitsHDU hdu(table);
397 143 fits.append_hdu(hdu);
398   - // cout << fits;
399 144  
400 145 // Save FITS file
401 146 fits.save();
... ... @@ -497,15 +242,19 @@ void test_image_double(void)
497 242  
498 243  
499 244 /***************************************************************************
500   - * Test: FITS binary table test *
  245 + * Test: double precision FITS binary table *
501 246 ***************************************************************************/
502   -void test_bin_table(void)
  247 +void test_bintable_double(void)
503 248 {
504   - // Dump header
505   - cout << "Test GFitsBinTable: ";
  249 + // Set filename
  250 + std::string filename = "test_bintable_double.fits";
506 251  
  252 + // Dump header
  253 + cout << "Test GFitsTableDblCol: ";
  254 +
507 255 // Remove FITS file
508   - system("rm -rf test_bintables.fits");
  256 + std::string cmd = "rm -rf "+ filename;
  257 + system(cmd.c_str());
509 258  
510 259 // Allocate reference sums
511 260 double sum_dbl = 0.0;
... ... @@ -514,30 +263,12 @@ void test_bin_table(void)
514 263 int sum_dbl10_int = 0;
515 264 std::string sum_dbl_str;
516 265 std::string sum_dbl10_str;
517   - float sum_flt = 0.0;
518   - float sum_flt10 = 0.0;
519   - int sum_flt_int = 0;
520   - int sum_flt10_int = 0;
521   - std::string sum_flt_str;
522   - std::string sum_flt10_str;
523   - short sum_sht = 0;
524   - short sum_sht10 = 0;
525   - short sum_sht_int = 0;
526   - short sum_sht10_int = 0;
527   - std::string sum_sht_str;
528   - std::string sum_sht10_str;
529   - long sum_lng = 0;
530   - long sum_lng10 = 0;
531   - long sum_lng_int = 0;
532   - long sum_lng10_int = 0;
533   - std::string sum_lng_str;
534   - std::string sum_lng10_str;
535 266  
536 267 // Build tables
537 268 try {
538 269 // Open FITS file
539 270 GFits fits;
540   - fits.open("test_bintables.fits");
  271 + fits.open(filename);
541 272  
542 273 // Set number of rows
543 274 int nrows = 10;
... ... @@ -692,113 +423,140 @@ void test_bin_table(void)
692 423 cout << ".";
693 424  
694 425 //
695   - // ===== F L O A T =====
  426 + // ===== W R I T E T A B L E =====
696 427 //
697 428  
698   - // Set single precision table
699   - GFitsTableFltCol col_flt = GFitsTableFltCol("FLOAT", nrows);
700   - for (int i = 0; i < nrows; ++i) {
701   - float val_flt = cos(0.1*float(i));
702   - col_flt(i) = val_flt;
703   - sum_flt += val_flt;
704   - sum_flt_int += int(val_flt);
705   - ostringstream s_value;
706   - s_value << scientific << val_flt;
707   - sum_flt_str += ":"+s_value.str();
708   - }
  429 + // Build binary table
  430 + GFitsBinTable table = GFitsBinTable(nrows);
  431 + table.append_column(col_dbl);
  432 + table.insert_column(1, col_dbl10);
  433 +
  434 + // Create HDU and append to FILE file
  435 + GFitsHDU hdu(table);
  436 + fits.append_hdu(hdu);
  437 +
  438 + // Save FITS file
  439 + fits.save();
709 440 cout << ".";
  441 + }
  442 + catch (exception &e) {
  443 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  444 + cout << e.what() << endl;
  445 + throw;
  446 + }
  447 + cout << ".";
710 448  
711   - // Check single precision table (operator access)
712   - tot_flt = 0.0;
  449 +
  450 + //================================================================
  451 + //================================================================
  452 + //================================================================
  453 + // Read tables
  454 + //================================================================
  455 + //================================================================
  456 + //================================================================
  457 + try {
  458 + // Open FITS file
  459 + GFits fits;
  460 + fits.open(filename);
  461 +
  462 + // Set number of rows
  463 + int nrows = 10;
  464 + int nvec = 10;
  465 +
  466 + // Initial control sums
  467 + float tot_flt = 0.0;
  468 + double tot_dbl = 0.0;
  469 + int tot_int = 0;
  470 + std::string tot_str;
  471 +
  472 + //
  473 + // ===== D O U B L E =====
  474 + //
  475 +
  476 + // Get column
  477 + GFitsTableDblCol* col_dbl =
  478 + (GFitsTableDblCol*)fits.hdu(2)->column("DOUBLE");
  479 +
  480 + // Check double precision table (operator access)
  481 + tot_dbl = 0.0;
713 482 for (int i = 0; i < nrows; ++i)
714   - tot_flt += col_flt(i);
715   - if (!fequal(tot_flt, sum_flt)) {
716   - cout << endl << "TEST ERROR: GFitsTableFltCol::operator()";
717   - cout << endl << " Reference sum: " << sum_flt;
718   - cout << endl << " Derived sum: " << tot_flt << endl;
  483 + tot_dbl += (*col_dbl)(i);
  484 + if (!dequal(tot_dbl, sum_dbl)) {
  485 + cout << endl << "TEST ERROR: GFitsTableDblCol::operator()";
  486 + cout << endl << " Reference sum: " << sum_dbl;
  487 + cout << endl << " Derived sum: " << tot_dbl << endl;
719 488 throw;
720 489 }
721 490 cout << ".";
722 491  
723   - // Check single precision table (real access)
724   - tot_flt = 0.0;
  492 + // Check double precision table (real access)
  493 + tot_dbl = 0.0;
725 494 for (int i = 0; i < nrows; ++i)
726   - tot_flt += col_flt.real(i);
727   - if (!fequal(tot_flt, sum_flt)) {
728   - cout << endl << "TEST ERROR: GFitsTableFltCol::real()";
729   - cout << endl << " Reference sum: " << sum_flt;
730   - cout << endl << " Derived sum: " << tot_flt << endl;
  495 + tot_dbl += (*col_dbl).real(i);
  496 + if (!dequal(tot_dbl, sum_dbl)) {
  497 + cout << endl << "TEST ERROR: GFitsTableDblCol::real()";
  498 + cout << endl << " Reference sum: " << sum_dbl;
  499 + cout << endl << " Derived sum: " << tot_dbl << endl;
731 500 throw;
732 501 }
733 502 cout << ".";
734 503  
735   - // Check single precision table (int access)
  504 + // Check double precision table (int access)
736 505 tot_int = 0;
737 506 for (int i = 0; i < nrows; ++i)
738   - tot_int += col_flt.integer(i);
739   - if (tot_int != sum_flt_int) {
740   - cout << endl << "TEST ERROR: GFitsTableFltCol::integer()";
741   - cout << endl << " Reference sum: " << sum_flt_int;
  507 + tot_int += (*col_dbl).integer(i);
  508 + if (tot_int != sum_dbl_int) {
  509 + cout << endl << "TEST ERROR: GFitsTableDblCol::integer()";
  510 + cout << endl << " Reference sum: " << sum_dbl_int;
742 511 cout << endl << " Derived sum: " << tot_int << endl;
743 512 throw;
744 513 }
745 514 cout << ".";
746 515  
747   - // Check single precision table (string access)
  516 + // Check double precision table (string access)
748 517 tot_str.clear();
749 518 for (int i = 0; i < nrows; ++i)
750   - tot_str += ":"+col_flt.string(i);
751   - if (tot_str != sum_flt_str) {
752   - cout << endl << "TEST ERROR: GFitsTableFltCol::string()";
753   - cout << endl << " Reference sum: " << sum_flt_str;
  519 + tot_str += ":"+ (*col_dbl).string(i);
  520 + if (tot_str != sum_dbl_str) {
  521 + cout << endl << "TEST ERROR: GFitsTableDblCol::string()";
  522 + cout << endl << " Reference sum: " << sum_dbl_str;
754 523 cout << endl << " Derived sum: " << tot_str << endl;
755 524 throw;
756 525 }
757 526 cout << ".";
758 527  
759 528 //
760   - // ===== F L O A T 1 0 =====
  529 + // ===== D O U B L E 1 0 =====
761 530 //
762 531  
763   - // Set single precision table
764   - GFitsTableFltCol col_flt10 = GFitsTableFltCol("FLOAT10", nrows, nvec);
765   - for (int i = 0; i < nrows; ++i) {
766   - for (int j = 0; j < nvec; ++j) {
767   - float val_flt = cos(0.1*float(i))*cos(0.33*float(j));
768   - col_flt10(i,j) = val_flt;
769   - sum_flt10 += val_flt;
770   - sum_flt10_int += int(val_flt);
771   - ostringstream s_value;
772   - s_value << scientific << val_flt;
773   - sum_flt10_str += ":"+s_value.str();
774   - }
775   - }
776   - cout << ".";
  532 + // Get column
  533 + GFitsTableDblCol* col_dbl10 =
  534 + (GFitsTableDblCol*)fits.hdu(2)->column("DOUBLE10");
777 535  
778   - // Check single precision table (operator access)
779   - tot_flt = 0.0;
  536 + // Check double precision table (operator access)
  537 + tot_dbl = 0.0;
780 538 for (int i = 0; i < nrows; ++i) {
781 539 for (int j = 0; j < nvec; ++j)
782   - tot_flt += col_flt10(i,j);
  540 + tot_dbl += (*col_dbl10)(i,j);
783 541 }
784   - if (!fequal(tot_flt, sum_flt10)) {
785   - cout << endl << "TEST ERROR: GFitsTableFltCol::operator() - 10";
786   - cout << endl << " Reference sum: " << sum_flt10;
787   - cout << endl << " Derived sum: " << tot_flt << endl;
  542 + if (!dequal(tot_dbl, sum_dbl10)) {
  543 + cout << endl << "TEST ERROR: GFitsTableDblCol::operator() - 10";
  544 + cout << endl << " Reference sum: " << sum_dbl10;
  545 + cout << endl << " Derived sum: " << tot_dbl << endl;
788 546 throw;
789 547 }
790 548 cout << ".";
791 549  
792   - // Check single precision table (real access)
793   - tot_flt = 0.0;
  550 + // Check double precision table (real access)
  551 + tot_dbl = 0.0;
794 552 for (int i = 0; i < nrows; ++i) {
795 553 for (int j = 0; j < nvec; ++j)
796   - tot_flt += col_flt10.real(i,j);
  554 + tot_dbl += col_dbl10->real(i,j);
797 555 }
798   - if (!fequal(tot_flt, sum_flt10)) {
799   - cout << endl << "TEST ERROR: GFitsTableFltCol::real() - 10";
800   - cout << endl << " Reference sum: " << sum_flt10;
801   - cout << endl << " Derived sum: " << tot_flt << endl;
  556 + if (!dequal(tot_dbl, sum_dbl10)) {
  557 + cout << endl << "TEST ERROR: GFitsTableDblCol::real() - 10";
  558 + cout << endl << " Reference sum: " << sum_dbl10;
  559 + cout << endl << " Derived sum: " << tot_dbl << endl;
802 560 throw;
803 561 }
804 562 cout << ".";
... ... @@ -807,78 +565,129 @@ void test_bin_table(void)
807 565 tot_int = 0;
808 566 for (int i = 0; i < nrows; ++i) {
809 567 for (int j = 0; j < nvec; ++j)
810   - tot_int += col_flt10.integer(i,j);
  568 + tot_int += col_dbl10->integer(i,j);
811 569 }
812   - if (tot_int != sum_flt10_int) {
813   - cout << endl << "TEST ERROR: GFitsTableFltCol::integer() - 10";
814   - cout << endl << " Reference sum: " << sum_flt10_int;
  570 + if (tot_int != sum_dbl10_int) {
  571 + cout << endl << "TEST ERROR: GFitsTableDblCol::integer() - 10";
  572 + cout << endl << " Reference sum: " << sum_dbl10_int;
815 573 cout << endl << " Derived sum: " << tot_int << endl;
816 574 throw;
817 575 }
818 576 cout << ".";
819 577  
820   - // Check single precision table (string access)
  578 + // Check double precision table (string access)
821 579 tot_str.clear();
822 580 for (int i = 0; i < nrows; ++i) {
823 581 for (int j = 0; j < nvec; ++j)
824   - tot_str += ":"+col_flt10.string(i,j);
  582 + tot_str += ":"+col_dbl10->string(i,j);
825 583 }
826   - if (tot_str != sum_flt10_str) {
827   - cout << endl << "TEST ERROR: GFitsTableFltCol::string() - 10";
828   - cout << endl << " Reference sum: " << sum_flt10_str;
  584 + if (tot_str != sum_dbl10_str) {
  585 + cout << endl << "TEST ERROR: GFitsTableDblCol::string() - 10";
  586 + cout << endl << " Reference sum: " << sum_dbl10_str;
829 587 cout << endl << " Derived sum: " << tot_str << endl;
830 588 throw;
831 589 }
832 590 cout << ".";
  591 + }
  592 + catch (exception &e) {
  593 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  594 + cout << e.what() << endl;
  595 + throw;
  596 + }
  597 + cout << ". ok." << endl;
  598 +
  599 +}
  600 +
  601 +
  602 +/***************************************************************************
  603 + * Test: single precision FITS binary table *
  604 + ***************************************************************************/
  605 +void test_bintable_float(void)
  606 +{
  607 + // Set filename
  608 + std::string filename = "test_bintable_float.fits";
  609 +
  610 + // Dump header
  611 + cout << "Test GFitsTableFltCol: ";
  612 +
  613 + // Remove FITS file
  614 + std::string cmd = "rm -rf "+ filename;
  615 + system(cmd.c_str());
  616 +
  617 + // Allocate reference sums
  618 + float sum_flt = 0.0;
  619 + float sum_flt10 = 0.0;
  620 + int sum_flt_int = 0;
  621 + int sum_flt10_int = 0;
  622 + std::string sum_flt_str;
  623 + std::string sum_flt10_str;
  624 +
  625 + // Build tables
  626 + try {
  627 + // Open FITS file
  628 + GFits fits;
  629 + fits.open(filename);
  630 +
  631 + // Set number of rows
  632 + int nrows = 10;
  633 + int nvec = 10;
  634 +
  635 + // Initial control sums
  636 + float tot_flt = 0.0;
  637 + double tot_dbl = 0.0;
  638 + int tot_int = 0;
  639 + long tot_lng = 0;
  640 + short tot_sht = 0;
  641 + std::string tot_str;
833 642  
834 643 //
835   - // ===== S H O R T =====
  644 + // ===== F L O A T =====
836 645 //
837 646  
838   - // Set short table
839   - GFitsTableShtCol col_sht = GFitsTableShtCol("SHORT", nrows);
  647 + // Set single precision table
  648 + GFitsTableFltCol col_flt = GFitsTableFltCol("FLOAT", nrows);
840 649 for (int i = 0; i < nrows; ++i) {
841   - short val_sht = short(1000.0 * cos(0.1*float(i)));
842   - col_sht(i) = val_sht;
843   - sum_sht += val_sht;
844   - sum_sht_int += int(val_sht);
  650 + float val_flt = cos(0.1*float(i));
  651 + col_flt(i) = val_flt;
  652 + sum_flt += val_flt;
  653 + sum_flt_int += int(val_flt);
845 654 ostringstream s_value;
846   - s_value << val_sht;
847   - sum_sht_str += ":"+s_value.str();
  655 + s_value << scientific << val_flt;
  656 + sum_flt_str += ":"+s_value.str();
848 657 }
849 658 cout << ".";
850 659  
851   - // Check short table (operator access)
852   - tot_sht = 0;
  660 + // Check single precision table (operator access)
  661 + tot_flt = 0.0;
853 662 for (int i = 0; i < nrows; ++i)
854   - tot_sht += col_sht(i);
855   - if (tot_sht != sum_sht) {
856   - cout << endl << "TEST ERROR: GFitsTableShtCol::operator()";
857   - cout << endl << " Reference sum: " << sum_sht;
858   - cout << endl << " Derived sum: " << tot_sht << endl;
  663 + tot_flt += col_flt(i);
  664 + if (!fequal(tot_flt, sum_flt)) {
  665 + cout << endl << "TEST ERROR: GFitsTableFltCol::operator()";
  666 + cout << endl << " Reference sum: " << sum_flt;
  667 + cout << endl << " Derived sum: " << tot_flt << endl;
859 668 throw;
860 669 }
861 670 cout << ".";
862 671  
863   - // Check short table (real access)
864   - tot_dbl = 0.0;
  672 + // Check single precision table (real access)
  673 + tot_flt = 0.0;
865 674 for (int i = 0; i < nrows; ++i)
866   - tot_dbl += col_sht.real(i);
867   - if (!dequal(tot_dbl, double(sum_sht))) {
868   - cout << endl << "TEST ERROR: GFitsTableShtCol::real()";
869   - cout << endl << " Reference sum: " << sum_sht;
870   - cout << endl << " Derived sum: " << tot_dbl << endl;
  675 + tot_flt += col_flt.real(i);
  676 + if (!fequal(tot_flt, sum_flt)) {
  677 + cout << endl << "TEST ERROR: GFitsTableFltCol::real()";
  678 + cout << endl << " Reference sum: " << sum_flt;
  679 + cout << endl << " Derived sum: " << tot_flt << endl;
871 680 throw;
872 681 }
873 682 cout << ".";
874 683  
875   - // Check short table (int access)
  684 + // Check single precision table (int access)
876 685 tot_int = 0;
877 686 for (int i = 0; i < nrows; ++i)
878   - tot_int += col_sht.integer(i);
879   - if (tot_int != sum_sht_int) {
880   - cout << endl << "TEST ERROR: GFitsTableShtCol::integer()";
881   - cout << endl << " Reference sum: " << sum_sht_int;
  687 + tot_int += col_flt.integer(i);
  688 + if (tot_int != sum_flt_int) {
  689 + cout << endl << "TEST ERROR: GFitsTableFltCol::integer()";
  690 + cout << endl << " Reference sum: " << sum_flt_int;
882 691 cout << endl << " Derived sum: " << tot_int << endl;
883 692 throw;
884 693 }
... ... @@ -887,72 +696,961 @@ void test_bin_table(void)
887 696 // Check single precision table (string access)
888 697 tot_str.clear();
889 698 for (int i = 0; i < nrows; ++i)
890   - tot_str += ":"+col_sht.string(i);
891   - if (tot_str != sum_sht_str) {
892   - cout << endl << "TEST ERROR: GFitsTableShtCol::string()";
893   - cout << endl << " Reference sum: " << sum_sht_str;
  699 + tot_str += ":"+col_flt.string(i);
  700 + if (tot_str != sum_flt_str) {
  701 + cout << endl << "TEST ERROR: GFitsTableFltCol::string()";
  702 + cout << endl << " Reference sum: " << sum_flt_str;
  703 + cout << endl << " Derived sum: " << tot_str << endl;
  704 + throw;
  705 + }
  706 + cout << ".";
  707 +
  708 + //
  709 + // ===== F L O A T 1 0 =====
  710 + //
  711 +
  712 + // Set single precision table
  713 + GFitsTableFltCol col_flt10 = GFitsTableFltCol("FLOAT10", nrows, nvec);
  714 + for (int i = 0; i < nrows; ++i) {
  715 + for (int j = 0; j < nvec; ++j) {
  716 + float val_flt = cos(0.1*float(i))*cos(0.33*float(j));
  717 + col_flt10(i,j) = val_flt;
  718 + sum_flt10 += val_flt;
  719 + sum_flt10_int += int(val_flt);
  720 + ostringstream s_value;
  721 + s_value << scientific << val_flt;
  722 + sum_flt10_str += ":"+s_value.str();
  723 + }
  724 + }
  725 + cout << ".";
  726 +
  727 + // Check single precision table (operator access)
  728 + tot_flt = 0.0;
  729 + for (int i = 0; i < nrows; ++i) {
  730 + for (int j = 0; j < nvec; ++j)
  731 + tot_flt += col_flt10(i,j);
  732 + }
  733 + if (!fequal(tot_flt, sum_flt10)) {
  734 + cout << endl << "TEST ERROR: GFitsTableFltCol::operator() - 10";
  735 + cout << endl << " Reference sum: " << sum_flt10;
  736 + cout << endl << " Derived sum: " << tot_flt << endl;
  737 + throw;
  738 + }
  739 + cout << ".";
  740 +
  741 + // Check single precision table (real access)
  742 + tot_flt = 0.0;
  743 + for (int i = 0; i < nrows; ++i) {
  744 + for (int j = 0; j < nvec; ++j)
  745 + tot_flt += col_flt10.real(i,j);
  746 + }
  747 + if (!fequal(tot_flt, sum_flt10)) {
  748 + cout << endl << "TEST ERROR: GFitsTableFltCol::real() - 10";
  749 + cout << endl << " Reference sum: " << sum_flt10;
  750 + cout << endl << " Derived sum: " << tot_flt << endl;
  751 + throw;
  752 + }
  753 + cout << ".";
  754 +
  755 + // Check double precision table (int access)
  756 + tot_int = 0;
  757 + for (int i = 0; i < nrows; ++i) {
  758 + for (int j = 0; j < nvec; ++j)
  759 + tot_int += col_flt10.integer(i,j);
  760 + }
  761 + if (tot_int != sum_flt10_int) {
  762 + cout << endl << "TEST ERROR: GFitsTableFltCol::integer() - 10";
  763 + cout << endl << " Reference sum: " << sum_flt10_int;
  764 + cout << endl << " Derived sum: " << tot_int << endl;
  765 + throw;
  766 + }
  767 + cout << ".";
  768 +
  769 + // Check single precision table (string access)
  770 + tot_str.clear();
  771 + for (int i = 0; i < nrows; ++i) {
  772 + for (int j = 0; j < nvec; ++j)
  773 + tot_str += ":"+col_flt10.string(i,j);
  774 + }
  775 + if (tot_str != sum_flt10_str) {
  776 + cout << endl << "TEST ERROR: GFitsTableFltCol::string() - 10";
  777 + cout << endl << " Reference sum: " << sum_flt10_str;
  778 + cout << endl << " Derived sum: " << tot_str << endl;
  779 + throw;
  780 + }
  781 + cout << ".";
  782 +
  783 + //
  784 + // ===== W R I T E T A B L E =====
  785 + //
  786 +
  787 + // Build binary table
  788 + GFitsBinTable table = GFitsBinTable(nrows);
  789 + table.append_column(col_flt10);
  790 + table.insert_column(0, col_flt);
  791 +
  792 + // Create HDU and append to FILE file
  793 + GFitsHDU hdu(table);
  794 + fits.append_hdu(hdu);
  795 +
  796 + // Save FITS file
  797 + fits.save();
  798 + cout << ".";
  799 + }
  800 + catch (exception &e) {
  801 + cout << endl << "TEST ERROR: Unable to test floating point column in"
  802 + " binary tables." << endl;
  803 + cout << e.what() << endl;
  804 + throw;
  805 + }
  806 + cout << ".";
  807 +
  808 +
  809 + //================================================================
  810 + //================================================================
  811 + //================================================================
  812 + // Read tables
  813 + //================================================================
  814 + //================================================================
  815 + //================================================================
  816 + try {
  817 + // Open FITS file
  818 + GFits fits;
  819 + fits.open(filename);
  820 +
  821 + // Set number of rows
  822 + int nrows = 10;
  823 + int nvec = 10;
  824 +
  825 + // Initial control sums
  826 + float tot_flt = 0.0;
  827 + double tot_dbl = 0.0;
  828 + int tot_int = 0;
  829 + std::string tot_str;
  830 +
  831 + //
  832 + // ===== F L O A T =====
  833 + //
  834 +
  835 + // Get column
  836 + GFitsTableFltCol* col_flt =
  837 + (GFitsTableFltCol*)fits.hdu(2)->column("FLOAT");
  838 +
  839 + // Check single precision table (operator access)
  840 + tot_flt = 0.0;
  841 + for (int i = 0; i < nrows; ++i)
  842 + tot_flt += (*col_flt)(i);
  843 + if (!fequal(tot_flt, sum_flt)) {
  844 + cout << endl << "TEST ERROR: GFitsTableFltCol::operator()";
  845 + cout << endl << " Reference sum: " << sum_flt;
  846 + cout << endl << " Derived sum: " << tot_flt << endl;
  847 + throw;
  848 + }
  849 + cout << ".";
  850 +
  851 + // Check single precision table (real access)
  852 + tot_flt = 0.0;
  853 + for (int i = 0; i < nrows; ++i)
  854 + tot_flt += col_flt->real(i);
  855 + if (!fequal(tot_flt, sum_flt)) {
  856 + cout << endl << "TEST ERROR: GFitsTableFltCol::real()";
  857 + cout << endl << " Reference sum: " << sum_flt;
  858 + cout << endl << " Derived sum: " << tot_flt << endl;
  859 + throw;
  860 + }
  861 + cout << ".";
  862 +
  863 + // Check single precision table (int access)
  864 + tot_int = 0;
  865 + for (int i = 0; i < nrows; ++i)
  866 + tot_int += col_flt->integer(i);
  867 + if (tot_int != sum_flt_int) {
  868 + cout << endl << "TEST ERROR: GFitsTableFltCol::integer()";
  869 + cout << endl << " Reference sum: " << sum_flt_int;
  870 + cout << endl << " Derived sum: " << tot_int << endl;
  871 + throw;
  872 + }
  873 + cout << ".";
  874 +
  875 + // Check single precision table (string access)
  876 + tot_str.clear();
  877 + for (int i = 0; i < nrows; ++i)
  878 + tot_str += ":"+col_flt->string(i);
  879 + if (tot_str != sum_flt_str) {
  880 + cout << endl << "TEST ERROR: GFitsTableFltCol::string()";
  881 + cout << endl << " Reference sum: " << sum_flt_str;
  882 + cout << endl << " Derived sum: " << tot_str << endl;
  883 + throw;
  884 + }
  885 + cout << ".";
  886 +
  887 + //
  888 + // ===== F L O A T 1 0 =====
  889 + //
  890 +
  891 + // Get column
  892 + GFitsTableFltCol* col_flt10 =
  893 + (GFitsTableFltCol*)fits.hdu(2)->column("FLOAT10");
  894 +
  895 + // Check single precision table (operator access)
  896 + tot_flt = 0.0;
  897 + for (int i = 0; i < nrows; ++i) {
  898 + for (int j = 0; j < nvec; ++j)
  899 + tot_flt += (*col_flt10)(i,j);
  900 + }
  901 + if (!fequal(tot_flt, sum_flt10)) {
  902 + cout << endl << "TEST ERROR: GFitsTableFltCol::operator() - 10";
  903 + cout << endl << " Reference sum: " << sum_flt10;
  904 + cout << endl << " Derived sum: " << tot_flt << endl;
  905 + throw;
  906 + }
  907 + cout << ".";
  908 +
  909 + // Check single precision table (real access)
  910 + tot_flt = 0.0;
  911 + for (int i = 0; i < nrows; ++i) {
  912 + for (int j = 0; j < nvec; ++j)
  913 + tot_flt += col_flt10->real(i,j);
  914 + }
  915 + if (!fequal(tot_flt, sum_flt10)) {
  916 + cout << endl << "TEST ERROR: GFitsTableFltCol::real() - 10";
  917 + cout << endl << " Reference sum: " << sum_flt10;
  918 + cout << endl << " Derived sum: " << tot_flt << endl;
  919 + throw;
  920 + }
  921 + cout << ".";
  922 +
  923 + // Check double precision table (int access)
  924 + tot_int = 0;
  925 + for (int i = 0; i < nrows; ++i) {
  926 + for (int j = 0; j < nvec; ++j)
  927 + tot_int += col_flt10->integer(i,j);
  928 + }
  929 + if (tot_int != sum_flt10_int) {
  930 + cout << endl << "TEST ERROR: GFitsTableFltCol::integer() - 10";
  931 + cout << endl << " Reference sum: " << sum_flt10_int;
  932 + cout << endl << " Derived sum: " << tot_int << endl;
  933 + throw;
  934 + }
  935 + cout << ".";
  936 +
  937 + // Check single precision table (string access)
  938 + tot_str.clear();
  939 + for (int i = 0; i < nrows; ++i) {
  940 + for (int j = 0; j < nvec; ++j)
  941 + tot_str += ":"+col_flt10->string(i,j);
  942 + }
  943 + if (tot_str != sum_flt10_str) {
  944 + cout << endl << "TEST ERROR: GFitsTableFltCol::string() - 10";
  945 + cout << endl << " Reference sum: " << sum_flt10_str;
  946 + cout << endl << " Derived sum: " << tot_str << endl;
  947 + throw;
  948 + }
  949 + cout << ".";
  950 +
  951 + }
  952 + catch (exception &e) {
  953 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  954 + cout << e.what() << endl;
  955 + throw;
  956 + }
  957 + cout << ". ok." << endl;
  958 +
  959 +}
  960 +
  961 +
  962 +/***************************************************************************
  963 + * Test: FITS binary table test *
  964 + ***************************************************************************/
  965 +void test_bintable_short(void)
  966 +{
  967 + // Set filename
  968 + std::string filename = "test_bintable_short.fits";
  969 +
  970 + // Dump header
  971 + cout << "Test GFitsTableShtCol: ";
  972 +
  973 + // Remove FITS file
  974 + std::string cmd = "rm -rf "+ filename;
  975 + system(cmd.c_str());
  976 +
  977 + // Allocate reference sums
  978 + short sum_sht = 0;
  979 + short sum_sht10 = 0;
  980 + short sum_sht_int = 0;
  981 + short sum_sht10_int = 0;
  982 + std::string sum_sht_str;
  983 + std::string sum_sht10_str;
  984 +
  985 + // Build tables
  986 + try {
  987 + // Open FITS file
  988 + GFits fits;
  989 + fits.open(filename);
  990 +
  991 + // Set number of rows
  992 + int nrows = 10;
  993 + int nvec = 10;
  994 +
  995 + // Initial control sums
  996 + float tot_flt = 0.0;
  997 + double tot_dbl = 0.0;
  998 + int tot_int = 0;
  999 + long tot_lng = 0;
  1000 + short tot_sht = 0;
  1001 + std::string tot_str;
  1002 +
  1003 + //
  1004 + // ===== S H O R T =====
  1005 + //
  1006 +
  1007 + // Set short table
  1008 + GFitsTableShtCol col_sht = GFitsTableShtCol("SHORT", nrows);
  1009 + for (int i = 0; i < nrows; ++i) {
  1010 + short val_sht = short(1000.0 * cos(0.1*float(i)));
  1011 + col_sht(i) = val_sht;
  1012 + sum_sht += val_sht;
  1013 + sum_sht_int += int(val_sht);
  1014 + ostringstream s_value;
  1015 + s_value << val_sht;
  1016 + sum_sht_str += ":"+s_value.str();
  1017 + }
  1018 + cout << ".";
  1019 +
  1020 + // Check short table (operator access)
  1021 + tot_sht = 0;
  1022 + for (int i = 0; i < nrows; ++i)
  1023 + tot_sht += col_sht(i);
  1024 + if (tot_sht != sum_sht) {
  1025 + cout << endl << "TEST ERROR: GFitsTableShtCol::operator()";
  1026 + cout << endl << " Reference sum: " << sum_sht;
  1027 + cout << endl << " Derived sum: " << tot_sht << endl;
  1028 + throw;
  1029 + }
  1030 + cout << ".";
  1031 +
  1032 + // Check short table (real access)
  1033 + tot_dbl = 0.0;
  1034 + for (int i = 0; i < nrows; ++i)
  1035 + tot_dbl += col_sht.real(i);
  1036 + if (!dequal(tot_dbl, double(sum_sht))) {
  1037 + cout << endl << "TEST ERROR: GFitsTableShtCol::real()";
  1038 + cout << endl << " Reference sum: " << sum_sht;
  1039 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1040 + throw;
  1041 + }
  1042 + cout << ".";
  1043 +
  1044 + // Check short table (int access)
  1045 + tot_int = 0;
  1046 + for (int i = 0; i < nrows; ++i)
  1047 + tot_int += col_sht.integer(i);
  1048 + if (tot_int != sum_sht_int) {
  1049 + cout << endl << "TEST ERROR: GFitsTableShtCol::integer()";
  1050 + cout << endl << " Reference sum: " << sum_sht_int;
  1051 + cout << endl << " Derived sum: " << tot_int << endl;
  1052 + throw;
  1053 + }
  1054 + cout << ".";
  1055 +
  1056 + // Check single precision table (string access)
  1057 + tot_str.clear();
  1058 + for (int i = 0; i < nrows; ++i)
  1059 + tot_str += ":"+col_sht.string(i);
  1060 + if (tot_str != sum_sht_str) {
  1061 + cout << endl << "TEST ERROR: GFitsTableShtCol::string()";
  1062 + cout << endl << " Reference sum: " << sum_sht_str;
  1063 + cout << endl << " Derived sum: " << tot_str << endl;
  1064 + throw;
  1065 + }
  1066 + cout << ".";
  1067 +
  1068 + //
  1069 + // ===== S H O R T 1 0 =====
  1070 + //
  1071 +
  1072 + // Set short table
  1073 + GFitsTableShtCol col_sht10 = GFitsTableShtCol("SHORT10", nrows, nvec);
  1074 + for (int i = 0; i < nrows; ++i) {
  1075 + for (int j = 0; j < nvec; ++j) {
  1076 + short val_sht = short(100.0*cos(0.1*float(i))*
  1077 + cos(0.33*float(j)));
  1078 + col_sht10(i,j) = val_sht;
  1079 + sum_sht10 += val_sht;
  1080 + sum_sht10_int += int(val_sht);
  1081 + ostringstream s_value;
  1082 + s_value << val_sht;
  1083 + sum_sht10_str += ":"+s_value.str();
  1084 + }
  1085 + }
  1086 + cout << ".";
  1087 +
  1088 + // Check short table (operator access)
  1089 + tot_sht = 0;
  1090 + for (int i = 0; i < nrows; ++i) {
  1091 + for (int j = 0; j < nvec; ++j)
  1092 + tot_sht += col_sht10(i,j);
  1093 + }
  1094 + if (tot_sht != sum_sht10) {
  1095 + cout << endl << "TEST ERROR: GFitsTableShtCol::operator() - 10";
  1096 + cout << endl << " Reference sum: " << sum_sht10;
  1097 + cout << endl << " Derived sum: " << tot_sht << endl;
  1098 + throw;
  1099 + }
  1100 + cout << ".";
  1101 +
  1102 + // Check short table (real access)
  1103 + tot_dbl = 0.0;
  1104 + for (int i = 0; i < nrows; ++i) {
  1105 + for (int j = 0; j < nvec; ++j)
  1106 + tot_dbl += col_sht10.real(i,j);
  1107 + }
  1108 + if (!dequal(tot_dbl, sum_sht10)) {
  1109 + cout << endl << "TEST ERROR: GFitsTableShtCol::real() - 10";
  1110 + cout << endl << " Reference sum: " << sum_sht10;
  1111 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1112 + throw;
  1113 + }
  1114 + cout << ".";
  1115 +
  1116 + // Check short table (int access)
  1117 + tot_int = 0;
  1118 + for (int i = 0; i < nrows; ++i) {
  1119 + for (int j = 0; j < nvec; ++j)
  1120 + tot_int += col_sht10.integer(i,j);
  1121 + }
  1122 + if (tot_int != sum_sht10_int) {
  1123 + cout << endl << "TEST ERROR: GFitsTableShtCol::integer() - 10";
  1124 + cout << endl << " Reference sum: " << sum_sht10_int;
  1125 + cout << endl << " Derived sum: " << tot_int << endl;
  1126 + throw;
  1127 + }
  1128 + cout << ".";
  1129 +
  1130 + // Check single precision table (string access)
  1131 + tot_str.clear();
  1132 + for (int i = 0; i < nrows; ++i) {
  1133 + for (int j = 0; j < nvec; ++j)
  1134 + tot_str += ":"+col_sht10.string(i,j);
  1135 + }
  1136 + if (tot_str != sum_sht10_str) {
  1137 + cout << endl << "TEST ERROR: GFitsTableShtCol::string() - 10";
  1138 + cout << endl << " Reference sum: " << sum_sht10_str;
  1139 + cout << endl << " Derived sum: " << tot_str << endl;
  1140 + throw;
  1141 + }
  1142 + cout << ".";
  1143 +
  1144 + //
  1145 + // ===== W R I T E T A B L E =====
  1146 + //
  1147 +
  1148 + // Build binary table
  1149 + GFitsBinTable table = GFitsBinTable(nrows);
  1150 + table.append_column(col_sht);
  1151 + table.insert_column(0, col_sht10);
  1152 +
  1153 + // Create HDU and append to FILE file
  1154 + GFitsHDU hdu(table);
  1155 + fits.append_hdu(hdu);
  1156 +
  1157 + // Save FITS file
  1158 + fits.save();
  1159 + cout << ".";
  1160 +
  1161 + }
  1162 + catch (exception &e) {
  1163 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  1164 + cout << e.what() << endl;
  1165 + throw;
  1166 + }
  1167 + cout << ".";
  1168 +
  1169 +
  1170 + //================================================================
  1171 + //================================================================
  1172 + //================================================================
  1173 + // Read tables
  1174 + //================================================================
  1175 + //================================================================
  1176 + //================================================================
  1177 + try {
  1178 + // Open FITS file
  1179 + GFits fits;
  1180 + fits.open(filename);
  1181 +
  1182 + // Set number of rows
  1183 + int nrows = 10;
  1184 + int nvec = 10;
  1185 +
  1186 + // Initial control sums
  1187 + float tot_flt = 0.0;
  1188 + short tot_sht = 0;
  1189 + double tot_dbl = 0.0;
  1190 + int tot_int = 0;
  1191 + std::string tot_str;
  1192 +
  1193 + //
  1194 + // ===== S H O R T =====
  1195 + //
  1196 +
  1197 + // Get column
  1198 + GFitsTableShtCol* col_sht =
  1199 + (GFitsTableShtCol*)fits.hdu(2)->column("SHORT");
  1200 +
  1201 + // Check short table (operator access)
  1202 + tot_sht = 0;
  1203 + for (int i = 0; i < nrows; ++i)
  1204 + tot_sht += (*col_sht)(i);
  1205 + if (tot_sht != sum_sht) {
  1206 + cout << endl << "TEST ERROR: GFitsTableShtCol::operator()";
  1207 + cout << endl << " Reference sum: " << sum_sht;
  1208 + cout << endl << " Derived sum: " << tot_sht << endl;
  1209 + throw;
  1210 + }
  1211 + cout << ".";
  1212 +
  1213 + // Check short table (real access)
  1214 + tot_dbl = 0.0;
  1215 + for (int i = 0; i < nrows; ++i)
  1216 + tot_dbl += col_sht->real(i);
  1217 + if (!dequal(tot_dbl, double(sum_sht))) {
  1218 + cout << endl << "TEST ERROR: GFitsTableShtCol::real()";
  1219 + cout << endl << " Reference sum: " << sum_sht;
  1220 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1221 + throw;
  1222 + }
  1223 + cout << ".";
  1224 +
  1225 + // Check short table (int access)
  1226 + tot_int = 0;
  1227 + for (int i = 0; i < nrows; ++i)
  1228 + tot_int += col_sht->integer(i);
  1229 + if (tot_int != sum_sht_int) {
  1230 + cout << endl << "TEST ERROR: GFitsTableShtCol::integer()";
  1231 + cout << endl << " Reference sum: " << sum_sht_int;
  1232 + cout << endl << " Derived sum: " << tot_int << endl;
  1233 + throw;
  1234 + }
  1235 + cout << ".";
  1236 +
  1237 + // Check single precision table (string access)
  1238 + tot_str.clear();
  1239 + for (int i = 0; i < nrows; ++i)
  1240 + tot_str += ":"+col_sht->string(i);
  1241 + if (tot_str != sum_sht_str) {
  1242 + cout << endl << "TEST ERROR: GFitsTableShtCol::string()";
  1243 + cout << endl << " Reference sum: " << sum_sht_str;
  1244 + cout << endl << " Derived sum: " << tot_str << endl;
  1245 + throw;
  1246 + }
  1247 + cout << ".";
  1248 +
  1249 + //
  1250 + // ===== S H O R T 1 0 =====
  1251 + //
  1252 +
  1253 + // Get column
  1254 + GFitsTableShtCol* col_sht10 =
  1255 + (GFitsTableShtCol*)fits.hdu(2)->column("SHORT10");
  1256 +
  1257 + // Check short table (operator access)
  1258 + tot_sht = 0;
  1259 + for (int i = 0; i < nrows; ++i) {
  1260 + for (int j = 0; j < nvec; ++j)
  1261 + tot_sht += (*col_sht10)(i,j);
  1262 + }
  1263 + if (tot_sht != sum_sht10) {
  1264 + cout << endl << "TEST ERROR: GFitsTableShtCol::operator() - 10";
  1265 + cout << endl << " Reference sum: " << sum_sht10;
  1266 + cout << endl << " Derived sum: " << tot_sht << endl;
  1267 + throw;
  1268 + }
  1269 + cout << ".";
  1270 +
  1271 + // Check short table (real access)
  1272 + tot_dbl = 0.0;
  1273 + for (int i = 0; i < nrows; ++i) {
  1274 + for (int j = 0; j < nvec; ++j)
  1275 + tot_dbl += col_sht10->real(i,j);
  1276 + }
  1277 + if (!dequal(tot_dbl, sum_sht10)) {
  1278 + cout << endl << "TEST ERROR: GFitsTableShtCol::real() - 10";
  1279 + cout << endl << " Reference sum: " << sum_sht10;
  1280 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1281 + throw;
  1282 + }
  1283 + cout << ".";
  1284 +
  1285 + // Check short table (int access)
  1286 + tot_int = 0;
  1287 + for (int i = 0; i < nrows; ++i) {
  1288 + for (int j = 0; j < nvec; ++j)
  1289 + tot_int += col_sht10->integer(i,j);
  1290 + }
  1291 + if (tot_int != sum_sht10_int) {
  1292 + cout << endl << "TEST ERROR: GFitsTableShtCol::integer() - 10";
  1293 + cout << endl << " Reference sum: " << sum_sht10_int;
  1294 + cout << endl << " Derived sum: " << tot_int << endl;
  1295 + throw;
  1296 + }
  1297 + cout << ".";
  1298 +
  1299 + // Check single precision table (string access)
  1300 + tot_str.clear();
  1301 + for (int i = 0; i < nrows; ++i) {
  1302 + for (int j = 0; j < nvec; ++j)
  1303 + tot_str += ":"+col_sht10->string(i,j);
  1304 + }
  1305 + if (tot_str != sum_sht10_str) {
  1306 + cout << endl << "TEST ERROR: GFitsTableShtCol::string() - 10";
  1307 + cout << endl << " Reference sum: " << sum_sht10_str;
  1308 + cout << endl << " Derived sum: " << tot_str << endl;
  1309 + throw;
  1310 + }
  1311 + cout << ".";
  1312 + }
  1313 + catch (exception &e) {
  1314 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  1315 + cout << e.what() << endl;
  1316 + throw;
  1317 + }
  1318 + cout << ". ok." << endl;
  1319 +
  1320 +}
  1321 +
  1322 +
  1323 +/***************************************************************************
  1324 + * Test: FITS binary table test *
  1325 + ***************************************************************************/
  1326 +void test_bintable_long(void)
  1327 +{
  1328 + // Set filename
  1329 + std::string filename = "test_bintable_long.fits";
  1330 +
  1331 + // Dump header
  1332 + cout << "Test GFitsTableLngCol: ";
  1333 +
  1334 + // Remove FITS file
  1335 + std::string cmd = "rm -rf "+ filename;
  1336 + system(cmd.c_str());
  1337 +
  1338 + // Allocate reference sums
  1339 + long sum_lng = 0;
  1340 + long sum_lng10 = 0;
  1341 + long sum_lng_int = 0;
  1342 + long sum_lng10_int = 0;
  1343 + std::string sum_lng_str;
  1344 + std::string sum_lng10_str;
  1345 +
  1346 + // Build tables
  1347 + try {
  1348 + // Open FITS file
  1349 + GFits fits;
  1350 + fits.open(filename);
  1351 +
  1352 + // Set number of rows
  1353 + int nrows = 10;
  1354 + int nvec = 10;
  1355 +
  1356 + // Initial control sums
  1357 + float tot_flt = 0.0;
  1358 + double tot_dbl = 0.0;
  1359 + int tot_int = 0;
  1360 + long tot_lng = 0;
  1361 + short tot_sht = 0;
  1362 + std::string tot_str;
  1363 +
  1364 + //
  1365 + // ===== L O N G =====
  1366 + //
  1367 +
  1368 + // Set long table
  1369 + GFitsTableLngCol col_lng = GFitsTableLngCol("LONG", nrows);
  1370 + for (int i = 0; i < nrows; ++i) {
  1371 + long val_lng = long(100000.0 * cos(0.1*float(i)));
  1372 + col_lng(i) = val_lng;
  1373 + sum_lng += val_lng;
  1374 + sum_lng_int += int(val_lng);
  1375 + ostringstream s_value;
  1376 + s_value << val_lng;
  1377 + sum_lng_str += ":"+s_value.str();
  1378 + }
  1379 + cout << ".";
  1380 +
  1381 + // Check long table (operator access)
  1382 + tot_lng = 0;
  1383 + for (int i = 0; i < nrows; ++i)
  1384 + tot_lng += col_lng(i);
  1385 + if (tot_lng != sum_lng) {
  1386 + cout << endl << "TEST ERROR: GFitsTableLngCol::operator()";
  1387 + cout << endl << " Reference sum: " << sum_lng;
  1388 + cout << endl << " Derived sum: " << tot_lng << endl;
  1389 + throw;
  1390 + }
  1391 + cout << ".";
  1392 +
  1393 + // Check long table (real access)
  1394 + tot_dbl = 0.0;
  1395 + for (int i = 0; i < nrows; ++i)
  1396 + tot_dbl += col_lng.real(i);
  1397 + if (!dequal(tot_dbl, double(sum_lng))) {
  1398 + cout << endl << "TEST ERROR: GFitsTableLngCol::real()";
  1399 + cout << endl << " Reference sum: " << sum_lng;
  1400 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1401 + throw;
  1402 + }
  1403 + cout << ".";
  1404 +
  1405 + // Check long table (int access)
  1406 + tot_int = 0;
  1407 + for (int i = 0; i < nrows; ++i)
  1408 + tot_int += col_lng.integer(i);
  1409 + if (tot_int != sum_lng_int) {
  1410 + cout << endl << "TEST ERROR: GFitsTableLngCol::integer()";
  1411 + cout << endl << " Reference sum: " << sum_lng_int;
  1412 + cout << endl << " Derived sum: " << tot_int << endl;
  1413 + throw;
  1414 + }
  1415 + cout << ".";
  1416 +
  1417 + // Check long table (string access)
  1418 + tot_str.clear();
  1419 + for (int i = 0; i < nrows; ++i)
  1420 + tot_str += ":"+col_lng.string(i);
  1421 + if (tot_str != sum_lng_str) {
  1422 + cout << endl << "TEST ERROR: GFitsTableLngCol::string()";
  1423 + cout << endl << " Reference sum: " << sum_lng_str;
  1424 + cout << endl << " Derived sum: " << tot_str << endl;
  1425 + throw;
  1426 + }
  1427 + cout << ".";
  1428 +
  1429 + //
  1430 + // ===== L O N G 1 0 =====
  1431 + //
  1432 +
  1433 + // Set long table
  1434 + GFitsTableLngCol col_lng10 = GFitsTableLngCol("LONG10", nrows, nvec);
  1435 + for (int i = 0; i < nrows; ++i) {
  1436 + for (int j = 0; j < nvec; ++j) {
  1437 + long val_lng = long(1000.0*cos(0.1*float(i))*
  1438 + cos(0.33*float(j)));
  1439 + col_lng10(i,j) = val_lng;
  1440 + sum_lng10 += val_lng;
  1441 + sum_lng10_int += int(val_lng);
  1442 + ostringstream s_value;
  1443 + s_value << val_lng;
  1444 + sum_lng10_str += ":"+s_value.str();
  1445 + }
  1446 + }
  1447 + cout << ".";
  1448 +
  1449 + // Check long table (operator access)
  1450 + tot_lng = 0;
  1451 + for (int i = 0; i < nrows; ++i) {
  1452 + for (int j = 0; j < nvec; ++j)
  1453 + tot_lng += col_lng10(i,j);
  1454 + }
  1455 + if (tot_lng != sum_lng10) {
  1456 + cout << endl << "TEST ERROR: GFitsTableLngCol::operator() - 10";
  1457 + cout << endl << " Reference sum: " << sum_lng10;
  1458 + cout << endl << " Derived sum: " << tot_lng << endl;
  1459 + throw;
  1460 + }
  1461 + cout << ".";
  1462 +
  1463 + // Check long table (real access)
  1464 + tot_dbl = 0.0;
  1465 + for (int i = 0; i < nrows; ++i) {
  1466 + for (int j = 0; j < nvec; ++j)
  1467 + tot_dbl += col_lng10.real(i,j);
  1468 + }
  1469 + if (!dequal(tot_dbl, sum_lng10)) {
  1470 + cout << endl << "TEST ERROR: GFitsTableLngCol::real() - 10";
  1471 + cout << endl << " Reference sum: " << sum_lng10;
  1472 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1473 + throw;
  1474 + }
  1475 + cout << ".";
  1476 +
  1477 + // Check long table (int access)
  1478 + tot_int = 0;
  1479 + for (int i = 0; i < nrows; ++i) {
  1480 + for (int j = 0; j < nvec; ++j)
  1481 + tot_int += col_lng10.integer(i,j);
  1482 + }
  1483 + if (tot_int != sum_lng10_int) {
  1484 + cout << endl << "TEST ERROR: GFitsTableLngCol::integer() - 10";
  1485 + cout << endl << " Reference sum: " << sum_lng10_int;
  1486 + cout << endl << " Derived sum: " << tot_int << endl;
  1487 + throw;
  1488 + }
  1489 + cout << ".";
  1490 +
  1491 + // Check single precision table (string access)
  1492 + tot_str.clear();
  1493 + for (int i = 0; i < nrows; ++i) {
  1494 + for (int j = 0; j < nvec; ++j)
  1495 + tot_str += ":"+col_lng10.string(i,j);
  1496 + }
  1497 + if (tot_str != sum_lng10_str) {
  1498 + cout << endl << "TEST ERROR: GFitsTableLngCol::string() - 10";
  1499 + cout << endl << " Reference sum: " << sum_lng10_str;
  1500 + cout << endl << " Derived sum: " << tot_str << endl;
  1501 + throw;
  1502 + }
  1503 + cout << ".";
  1504 +
  1505 + //
  1506 + // ===== W R I T E T A B L E =====
  1507 + //
  1508 +
  1509 + // Build binary table
  1510 + GFitsBinTable table = GFitsBinTable(nrows);
  1511 + table.append_column(col_lng);
  1512 + table.insert_column(99, col_lng10);
  1513 +
  1514 + // Create HDU and append to FILE file
  1515 + GFitsHDU hdu(table);
  1516 + fits.append_hdu(hdu);
  1517 +
  1518 + // Save FITS file
  1519 + fits.save();
  1520 + cout << ".";
  1521 + }
  1522 + catch (exception &e) {
  1523 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  1524 + cout << e.what() << endl;
  1525 + throw;
  1526 + }
  1527 + cout << ".";
  1528 +
  1529 +
  1530 + //================================================================
  1531 + //================================================================
  1532 + //================================================================
  1533 + // Read tables
  1534 + //================================================================
  1535 + //================================================================
  1536 + //================================================================
  1537 + try {
  1538 + // Open FITS file
  1539 + GFits fits;
  1540 + fits.open(filename);
  1541 +
  1542 + // Set number of rows
  1543 + int nrows = 10;
  1544 + int nvec = 10;
  1545 +
  1546 + // Initial control sums
  1547 + float tot_flt = 0.0;
  1548 + double tot_dbl = 0.0;
  1549 + int tot_int = 0;
  1550 + long tot_lng = 0;
  1551 + std::string tot_str;
  1552 +
  1553 + //
  1554 + // ===== L O N G =====
  1555 + //
  1556 +
  1557 + // Get column
  1558 + GFitsTableLngCol* col_lng =
  1559 + (GFitsTableLngCol*)fits.hdu(2)->column("LONG");
  1560 +
  1561 + // Check long table (operator access)
  1562 + tot_lng = 0;
  1563 + for (int i = 0; i < nrows; ++i)
  1564 + tot_lng += (*col_lng)(i);
  1565 + if (tot_lng != sum_lng) {
  1566 + cout << endl << "TEST ERROR: GFitsTableLngCol::operator()";
  1567 + cout << endl << " Reference sum: " << sum_lng;
  1568 + cout << endl << " Derived sum: " << tot_lng << endl;
  1569 + throw;
  1570 + }
  1571 + cout << ".";
  1572 +
  1573 + // Check long table (real access)
  1574 + tot_dbl = 0.0;
  1575 + for (int i = 0; i < nrows; ++i)
  1576 + tot_dbl += col_lng->real(i);
  1577 + if (!dequal(tot_dbl, double(sum_lng))) {
  1578 + cout << endl << "TEST ERROR: GFitsTableLngCol::real()";
  1579 + cout << endl << " Reference sum: " << sum_lng;
  1580 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1581 + throw;
  1582 + }
  1583 + cout << ".";
  1584 +
  1585 + // Check long table (int access)
  1586 + tot_int = 0;
  1587 + for (int i = 0; i < nrows; ++i)
  1588 + tot_int += col_lng->integer(i);
  1589 + if (tot_int != sum_lng_int) {
  1590 + cout << endl << "TEST ERROR: GFitsTableLngCol::integer()";
  1591 + cout << endl << " Reference sum: " << sum_lng_int;
  1592 + cout << endl << " Derived sum: " << tot_int << endl;
  1593 + throw;
  1594 + }
  1595 + cout << ".";
  1596 +
  1597 + // Check long table (string access)
  1598 + tot_str.clear();
  1599 + for (int i = 0; i < nrows; ++i)
  1600 + tot_str += ":"+col_lng->string(i);
  1601 + if (tot_str != sum_lng_str) {
  1602 + cout << endl << "TEST ERROR: GFitsTableLngCol::string()";
  1603 + cout << endl << " Reference sum: " << sum_lng_str;
894 1604 cout << endl << " Derived sum: " << tot_str << endl;
895 1605 throw;
896 1606 }
897 1607 cout << ".";
898 1608  
899 1609 //
900   - // ===== S H O R T 1 0 =====
  1610 + // ===== L O N G 1 0 =====
901 1611 //
902 1612  
903   - // Set short table
904   - GFitsTableShtCol col_sht10 = GFitsTableShtCol("SHORT10", nrows, nvec);
905   - for (int i = 0; i < nrows; ++i) {
906   - for (int j = 0; j < nvec; ++j) {
907   - short val_sht = short(100.0*cos(0.1*float(i))*
908   - cos(0.33*float(j)));
909   - col_sht10(i,j) = val_sht;
910   - sum_sht10 += val_sht;
911   - sum_sht10_int += int(val_sht);
912   - ostringstream s_value;
913   - s_value << val_sht;
914   - sum_sht10_str += ":"+s_value.str();
915   - }
916   - }
917   - cout << ".";
  1613 + // Get column
  1614 + GFitsTableLngCol* col_lng10 =
  1615 + (GFitsTableLngCol*)fits.hdu(2)->column("LONG10");
918 1616  
919   - // Check short table (operator access)
920   - tot_sht = 0;
  1617 + // Check long table (operator access)
  1618 + tot_lng = 0;
921 1619 for (int i = 0; i < nrows; ++i) {
922 1620 for (int j = 0; j < nvec; ++j)
923   - tot_sht += col_sht10(i,j);
  1621 + tot_lng += (*col_lng10)(i,j);
924 1622 }
925   - if (tot_sht != sum_sht10) {
926   - cout << endl << "TEST ERROR: GFitsTableShtCol::operator() - 10";
927   - cout << endl << " Reference sum: " << sum_sht10;
928   - cout << endl << " Derived sum: " << tot_sht << endl;
  1623 + if (tot_lng != sum_lng10) {
  1624 + cout << endl << "TEST ERROR: GFitsTableLngCol::operator() - 10";
  1625 + cout << endl << " Reference sum: " << sum_lng10;
  1626 + cout << endl << " Derived sum: " << tot_lng << endl;
929 1627 throw;
930 1628 }
931 1629 cout << ".";
932 1630  
933   - // Check short table (real access)
  1631 + // Check long table (real access)
934 1632 tot_dbl = 0.0;
935 1633 for (int i = 0; i < nrows; ++i) {
936 1634 for (int j = 0; j < nvec; ++j)
937   - tot_dbl += col_sht10.real(i,j);
  1635 + tot_dbl += col_lng10->real(i,j);
938 1636 }
939   - if (!dequal(tot_dbl, sum_sht10)) {
940   - cout << endl << "TEST ERROR: GFitsTableShtCol::real() - 10";
941   - cout << endl << " Reference sum: " << sum_sht10;
  1637 + if (!dequal(tot_dbl, sum_lng10)) {
  1638 + cout << endl << "TEST ERROR: GFitsTableLngCol::real() - 10";
  1639 + cout << endl << " Reference sum: " << sum_lng10;
942 1640 cout << endl << " Derived sum: " << tot_dbl << endl;
943 1641 throw;
944 1642 }
945 1643 cout << ".";
946 1644  
947   - // Check short table (int access)
  1645 + // Check long table (int access)
948 1646 tot_int = 0;
949 1647 for (int i = 0; i < nrows; ++i) {
950 1648 for (int j = 0; j < nvec; ++j)
951   - tot_int += col_sht10.integer(i,j);
  1649 + tot_int += col_lng10->integer(i,j);
952 1650 }
953   - if (tot_int != sum_sht10_int) {
954   - cout << endl << "TEST ERROR: GFitsTableShtCol::integer() - 10";
955   - cout << endl << " Reference sum: " << sum_sht10_int;
  1651 + if (tot_int != sum_lng10_int) {
  1652 + cout << endl << "TEST ERROR: GFitsTableLngCol::integer() - 10";
  1653 + cout << endl << " Reference sum: " << sum_lng10_int;
956 1654 cout << endl << " Derived sum: " << tot_int << endl;
957 1655 throw;
958 1656 }
... ... @@ -962,186 +1660,215 @@ void test_bin_table(void)
962 1660 tot_str.clear();
963 1661 for (int i = 0; i < nrows; ++i) {
964 1662 for (int j = 0; j < nvec; ++j)
965   - tot_str += ":"+col_sht10.string(i,j);
  1663 + tot_str += ":"+col_lng10->string(i,j);
966 1664 }
967   - if (tot_str != sum_sht10_str) {
968   - cout << endl << "TEST ERROR: GFitsTableShtCol::string() - 10";
969   - cout << endl << " Reference sum: " << sum_sht10_str;
  1665 + if (tot_str != sum_lng10_str) {
  1666 + cout << endl << "TEST ERROR: GFitsTableLngCol::string() - 10";
  1667 + cout << endl << " Reference sum: " << sum_lng10_str;
970 1668 cout << endl << " Derived sum: " << tot_str << endl;
971 1669 throw;
972 1670 }
973 1671 cout << ".";
  1672 + }
  1673 + catch (exception &e) {
  1674 + cout << endl << "TEST ERROR: Unable to build tables." << endl;
  1675 + cout << e.what() << endl;
  1676 + throw;
  1677 + }
  1678 + cout << ". ok." << endl;
  1679 +
  1680 +}
  1681 +
  1682 +
  1683 +/***************************************************************************
  1684 + * Test: FITS binary table test *
  1685 + ***************************************************************************/
  1686 +void test_bintable_string(void)
  1687 +{
  1688 + // Set filename
  1689 + std::string filename = "test_bintable_string.fits";
  1690 +
  1691 + // Dump header
  1692 + cout << "Test GFitsTableStrCol: ";
  1693 +
  1694 + // Remove FITS file
  1695 + std::string cmd = "rm -rf "+ filename;
  1696 + system(cmd.c_str());
  1697 +
  1698 + // Allocate reference sums
  1699 + std::string sum_str;
  1700 + std::string sum_str10;
  1701 + double sum_str_dbl = 0;
  1702 + double sum_str10_dbl = 0;
  1703 + double sum_str_int = 0;
  1704 + double sum_str10_int = 0;
  1705 +
  1706 + // Build tables
  1707 + try {
  1708 + // Open FITS file
  1709 + GFits fits;
  1710 + fits.open(filename);
  1711 +
  1712 + // Set number of rows
  1713 + int nrows = 10;
  1714 + int nvec = 10;
  1715 +
  1716 + // Initial control sums
  1717 + float tot_flt = 0.0;
  1718 + double tot_dbl = 0.0;
  1719 + int tot_int = 0;
  1720 + long tot_lng = 0;
  1721 + short tot_sht = 0;
  1722 + std::string tot_str;
974 1723  
975 1724 //
976   - // ===== L O N G =====
  1725 + // ===== S T R I N G =====
977 1726 //
978 1727  
979   - // Set long table
980   - GFitsTableLngCol col_lng = GFitsTableLngCol("LONG", nrows);
  1728 + // Set string table
  1729 + GFitsTableStrCol col_str = GFitsTableStrCol("STRING", nrows, 20);
981 1730 for (int i = 0; i < nrows; ++i) {
982   - long val_lng = long(100000.0 * cos(0.1*float(i)));
983   - col_lng(i) = val_lng;
984   - sum_lng += val_lng;
985   - sum_lng_int += int(val_lng);
  1731 + double val_dbl = 100.0 * cos(0.1*double(i));
986 1732 ostringstream s_value;
987   - s_value << val_lng;
988   - sum_lng_str += ":"+s_value.str();
  1733 + s_value << scientific << val_dbl;
  1734 + col_str(i) = s_value.str();
  1735 + sum_str += ":" + s_value.str();
  1736 + sum_str_dbl += val_dbl;
  1737 + sum_str_int += int(val_dbl);
989 1738 }
990 1739 cout << ".";
991 1740  
992   - // Check long table (operator access)
993   - tot_lng = 0;
  1741 + // Check string table (operator access)
  1742 + tot_str.clear();
994 1743 for (int i = 0; i < nrows; ++i)
995   - tot_lng += col_lng(i);
996   - if (tot_lng != sum_lng) {
997   - cout << endl << "TEST ERROR: GFitsTableLngCol::operator()";
998   - cout << endl << " Reference sum: " << sum_lng;
999   - cout << endl << " Derived sum: " << tot_lng << endl;
  1744 + tot_str += ":" + col_str(i);
  1745 + if (tot_str != sum_str) {
  1746 + cout << endl << "TEST ERROR: GFitsTableStrCol::operator()";
  1747 + cout << endl << " Reference sum: " << sum_str;
  1748 + cout << endl << " Derived sum: " << tot_str << endl;
1000 1749 throw;
1001 1750 }
1002 1751 cout << ".";
1003 1752  
1004   - // Check long table (real access)
  1753 + // Check string table (real access)
1005 1754 tot_dbl = 0.0;
1006 1755 for (int i = 0; i < nrows; ++i)
1007   - tot_dbl += col_lng.real(i);
1008   - if (!dequal(tot_dbl, double(sum_lng))) {
1009   - cout << endl << "TEST ERROR: GFitsTableLngCol::real()";
1010   - cout << endl << " Reference sum: " << sum_lng;
  1756 + tot_dbl += col_str.real(i);
  1757 + if (!equal(tot_dbl, sum_str_dbl, 1.0e-4)) {
  1758 + cout << endl << "TEST ERROR: GFitsTableStrCol::real()";
  1759 + cout << endl << " Reference sum: " << sum_str_dbl;
1011 1760 cout << endl << " Derived sum: " << tot_dbl << endl;
1012 1761 throw;
1013 1762 }
1014 1763 cout << ".";
1015 1764  
1016   - // Check long table (int access)
  1765 + // Check string table (int access)
1017 1766 tot_int = 0;
1018 1767 for (int i = 0; i < nrows; ++i)
1019   - tot_int += col_lng.integer(i);
1020   - if (tot_int != sum_lng_int) {
1021   - cout << endl << "TEST ERROR: GFitsTableLngCol::integer()";
1022   - cout << endl << " Reference sum: " << sum_lng_int;
  1768 + tot_int += col_str.integer(i);
  1769 + if (tot_int != sum_str_int) {
  1770 + cout << endl << "TEST ERROR: GFitsTableStrCol::integer()";
  1771 + cout << endl << " Reference sum: " << sum_str_int;
1023 1772 cout << endl << " Derived sum: " << tot_int << endl;
1024 1773 throw;
1025 1774 }
1026 1775 cout << ".";
1027 1776  
1028   - // Check long table (string access)
  1777 + // Check string table (string access)
1029 1778 tot_str.clear();
1030 1779 for (int i = 0; i < nrows; ++i)
1031   - tot_str += ":"+col_lng.string(i);
1032   - if (tot_str != sum_lng_str) {
1033   - cout << endl << "TEST ERROR: GFitsTableLngCol::string()";
1034   - cout << endl << " Reference sum: " << sum_lng_str;
  1780 + tot_str += ":"+col_str.string(i);
  1781 + if (tot_str != sum_str) {
  1782 + cout << endl << "TEST ERROR: GFitsTableStrCol::string()";
  1783 + cout << endl << " Reference sum: " << sum_str;
1035 1784 cout << endl << " Derived sum: " << tot_str << endl;
1036 1785 throw;
1037 1786 }
1038 1787 cout << ".";
1039 1788  
1040 1789 //
1041   - // ===== L O N G 1 0 =====
  1790 + // ===== S T R I N G 1 0 =====
1042 1791 //
1043 1792  
1044   - // Set long table
1045   - GFitsTableLngCol col_lng10 = GFitsTableLngCol("LONG10", nrows, nvec);
  1793 + // Set string table
  1794 + GFitsTableStrCol col_str10 = GFitsTableStrCol("STRING10", nrows, 20, nvec);
1046 1795 for (int i = 0; i < nrows; ++i) {
1047 1796 for (int j = 0; j < nvec; ++j) {
1048   - long val_lng = long(1000.0*cos(0.1*float(i))*
1049   - cos(0.33*float(j)));
1050   - col_lng10(i,j) = val_lng;
1051   - sum_lng10 += val_lng;
1052   - sum_lng10_int += int(val_lng);
  1797 + double val_dbl = 100.0 * cos(0.1*double(i)) * cos(0.3*double(j));
1053 1798 ostringstream s_value;
1054   - s_value << val_lng;
1055   - sum_lng10_str += ":"+s_value.str();
  1799 + s_value << scientific << val_dbl;
  1800 + col_str10(i,j) = s_value.str();
  1801 + sum_str10 += ":" + s_value.str();
  1802 + sum_str10_dbl += val_dbl;
  1803 + sum_str10_int += int(val_dbl);
1056 1804 }
1057 1805 }
1058 1806 cout << ".";
1059 1807  
1060   - // Check long table (operator access)
1061   - tot_lng = 0;
  1808 + // Check string table (operator access)
  1809 + tot_str.clear();
1062 1810 for (int i = 0; i < nrows; ++i) {
1063 1811 for (int j = 0; j < nvec; ++j)
1064   - tot_lng += col_lng10(i,j);
  1812 + tot_str += ":" + col_str10(i,j);
1065 1813 }
1066   - if (tot_lng != sum_lng10) {
1067   - cout << endl << "TEST ERROR: GFitsTableLngCol::operator() - 10";
1068   - cout << endl << " Reference sum: " << sum_lng10;
1069   - cout << endl << " Derived sum: " << tot_lng << endl;
  1814 + if (tot_str != sum_str10) {
  1815 + cout << endl << "TEST ERROR: GFitsTableStrCol::operator() - 10";
  1816 + cout << endl << " Reference sum: " << sum_str10;
  1817 + cout << endl << " Derived sum: " << tot_str << endl;
1070 1818 throw;
1071 1819 }
1072 1820 cout << ".";
1073 1821  
1074   - // Check long table (real access)
  1822 + // Check string table (real access)
1075 1823 tot_dbl = 0.0;
1076 1824 for (int i = 0; i < nrows; ++i) {
1077 1825 for (int j = 0; j < nvec; ++j)
1078   - tot_dbl += col_lng10.real(i,j);
  1826 + tot_dbl += col_str10.real(i,j);
1079 1827 }
1080   - if (!dequal(tot_dbl, sum_lng10)) {
1081   - cout << endl << "TEST ERROR: GFitsTableLngCol::real() - 10";
1082   - cout << endl << " Reference sum: " << sum_lng10;
  1828 + if (!equal(tot_dbl, sum_str10_dbl, 1.0e-4)) {
  1829 + cout << endl << "TEST ERROR: GFitsTableStrCol::real() - 10";
  1830 + cout << endl << " Reference sum: " << sum_str10_dbl;
1083 1831 cout << endl << " Derived sum: " << tot_dbl << endl;
1084 1832 throw;
1085 1833 }
1086 1834 cout << ".";
1087 1835  
1088   - // Check long table (int access)
  1836 + // Check string table (int access)
1089 1837 tot_int = 0;
1090 1838 for (int i = 0; i < nrows; ++i) {
1091 1839 for (int j = 0; j < nvec; ++j)
1092   - tot_int += col_lng10.integer(i,j);
  1840 + tot_int += col_str10.integer(i,j);
1093 1841 }
1094   - if (tot_int != sum_lng10_int) {
1095   - cout << endl << "TEST ERROR: GFitsTableLngCol::integer() - 10";
1096   - cout << endl << " Reference sum: " << sum_lng10_int;
  1842 + if (tot_int != sum_str10_int) {
  1843 + cout << endl << "TEST ERROR: GFitsTableStrCol::integer() - 10";
  1844 + cout << endl << " Reference sum: " << sum_str10_int;
1097 1845 cout << endl << " Derived sum: " << tot_int << endl;
1098 1846 throw;
1099 1847 }
1100 1848 cout << ".";
1101 1849  
1102   - // Check single precision table (string access)
  1850 + // Check string table (string access)
1103 1851 tot_str.clear();
1104 1852 for (int i = 0; i < nrows; ++i) {
1105 1853 for (int j = 0; j < nvec; ++j)
1106   - tot_str += ":"+col_lng10.string(i,j);
  1854 + tot_str += ":"+col_str10.string(i,j);
1107 1855 }
1108   - if (tot_str != sum_lng10_str) {
1109   - cout << endl << "TEST ERROR: GFitsTableLngCol::string() - 10";
1110   - cout << endl << " Reference sum: " << sum_lng10_str;
  1856 + if (tot_str != sum_str10) {
  1857 + cout << endl << "TEST ERROR: GFitsTableStrCol::string() - 10";
  1858 + cout << endl << " Reference sum: " << sum_str10;
1111 1859 cout << endl << " Derived sum: " << tot_str << endl;
1112 1860 throw;
1113 1861 }
1114 1862 cout << ".";
1115 1863  
1116 1864 //
1117   - // ===== S T R I N G =====
1118   - //
1119   -
1120   - // Set string table
1121   - GFitsTableStrCol col_str = GFitsTableStrCol("STRING", nrows, 20);
1122   - for (int i = 0; i < nrows; ++i) {
1123   - double val_dbl = cos(0.1*double(i));
1124   - ostringstream s_value;
1125   - s_value << scientific << val_dbl;
1126   - col_str(i) = s_value.str();
1127   - }
1128   - cout << ".";
1129   -
1130   - //
1131 1865 // ===== W R I T E T A B L E =====
1132 1866 //
1133 1867  
1134 1868 // Build binary table
1135 1869 GFitsBinTable table = GFitsBinTable(nrows);
1136   - table.append_column(col_dbl);
1137   - table.append_column(col_flt);
1138   - table.append_column(col_sht);
1139   - table.append_column(col_lng);
1140 1870 table.append_column(col_str);
1141   - table.insert_column(1, col_dbl10);
1142   - table.insert_column(1, col_flt10);
1143   - table.insert_column(0, col_sht10);
1144   - table.insert_column(99, col_lng10);
  1871 + table.append_column(col_str10);
1145 1872  
1146 1873 // Create HDU and append to FILE file
1147 1874 GFitsHDU hdu(table);
... ... @@ -1149,7 +1876,6 @@ void test_bin_table(void)
1149 1876  
1150 1877 // Save FITS file
1151 1878 fits.save();
1152   - //cout << fits;
1153 1879 cout << ".";
1154 1880 }
1155 1881 catch (exception &e) {
... ... @@ -1170,7 +1896,7 @@ void test_bin_table(void)
1170 1896 try {
1171 1897 // Open FITS file
1172 1898 GFits fits;
1173   - fits.open("test_bintables.fits");
  1899 + fits.open(filename);
1174 1900  
1175 1901 // Set number of rows
1176 1902 int nrows = 10;
... ... @@ -1183,63 +1909,128 @@ void test_bin_table(void)
1183 1909 std::string tot_str;
1184 1910  
1185 1911 //
1186   - // ===== D O U B L E =====
  1912 + // ===== S T R I N G =====
1187 1913 //
1188 1914  
1189 1915 // Get column
1190   - GFitsTableDblCol* col_dbl =
1191   - (GFitsTableDblCol*)fits.hdu(2)->column("DOUBLE");
  1916 + GFitsTableStrCol* col_str =
  1917 + (GFitsTableStrCol*)fits.hdu(2)->column("STRING");
1192 1918  
1193   - // Check double precision table (operator access)
1194   - tot_dbl = 0.0;
  1919 + // Check string table (operator access)
  1920 + tot_str.clear();
1195 1921 for (int i = 0; i < nrows; ++i)
1196   - tot_dbl += (*col_dbl)(i);
1197   - if (!dequal(tot_dbl, sum_dbl)) {
1198   - cout << endl << "TEST ERROR: GFitsTableDblCol::operator()";
1199   - cout << endl << " Reference sum: " << sum_dbl;
1200   - cout << endl << " Derived sum: " << tot_dbl << endl;
  1922 + tot_str += ":" + (*col_str)(i);
  1923 + if (tot_str != sum_str) {
  1924 + cout << endl << "TEST ERROR: GFitsTableStrCol::operator()";
  1925 + cout << endl << " Reference sum: " << sum_str;
  1926 + cout << endl << " Derived sum: " << tot_str << endl;
1201 1927 throw;
1202 1928 }
1203 1929 cout << ".";
1204 1930  
1205   - // Check double precision table (real access)
  1931 + // Check string table (real access)
1206 1932 tot_dbl = 0.0;
1207 1933 for (int i = 0; i < nrows; ++i)
1208   - tot_dbl += (*col_dbl).real(i);
1209   - if (!dequal(tot_dbl, sum_dbl)) {
1210   - cout << endl << "TEST ERROR: GFitsTableDblCol::real()";
1211   - cout << endl << " Reference sum: " << sum_dbl;
  1934 + tot_dbl += col_str->real(i);
  1935 + if (!equal(tot_dbl, sum_str_dbl, 1.0e-4)) {
  1936 + cout << endl << "TEST ERROR: GFitsTableStrCol::real()";
  1937 + cout << endl << " Reference sum: " << sum_str_dbl;
1212 1938 cout << endl << " Derived sum: " << tot_dbl << endl;
1213 1939 throw;
1214 1940 }
1215 1941 cout << ".";
1216 1942  
1217   - // Check double precision table (int access)
  1943 + // Check string table (int access)
1218 1944 tot_int = 0;
1219 1945 for (int i = 0; i < nrows; ++i)
1220   - tot_int += (*col_dbl).integer(i);
1221   - if (tot_int != sum_dbl_int) {
1222   - cout << endl << "TEST ERROR: GFitsTableDblCol::integer()";
1223   - cout << endl << " Reference sum: " << sum_dbl_int;
  1946 + tot_int += col_str->integer(i);
  1947 + if (tot_int != sum_str_int) {
  1948 + cout << endl << "TEST ERROR: GFitsTableStrCol::integer()";
  1949 + cout << endl << " Reference sum: " << sum_str_int;
1224 1950 cout << endl << " Derived sum: " << tot_int << endl;
1225 1951 throw;
1226 1952 }
1227 1953 cout << ".";
1228 1954  
1229   - // Check double precision table (string access)
  1955 + // Check string table (string access)
1230 1956 tot_str.clear();
1231 1957 for (int i = 0; i < nrows; ++i)
1232   - tot_str += ":"+ (*col_dbl).string(i);
1233   - if (tot_str != sum_dbl_str) {
1234   - cout << endl << "TEST ERROR: GFitsTableDblCol::string()";
1235   - cout << endl << " Reference sum: " << sum_dbl_str;
  1958 + tot_str += ":"+col_str->string(i);
  1959 + if (tot_str != sum_str) {
  1960 + cout << endl << "TEST ERROR: GFitsTableStrCol::string()";
  1961 + cout << endl << " Reference sum: " << sum_str;
  1962 + cout << endl << " Derived sum: " << tot_str << endl;
  1963 + throw;
  1964 + }
  1965 + cout << ".";
  1966 +
  1967 + //
  1968 + // ===== S T R I N G 1 0 =====
  1969 + //
  1970 +
  1971 + // Get column
  1972 + GFitsTableStrCol* col_str10 =
  1973 + (GFitsTableStrCol*)fits.hdu(2)->column("STRING10");
  1974 +
  1975 + // Check string table (operator access)
  1976 + tot_str.clear();
  1977 + for (int i = 0; i < nrows; ++i) {
  1978 + for (int j = 0; j < nvec; ++j)
  1979 + tot_str += ":" + (*col_str10)(i,j);
  1980 + }
  1981 + if (tot_str != sum_str10) {
  1982 + cout << endl << "TEST ERROR: GFitsTableStrCol::operator() - 10";
  1983 + cout << endl << " Reference sum: " << sum_str10;
  1984 + cout << endl << " Derived sum: " << tot_str << endl;
  1985 + throw;
  1986 + }
  1987 + cout << ".";
  1988 +
  1989 + // Check string table (real access)
  1990 + tot_dbl = 0.0;
  1991 + for (int i = 0; i < nrows; ++i) {
  1992 + for (int j = 0; j < nvec; ++j)
  1993 + tot_dbl += col_str10->real(i,j);
  1994 + }
  1995 + if (!equal(tot_dbl, sum_str10_dbl, 1.0e-4)) {
  1996 + cout << endl << "TEST ERROR: GFitsTableStrCol::real() - 10";
  1997 + cout << endl << " Reference sum: " << sum_str10_dbl;
  1998 + cout << endl << " Derived sum: " << tot_dbl << endl;
  1999 + throw;
  2000 + }
  2001 + cout << ".";
  2002 +
  2003 + // Check string table (int access)
  2004 + tot_int = 0;
  2005 + for (int i = 0; i < nrows; ++i) {
  2006 + for (int j = 0; j < nvec; ++j)
  2007 + tot_int += col_str10->integer(i,j);
  2008 + }
  2009 + if (tot_int != sum_str10_int) {
  2010 + cout << endl << "TEST ERROR: GFitsTableStrCol::integer() - 10";
  2011 + cout << endl << " Reference sum: " << sum_str10_int;
  2012 + cout << endl << " Derived sum: " << tot_int << endl;
  2013 + throw;
  2014 + }
  2015 + cout << ".";
  2016 +
  2017 + // Check string table (string access)
  2018 + tot_str.clear();
  2019 + for (int i = 0; i < nrows; ++i) {
  2020 + for (int j = 0; j < nvec; ++j)
  2021 + tot_str += ":"+col_str10->string(i,j);
  2022 + }
  2023 + if (tot_str != sum_str10) {
  2024 + cout << endl << "TEST ERROR: GFitsTableStrCol::string() - 10";
  2025 + cout << endl << " Reference sum: " << sum_str10;
1236 2026 cout << endl << " Derived sum: " << tot_str << endl;
1237 2027 throw;
1238 2028 }
1239 2029 cout << ".";
  2030 +
1240 2031 }
1241 2032 catch (exception &e) {
1242   - cout << endl << "TEST ERROR: Unable to build tables." << endl;
  2033 + cout << endl << "TEST ERROR: Unable to read tables." << endl;
1243 2034 cout << e.what() << endl;
1244 2035 throw;
1245 2036 }
... ... @@ -1247,6 +2038,7 @@ void test_bin_table(void)
1247 2038  
1248 2039 }
1249 2040  
  2041 +
1250 2042 /***************************************************************************
1251 2043 * Main test function *
1252 2044 ***************************************************************************/
... ... @@ -1261,7 +2053,12 @@ int main(void)
1261 2053 // Execute the tests
1262 2054 test_create();
1263 2055 test_image_double();
1264   - test_bin_table();
  2056 + test_bintable_double();
  2057 + test_bintable_float();
  2058 + test_bintable_short();
  2059 + test_bintable_long();
  2060 + test_bintable_string();
  2061 +
1265 2062 //test_open();
1266 2063 //test_columns();
1267 2064  
... ...