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