| 1 | //                               Eric Aubourg
 | 
|---|
| 2 | //                               Christophe Magneville
 | 
|---|
| 3 | //                               Reza Ansari
 | 
|---|
| 4 | // $Id: fitsringrdr.cc,v 1.7 2003-10-13 20:48:36 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 | /*
 | 
|---|
| 34 | void FITSRingReader::setNRings(long n) {
 | 
|---|
| 35 |   nRings = n;
 | 
|---|
| 36 |   }*/
 | 
|---|
| 37 | 
 | 
|---|
| 38 | void FITSRingReader::openFile(string fn) {
 | 
|---|
| 39 |   cout << "(((((((((((((((((((((((((((((((((((((((((((" << endl;
 | 
|---|
| 40 |   
 | 
|---|
| 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 |   
 | 
|---|
| 68 |   fits_get_num_rows(fptr,&nSamples,&fstatus);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   cout << "FITSRingReader nSamples = " << nSamples << endl;  
 | 
|---|
| 71 |  
 | 
|---|
| 72 |   fits_unlock();  
 | 
|---|
| 73 | }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | void FITSRingReader::init() {
 | 
|---|
| 76 | 
 | 
|---|
| 77 |   declareOutput("signal");
 | 
|---|
| 78 |   openFile(fname);  
 | 
|---|
| 79 | }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | long FITSRingReader::calcMinOut() {
 | 
|---|
| 82 |   chkinit();
 | 
|---|
| 83 |   TOIManager* mgr = TOIManager::getManager();
 | 
|---|
| 84 |   long firstReq = mgr->getRequestedBegin();
 | 
|---|
| 85 |   return snBegin > firstReq ? snBegin : firstReq;
 | 
|---|
| 86 | }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | long FITSRingReader::calcMaxOut() {
 | 
|---|
| 89 |   chkinit();
 | 
|---|
| 90 |   TOIManager* mgr = TOIManager::getManager();
 | 
|---|
| 91 |   long lastReq = mgr->getRequestedEnd();
 | 
|---|
| 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 | 
 | 
|---|
| 121 | void FITSRingReader::run() {
 | 
|---|
| 122 |     cout << "!!!!!!! RING " <<  endl;
 | 
|---|
| 123 | 
 | 
|---|
| 124 |   fits_lock();
 | 
|---|
| 125 |   fits_movabs_hdu(fptr, 1, NULL, &fstatus);
 | 
|---|
| 126 |   char commt[200];
 | 
|---|
| 127 |   fits_read_key(fptr, TLONG,   "NCIRCLES", &nRings, commt, &fstatus);
 | 
|---|
| 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");
 | 
|---|
| 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);
 | 
|---|
| 145 |     fits_unlock();
 | 
|---|
| 146 |     wontNeedBefore(ring*(nSamples+2));
 | 
|---|
| 147 |     cout << "!!!!!!! RING " << ring << endl;
 | 
|---|
| 148 |     
 | 
|---|
| 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();      
 | 
|---|
| 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);
 | 
|---|
| 157 |       putData(0, ring*(nSamples+2)+2+i,data);
 | 
|---|
| 158 |       fits_unlock();      
 | 
|---|
| 159 |     }
 | 
|---|
| 160 |   }
 | 
|---|
| 161 |   
 | 
|---|
| 162 |   fits_lock();
 | 
|---|
| 163 |   fits_report_error(stderr, fstatus);
 | 
|---|
| 164 |   fits_close_file(fptr,&fstatus);
 | 
|---|
| 165 |   fits_unlock();
 | 
|---|
| 166 | }
 | 
|---|
| 167 | 
 | 
|---|
| 168 | 
 | 
|---|
| 169 | // affichage des limites
 | 
|---|
| 170 | void FITSRingReader::printLimits()
 | 
|---|
| 171 | {
 | 
|---|
| 172 |   cout << "fitsringrdr " << name <<" : limites calculees : " << snBegin << " , " << snEnd << endl;
 | 
|---|
| 173 | }
 | 
|---|
| 174 | 
 | 
|---|