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

Last change on this file since 1685 was 1629, checked in by ansari, 24 years ago
  • Ajout pthread_exit apres l'execution de run() ds TOIProcessor::ThreadStart()
  • Ajout de la classe ProcSampleCounter<T> pour affichage continu de stats ds toimanager.h .cc
  • correction mineure de toi2map.cc
  • Utilisation de ProcSampleCounter<T> ds tsttoi2map.cc et simtst.cc

Reza 8/8/2001

File size: 4.2 KB
Line 
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;
12 nCols = 1;
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 totnscount = 0;
22}
23
24FITSTOIWriter::~FITSTOIWriter() {
25}
26
27
28void FITSTOIWriter::addInput(string name, TOI* toi, bool withFlag) {
29 declareInput(name);
30 int iTOI = fwinputs.size();
31 fwinputs.push_back(toi);
32 colsinput[iTOI] = pair<int,bool>(nCols, withFlag);
33 nCols++;
34 if (withFlag) nCols++;
35}
36
37void FITSTOIWriter::afterinit()
38{
39 if (inTOIs) delete[] inTOIs;
40 inTOIs = new (TOI*[fwinputs.size()]);
41
42 for (int i=0; i<fwinputs.size(); i++) {
43 inTOIs[i] = fwinputs[i];
44 }
45
46}
47
48void FITSTOIWriter::run() {
49 cout << "fitstoiwriter running" << endl;
50 // init done here
51 afterinit();
52 inited=true;
53
54 int ndata = inIx.size();
55 //int ncols = inIx.size() * (outFlags ? 2 : 1) + 1;
56
57 char** colnames = new (char*[nCols]);
58 char** coltypes = new (char*[nCols]);
59 char** colunits = new (char*[nCols]);
60
61 colnames[0] = "sampleNum";
62 coltypes[0] = "1D";
63 colunits[0] = "integer";
64
65 cout << " FITSTOIWriter::run() - Creating output FITS file: "
66 << fname << endl;
67
68 string * coln = new string[nCols];
69 for (map<string, int>::iterator ii = inIx.begin(); ii != inIx.end(); ii++) {
70 int jTOI = (*ii).second;
71 pair<int,bool> p = colsinput[jTOI];
72 int ck = p.first;
73 coln[ck] = (*ii).first;
74 colnames[ck] = const_cast<char*>(coln[ck].c_str());
75 cout << " Column[" << ck << "] Name=" << coln[ck] << endl;
76 coltypes[ck] = "1D";
77 colunits[ck] = "double";
78 if (p.second) {
79 ck++;
80 coln[ck] = "fg_" + coln[ck-1];
81 colnames[ck] = const_cast<char*>(coln[ck].c_str());
82 cout << " Column[" << ck << "] -Flag- Name=" << coln[ck] << endl;
83 coltypes[ck] = "1J";
84 colunits[ck] = "UInt_8Flag";
85 }
86 }
87
88 fits_lock();
89 fits_create_tbl(fptr, BINARY_TBL, 0, nCols, colnames, coltypes, colunits, NULL, &fstatus);
90 fits_write_date(fptr, &fstatus);
91 fits_unlock();
92
93 delete[] colunits;
94 delete[] coltypes;
95 delete[] colnames;
96 delete[] coln;
97
98 // Add headers ?
99
100 // loop
101
102 int fitsLine = 1;
103 int snb = getMinIn();
104 int sne = getMaxIn();
105
106 double* tabdata = new double[ndata];
107 uint_8* tabflag = new uint_8[ndata];
108 long* tabflagl = (long*) tabflag; // il faut uint_8 == long,
109 // c'est long long dans sophya
110 bool* tabck = new bool[ndata];
111 int i;
112 for(i=0; i<ndata; i++) {
113 tabdata[i] = -9.e19; // $CHECK$ - Reza valeur par defaut !
114 tabflag[i] = 0; // $CHECK$ - Reza valeur par defaut !
115 tabck[i] = checkInputTOIIndex(i);
116 }
117
118 for (int sn = snb; sn <= sne; sn++) {
119 // if ((sn%2000 == 0) || (sn<snb+5))
120 // cout << " DBG-A-FitsWriter::run()" << sn << endl;
121 try {
122 uint_8 out_flg;
123 double out_val;
124 for (i=0; i<ndata; i++) {
125 if (tabck[i]) {
126 getData(i,sn, out_val, out_flg);
127 tabdata[i] = out_val;
128 tabflag[i] = out_flg & 0xFFFFFFFF;
129 }
130 }
131 fits_lock();
132 // if ((sn%2000 == 0) || (sn<snb+5))
133 //cout << " DBG-B-FitsWriter::run()" << sn << endl;
134 double xx = sn;
135 fits_write_col_dbl(fptr, 1, fitsLine, 1, 1, &xx, &fstatus);
136
137 for (i=0; i<ndata; i++) {
138 pair<int,bool> p = colsinput[i];
139 fits_write_col_dbl(fptr, p.first+1, fitsLine, 1, 1, tabdata+i, &fstatus);
140 if (p.second) {
141 fits_write_col_lng(fptr, p.first+2, fitsLine, 1, 1, tabflagl+i, &fstatus);
142 }
143 if (fstatus != 0) {
144 cerr << "fitstoiwtr error sn = " << sn << " i = "<< i << endl;
145 fits_report_error(stderr, fstatus);
146 abort();
147 }
148 }
149 fits_unlock();
150 // if ((sn%2000 == 0) || (sn<snb+5))
151 // cout << " DBG-C-FitsWriter::run()" << sn << " line=" << fitsLine << endl;
152 fitsLine++; totnscount++;
153 } catch (PException e) {
154 cout << "fitstoiwtr exception " << e.Msg() << endl;
155 continue;
156 }
157 }
158
159 delete[] tabdata;
160 delete[] tabflag;
161 delete[] tabck;
162
163 fits_lock();
164 fits_close_file(fptr, &fstatus);
165 fits_report_error(stderr, fstatus);
166 fits_unlock();
167 cout << "fitstoiwriter done fitsLine= " << fitsLine << endl;
168}
169
170
171
172
173
174
175
176
Note: See TracBrowser for help on using the repository browser.