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 | dt.AddStringColumn("str_line");
|
---|
43 | dt.AddComplexColumn("cmplx_cos_sin");
|
---|
44 | MuTyV rec[10];
|
---|
45 | char sbuff[32];
|
---|
46 | cout << " Filling ... (NLines=" << NL << ")" << endl;
|
---|
47 | for(int k = 0; k<NL; k++) {
|
---|
48 | rec[0] = k;
|
---|
49 | double x = M_PI*k/100.;
|
---|
50 | double fx = sin(x)*cos(x);
|
---|
51 | rec[1] = x+1;
|
---|
52 | rec[2] = sin(x);
|
---|
53 | rec[3] = x*x;
|
---|
54 | sprintf(sbuff, "SL-%d", k);
|
---|
55 | rec[4] = sbuff;
|
---|
56 | double sx = sin(x);
|
---|
57 | double cx = cos(x);
|
---|
58 | rec[5] = complex<r_4>(cx, sx);
|
---|
59 | dt.AddLine(rec);
|
---|
60 | }
|
---|
61 | cout << dt;
|
---|
62 | cout << " Writing dt to fits file dtable.fits ... " << endl;
|
---|
63 | FitsInOutFile fios("!dtable.fits", FitsInOutFile::Fits_Create);
|
---|
64 | fios << dt;
|
---|
65 | cout << " Writing dt to fits as ASCII table with extname= ASC_DTable ... " << endl;
|
---|
66 | fios.SetDef_AscTable();
|
---|
67 | fios.SetNextExtensionName("ASC_DTable");
|
---|
68 | fios << dt;
|
---|
69 | }
|
---|
70 | {
|
---|
71 | cout << "2/ Reading DataTable from FITS " << endl;
|
---|
72 | FitsInOutFile fios("dtable.fits", FitsInOutFile::Fits_RO);
|
---|
73 | cout << fios ;
|
---|
74 | fios.MoveToNextHDU();
|
---|
75 | DataTable dtr;
|
---|
76 | fios >> dtr;
|
---|
77 | cout << dtr;
|
---|
78 | cout << "2.b/ dtr.LineHeaderToString() dtr.LineToString(k) : " << endl;
|
---|
79 | cout << dtr.LineHeaderToString() << endl;
|
---|
80 | for(int k = 0; k<NL; k+=NL/12)
|
---|
81 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ;
|
---|
82 | cout << "2.c/ Reading from ASCII table " << endl;
|
---|
83 | DataTable dtra;
|
---|
84 | fios >> dtra;
|
---|
85 | cout << dtra;
|
---|
86 | cout << dtra.LineHeaderToString() << endl;
|
---|
87 | for(int k = 0; k<NL; k+=NL/12)
|
---|
88 | cout << "Line[" << k << "] " << dtra.LineToString(k) << endl ;
|
---|
89 |
|
---|
90 | }
|
---|
91 | cout << "============ FIN test_fdtable ======== ======= " << endl;
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|