[1723] | 1 | //#define TOISEQBUFFERED
|
---|
| 2 |
|
---|
[1463] | 3 | #include <unistd.h>
|
---|
| 4 | #include <stdexcept>
|
---|
[1498] | 5 | #include <stdlib.h>
|
---|
| 6 | #include <stdio.h>
|
---|
[1463] | 7 | #include "toi.h"
|
---|
| 8 | #include "toiprocessor.h"
|
---|
| 9 | #include "fitstoirdr.h"
|
---|
| 10 | #include "fitstoiwtr.h"
|
---|
| 11 | #include "toimanager.h"
|
---|
[1723] | 12 | #ifdef TOISEQBUFFERED
|
---|
[1463] | 13 | #include "toiseqbuff.h"
|
---|
[1723] | 14 | #else
|
---|
| 15 | #include "toisegment.h"
|
---|
| 16 | #endif
|
---|
[1463] | 17 |
|
---|
| 18 | #include "sambainit.h"
|
---|
| 19 | #include "toi2map.h"
|
---|
[1723] | 20 | #include "fitsspherehealpix.h"
|
---|
[1463] | 21 | #include "timing.h"
|
---|
| 22 |
|
---|
| 23 | void usage(void);
|
---|
| 24 | void usage(void) {
|
---|
| 25 | cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
|
---|
[1498] | 26 | <<" [-a label_coord1] [-d label_coord2] [-b label_bolomuv]"<<endl
|
---|
[1516] | 27 | <<" [-n nlat] [-i c,h] [-o c,h]"<<endl
|
---|
[1530] | 28 | <<" [-m vmin] [-M vmax] [-f flag]"<<endl
|
---|
[1516] | 29 | <<" fitsin_point fitsin_bolo fitsphout [fitsphwout]"<<endl
|
---|
| 30 | <<" -p lp : print level (def=0)"<<endl
|
---|
| 31 | <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
|
---|
| 32 | <<" -w data_window_size : window size for pipe (def=8192)"<<endl
|
---|
| 33 | <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
|
---|
| 34 | <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
|
---|
| 35 | <<" coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
|
---|
| 36 | <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
|
---|
| 37 | <<" -n nlat : nlat for Healpix sphere (def=128)"<<endl
|
---|
[1530] | 38 | <<" -i c,h : coordIn caracteristics (c=G/E h=H/D/R) (def=G,D)"<<endl
|
---|
[1520] | 39 | <<" -o c,h : idem -i for coordOut"<<endl
|
---|
[1530] | 40 | <<" -m vmin : samples are good if sample value >= vmin"<<endl
|
---|
| 41 | <<" -M vmax : samples are good if sample value <= vmax"<<endl
|
---|
| 42 | <<" -f flag : samples are bad if match flag"<<endl
|
---|
[1516] | 43 | <<" fitsin_point : fits file for pointing"<<endl
|
---|
| 44 | <<" fitsin_bolo : fits file for bolo values"<<endl
|
---|
| 45 | <<" fitsphout : fits file for output Healpix sphere"<<endl
|
---|
| 46 | <<" fitsphwout : fits file for output Healpix nFilled sphere (def=no)"<<endl;
|
---|
[1463] | 47 | }
|
---|
| 48 |
|
---|
[1516] | 49 | unsigned long typecoord(char typc=' ',char hd=' ');
|
---|
| 50 | unsigned long typecoord(char typc,char hd)
|
---|
| 51 | // typc : G=galactiques, E=equatoriales, autres=galactiques
|
---|
[1530] | 52 | // hd : H=heure, D=degre, R=radian, autres=(heure si typc==E, degre si typc==G)
|
---|
[1516] | 53 | {
|
---|
| 54 | if(typc!='G' && typc!='E') typc='G';
|
---|
[1530] | 55 | if(hd!='H' && hd!='D' && hd!='R') {if(typc=='E') hd='H'; else hd='D';}
|
---|
[1516] | 56 | unsigned long rc=TypCoordUndef;
|
---|
| 57 | if(typc=='G') rc |= TypCoordGal;
|
---|
| 58 | else rc |= TypCoordEq;
|
---|
[1530] | 59 | if(hd=='D') rc |= TypCoordDD;
|
---|
| 60 | else if(hd=='R') rc |= TypCoordRR;
|
---|
| 61 | else rc |= TypCoordHD;
|
---|
[1516] | 62 | return rc;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[1463] | 65 | ////////////////////////////////////////////////////////////////
|
---|
| 66 | int main(int narg, char** arg) {
|
---|
| 67 |
|
---|
| 68 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 69 |
|
---|
| 70 | //-- Decodage arguments
|
---|
| 71 | int lp = 0, width = 8192;
|
---|
| 72 | int nlat = 128; // npixel = 12 * nlat^2
|
---|
[1530] | 73 | bool tflg=false, tmin=false, tmax=false;
|
---|
[1536] | 74 | r_8 vmin=-1.e30, vmax=1.e30; uint_8 badflg=0;
|
---|
[1530] | 75 | char *label_coord1 = "coord1", *label_coord2 = "coord2"
|
---|
| 76 | , *label_bolomuv = "boloMuV";
|
---|
[1463] | 77 | long sdeb,sfin;
|
---|
[1516] | 78 | string fitsphwout = "";
|
---|
| 79 | unsigned long tcoorin=typecoord(), tcoorout=typecoord();
|
---|
| 80 | int c; char t=' ',h=' ';
|
---|
[1530] | 81 | while((c = getopt(narg,arg,"hp:s:w:a:d:b:n:i:o:m:M:f:")) != -1) {
|
---|
[1463] | 82 | switch (c) {
|
---|
| 83 | case 's' :
|
---|
| 84 | sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
|
---|
| 85 | cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
|
---|
| 86 | if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
|
---|
[1516] | 87 | else {cout<<"Bad sample interval "<<endl; exit(2);}
|
---|
[1463] | 88 | break;
|
---|
| 89 | case 'w' :
|
---|
| 90 | sscanf(optarg,"%d",&width);
|
---|
| 91 | if(width<=0) width=8192;
|
---|
| 92 | cout<<"Data window size "<<width<<endl;
|
---|
| 93 | break;
|
---|
| 94 | case 'p' :
|
---|
| 95 | sscanf(optarg,"%d",&lp);
|
---|
| 96 | if(lp<0) lp=0;
|
---|
| 97 | break;
|
---|
| 98 | case 'a' :
|
---|
[1498] | 99 | label_coord1 = optarg;
|
---|
[1463] | 100 | break;
|
---|
| 101 | case 'd' :
|
---|
[1498] | 102 | label_coord2 = optarg;
|
---|
[1463] | 103 | break;
|
---|
| 104 | case 'b' :
|
---|
| 105 | label_bolomuv = optarg;
|
---|
| 106 | break;
|
---|
| 107 | case 'n' :
|
---|
| 108 | sscanf(optarg,"%d",&nlat);
|
---|
| 109 | if(nlat<0) nlat=128;
|
---|
| 110 | break;
|
---|
[1516] | 111 | case 'i' :
|
---|
| 112 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
| 113 | tcoorin=typecoord(t,h);
|
---|
| 114 | break;
|
---|
| 115 | case 'o' :
|
---|
| 116 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
| 117 | tcoorout=typecoord(t,h);
|
---|
| 118 | break;
|
---|
[1530] | 119 | case 'm' :
|
---|
| 120 | sscanf(optarg,"%lf",&vmin);
|
---|
| 121 | tmin = true;
|
---|
| 122 | break;
|
---|
| 123 | case 'M' :
|
---|
| 124 | sscanf(optarg,"%lf",&vmax);
|
---|
| 125 | tmax = true;
|
---|
| 126 | break;
|
---|
| 127 | case 'f' :
|
---|
[1537] | 128 | sscanf(optarg,"%ul",&badflg);
|
---|
[1530] | 129 | tflg = true;
|
---|
| 130 | break;
|
---|
[1463] | 131 | case 'h' :
|
---|
[1516] | 132 | default:
|
---|
| 133 | usage(); exit(1);
|
---|
[1463] | 134 | break;
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
[1516] | 137 | if(optind+2>=narg) {usage(); exit(3);}
|
---|
[1498] | 138 |
|
---|
[1516] | 139 | char * fitsin_point = arg[optind];
|
---|
| 140 | char * fitsin_bolo = arg[optind+1];
|
---|
| 141 | string const fitsphout = arg[optind+2];
|
---|
| 142 | if(optind+3<narg) fitsphwout = arg[optind+3];
|
---|
[1463] | 143 |
|
---|
| 144 | cout<<">>>> tsttoi2map:"<<endl
|
---|
[1516] | 145 | <<"Pipe Window Size "<<width<<endl
|
---|
| 146 | <<"Fits Infile Bolo "<<fitsin_bolo<<endl
|
---|
| 147 | <<" ...label_bolomuv "<<label_bolomuv<<endl;
|
---|
[1520] | 148 | cout<<"Fits Infile Pointing "<<fitsin_point<<endl
|
---|
| 149 | <<" ...label_coord1 "<<label_coord1<<endl
|
---|
[1530] | 150 | <<" ...label_coord2 "<<label_coord2<<endl;
|
---|
[1516] | 151 | cout<<"Fits Healpix Sphere "<<fitsphout<<endl
|
---|
[1530] | 152 | <<" ...nlat "<<nlat<<endl;
|
---|
[1516] | 153 | cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl;
|
---|
[1463] | 154 |
|
---|
| 155 | SophyaInit();
|
---|
| 156 | InitTim();
|
---|
| 157 |
|
---|
| 158 | //--------------------------------------------------------------------
|
---|
| 159 | try {
|
---|
| 160 | //--------------------------------------------------------------------
|
---|
| 161 |
|
---|
[1629] | 162 |
|
---|
[1463] | 163 | // FITS reader
|
---|
[1498] | 164 | FITSTOIReader rfitsb(fitsin_bolo);
|
---|
| 165 | int ncolb = rfitsb.getNOut();
|
---|
| 166 | cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
|
---|
[1516] | 167 | if(ncolb<1) exit(-4);
|
---|
[1463] | 168 |
|
---|
[1498] | 169 | FITSTOIReader rfitsp(fitsin_point);
|
---|
| 170 | int ncolp = rfitsp.getNOut();
|
---|
| 171 | cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
|
---|
[1516] | 172 | if(ncolp<2) exit(-5);
|
---|
[1498] | 173 |
|
---|
[1463] | 174 | // Creation de la sphere Healpix
|
---|
| 175 | SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
|
---|
| 176 | cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
|
---|
[1530] | 177 | <<" Nombre de pixels : "<<sph->NbPixels()<<endl
|
---|
| 178 | <<" Nlat : "<<sph->SizeIndex()<<endl;
|
---|
[1463] | 179 |
|
---|
| 180 | // Creation de la sphere de poids Healpix
|
---|
| 181 | SphereHEALPix<r_8>* wsph = NULL;
|
---|
| 182 | if(fitsphwout.size()>0) {
|
---|
| 183 | wsph = new SphereHEALPix<r_8>;
|
---|
[1530] | 184 | cout<<"SphereHEALPix Weight Created"<<endl;
|
---|
[1463] | 185 | }
|
---|
| 186 |
|
---|
| 187 | // TOI Processor
|
---|
| 188 | TOI2Map toi2m(sph,wsph);
|
---|
| 189 | cout<<"TOI2Map created"<<endl;
|
---|
[1516] | 190 | toi2m.SetEquinox(2000.);
|
---|
| 191 | toi2m.SetCoorIn((TypAstroCoord) tcoorin);
|
---|
| 192 | toi2m.SetCoorOut((TypAstroCoord) tcoorout);
|
---|
[1530] | 193 | toi2m.SetTestFlag(tflg,badflg);
|
---|
| 194 | toi2m.SetTestMin(tmin,vmin);
|
---|
| 195 | toi2m.SetTestMax(tmax,vmax);
|
---|
| 196 | toi2m.Print(cout);
|
---|
[1463] | 197 |
|
---|
| 198 | // Definition des tuyaux
|
---|
[1723] | 199 | #ifdef TOISEQBUFFERED
|
---|
| 200 | cout<<">>>> Using TOISeqBuffered"<<endl;
|
---|
[1498] | 201 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
[1723] | 202 | #else
|
---|
| 203 | cout<<">>>> Using TOISegmented"<<endl;
|
---|
| 204 | TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
|
---|
| 205 | #endif
|
---|
[1516] | 206 | // toicoord1in->setDebugLevel(1);
|
---|
[1498] | 207 | rfitsp.addOutput(label_coord1,toicoord1in);
|
---|
| 208 | toi2m.addInput("Coord1In",toicoord1in);
|
---|
[1463] | 209 |
|
---|
[1723] | 210 | #ifdef TOISEQBUFFERED
|
---|
[1498] | 211 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
[1723] | 212 | #else
|
---|
| 213 | TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
|
---|
| 214 | #endif
|
---|
[1516] | 215 | // toicoord2in->setDebugLevel(1);
|
---|
[1498] | 216 | rfitsp.addOutput(label_coord2,toicoord2in);
|
---|
| 217 | toi2m.addInput("Coord2In",toicoord2in);
|
---|
| 218 |
|
---|
[1723] | 219 | #ifdef TOISEQBUFFERED
|
---|
[1463] | 220 | TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
|
---|
[1723] | 221 | #else
|
---|
| 222 | TOISegmented * toibolin = new TOISegmented("toi_bolo_in",width);
|
---|
| 223 | #endif
|
---|
[1516] | 224 | // toibolin->setDebugLevel(1);
|
---|
[1498] | 225 | rfitsb.addOutput(label_bolomuv,toibolin);
|
---|
[1463] | 226 | toi2m.addInput("BoloIn",toibolin);
|
---|
| 227 |
|
---|
| 228 | // Run
|
---|
| 229 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
[1498] | 230 | rfitsp.PrintStatus(cout);
|
---|
| 231 | rfitsb.PrintStatus(cout);
|
---|
[1463] | 232 |
|
---|
| 233 | PrtTim("starting threads");
|
---|
[1498] | 234 | rfitsp.start();
|
---|
| 235 | rfitsb.start();
|
---|
[1463] | 236 | toi2m.start();
|
---|
| 237 |
|
---|
[1723] | 238 | // if(lp>1)
|
---|
| 239 | // for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
| 240 | // cout<<*toicoord1in;
|
---|
| 241 | // cout<<*toibolin;
|
---|
| 242 | // sleep(2);
|
---|
| 243 | // }
|
---|
[1463] | 244 |
|
---|
[1629] | 245 | // Affichage de l'avancement des TOIProcessors
|
---|
[1723] | 246 | // ProcSampleCounter<FITSTOIReader> stats(rfitsb);
|
---|
| 247 | // stats.InfoMessage() = "tsttoi2map/Info";
|
---|
| 248 | // stats.PrintStats();
|
---|
[1629] | 249 |
|
---|
| 250 | // Fin des traitements des TOIProcessors
|
---|
[1463] | 251 | mgr->joinAll();
|
---|
| 252 | PrtTim("End threads");
|
---|
| 253 |
|
---|
[1629] | 254 |
|
---|
[1463] | 255 | // Ecriture de la sphere Healpix sur fits
|
---|
| 256 | {
|
---|
[1633] | 257 | FitsOutFile sfits(fitsphout,FitsFile::clear);
|
---|
[1463] | 258 | cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
|
---|
| 259 | sfits << *sph;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | // Ecriture de la sphere Healpix sur fits
|
---|
| 263 | if(wsph) {
|
---|
[1633] | 264 | FitsOutFile swfits(fitsphwout,FitsFile::clear);
|
---|
[1463] | 265 | cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
|
---|
| 266 | swfits << *wsph;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | // Nettoyage
|
---|
[1629] | 270 | cout << "tsttoi2map: cleanup " << endl;
|
---|
[1463] | 271 | delete sph;
|
---|
| 272 | if(wsph) delete wsph;
|
---|
[1629] | 273 | cout << "tsttoi2map: ----------- End of job -------------- " << endl;
|
---|
[1463] | 274 |
|
---|
| 275 | //--------------------------------------------------------------------
|
---|
| 276 | } catch (PThrowable & exc) {
|
---|
| 277 | cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
| 278 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 279 | } catch (const std::exception & sex) {
|
---|
| 280 | cout<<"\ntsttoi2map: Catched std::exception \n"
|
---|
| 281 | <<(string)typeid(sex).name()<<endl;
|
---|
| 282 | } catch (...) {
|
---|
| 283 | cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
|
---|
| 284 | }
|
---|
| 285 | //--------------------------------------------------------------------
|
---|
| 286 |
|
---|
| 287 | exit(0);
|
---|
| 288 | }
|
---|