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

Last change on this file since 1731 was 1712, checked in by aubourg, 24 years ago

pb flags uint_8/long

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