[1365] | 1 | #include "fitstoirdr.h"
|
---|
| 2 | #include "toimanager.h"
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | FITSTOIReader::FITSTOIReader(string fn) {
|
---|
| 7 | fname = fn;
|
---|
| 8 | cout << "FITSTOIReader::FITSTOIReader" << endl;
|
---|
| 9 | cout << "FITSTOIReader::inited " << inited << endl;
|
---|
| 10 | name = "rdr";
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | FITSTOIReader::~FITSTOIReader() {
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | pthread_mutex_t fits_mutex = PTHREAD_MUTEX_INITIALIZER;
|
---|
| 17 | void fits_lock();
|
---|
| 18 | void fits_unlock();
|
---|
| 19 |
|
---|
| 20 | void fits_lock() {
|
---|
| 21 | pthread_mutex_lock(&fits_mutex);
|
---|
| 22 | }
|
---|
| 23 | void fits_unlock() {
|
---|
| 24 | pthread_mutex_unlock(&fits_mutex);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | void FITSTOIReader::init() {
|
---|
| 28 | fits_lock();
|
---|
[1454] | 29 | cout << "FITSTOIReader::init FileName=" << fname << endl;
|
---|
[1365] | 30 | fstatus = 0;
|
---|
| 31 | // Open file
|
---|
| 32 | fits_open_file(&fptr,fname.c_str(),READONLY,&fstatus);
|
---|
| 33 | if (fstatus != 0) {
|
---|
| 34 | fits_report_error(stderr, fstatus);
|
---|
| 35 | fits_unlock();
|
---|
| 36 | exit (-1);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | // Go to first extension, which should be a BINTABLE
|
---|
| 40 |
|
---|
| 41 | int simple, bitpix, naxis;
|
---|
| 42 | long naxes;
|
---|
| 43 | long pcount, gcount;
|
---|
| 44 | int extend;
|
---|
| 45 | fits_read_imghdr(fptr, 1, &simple, &bitpix,
|
---|
| 46 | &naxis, &naxes, &pcount, &gcount, &extend, &fstatus);
|
---|
| 47 |
|
---|
| 48 | fits_movabs_hdu(fptr, 2, NULL, &fstatus);
|
---|
| 49 |
|
---|
| 50 | int ncols;
|
---|
| 51 | fits_get_num_cols(fptr,&ncols,&fstatus);
|
---|
| 52 | fits_get_num_rows(fptr,&nrows,&fstatus);
|
---|
| 53 |
|
---|
[1454] | 54 | cout << "FITSTOIReader cols = " << ncols << " rows=" << nrows << endl;
|
---|
[1365] | 55 |
|
---|
| 56 | // Dans cette version, on s'attend a ce que la premiere colonne soit le samplenum
|
---|
| 57 | for (int i=1; i<ncols; i++) {
|
---|
| 58 | char templt[10];
|
---|
| 59 | sprintf(templt, "%d", i+1);
|
---|
| 60 | char colname[200];
|
---|
| 61 | int colnum;
|
---|
| 62 | fits_get_colname(fptr, CASESEN, templt, colname, &colnum, &fstatus);
|
---|
| 63 | cout << "FITSTOIReader col " << colname << endl;
|
---|
| 64 | declareOutput(colname);
|
---|
| 65 | }
|
---|
| 66 | int anyNul;
|
---|
| 67 | double y;
|
---|
| 68 | fits_read_col_dbl(fptr,1,1,1,1,0,&y,&anyNul,&fstatus);
|
---|
| 69 | firstSn = (int) (y+.1);
|
---|
| 70 | fits_unlock();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | int FITSTOIReader::calcMinOut() {
|
---|
[1367] | 74 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 75 | int firstReq = mgr->getRequestedBegin();
|
---|
| 76 | return firstSn > firstReq ? firstSn : firstReq;
|
---|
[1365] | 77 | }
|
---|
| 78 |
|
---|
| 79 | int FITSTOIReader::calcMaxOut() {
|
---|
[1367] | 80 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 81 | int lastReq = mgr->getRequestedEnd();
|
---|
| 82 | int lastSn = firstSn + nrows - 1;
|
---|
| 83 | return lastSn < lastReq ? lastSn : lastReq;
|
---|
[1365] | 84 | }
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | void FITSTOIReader::run() {
|
---|
| 88 | // Il faudrait optimiser en fonction de ce qui a ete demande comme samplenum,
|
---|
| 89 | // mais cela implique de gerer aussi bien echant uniforme que non.
|
---|
| 90 | // On pourrait aussi lire plusieurs elements d'un coup.
|
---|
| 91 | int ncols = outIx.size();
|
---|
[1454] | 92 | cout << "reader reading... NRows=" << nrows << " firstSn= "
|
---|
| 93 | << firstSn << endl;
|
---|
[1365] | 94 | for (int i=0; i<nrows; i++) {
|
---|
| 95 | int anyNul;
|
---|
| 96 | double y;
|
---|
| 97 | fits_lock();
|
---|
| 98 | fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
|
---|
| 99 | fits_unlock();
|
---|
| 100 | int sn = (int) (y+.1);
|
---|
| 101 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 102 | if (sn > mgr->getRequestedEnd()) break;
|
---|
| 103 | if (sn < mgr->getRequestedBegin()) continue;
|
---|
[1454] | 104 | // if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl;
|
---|
[1365] | 105 | for (int j=1; j<=ncols; j++) {
|
---|
[1437] | 106 | if ( !checkOutputTOIIndex(j-1) ) continue; // Reza - Si TOI non connecte
|
---|
[1365] | 107 | fits_lock();
|
---|
| 108 | fits_read_col_dbl(fptr,j+1,i+1,1,1,0,&y,&anyNul,&fstatus);
|
---|
| 109 | fits_unlock();
|
---|
| 110 | putData(j-1, sn, y);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | cout << "reader done reading... " << pthread_self() << endl;
|
---|
| 114 | }
|
---|