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