1 | // Eric Aubourg
|
---|
2 | // Christophe Magneville
|
---|
3 | // Reza Ansari
|
---|
4 | // $Id: fitsringrdr.cc,v 1.5 2003-04-17 13:47:34 cecile Exp $
|
---|
5 |
|
---|
6 | #include "fitsringrdr.h"
|
---|
7 | #include "toimanager.h"
|
---|
8 | #include <sched.h>
|
---|
9 |
|
---|
10 | extern void fits_lock();
|
---|
11 | extern void fits_unlock();
|
---|
12 |
|
---|
13 | FITSRingReader::FITSRingReader(string fn,int buff_sz) {
|
---|
14 | fname = fn;
|
---|
15 | allfn.push_back(fn);
|
---|
16 | cout<<"FITSRingReader::FITSRingReader"<<endl;
|
---|
17 | cout<<"FITSTOIReader::inited "<<inited<<" bsz="<<Buff_Sz<<endl;
|
---|
18 | name = "rdr";
|
---|
19 | fptr = NULL;
|
---|
20 | totnscount = 0;
|
---|
21 | }
|
---|
22 |
|
---|
23 | FITSRingReader::~FITSRingReader() {
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | void FITSRingReader::setBufferSize(int buffsz)
|
---|
28 | {
|
---|
29 | Buff_Sz = (buffsz>0) ? buffsz: 1024;
|
---|
30 | return;
|
---|
31 | }
|
---|
32 |
|
---|
33 | void FITSRingReader::setNRings(long n) {
|
---|
34 | nRings = n;
|
---|
35 | }
|
---|
36 |
|
---|
37 | void FITSRingReader::openFile(string fn) {
|
---|
38 | cout << "(((((((((((((((((((((((((((((((((((((((((((" << endl;
|
---|
39 |
|
---|
40 | fits_lock();
|
---|
41 | if (fptr) {
|
---|
42 | fits_close_file(fptr,&fstatus);
|
---|
43 | fptr = NULL;
|
---|
44 | }
|
---|
45 | fname = fn;
|
---|
46 | cout << "FITSRingReader::open FileName=" << fname << endl;
|
---|
47 | fstatus = 0;
|
---|
48 | // Open file
|
---|
49 | fits_open_file(&fptr,fname.c_str(),READONLY,&fstatus);
|
---|
50 | if (fstatus != 0) {
|
---|
51 | fits_report_error(stderr, fstatus);
|
---|
52 | fits_unlock();
|
---|
53 | throw IOExc("FITSRingReader::openFile() fitsio error");
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Go to first extension, which should be a BINTABLE
|
---|
57 |
|
---|
58 | int simple, bitpix, naxis;
|
---|
59 | long naxes;
|
---|
60 | long pcount, gcount;
|
---|
61 | int extend;
|
---|
62 | fits_read_imghdr(fptr, 1, &simple, &bitpix,
|
---|
63 | &naxis, &naxes, &pcount, &gcount, &extend, &fstatus);
|
---|
64 |
|
---|
65 | fits_movabs_hdu(fptr, 2, NULL, &fstatus);
|
---|
66 |
|
---|
67 | fits_get_num_rows(fptr,&nSamples,&fstatus);
|
---|
68 |
|
---|
69 | cout << "FITSRingReader nSamples = " << nSamples << endl;
|
---|
70 |
|
---|
71 | fits_unlock();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void FITSRingReader::init() {
|
---|
75 |
|
---|
76 | declareOutput("signal");
|
---|
77 | openFile(fname);
|
---|
78 | }
|
---|
79 |
|
---|
80 | int FITSRingReader::calcMinOut() {
|
---|
81 | chkinit();
|
---|
82 | TOIManager* mgr = TOIManager::getManager();
|
---|
83 | int firstReq = mgr->getRequestedBegin();
|
---|
84 | return snBegin > firstReq ? snBegin : firstReq;
|
---|
85 | }
|
---|
86 |
|
---|
87 | int FITSRingReader::calcMaxOut() {
|
---|
88 | chkinit();
|
---|
89 | TOIManager* mgr = TOIManager::getManager();
|
---|
90 | int lastReq = mgr->getRequestedEnd();
|
---|
91 | return snEnd < lastReq ? snEnd : lastReq;
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | // ajout vf 31/07/2002
|
---|
96 | bool FITSRingReader::checkSampleLimits(long& min, long& max, int pass)
|
---|
97 | {
|
---|
98 | bool sample_ok=true;
|
---|
99 | chkinit();
|
---|
100 | return TOIProcessor::checkSampleLimits(min, max, pass);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void FITSRingReader::calcSampleLimits(long& min, long& max)
|
---|
104 | {
|
---|
105 | chkinit();
|
---|
106 | cout << "calc " << name << " in " << min << " - " << max << " ; " << snBegin << " - " << snEnd << endl;
|
---|
107 |
|
---|
108 | min=min<snMin?snMin:min;
|
---|
109 | max=max>snMax?snMax:max;
|
---|
110 | snBegin=snMin;
|
---|
111 | snEnd=snMax;
|
---|
112 | cout << "calc " << name << " out " << min << " - " << max << " ; " << snBegin << " - " << snEnd << endl;
|
---|
113 | //cout << "fitstoirdr : limites temporaires calculees : " << snBegin << " , " << snEnd << endl;
|
---|
114 |
|
---|
115 | }
|
---|
116 | // fin ajout vf
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | void FITSRingReader::run() {
|
---|
121 | cout << "!!!!!!! RING " << endl;
|
---|
122 |
|
---|
123 | fits_lock();
|
---|
124 | fits_movabs_hdu(fptr, 1, NULL, &fstatus);
|
---|
125 | char commt[200];
|
---|
126 | fits_read_key(fptr, TLONG, "NCIRCLES", &nRings, commt, &fstatus);
|
---|
127 | fits_unlock();
|
---|
128 |
|
---|
129 | char xname[100],buf[100];
|
---|
130 | double theta,phi;
|
---|
131 | int anyNul;
|
---|
132 |
|
---|
133 | for (int ring = 0; ring<nRings; ring++) {
|
---|
134 | sprintf(xname, "CRing_%d", ring);
|
---|
135 |
|
---|
136 | fits_lock();
|
---|
137 | fits_movabs_hdu(fptr, ring+2, NULL, &fstatus);
|
---|
138 | strcpy(buf, "RINGDATA");
|
---|
139 | fits_read_key(fptr, TSTRING, "PDMTYPE", &buf, commt, &fstatus);
|
---|
140 | fits_read_key(fptr, TDOUBLE, "CIRTHETA", &theta, commt, &fstatus);
|
---|
141 | fits_read_key(fptr, TDOUBLE, "CIRPHI", &phi, commt, &fstatus);
|
---|
142 | fits_read_key(fptr, TDOUBLE, "CIRAPER", &aperture, commt, &fstatus);
|
---|
143 | fits_read_key(fptr, TLONG, "NSAMPLES", &nSamples, commt, &fstatus);
|
---|
144 | fits_unlock();
|
---|
145 | wontNeedBefore(ring*(nSamples+2));
|
---|
146 | cout << "!!!!!!! RING " << ring << endl;
|
---|
147 |
|
---|
148 | double data;
|
---|
149 | fits_lock();
|
---|
150 | putData(0, ring*(nSamples+2)+0,theta);
|
---|
151 | putData(0, ring*(nSamples+2)+1,phi);
|
---|
152 | fits_unlock();
|
---|
153 | for (int i=0; i<nSamples; i++) {
|
---|
154 | fits_lock();
|
---|
155 | fits_read_col_dbl(fptr,1,i+1,1,1,0,&data,&anyNul,&fstatus);
|
---|
156 | putData(0, ring*(nSamples+2)+2+i,data);
|
---|
157 | fits_unlock();
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | fits_lock();
|
---|
162 | fits_report_error(stderr, fstatus);
|
---|
163 | fits_close_file(fptr,&fstatus);
|
---|
164 | fits_unlock();
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | // affichage des limites
|
---|
169 | void FITSRingReader::printLimits()
|
---|
170 | {
|
---|
171 | cout << "fitsringrdr " << name <<" : limites calculees : " << snBegin << " , " << snEnd << endl;
|
---|
172 | }
|
---|
173 |
|
---|