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

Last change on this file since 1490 was 1480, checked in by aubourg, 24 years ago

join & merge

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