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