[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 |
|
---|
| 22 |
|
---|
[1463] | 23 | void usage(void);
|
---|
| 24 | void usage(void) {
|
---|
| 25 | cout<<"tstmap2toi [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
|
---|
[1520] | 26 | <<" [-a label_coord1In] [-d label_coord2In] [-b label_bolomuv]"<<endl
|
---|
| 27 | <<" [-i c,h] [-m c,h]"<<endl
|
---|
| 28 | <<" fitsin_point fitsphere fitsout"<<endl
|
---|
| 29 | <<" -p lp : print level (def=0)"<<endl
|
---|
| 30 | <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
|
---|
| 31 | <<" -w data_window_size : window size for pipe (def=8192)"<<endl
|
---|
| 32 | <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
|
---|
| 33 | <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
|
---|
| 34 | <<" coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
|
---|
| 35 | <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
|
---|
| 36 | <<" -i c,h : coordIn caracteristics (c=G/E h=H/D) (def=G,D)"<<endl
|
---|
| 37 | <<" -m c,h : idem -i for Sphere"<<endl
|
---|
| 38 | <<" fitsin_point : fits file for pointing"<<endl
|
---|
| 39 | <<" fitsphere : fits file for input Healpix sphere"<<endl
|
---|
| 40 | <<" fitsout : fits file for output"<<endl;
|
---|
[1463] | 41 | return;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[1520] | 44 | unsigned long typecoord(char typc=' ',char hd=' ');
|
---|
| 45 | unsigned long typecoord(char typc,char hd)
|
---|
| 46 | // typc : G=galactiques, E=equatoriales, autres=galactiques
|
---|
| 47 | // hd : H=heure, D=degre, autres=(heure si typc==E, degre si typc==G)
|
---|
| 48 | {
|
---|
| 49 | if(typc!='G' && typc!='E') typc='G';
|
---|
| 50 | if(hd!='H' && hd!='D') {if(typc=='E') hd='H'; else hd='D';}
|
---|
| 51 | unsigned long rc=TypCoordUndef;
|
---|
| 52 | if(typc=='G') rc |= TypCoordGal;
|
---|
| 53 | else rc |= TypCoordEq;
|
---|
| 54 | if(hd=='D') rc |= TypCoordDD;
|
---|
| 55 | else rc |= TypCoordHD;
|
---|
| 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;
|
---|
[1520] | 66 | char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
|
---|
[1463] | 67 | long sdeb,sfin;
|
---|
[1520] | 68 | unsigned long tcoorin=typecoord(), tcoormap=typecoord();
|
---|
| 69 | int c; char t=' ',h=' ';
|
---|
| 70 | while((c = getopt(narg,arg,"hp:s:w:a:d:b:i:m:")) != -1) {
|
---|
[1463] | 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);
|
---|
[1520] | 76 | else {cout<<"Bad sample interval "<<endl; exit(1);}
|
---|
[1463] | 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' :
|
---|
[1520] | 88 | label_coord1 = optarg;
|
---|
[1463] | 89 | break;
|
---|
| 90 | case 'd' :
|
---|
[1520] | 91 | label_coord2 = optarg;
|
---|
[1463] | 92 | break;
|
---|
| 93 | case 'b' :
|
---|
| 94 | label_bolomuv = optarg;
|
---|
| 95 | break;
|
---|
[1520] | 96 | case 'i' :
|
---|
| 97 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
| 98 | tcoorin=typecoord(t,h);
|
---|
| 99 | break;
|
---|
| 100 | case 'm' :
|
---|
| 101 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
| 102 | tcoormap=typecoord(t,h);
|
---|
| 103 | break;
|
---|
[1463] | 104 | case 'h' :
|
---|
| 105 | default:
|
---|
[1520] | 106 | usage(); exit(1);
|
---|
[1463] | 107 | }
|
---|
| 108 | }
|
---|
[1520] | 109 | if(optind+2>=narg) {usage(); exit(2);}
|
---|
| 110 | char * fitsin_point = arg[optind];
|
---|
[1463] | 111 | string const fitsphere = arg[optind+1];
|
---|
| 112 | char * fitsout = arg[optind+2];
|
---|
| 113 |
|
---|
[1520] | 114 | {
|
---|
| 115 | unsigned long tg,te,hd,dd;
|
---|
[1463] | 116 | cout<<">>>> tstmap2toi:"<<endl
|
---|
[1520] | 117 | <<"Pipe Window Size "<<width<<endl
|
---|
| 118 | <<"Fits OutFile "<<fitsout<<endl
|
---|
[1463] | 119 | <<" ...label_bolomuv "<<label_bolomuv<<endl;
|
---|
[1520] | 120 | tg = tcoorin&TypCoordGal; te = tcoorin&TypCoordEq;
|
---|
| 121 | hd = tcoorin&TypCoordHD; dd = tcoorin&TypCoordDD;
|
---|
| 122 | cout<<"Fits Infile Pointing "<<fitsin_point<<endl
|
---|
| 123 | <<" ...label_coord1 "<<label_coord1<<endl
|
---|
| 124 | <<" ...label_coord2 "<<label_coord2<<endl
|
---|
| 125 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
| 126 | tg = tcoormap&TypCoordGal; te = tcoormap&TypCoordEq;
|
---|
| 127 | hd = tcoormap&TypCoordHD; dd = tcoormap&TypCoordDD;
|
---|
| 128 | cout<<"Fits Healpix Sphere "<<fitsphere<<endl
|
---|
| 129 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
| 130 | }
|
---|
[1463] | 131 |
|
---|
| 132 | SophyaInit();
|
---|
| 133 | InitTim();
|
---|
| 134 |
|
---|
| 135 | //--------------------------------------------------------------------
|
---|
| 136 | try {
|
---|
| 137 | //--------------------------------------------------------------------
|
---|
| 138 |
|
---|
| 139 | // FITS reader et writer
|
---|
[1520] | 140 | FITSTOIReader rfits(fitsin_point);
|
---|
[1463] | 141 | int ncol = rfits.getNOut();
|
---|
[1520] | 142 | cout<<"Number of columns in fits Infile Pointing : "<<ncol<<endl;
|
---|
| 143 | if(ncol<2) exit(3);
|
---|
[1463] | 144 |
|
---|
| 145 | FITSTOIWriter wfits(fitsout);
|
---|
[1530] | 146 | //wfits.setOutFlags(true);
|
---|
[1463] | 147 | cout << "fits reader and writer created"<<endl;
|
---|
| 148 |
|
---|
| 149 | // Lecture de la sphere Healpix
|
---|
| 150 | SphereHEALPix<r_8> sph;
|
---|
| 151 | FitsInFile sfits(fitsphere);
|
---|
| 152 | sfits >> sph;
|
---|
| 153 | cout<<"SphereHEALPix: Type de map : "<<sph.TypeOfMap()<<endl
|
---|
| 154 | <<" Nombre de pixels : "<<sph.NbPixels()<<endl;
|
---|
| 155 |
|
---|
| 156 | // TOI Processor
|
---|
| 157 | Map2TOI m2toi(sph);
|
---|
| 158 | cout<<"Map2TOI created"<<endl;
|
---|
[1520] | 159 | m2toi.SetEquinox(2000.);
|
---|
| 160 | m2toi.SetCoorIn((TypAstroCoord) tcoorin);
|
---|
| 161 | m2toi.SetCoorMap((TypAstroCoord) tcoormap);
|
---|
[1530] | 162 | m2toi.Print(cout);
|
---|
[1463] | 163 |
|
---|
| 164 | // Definition des tuyaux
|
---|
[1723] | 165 | #ifdef TOISEQBUFFERED
|
---|
| 166 | cout<<">>>> Using TOISeqBuffered"<<endl;
|
---|
[1520] | 167 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
[1723] | 168 | #else
|
---|
| 169 | cout<<">>>> Using TOISegmented"<<endl;
|
---|
| 170 | TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
|
---|
| 171 | #endif
|
---|
[1520] | 172 | // toicoord1in->setDebugLevel(1);
|
---|
| 173 | rfits.addOutput(label_coord1,toicoord1in);
|
---|
| 174 | m2toi.addInput("Coord1In",toicoord1in);
|
---|
[1463] | 175 |
|
---|
[1723] | 176 | #ifdef TOISEQBUFFERED
|
---|
[1520] | 177 | TOISeqBuffered * toicoord1out = new TOISeqBuffered("toi_coord1_out",width);
|
---|
[1723] | 178 | #else
|
---|
| 179 | TOISegmented * toicoord1out = new TOISegmented("toi_coord1_out",width);
|
---|
| 180 | #endif
|
---|
[1520] | 181 | m2toi.addOutput("Coord1Out",toicoord1out);
|
---|
| 182 | wfits.addInput(label_coord1,toicoord1out);
|
---|
[1463] | 183 |
|
---|
[1723] | 184 | #ifdef TOISEQBUFFERED
|
---|
[1520] | 185 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
[1723] | 186 | #else
|
---|
| 187 | TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
|
---|
| 188 | #endif
|
---|
[1520] | 189 | // toicoord2in->setDebugLevel(1);
|
---|
| 190 | rfits.addOutput(label_coord2,toicoord2in);
|
---|
| 191 | m2toi.addInput("Coord2In",toicoord2in);
|
---|
[1463] | 192 |
|
---|
[1723] | 193 | #ifdef TOISEQBUFFERED
|
---|
[1520] | 194 | TOISeqBuffered * toicoord2out = new TOISeqBuffered("toi_coord2_out",width);
|
---|
[1723] | 195 | #else
|
---|
| 196 | TOISegmented * toicoord2out = new TOISegmented("toi_coord2_out",width);
|
---|
| 197 | #endif
|
---|
[1520] | 198 | m2toi.addOutput("Coord2Out",toicoord2out);
|
---|
| 199 | wfits.addInput(label_coord2,toicoord2out);
|
---|
[1463] | 200 |
|
---|
[1723] | 201 | #ifdef TOISEQBUFFERED
|
---|
[1463] | 202 | TOISeqBuffered * toibolout = new TOISeqBuffered("toi_bolo_out",width);
|
---|
[1723] | 203 | #else
|
---|
| 204 | TOISegmented * toibolout = new TOISegmented("toi_bolo_out",width);
|
---|
| 205 | #endif
|
---|
[1520] | 206 | // toibolout->setDebugLevel(1);
|
---|
[1463] | 207 | m2toi.addOutput("BoloOut",toibolout);
|
---|
| 208 | wfits.addInput(label_bolomuv,toibolout);
|
---|
| 209 |
|
---|
| 210 | // Run
|
---|
| 211 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
| 212 | rfits.PrintStatus(cout);
|
---|
| 213 | cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl;
|
---|
| 214 | wfits.PrintStatus(cout);
|
---|
| 215 |
|
---|
| 216 | PrtTim("starting threads");
|
---|
| 217 | rfits.start();
|
---|
| 218 | m2toi.start();
|
---|
| 219 | wfits.start();
|
---|
| 220 |
|
---|
| 221 | if(lp>1)
|
---|
| 222 | for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
[1520] | 223 | cout<<*toicoord1in;
|
---|
[1463] | 224 | cout<<*toibolout;
|
---|
| 225 | sleep(2);
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[1651] | 228 | // Affichage de l'avancement des TOIProcessors
|
---|
[1723] | 229 | //ProcSampleCounter<FITSTOIReader> stats(rfits);
|
---|
| 230 | //stats.InfoMessage() = "tstmap2toi/Info";
|
---|
| 231 | //stats.PrintStats();
|
---|
[1651] | 232 |
|
---|
[1463] | 233 | mgr->joinAll();
|
---|
| 234 | PrtTim("End threads");
|
---|
| 235 |
|
---|
| 236 | //--------------------------------------------------------------------
|
---|
| 237 | } catch (PThrowable & exc) {
|
---|
| 238 | cout<<"\ntstmap2toi: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
| 239 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 240 | } catch (const std::exception & sex) {
|
---|
| 241 | cout<<"\ntstmap2toi: Catched std::exception \n"
|
---|
| 242 | <<(string)typeid(sex).name()<<endl;
|
---|
| 243 | } catch (...) {
|
---|
| 244 | cout<<"\ntstmap2toi: some other exception was caught ! "<<endl;
|
---|
| 245 | }
|
---|
| 246 | //--------------------------------------------------------------------
|
---|
| 247 |
|
---|
| 248 | exit(0);
|
---|
| 249 | }
|
---|