source: Sophya/trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc@ 1439

Last change on this file since 1439 was 1439, checked in by ansari, 25 years ago

Correction bugs, protections, ameliorations - Reza 13/3/2001

File size: 3.3 KB
RevLine 
[1365]1#include "fitstoiwtr.h"
2#include "toimanager.h"
3
4
5
6extern void fits_lock();
7extern void fits_unlock();
8
9FITSTOIWriter::FITSTOIWriter(string fn) {
10 fname = fn;
11 fstatus = 0;
[1369]12 outFlags = false;
[1365]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
22FITSTOIWriter::~FITSTOIWriter() {
23}
24
[1369]25void FITSTOIWriter::setOutFlags(bool yn) {
26 outFlags = yn;
27}
28
[1365]29void FITSTOIWriter::addInput(string name, TOI* toi) {
30 declareInput(name);
31 fwinputs.push_back(toi);
32}
33
[1439]34void FITSTOIWriter::afterinit()
35{
36 if (inTOIs) delete[] inTOIs;
[1365]37 inTOIs = new (TOI*[fwinputs.size()]);
38
39 for (int i=0; i<fwinputs.size(); i++) {
40 inTOIs[i] = fwinputs[i];
41 }
[1439]42
43}
[1365]44
[1439]45void FITSTOIWriter::run() {
46 cout << "fitstoiwriter running" << endl;
47 // init done here
48 afterinit();
49 inited=true;
50
[1369]51 int ndata = inIx.size();
52 int ncols = inIx.size() * (outFlags ? 2 : 1) + 1;
[1365]53
54 char** colnames = new (char*[ncols]);
55 char** coltypes = new (char*[ncols]);
56 char** colunits = new (char*[ncols]);
57
[1369]58 colnames[0] = "samplenum";
59 coltypes[0] = "1D";
60 colunits[0] = "integer";
61
[1439]62 cout << " FITSTOIWriter::run() - Creating output FITS file: "
63 << name << endl;
64
65 vector<string> coln;
66 int ck=0;
[1410]67 for (map<string, int>::iterator ii = inIx.begin(); ii != inIx.end(); ii++) {
68 int j = (*ii).second;
[1439]69 coln.push_back((*ii).first);
[1369]70 if (outFlags) j += j;
[1439]71 colnames[j+1] = const_cast<char*>(coln[ck].c_str());
72 cout << " Column[" << j+1 << "] Name=" << coln[ck] << endl;
73 ck++;
[1369]74 coltypes[j+1] = "1D";
[1439]75 colunits[j+1] = "double";
[1369]76 if (outFlags) {
[1439]77 coln.push_back("fg_" + coln[ck-1]);
78 colnames[j+2] = const_cast<char*>(coln[ck].c_str());
79 cout << " Column[" << j+1 << "] -Flag- Name=" << coln[ck] << endl;
80 ck++;
[1369]81 coltypes[j+2] = "1D";
[1439]82 colunits[j+2] = "IntFlag";
[1369]83 }
[1365]84 }
85
86 fits_lock();
87 fits_create_tbl(fptr, BINARY_TBL, 0, ncols, colnames, coltypes, colunits, NULL, &fstatus);
88 fits_write_date(fptr, &fstatus);
89 fits_unlock();
90
91 delete[] colunits;
92 delete[] coltypes;
93 delete[] colnames;
94
95 // Add headers ?
96
97 // loop
98
99 int fitsLine = 1;
100 int snb = getMinIn();
101 int sne = getMaxIn();
102
103 for (int sn = snb; sn <= sne; sn++) {
104 try {
[1369]105 fits_lock();
106 double xx = sn;
107 fits_write_col_dbl(fptr, 1, fitsLine, 1, 1, &xx, &fstatus);
108 fits_unlock();
109 for (int i=0; i<ndata; i++) {
[1437]110 double x = -9.e19; // $CHECK$ - Reza valeur par defaut !
111 if (checkInputTOIIndex(i)) x = getData(i, sn);
[1365]112 fits_lock();
[1369]113 if (outFlags) {
114 fits_write_col_dbl(fptr, 2*i+2, fitsLine, 1, 1, &x, &fstatus);
[1437]115 if (checkInputTOIIndex(i)) x = getFlag(i, sn);
116 else x = -9.e19; // $CHECK$ - Reza valeur par defaut !
[1369]117 fits_write_col_dbl(fptr, 2*i+3, fitsLine, 1, 1, &x, &fstatus);
118 } else {
119 fits_write_col_dbl(fptr, i+2, fitsLine, 1, 1, &x, &fstatus);
120 }
[1365]121 if (fstatus != 0) {
122 cerr << "fitstoiwtr error sn = " << sn << " i = "<< i << endl;
123 fits_report_error(stderr, fstatus);
124 abort();
125 }
126 fits_unlock();
127 }
128 } catch (PException e) {
129 cout << "fitstoiwtr exception " << e.Msg() << endl;
130 continue;
131 }
132 fitsLine++;
133 }
134
135 fits_lock();
136 fits_close_file(fptr, &fstatus);
137 fits_report_error(stderr, fstatus);
138 fits_unlock();
139 cout << "fitstoiwriter done" << endl;
140}
141
142
143
144
145
146
147
148
Note: See TracBrowser for help on using the repository browser.