source: Sophya/trunk/ArchTOIPipe/Kernel/fitstoirdr.cc@ 1368

Last change on this file since 1368 was 1367, checked in by aubourg, 25 years ago

bounds

File size: 3.0 KB
Line 
1#include "fitstoirdr.h"
2#include "toimanager.h"
3
4
5
6FITSTOIReader::FITSTOIReader(string fn) {
7 fname = fn;
8 cout << "FITSTOIReader::FITSTOIReader" << endl;
9 cout << "FITSTOIReader::inited " << inited << endl;
10 name = "rdr";
11}
12
13FITSTOIReader::~FITSTOIReader() {
14}
15
16pthread_mutex_t fits_mutex = PTHREAD_MUTEX_INITIALIZER;
17void fits_lock();
18void fits_unlock();
19
20void fits_lock() {
21 pthread_mutex_lock(&fits_mutex);
22}
23void fits_unlock() {
24 pthread_mutex_unlock(&fits_mutex);
25}
26
27void FITSTOIReader::init() {
28 fits_lock();
29 cout << "FITSTOIReader::init" << endl;
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
54 cout << "FITSTOIReader cols = " << ncols << endl;
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
73int FITSTOIReader::calcMinOut() {
74 TOIManager* mgr = TOIManager::getManager();
75 int firstReq = mgr->getRequestedBegin();
76 return firstSn > firstReq ? firstSn : firstReq;
77}
78
79int FITSTOIReader::calcMaxOut() {
80 TOIManager* mgr = TOIManager::getManager();
81 int lastReq = mgr->getRequestedEnd();
82 int lastSn = firstSn + nrows - 1;
83 return lastSn < lastReq ? lastSn : lastReq;
84}
85
86
87void 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();
92 cout << "reader reading..." << endl;
93 for (int i=0; i<nrows; i++) {
94 int anyNul;
95 double y;
96 fits_lock();
97 fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
98 fits_unlock();
99 int sn = (int) (y+.1);
100 TOIManager* mgr = TOIManager::getManager();
101 if (sn > mgr->getRequestedEnd()) break;
102 if (sn < mgr->getRequestedBegin()) continue;
103 // if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl;
104 for (int j=1; j<=ncols; j++) {
105 fits_lock();
106 fits_read_col_dbl(fptr,j+1,i+1,1,1,0,&y,&anyNul,&fstatus);
107 fits_unlock();
108 putData(j-1, sn, y);
109 }
110 }
111 cout << "reader done reading... " << pthread_self() << endl;
112}
Note: See TracBrowser for help on using the repository browser.