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