1 | #include "fitstoiwtr.h"
|
---|
2 | #include "toimanager.h"
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 | extern void fits_lock();
|
---|
7 | extern void fits_unlock();
|
---|
8 |
|
---|
9 | FITSTOIWriter::FITSTOIWriter(string fn) {
|
---|
10 | fname = fn;
|
---|
11 | fstatus = 0;
|
---|
12 | outFlags = false;
|
---|
13 |
|
---|
14 | // Open file
|
---|
15 | remove(fname.c_str());
|
---|
16 | fits_lock();
|
---|
17 | fits_create_file(&fptr,fname.c_str(),&fstatus);
|
---|
18 | fits_unlock();
|
---|
19 | name = "wtr";
|
---|
20 | }
|
---|
21 |
|
---|
22 | FITSTOIWriter::~FITSTOIWriter() {
|
---|
23 | }
|
---|
24 |
|
---|
25 | void FITSTOIWriter::setOutFlags(bool yn) {
|
---|
26 | outFlags = yn;
|
---|
27 | }
|
---|
28 |
|
---|
29 | void FITSTOIWriter::addInput(string name, TOI* toi) {
|
---|
30 | declareInput(name);
|
---|
31 | fwinputs.push_back(toi);
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 | void FITSTOIWriter::run() {
|
---|
36 | cout << "fitstoiwriter running" << endl;
|
---|
37 | // init done here
|
---|
38 | delete[] inTOIs;
|
---|
39 | inTOIs = new (TOI*[fwinputs.size()]);
|
---|
40 |
|
---|
41 | for (int i=0; i<fwinputs.size(); i++) {
|
---|
42 | inTOIs[i] = fwinputs[i];
|
---|
43 | }
|
---|
44 |
|
---|
45 | int ndata = inIx.size();
|
---|
46 | int ncols = inIx.size() * (outFlags ? 2 : 1) + 1;
|
---|
47 |
|
---|
48 | char** colnames = new (char*[ncols]);
|
---|
49 | char** coltypes = new (char*[ncols]);
|
---|
50 | char** colunits = new (char*[ncols]);
|
---|
51 |
|
---|
52 | colnames[0] = "samplenum";
|
---|
53 | coltypes[0] = "1D";
|
---|
54 | colunits[0] = "integer";
|
---|
55 |
|
---|
56 | for (map<string, int>::iterator ii = inIx.begin(); ii != inIx.end(); ii++) {
|
---|
57 | int j = (*ii).second;
|
---|
58 | string n = (*ii).first;
|
---|
59 | if (outFlags) j += j;
|
---|
60 | colnames[j+1] = const_cast<char*>(n.c_str());
|
---|
61 | coltypes[j+1] = "1D";
|
---|
62 | colunits[j+1] = "?";
|
---|
63 | if (outFlags) {
|
---|
64 | colnames[j+2] = const_cast<char*>((n+"_flg").c_str());
|
---|
65 | coltypes[j+2] = "1D";
|
---|
66 | colunits[j+2] = "?";
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | fits_lock();
|
---|
71 | fits_create_tbl(fptr, BINARY_TBL, 0, ncols, colnames, coltypes, colunits, NULL, &fstatus);
|
---|
72 | fits_write_date(fptr, &fstatus);
|
---|
73 | fits_unlock();
|
---|
74 |
|
---|
75 | delete[] colunits;
|
---|
76 | delete[] coltypes;
|
---|
77 | delete[] colnames;
|
---|
78 |
|
---|
79 | // Add headers ?
|
---|
80 |
|
---|
81 | // loop
|
---|
82 |
|
---|
83 | int fitsLine = 1;
|
---|
84 | int snb = getMinIn();
|
---|
85 | int sne = getMaxIn();
|
---|
86 |
|
---|
87 | for (int sn = snb; sn <= sne; sn++) {
|
---|
88 | try {
|
---|
89 | fits_lock();
|
---|
90 | double xx = sn;
|
---|
91 | fits_write_col_dbl(fptr, 1, fitsLine, 1, 1, &xx, &fstatus);
|
---|
92 | fits_unlock();
|
---|
93 | for (int i=0; i<ndata; i++) {
|
---|
94 | double x = -9.e19; // $CHECK$ - Reza valeur par defaut !
|
---|
95 | if (checkInputTOIIndex(i)) x = getData(i, sn);
|
---|
96 | fits_lock();
|
---|
97 | if (outFlags) {
|
---|
98 | fits_write_col_dbl(fptr, 2*i+2, fitsLine, 1, 1, &x, &fstatus);
|
---|
99 | if (checkInputTOIIndex(i)) x = getFlag(i, sn);
|
---|
100 | else x = -9.e19; // $CHECK$ - Reza valeur par defaut !
|
---|
101 | fits_write_col_dbl(fptr, 2*i+3, fitsLine, 1, 1, &x, &fstatus);
|
---|
102 | } else {
|
---|
103 | fits_write_col_dbl(fptr, i+2, fitsLine, 1, 1, &x, &fstatus);
|
---|
104 | }
|
---|
105 | if (fstatus != 0) {
|
---|
106 | cerr << "fitstoiwtr error sn = " << sn << " i = "<< i << endl;
|
---|
107 | fits_report_error(stderr, fstatus);
|
---|
108 | abort();
|
---|
109 | }
|
---|
110 | fits_unlock();
|
---|
111 | }
|
---|
112 | } catch (PException e) {
|
---|
113 | cout << "fitstoiwtr exception " << e.Msg() << endl;
|
---|
114 | continue;
|
---|
115 | }
|
---|
116 | fitsLine++;
|
---|
117 | }
|
---|
118 |
|
---|
119 | fits_lock();
|
---|
120 | fits_close_file(fptr, &fstatus);
|
---|
121 | fits_report_error(stderr, fstatus);
|
---|
122 | fits_unlock();
|
---|
123 | cout << "fitstoiwriter done" << endl;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|