#include "fitstoirdr.h" #include "toimanager.h" #include FITSTOIReader::FITSTOIReader(string fn) { fname = fn; allfn.push_back(fn); cout << "FITSTOIReader::FITSTOIReader" << endl; cout << "FITSTOIReader::inited " << inited << endl; name = "rdr"; fptr = NULL; totnscount = 0; } FITSTOIReader::~FITSTOIReader() { } pthread_mutex_t fits_mutex = PTHREAD_MUTEX_INITIALIZER; void fits_lock(); void fits_unlock(); void fits_lock() { pthread_mutex_lock(&fits_mutex); } void fits_unlock() { pthread_mutex_unlock(&fits_mutex); } void FITSTOIReader::openFile(string fn) { fits_lock(); if (fptr) { fits_close_file(fptr,&fstatus); fptr = NULL; } fname = fn; cout << "FITSTOIReader::open FileName=" << fname << endl; fstatus = 0; // Open file fits_open_file(&fptr,fname.c_str(),READONLY,&fstatus); if (fstatus != 0) { fits_report_error(stderr, fstatus); fits_unlock(); exit (-1); } // Go to first extension, which should be a BINTABLE int simple, bitpix, naxis; long naxes; long pcount, gcount; int extend; fits_read_imghdr(fptr, 1, &simple, &bitpix, &naxis, &naxes, &pcount, &gcount, &extend, &fstatus); fits_movabs_hdu(fptr, 2, NULL, &fstatus); fits_get_num_cols(fptr,&ncols,&fstatus); fits_get_num_rows(fptr,&nrows,&fstatus); cout << "FITSTOIReader cols = " << ncols << " rows=" << nrows << endl; int anyNul; double y; fits_read_col_dbl(fptr,1,1,1,1,0,&y,&anyNul,&fstatus); firstSn = (int) (y+.1); fits_unlock(); } void FITSTOIReader::init() { openFile(allfn.front()); fits_lock(); // Dans cette version, on s'attend a ce que la premiere colonne soit le samplenum int itoi=-1; for (int i=1; i(i,false); } } fits_unlock(); snBegin = firstSn; openFile(allfn.back()); snEnd = firstSn+nrows-1; cout << "FITSTOIReader range " << snBegin << " -> " << snEnd << endl; } int FITSTOIReader::calcMinOut() { TOIManager* mgr = TOIManager::getManager(); int firstReq = mgr->getRequestedBegin(); return snBegin > firstReq ? snBegin : firstReq; } int FITSTOIReader::calcMaxOut() { TOIManager* mgr = TOIManager::getManager(); int lastReq = mgr->getRequestedEnd(); return snEnd < lastReq ? snEnd : lastReq; } void FITSTOIReader::addFile(string fn) { allfn.push_back(fn); } void FITSTOIReader::run() { for (vector::iterator i=allfn.begin(); i!=allfn.end(); i++) { openFile(*i); run1(); } } void FITSTOIReader::run1() { // Il faudrait optimiser en fonction de ce qui a ete demande comme samplenum, // mais cela implique de gerer aussi bien echant uniforme que non. // On pourrait aussi lire plusieurs elements d'un coup. int ncols = outIx.size(); cout << "reader reading... NRows=" << nrows << " firstSn= " << firstSn << endl; for (int i=0; i mgr->getRequestedEnd()) break; if (sn < mgr->getRequestedBegin()) continue; // if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl; for (int k=0; k