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