[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;
|
---|
| 12 |
|
---|
| 13 | // Open file
|
---|
| 14 | remove(fname.c_str());
|
---|
| 15 | fits_lock();
|
---|
| 16 | fits_create_file(&fptr,fname.c_str(),&fstatus);
|
---|
| 17 | fits_unlock();
|
---|
| 18 | name = "wtr";
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | FITSTOIWriter::~FITSTOIWriter() {
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | void FITSTOIWriter::addInput(string name, TOI* toi) {
|
---|
| 25 | declareInput(name);
|
---|
| 26 | fwinputs.push_back(toi);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | void FITSTOIWriter::run() {
|
---|
| 31 | cout << "fitstoiwriter running" << endl;
|
---|
| 32 | // init done here
|
---|
| 33 | delete[] inTOIs;
|
---|
| 34 | inTOIs = new (TOI*[fwinputs.size()]);
|
---|
| 35 |
|
---|
| 36 | for (int i=0; i<fwinputs.size(); i++) {
|
---|
| 37 | inTOIs[i] = fwinputs[i];
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | int ncols = inIx.size();
|
---|
| 41 |
|
---|
| 42 | char** colnames = new (char*[ncols]);
|
---|
| 43 | char** coltypes = new (char*[ncols]);
|
---|
| 44 | char** colunits = new (char*[ncols]);
|
---|
| 45 |
|
---|
| 46 | for (map<string, int>::iterator i = inIx.begin(); i != inIx.end(); i++) {
|
---|
| 47 | int j = (*i).second;
|
---|
| 48 | string n = (*i).first;
|
---|
| 49 | colnames[j] = const_cast<char*>(n.c_str());
|
---|
| 50 | coltypes[j] = "1D";
|
---|
| 51 | colunits[j] = "?";
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | fits_lock();
|
---|
| 55 | fits_create_tbl(fptr, BINARY_TBL, 0, ncols, colnames, coltypes, colunits, NULL, &fstatus);
|
---|
| 56 | fits_write_date(fptr, &fstatus);
|
---|
| 57 | fits_unlock();
|
---|
| 58 |
|
---|
| 59 | delete[] colunits;
|
---|
| 60 | delete[] coltypes;
|
---|
| 61 | delete[] colnames;
|
---|
| 62 |
|
---|
| 63 | // Add headers ?
|
---|
| 64 |
|
---|
| 65 | // loop
|
---|
| 66 |
|
---|
| 67 | int fitsLine = 1;
|
---|
| 68 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 69 | // int snb = mgr->getRequestedBegin();
|
---|
| 70 | //int sne = mgr->getRequestedEnd();
|
---|
| 71 | int snb = getMinIn();
|
---|
| 72 | int sne = getMaxIn();
|
---|
| 73 |
|
---|
| 74 | for (int sn = snb; sn <= sne; sn++) {
|
---|
| 75 | try {
|
---|
| 76 | for (int i=0; i<ncols; i++) {
|
---|
| 77 | // cout << "wtr req " << sn << endl;
|
---|
| 78 | double x = getData(i, sn);
|
---|
| 79 | // cout << "wtr got " << sn << endl;
|
---|
| 80 | fits_lock();
|
---|
| 81 | fits_write_col_dbl(fptr, i+1, fitsLine, 1, 1, &x, &fstatus);
|
---|
| 82 | if (fstatus != 0) {
|
---|
| 83 | cerr << "fitstoiwtr error sn = " << sn << " i = "<< i << endl;
|
---|
| 84 | fits_report_error(stderr, fstatus);
|
---|
| 85 | abort();
|
---|
| 86 | }
|
---|
| 87 | fits_unlock();
|
---|
| 88 | }
|
---|
| 89 | } catch (PException e) {
|
---|
| 90 | cout << "fitstoiwtr exception " << e.Msg() << endl;
|
---|
| 91 | continue;
|
---|
| 92 | }
|
---|
| 93 | fitsLine++;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | fits_lock();
|
---|
| 97 | fits_close_file(fptr, &fstatus);
|
---|
| 98 | fits_report_error(stderr, fstatus);
|
---|
| 99 | fits_unlock();
|
---|
| 100 | cout << "fitstoiwriter done" << endl;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 |
|
---|