1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | #include "sopnamsp.h"
|
---|
7 | #include "histinit.h"
|
---|
8 | #include "datatable.h"
|
---|
9 | #include "fitshdtable.h"
|
---|
10 |
|
---|
11 | void test_fdtable() ;
|
---|
12 |
|
---|
13 | int main(int narg, char *arg[])
|
---|
14 | {
|
---|
15 | SophyaInit();
|
---|
16 | try {
|
---|
17 | test_fdtable();
|
---|
18 | }
|
---|
19 | catch(PThrowable exc ) {
|
---|
20 | cerr << "tnt-main() , Catched exception: \n" << exc.Msg() << endl;
|
---|
21 | }
|
---|
22 | catch(std::exception ex) {
|
---|
23 | cerr << "tnt-main() , Catched exception ! " << (string)(ex.what()) << endl;
|
---|
24 | }
|
---|
25 | catch(...) {
|
---|
26 | cerr << "tnt-main() , Catched ... ! " << endl;
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | void test_fdtable()
|
---|
32 | {
|
---|
33 | int NL = 600;
|
---|
34 | cout << "======= test_fdtable: simple DataTable+FITS test ======= " << endl;
|
---|
35 | {
|
---|
36 | cout << "1/ Creating DataTable / Writing to FITS " << endl;
|
---|
37 | DataTable dt(64);
|
---|
38 | dt.AddIntegerColumn("line");
|
---|
39 | dt.AddDoubleColumn("x");
|
---|
40 | dt.AddFloatColumn("f_sin");
|
---|
41 | dt.AddDoubleColumn("f_x2");
|
---|
42 | MuTyV rec[10];
|
---|
43 | cout << " Filling ... (NLines=" << NL << ")" << endl;
|
---|
44 | for(int k = 0; k<NL; k++) {
|
---|
45 | rec[0] = k;
|
---|
46 | double x = M_PI*k/100.;
|
---|
47 | double fx = sin(x)*cos(x);
|
---|
48 | rec[1] = x+1;
|
---|
49 | rec[2] = sin(x);
|
---|
50 | rec[3] = x*x;
|
---|
51 | dt.AddLine(rec);
|
---|
52 | }
|
---|
53 | cout << dt;
|
---|
54 | cout << " Writing dt to fits file dtable.fits ... " << endl;
|
---|
55 | FitsInOutFile fios("!dtable.fits", FitsInOutFile::Fits_Create);
|
---|
56 | fios << dt;
|
---|
57 | cout << " Writing dt to fits as ASCII table with extname= ASC_DTable ... " << endl;
|
---|
58 | fios.SetDef_AscTable();
|
---|
59 | fios.SetNextExtensionName("ASC_DTable");
|
---|
60 | fios << dt;
|
---|
61 | }
|
---|
62 | {
|
---|
63 | cout << "2/ Reading DataTable from FITS " << endl;
|
---|
64 | FitsInOutFile fios("dtable.fits", FitsInOutFile::Fits_RO);
|
---|
65 | cout << fios ;
|
---|
66 | fios.MoveToNextHDU();
|
---|
67 | DataTable dtr;
|
---|
68 | fios >> dtr;
|
---|
69 | cout << dtr;
|
---|
70 | cout << "2.b/ dtr.LineHeaderToString() dtr.LineToString(k) : " << endl;
|
---|
71 | cout << dtr.LineHeaderToString() ;
|
---|
72 | for(int k = 0; k<NL; k+=NL/12)
|
---|
73 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ;
|
---|
74 | cout << "2.c/ Reading from ASCII table " << endl;
|
---|
75 | DataTable dtra;
|
---|
76 | fios >> dtra;
|
---|
77 | cout << dtra;
|
---|
78 |
|
---|
79 | }
|
---|
80 | cout << "============ FIN test_fdtable ======== ======= " << endl;
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|