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