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