[2351] | 1 | // Eric Aubourg
|
---|
| 2 | // Christophe Magneville
|
---|
| 3 | // Reza Ansari
|
---|
[2360] | 4 | // $Id: fitsringrdr.cc,v 1.4 2003-04-04 14:17:03 cecile Exp $
|
---|
[2351] | 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;
|
---|
[2353] | 17 | cout<<"FITSTOIReader::inited "<<inited<<" bsz="<<Buff_Sz<<endl;
|
---|
[2351] | 18 | name = "rdr";
|
---|
| 19 | fptr = NULL;
|
---|
[2353] | 20 | totnscount = 0;
|
---|
[2351] | 21 | }
|
---|
| 22 |
|
---|
| 23 | FITSRingReader::~FITSRingReader() {
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
[2353] | 27 | void FITSRingReader::setBufferSize(int buffsz)
|
---|
| 28 | {
|
---|
| 29 | Buff_Sz = (buffsz>0) ? buffsz: 1024;
|
---|
| 30 | return;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[2360] | 33 | void FITSRingReader::setNRings(long n) {
|
---|
| 34 | nRings = n;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[2351] | 37 | void FITSRingReader::openFile(string fn) {
|
---|
[2353] | 38 | cout << "(((((((((((((((((((((((((((((((((((((((((((" << endl;
|
---|
| 39 |
|
---|
[2351] | 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 |
|
---|
[2359] | 67 | fits_get_num_rows(fptr,&nSamples,&fstatus);
|
---|
[2351] | 68 |
|
---|
| 69 | cout << "FITSRingReader nSamples = " << nSamples << endl;
|
---|
| 70 |
|
---|
| 71 | fits_unlock();
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void FITSRingReader::init() {
|
---|
| 75 |
|
---|
| 76 | declareOutput("CircTheta");
|
---|
| 77 | declareOutput("CircPhi");
|
---|
| 78 | declareOutput("signal");
|
---|
[2359] | 79 | openFile(fname);
|
---|
[2351] | 80 | }
|
---|
[2353] | 81 |
|
---|
| 82 | int FITSRingReader::calcMinOut() {
|
---|
| 83 | chkinit();
|
---|
| 84 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 85 | int firstReq = mgr->getRequestedBegin();
|
---|
| 86 | return snBegin > firstReq ? snBegin : firstReq;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | int FITSRingReader::calcMaxOut() {
|
---|
| 90 | chkinit();
|
---|
| 91 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 92 | int lastReq = mgr->getRequestedEnd();
|
---|
| 93 | return snEnd < lastReq ? snEnd : lastReq;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | // ajout vf 31/07/2002
|
---|
| 98 | bool FITSRingReader::checkSampleLimits(long& min, long& max, int pass)
|
---|
| 99 | {
|
---|
| 100 | bool sample_ok=true;
|
---|
| 101 | chkinit();
|
---|
| 102 | return TOIProcessor::checkSampleLimits(min, max, pass);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | void FITSRingReader::calcSampleLimits(long& min, long& max)
|
---|
| 106 | {
|
---|
| 107 | chkinit();
|
---|
| 108 | cout << "calc " << name << " in " << min << " - " << max << " ; " << snBegin << " - " << snEnd << endl;
|
---|
| 109 |
|
---|
| 110 | min=min<snMin?snMin:min;
|
---|
| 111 | max=max>snMax?snMax:max;
|
---|
| 112 | snBegin=snMin;
|
---|
| 113 | snEnd=snMax;
|
---|
| 114 | cout << "calc " << name << " out " << min << " - " << max << " ; " << snBegin << " - " << snEnd << endl;
|
---|
| 115 | //cout << "fitstoirdr : limites temporaires calculees : " << snBegin << " , " << snEnd << endl;
|
---|
| 116 |
|
---|
| 117 | }
|
---|
| 118 | // fin ajout vf
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 |
|
---|
[2351] | 122 | void FITSRingReader::run() {
|
---|
| 123 |
|
---|
| 124 | fits_lock();
|
---|
[2359] | 125 | fits_movabs_hdu(fptr, 1, NULL, &fstatus);
|
---|
| 126 | char commt[200];
|
---|
| 127 | fits_read_key(fptr, TLONG, "NCIRCLES", &nRings, commt, &fstatus);
|
---|
[2351] | 128 | fits_unlock();
|
---|
| 129 |
|
---|
| 130 | char xname[100],buf[100];
|
---|
| 131 | double theta,phi;
|
---|
| 132 | int anyNul;
|
---|
| 133 |
|
---|
| 134 | for (int ring = 0; ring<nRings; ring++) {
|
---|
| 135 | sprintf(xname, "CRing_%d", ring);
|
---|
| 136 |
|
---|
| 137 | fits_lock();
|
---|
| 138 | fits_movabs_hdu(fptr, ring+2, NULL, &fstatus);
|
---|
| 139 | strcpy(buf, "RINGDATA");
|
---|
[2359] | 140 | fits_read_key(fptr, TSTRING, "PDMTYPE", &buf, commt, &fstatus);
|
---|
| 141 | fits_read_key(fptr, TDOUBLE, "CIRTHETA", &theta, commt, &fstatus);
|
---|
| 142 | fits_read_key(fptr, TDOUBLE, "CIRPHI", &phi, commt, &fstatus);
|
---|
| 143 | fits_read_key(fptr, TDOUBLE, "CIRAPER", &aperture, commt, &fstatus);
|
---|
| 144 | fits_read_key(fptr, TLONG, "NSAMPLES", &nSamples, commt, &fstatus);
|
---|
[2351] | 145 | fits_unlock();
|
---|
[2360] | 146 | wontNeedBefore(ring*nSamples);
|
---|
| 147 | cout << "!!!!!!! RING " << ring << endl;
|
---|
| 148 |
|
---|
[2351] | 149 | for (int i=0; i<nSamples; i++) {
|
---|
| 150 | double data;
|
---|
| 151 | fits_lock();
|
---|
| 152 | fits_read_col_dbl(fptr,1,i+1,1,1,0,&data,&anyNul,&fstatus);
|
---|
| 153 | putData(0, ring*nSamples+i,theta);
|
---|
| 154 | putData(1, ring*nSamples+i,phi);
|
---|
| 155 | putData(2, ring*nSamples+i,data);
|
---|
| 156 | fits_unlock();
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | fits_lock();
|
---|
[2360] | 161 | fits_report_error(stderr, fstatus);
|
---|
| 162 | fits_close_file(fptr,&fstatus);
|
---|
[2351] | 163 | fits_unlock();
|
---|
| 164 | }
|
---|
[2353] | 165 |
|
---|
| 166 |
|
---|
| 167 | // affichage des limites
|
---|
| 168 | void FITSRingReader::printLimits()
|
---|
| 169 | {
|
---|
| 170 | cout << "fitsringrdr " << name <<" : limites calculees : " << snBegin << " , " << snEnd << endl;
|
---|
| 171 | }
|
---|
| 172 |
|
---|