| [1723] | 1 | //#define TOISEQBUFFERED
 | 
|---|
 | 2 | 
 | 
|---|
| [1463] | 3 | #include <unistd.h>
 | 
|---|
 | 4 | #include "toi.h"
 | 
|---|
 | 5 | #include "toiprocessor.h"
 | 
|---|
 | 6 | #include "fitstoirdr.h"
 | 
|---|
 | 7 | #include "fitstoiwtr.h"
 | 
|---|
 | 8 | #include "toimanager.h"
 | 
|---|
| [1723] | 9 | #ifdef TOISEQBUFFERED
 | 
|---|
| [1463] | 10 | #include "toiseqbuff.h"
 | 
|---|
| [1723] | 11 | #else
 | 
|---|
 | 12 | #include "toisegment.h"
 | 
|---|
 | 13 | #endif
 | 
|---|
| [1463] | 14 | 
 | 
|---|
 | 15 | #include "sambainit.h"
 | 
|---|
 | 16 | #include "map2toi.h"
 | 
|---|
 | 17 | #include "fitsspherehealpix.h" 
 | 
|---|
 | 18 | #include "timing.h"
 | 
|---|
 | 19 | 
 | 
|---|
| [1760] | 20 | #include <stdexcept>
 | 
|---|
 | 21 | 
 | 
|---|
| [1463] | 22 | void usage(void);
 | 
|---|
 | 23 | void usage(void) {
 | 
|---|
 | 24 |  cout<<"tstmap2toi [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
 | 
|---|
| [1520] | 25 |      <<"           [-a label_coord1In] [-d label_coord2In] [-b label_bolomuv]"<<endl
 | 
|---|
| [2039] | 26 |      <<"           [-i c,h] [-m c,h] [-C] "<<endl
 | 
|---|
| [1520] | 27 |      <<"           fitsin_point fitsphere fitsout"<<endl
 | 
|---|
 | 28 |      <<" -p lp : print level (def=0)"<<endl
 | 
|---|
 | 29 |      <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
 | 
|---|
 | 30 |      <<" -w data_window_size : window size for pipe (def=8192)"<<endl
 | 
|---|
 | 31 |      <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
 | 
|---|
 | 32 |      <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
 | 
|---|
 | 33 |      <<"          coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
 | 
|---|
 | 34 |      <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
 | 
|---|
| [1809] | 35 |      <<" -i cin : coordIn caracteristics (def=\"gdcdl\")"<<endl
 | 
|---|
 | 36 |      <<" -m cmap : idem -i for Sphere (def=\"g\")"<<endl
 | 
|---|
 | 37 |      <<" -e equi : equinoxe en annee (def=2000.)"<<endl
 | 
|---|
| [1810] | 38 |      <<" -I : sampleNum are implicit in fits files (def=no)"<<endl
 | 
|---|
| [2039] | 39 |      <<" -C : Copy ccordIn to output  fits file (def=no)"<<endl
 | 
|---|
| [1520] | 40 |      <<" fitsin_point : fits file for pointing"<<endl
 | 
|---|
 | 41 |      <<" fitsphere : fits file for input Healpix sphere"<<endl
 | 
|---|
 | 42 |      <<" fitsout : fits file for output"<<endl;
 | 
|---|
| [1463] | 43 |  return;
 | 
|---|
 | 44 | }
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | ////////////////////////////////////////////////////////////////
 | 
|---|
 | 47 | int main(int narg, char** arg) {
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | TOIManager* mgr = TOIManager::getManager();
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | //-- Decodage arguments
 | 
|---|
 | 52 | int lp = 0, width = 8192;
 | 
|---|
| [1520] | 53 | char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
 | 
|---|
| [1809] | 54 | char *tcoorin="gdcdl", *tcoormap="g";
 | 
|---|
 | 55 | double equi=2000.;
 | 
|---|
| [1463] | 56 | long sdeb,sfin;
 | 
|---|
| [1810] | 57 | bool snimplicit = false;
 | 
|---|
| [2039] | 58 | bool fgcopycoord = false;
 | 
|---|
| [1809] | 59 | int c;
 | 
|---|
| [1810] | 60 | while((c = getopt(narg,arg,"hIp:s:w:a:d:b:i:m:e:")) != -1) {
 | 
|---|
| [1463] | 61 |   switch (c) {
 | 
|---|
 | 62 |   case 's' :
 | 
|---|
 | 63 |     sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
 | 
|---|
 | 64 |     cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
 | 
|---|
 | 65 |     if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
 | 
|---|
| [1520] | 66 |     else {cout<<"Bad sample interval "<<endl; exit(1);}
 | 
|---|
| [1463] | 67 |     break;
 | 
|---|
 | 68 |   case 'w' :
 | 
|---|
 | 69 |     sscanf(optarg,"%d",&width);
 | 
|---|
 | 70 |     if(width<=0) width=8192;
 | 
|---|
 | 71 |     cout<<"Data window size "<<width<<endl;
 | 
|---|
 | 72 |     break;
 | 
|---|
 | 73 |   case 'p' :
 | 
|---|
 | 74 |     sscanf(optarg,"%d",&lp);
 | 
|---|
 | 75 |     if(lp<0) lp=0;
 | 
|---|
 | 76 |     break;
 | 
|---|
 | 77 |   case 'a' :
 | 
|---|
| [1520] | 78 |     label_coord1 = optarg;
 | 
|---|
| [1463] | 79 |     break;
 | 
|---|
 | 80 |   case 'd' :
 | 
|---|
| [1520] | 81 |     label_coord2 = optarg;
 | 
|---|
| [1463] | 82 |     break;
 | 
|---|
 | 83 |   case 'b' :
 | 
|---|
 | 84 |     label_bolomuv = optarg;
 | 
|---|
 | 85 |     break;
 | 
|---|
| [1520] | 86 |   case 'i' :
 | 
|---|
| [1809] | 87 |     tcoorin = optarg;
 | 
|---|
| [1520] | 88 |     break;
 | 
|---|
 | 89 |   case 'm' :
 | 
|---|
| [1809] | 90 |     tcoormap = optarg;
 | 
|---|
| [1520] | 91 |     break;
 | 
|---|
| [1809] | 92 |   case 'e' :
 | 
|---|
 | 93 |     sscanf(optarg,"%lf",&equi);
 | 
|---|
 | 94 |     break;
 | 
|---|
| [1810] | 95 |   case 'I' :
 | 
|---|
 | 96 |     snimplicit = true;
 | 
|---|
 | 97 |     break;
 | 
|---|
| [2039] | 98 |   case 'C' :
 | 
|---|
 | 99 |     fgcopycoord = true;
 | 
|---|
 | 100 |     break;
 | 
|---|
| [1463] | 101 |   case 'h' :
 | 
|---|
 | 102 |   default:
 | 
|---|
| [1520] | 103 |     usage(); exit(1);
 | 
|---|
| [1463] | 104 |   }
 | 
|---|
 | 105 | }
 | 
|---|
| [1520] | 106 | if(optind+2>=narg) {usage(); exit(2);}
 | 
|---|
 | 107 | char * fitsin_point    = arg[optind];
 | 
|---|
| [1463] | 108 | string const fitsphere = arg[optind+1];
 | 
|---|
 | 109 | char * fitsout         = arg[optind+2];
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 | cout<<">>>> tstmap2toi:"<<endl
 | 
|---|
| [1520] | 112 |     <<"Pipe Window Size "<<width<<endl
 | 
|---|
 | 113 |     <<"Fits OutFile "<<fitsout<<endl
 | 
|---|
| [1463] | 114 |     <<"  ...label_bolomuv "<<label_bolomuv<<endl;
 | 
|---|
| [1520] | 115 | cout<<"Fits Infile Pointing "<<fitsin_point<<endl
 | 
|---|
 | 116 |     <<"  ...label_coord1 "<<label_coord1<<endl
 | 
|---|
 | 117 |     <<"  ...label_coord2 "<<label_coord2<<endl
 | 
|---|
| [1809] | 118 |     <<"  ...... ctype="<<tcoorin<<endl;
 | 
|---|
| [1520] | 119 | cout<<"Fits Healpix Sphere "<<fitsphere<<endl
 | 
|---|
| [1809] | 120 |     <<"  ...... ctype="<<tcoormap<<endl;
 | 
|---|
 | 121 | cout<<"Equinoxe "<<equi<<" years"<<endl;
 | 
|---|
| [1463] | 122 | 
 | 
|---|
 | 123 | SophyaInit();
 | 
|---|
 | 124 | InitTim();
 | 
|---|
 | 125 | 
 | 
|---|
 | 126 | //--------------------------------------------------------------------
 | 
|---|
 | 127 | try {
 | 
|---|
 | 128 | //--------------------------------------------------------------------
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 |  // FITS reader et writer
 | 
|---|
| [1520] | 131 |  FITSTOIReader rfits(fitsin_point);
 | 
|---|
| [1810] | 132 |  if(snimplicit) rfits.setImplicitSN();
 | 
|---|
| [1463] | 133 |  int ncol = rfits.getNOut();
 | 
|---|
| [1520] | 134 |  cout<<"Number of columns in fits Infile Pointing : "<<ncol<<endl;
 | 
|---|
 | 135 |  if(ncol<2) exit(3);
 | 
|---|
| [1463] | 136 | 
 | 
|---|
 | 137 |  FITSTOIWriter wfits(fitsout);
 | 
|---|
| [1810] | 138 |  if(snimplicit) wfits.setImplicitSN();
 | 
|---|
| [1530] | 139 |  //wfits.setOutFlags(true);
 | 
|---|
| [1463] | 140 |  cout << "fits reader and writer created"<<endl;
 | 
|---|
 | 141 | 
 | 
|---|
 | 142 |  // Lecture de la sphere Healpix
 | 
|---|
 | 143 |  SphereHEALPix<r_8> sph;        
 | 
|---|
 | 144 |  FitsInFile sfits(fitsphere);
 | 
|---|
 | 145 |  sfits >> sph;
 | 
|---|
 | 146 |  cout<<"SphereHEALPix: Type de map : "<<sph.TypeOfMap()<<endl
 | 
|---|
 | 147 |      <<"               Nombre de pixels : "<<sph.NbPixels()<<endl;
 | 
|---|
 | 148 | 
 | 
|---|
 | 149 |  // TOI Processor
 | 
|---|
 | 150 |  Map2TOI m2toi(sph);
 | 
|---|
 | 151 |  cout<<"Map2TOI created"<<endl;
 | 
|---|
| [1809] | 152 |  m2toi.SetEquinox(equi);
 | 
|---|
 | 153 |  m2toi.SetCoorIn(tcoorin);
 | 
|---|
 | 154 |  m2toi.SetCoorMap(tcoormap);
 | 
|---|
| [1530] | 155 |  m2toi.Print(cout);
 | 
|---|
| [1463] | 156 | 
 | 
|---|
 | 157 |  // Definition des tuyaux
 | 
|---|
| [1723] | 158 | #ifdef TOISEQBUFFERED
 | 
|---|
 | 159 |  cout<<">>>> Using TOISeqBuffered"<<endl;
 | 
|---|
| [1520] | 160 |  TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
 | 
|---|
| [1723] | 161 | #else
 | 
|---|
 | 162 |  cout<<">>>> Using TOISegmented"<<endl;
 | 
|---|
 | 163 |  TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
 | 
|---|
 | 164 | #endif
 | 
|---|
| [1520] | 165 |  // toicoord1in->setDebugLevel(1);
 | 
|---|
 | 166 |  rfits.addOutput(label_coord1,toicoord1in);
 | 
|---|
 | 167 |  m2toi.addInput("Coord1In",toicoord1in);
 | 
|---|
| [1463] | 168 | 
 | 
|---|
| [2039] | 169 |  if (fgcopycoord) {
 | 
|---|
| [1723] | 170 | #ifdef TOISEQBUFFERED
 | 
|---|
| [1520] | 171 |  TOISeqBuffered * toicoord1out = new TOISeqBuffered("toi_coord1_out",width);
 | 
|---|
| [1723] | 172 | #else
 | 
|---|
 | 173 |  TOISegmented * toicoord1out = new TOISegmented("toi_coord1_out",width);
 | 
|---|
 | 174 | #endif
 | 
|---|
| [1520] | 175 |  m2toi.addOutput("Coord1Out",toicoord1out);
 | 
|---|
 | 176 |  wfits.addInput(label_coord1,toicoord1out);
 | 
|---|
| [2039] | 177 |  }
 | 
|---|
| [1463] | 178 | 
 | 
|---|
| [1723] | 179 | #ifdef TOISEQBUFFERED
 | 
|---|
| [1520] | 180 |  TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
 | 
|---|
| [1723] | 181 | #else
 | 
|---|
 | 182 |  TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
 | 
|---|
 | 183 | #endif
 | 
|---|
| [1520] | 184 |  // toicoord2in->setDebugLevel(1);
 | 
|---|
 | 185 |  rfits.addOutput(label_coord2,toicoord2in);
 | 
|---|
 | 186 |  m2toi.addInput("Coord2In",toicoord2in);
 | 
|---|
| [2039] | 187 |  
 | 
|---|
 | 188 |  if (fgcopycoord) {
 | 
|---|
| [1723] | 189 | #ifdef TOISEQBUFFERED
 | 
|---|
| [1520] | 190 |  TOISeqBuffered * toicoord2out = new TOISeqBuffered("toi_coord2_out",width);
 | 
|---|
| [1723] | 191 | #else
 | 
|---|
 | 192 |  TOISegmented * toicoord2out = new TOISegmented("toi_coord2_out",width);
 | 
|---|
 | 193 | #endif
 | 
|---|
| [1520] | 194 |  m2toi.addOutput("Coord2Out",toicoord2out);
 | 
|---|
 | 195 |  wfits.addInput(label_coord2,toicoord2out);
 | 
|---|
| [2039] | 196 |  }
 | 
|---|
| [1463] | 197 | 
 | 
|---|
| [1723] | 198 | #ifdef TOISEQBUFFERED
 | 
|---|
| [1463] | 199 |  TOISeqBuffered * toibolout = new TOISeqBuffered("toi_bolo_out",width);
 | 
|---|
| [1723] | 200 | #else
 | 
|---|
 | 201 |  TOISegmented * toibolout = new TOISegmented("toi_bolo_out",width);
 | 
|---|
 | 202 | #endif
 | 
|---|
| [1520] | 203 |  // toibolout->setDebugLevel(1);
 | 
|---|
| [1463] | 204 |  m2toi.addOutput("BoloOut",toibolout);
 | 
|---|
 | 205 |  wfits.addInput(label_bolomuv,toibolout);
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 |  // Run
 | 
|---|
 | 208 |  cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
 | 
|---|
 | 209 |  rfits.PrintStatus(cout);
 | 
|---|
 | 210 |  cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl;
 | 
|---|
 | 211 |  wfits.PrintStatus(cout);  
 | 
|---|
 | 212 | 
 | 
|---|
 | 213 |  PrtTim("starting threads");
 | 
|---|
 | 214 |  rfits.start();
 | 
|---|
 | 215 |  m2toi.start();
 | 
|---|
 | 216 |  wfits.start();
 | 
|---|
 | 217 | 
 | 
|---|
| [1809] | 218 |  //if(lp>1) for(int jjjj=0;jjjj<5;jjjj++) {
 | 
|---|
 | 219 |  //  cout<<*toicoord1in; 
 | 
|---|
 | 220 |  //  cout<<*toibolout; 
 | 
|---|
 | 221 |  //  sleep(2);
 | 
|---|
 | 222 |  //}
 | 
|---|
| [1463] | 223 | 
 | 
|---|
| [1651] | 224 |  //  Affichage de l'avancement des TOIProcessors 
 | 
|---|
| [2039] | 225 |  ProcSampleCounter<Map2TOI>  stats(m2toi);
 | 
|---|
 | 226 |  stats.InfoMessage() = "tstmap2toi/Info";
 | 
|---|
 | 227 |  stats.PrintStats();
 | 
|---|
| [1651] | 228 | 
 | 
|---|
| [1463] | 229 |  mgr->joinAll();
 | 
|---|
 | 230 |  PrtTim("End threads");
 | 
|---|
 | 231 | 
 | 
|---|
 | 232 | //--------------------------------------------------------------------
 | 
|---|
 | 233 | } catch (PThrowable & exc) {
 | 
|---|
 | 234 |  cout<<"\ntstmap2toi: Catched Exception \n"<<(string)typeid(exc).name() 
 | 
|---|
 | 235 |      <<" - Msg= "<<exc.Msg()<<endl;
 | 
|---|
 | 236 | } catch (const std::exception & sex) {
 | 
|---|
 | 237 |  cout<<"\ntstmap2toi: Catched std::exception \n" 
 | 
|---|
 | 238 |      <<(string)typeid(sex).name()<<endl; 
 | 
|---|
 | 239 | } catch (...) {
 | 
|---|
 | 240 |  cout<<"\ntstmap2toi: some other exception was caught ! "<<endl;
 | 
|---|
 | 241 | }
 | 
|---|
 | 242 | //--------------------------------------------------------------------
 | 
|---|
 | 243 | 
 | 
|---|
 | 244 | exit(0);
 | 
|---|
 | 245 | }
 | 
|---|