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