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