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 "dvlist.h"
|
---|
9 | #include "fitsswapper.h"
|
---|
10 | #include "fiosinit.h"
|
---|
11 | #include "swfitsdtable.h"
|
---|
12 |
|
---|
13 | #include "datatable.h"
|
---|
14 | #include "fitshdtable.h"
|
---|
15 |
|
---|
16 | void test_fdtable() ;
|
---|
17 | static long NROW = 64;
|
---|
18 | static long NPRT = 10;
|
---|
19 |
|
---|
20 | int main(int narg, char *arg[])
|
---|
21 | {
|
---|
22 | SophyaInit();
|
---|
23 | FitsIOServerInit();
|
---|
24 | if (narg < 3) {
|
---|
25 | cout << "Erreur arg/Usage: tswfits NRowTable NPRT" << endl;
|
---|
26 | return 1;
|
---|
27 | }
|
---|
28 | NROW = atoi(arg[1]);
|
---|
29 | NPRT = atoi(arg[2]);
|
---|
30 | try {
|
---|
31 | test_fdtable();
|
---|
32 | }
|
---|
33 | catch(PThrowable exc ) {
|
---|
34 | cerr << "tswfits-main() , Catched exception: \n" << exc.Msg() << endl;
|
---|
35 | }
|
---|
36 | catch(std::exception ex) {
|
---|
37 | cerr << "tswfits-main() , Catched exception ! " << (string)(ex.what()) << endl;
|
---|
38 | }
|
---|
39 | catch(...) {
|
---|
40 | cerr << "tswfits-main() , Catched ... ! " << endl;
|
---|
41 | }
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | void test_fdtable()
|
---|
47 | {
|
---|
48 | cout << "======= test_fdtable: simple SwapOnFits test ======= " << endl;
|
---|
49 | int SWSEGSZ = 4;
|
---|
50 | vector<int_8> tags;
|
---|
51 | {
|
---|
52 | cout << "1/ Creation FITSDataSwapper<double> swout(so) avec swseg.fits " << endl;
|
---|
53 | vector<string> ttype, tform, tunit;
|
---|
54 | ttype.push_back("D-Col1");
|
---|
55 | tform.push_back("D");
|
---|
56 | tunit.push_back("");
|
---|
57 | // ttype.push_back("I-Col2");
|
---|
58 | // tform.push_back("J");
|
---|
59 | // tunit.push_back("");
|
---|
60 | string tblnm = "SwapMyExt";
|
---|
61 | FitsInOutFile fiosc("!swseg.fits", FitsInOutFile::Fits_Create);
|
---|
62 | // fiosc.MoveAbsToHDU(2);
|
---|
63 | cout << " DBG-Appel CreateTable ... " << endl;
|
---|
64 | fiosc.CreateTable(BINARY_TBL, "rzbintbl", ttype, tform, tunit);
|
---|
65 | cout << " ---- Appel a FITSDataSwapper<double> --- " << endl;
|
---|
66 | FITSDataSwapper<double> swout(fiosc, 1);
|
---|
67 | SwSegDataBlock<double> swsd(swout, SWSEGSZ, 3);
|
---|
68 | // FITSDataSwapper<int_4> swout(&fiosc, 1);
|
---|
69 | // SwSegDataBlock<int_4> swsd(swout, SWSEGSZ, 3);
|
---|
70 | double * fp = swsd.GetSegment(0);
|
---|
71 | fp[0] = 6.54321; fp[1] = 65.4321; fp[2] = 654.321; fp[3] = 6543.21;
|
---|
72 | fp = swsd.GetSegment(1);
|
---|
73 | fp[0] = 2.56789; fp[1] = 25.6789; fp[2] = 256.789; fp[3] = 2567.89;
|
---|
74 | fp = swsd.GetSegment(2);
|
---|
75 | fp[0] = 12.567; fp[1] = 225.67; fp[2] = 3256.7; fp[3] = 42567.;
|
---|
76 | tags = swsd.GetSwapPosTagTable();
|
---|
77 | cout << " Les pos-tags du FITS NbTag=" << tags.size() << endl;
|
---|
78 | for (int kk=0; kk<tags.size(); kk++) cout << tags[kk] << " ," ;
|
---|
79 | cout << endl;
|
---|
80 | }
|
---|
81 | {
|
---|
82 | cout << "2/ Creation FITSDataSwapper<double> avec lecture depuis swseg.fits" << endl;
|
---|
83 | FitsInOutFile si("swseg.fits", FitsInOutFile::Fits_RO);
|
---|
84 | si.MoveAbsToHDU(2);
|
---|
85 | FITSDataSwapper<double> swin(si, 1);
|
---|
86 | SwSegDataBlock<double> swsd(swin, tags, SWSEGSZ);
|
---|
87 | cout <<"2.b/ Recopie ds SegDataBlock<double> depuis SwSegDataBlock<double> et print" << endl;
|
---|
88 | SegDataBlock<double> segd;
|
---|
89 | segd = swsd;
|
---|
90 | segd.Print(cout, 4, " ");
|
---|
91 | }
|
---|
92 |
|
---|
93 | {
|
---|
94 | cout << " ------------------------------------------------ " << endl;
|
---|
95 | cout << "3/ Creation SwFitsDataTable sur myswtable.fits " << endl;
|
---|
96 | FitsInOutFile so("!myswtable.fits", FitsInOutFile::Fits_Create);
|
---|
97 | SwFitsDataTable dt(so, 45);
|
---|
98 | // define table columns
|
---|
99 | dt.AddFloatColumn("X0_f");
|
---|
100 | dt.AddFloatColumn("X1_f");
|
---|
101 | dt.AddDoubleColumn("X0X0pX1X1_d");
|
---|
102 | cout << "3.b/ start fill " << endl;
|
---|
103 | // Fill the table
|
---|
104 | r_8 x[5];
|
---|
105 | int pmod = NROW/50;
|
---|
106 | if (pmod < 10) pmod = 10;
|
---|
107 | for(int i=0; i<NROW; i++) {
|
---|
108 | // if (i%pmod == 0) cout << " DBG - i= " << i << endl;
|
---|
109 | x[0] = (i%9)-4.; x[1] = (i/9)-3.; x[2] = x[0]*x[0]+x[1]*x[1];
|
---|
110 | dt.AddLine(x);
|
---|
111 | }
|
---|
112 | cout << "3.c/ End fill " << endl;
|
---|
113 |
|
---|
114 | // Printing table info
|
---|
115 | cout << dt ;
|
---|
116 | for(int k = 0; k<NPRT; k++)
|
---|
117 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ;
|
---|
118 |
|
---|
119 | }
|
---|
120 | {
|
---|
121 | cout << " ------------------------------------------------ " << endl;
|
---|
122 | cout << "4/ Lecture SwFitsDataTable depuis myswtable.fits " << endl;
|
---|
123 | FitsInOutFile si("myswtable.fits", FitsInOutFile::Fits_RO);
|
---|
124 | si.SkipEmptyFirstHDU();
|
---|
125 | SwFitsDataTable dt(si,40,false);
|
---|
126 | // si >> dt;
|
---|
127 | // Printing table info
|
---|
128 | cout << dt ;
|
---|
129 | for(int k = 0; k<NPRT; k++)
|
---|
130 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ;
|
---|
131 | }
|
---|
132 |
|
---|
133 | cout << "============ FIN test_fdtable ======== ======= " << endl;
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|