[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;
|
---|
| 68 | r_8 vmin=-1.e30, vmax=1.e30; int_8 badflg=0;
|
---|
| 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' :
|
---|
| 122 | sscanf(optarg,"%ld",&badflg);
|
---|
| 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 |
|
---|
| 156 | // FITS reader
|
---|
[1498] | 157 | FITSTOIReader rfitsb(fitsin_bolo);
|
---|
| 158 | int ncolb = rfitsb.getNOut();
|
---|
| 159 | cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
|
---|
[1516] | 160 | if(ncolb<1) exit(-4);
|
---|
[1463] | 161 |
|
---|
[1498] | 162 | FITSTOIReader rfitsp(fitsin_point);
|
---|
| 163 | int ncolp = rfitsp.getNOut();
|
---|
| 164 | cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
|
---|
[1516] | 165 | if(ncolp<2) exit(-5);
|
---|
[1498] | 166 |
|
---|
[1463] | 167 | // Creation de la sphere Healpix
|
---|
| 168 | SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
|
---|
| 169 | cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
|
---|
[1530] | 170 | <<" Nombre de pixels : "<<sph->NbPixels()<<endl
|
---|
| 171 | <<" Nlat : "<<sph->SizeIndex()<<endl;
|
---|
[1463] | 172 |
|
---|
| 173 | // Creation de la sphere de poids Healpix
|
---|
| 174 | SphereHEALPix<r_8>* wsph = NULL;
|
---|
| 175 | if(fitsphwout.size()>0) {
|
---|
| 176 | wsph = new SphereHEALPix<r_8>;
|
---|
[1530] | 177 | cout<<"SphereHEALPix Weight Created"<<endl;
|
---|
[1463] | 178 | }
|
---|
| 179 |
|
---|
| 180 | // TOI Processor
|
---|
| 181 | TOI2Map toi2m(sph,wsph);
|
---|
| 182 | cout<<"TOI2Map created"<<endl;
|
---|
[1516] | 183 | toi2m.SetEquinox(2000.);
|
---|
| 184 | toi2m.SetCoorIn((TypAstroCoord) tcoorin);
|
---|
| 185 | toi2m.SetCoorOut((TypAstroCoord) tcoorout);
|
---|
[1530] | 186 | toi2m.SetTestFlag(tflg,badflg);
|
---|
| 187 | toi2m.SetTestMin(tmin,vmin);
|
---|
| 188 | toi2m.SetTestMax(tmax,vmax);
|
---|
| 189 | toi2m.Print(cout);
|
---|
[1463] | 190 |
|
---|
| 191 | // Definition des tuyaux
|
---|
[1498] | 192 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
[1516] | 193 | // toicoord1in->setDebugLevel(1);
|
---|
[1498] | 194 | rfitsp.addOutput(label_coord1,toicoord1in);
|
---|
| 195 | toi2m.addInput("Coord1In",toicoord1in);
|
---|
[1463] | 196 |
|
---|
[1498] | 197 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
[1516] | 198 | // toicoord2in->setDebugLevel(1);
|
---|
[1498] | 199 | rfitsp.addOutput(label_coord2,toicoord2in);
|
---|
| 200 | toi2m.addInput("Coord2In",toicoord2in);
|
---|
| 201 |
|
---|
[1463] | 202 | TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
|
---|
[1516] | 203 | // toibolin->setDebugLevel(1);
|
---|
[1498] | 204 | rfitsb.addOutput(label_bolomuv,toibolin);
|
---|
[1463] | 205 | toi2m.addInput("BoloIn",toibolin);
|
---|
| 206 |
|
---|
| 207 | // Run
|
---|
| 208 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
[1498] | 209 | rfitsp.PrintStatus(cout);
|
---|
| 210 | rfitsb.PrintStatus(cout);
|
---|
[1463] | 211 |
|
---|
| 212 | PrtTim("starting threads");
|
---|
[1498] | 213 | rfitsp.start();
|
---|
| 214 | rfitsb.start();
|
---|
[1463] | 215 | toi2m.start();
|
---|
| 216 |
|
---|
| 217 | if(lp>1)
|
---|
| 218 | for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
[1498] | 219 | cout<<*toicoord1in;
|
---|
[1463] | 220 | cout<<*toibolin;
|
---|
| 221 | sleep(2);
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | mgr->joinAll();
|
---|
| 225 | PrtTim("End threads");
|
---|
| 226 |
|
---|
| 227 | // Ecriture de la sphere Healpix sur fits
|
---|
| 228 | {
|
---|
| 229 | FitsOutFile sfits(fitsphout);
|
---|
| 230 | cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
|
---|
| 231 | sfits << *sph;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | // Ecriture de la sphere Healpix sur fits
|
---|
| 235 | if(wsph) {
|
---|
| 236 | FitsOutFile swfits(fitsphwout);
|
---|
| 237 | cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
|
---|
| 238 | swfits << *wsph;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | // Nettoyage
|
---|
| 242 | delete sph;
|
---|
| 243 | if(wsph) delete wsph;
|
---|
| 244 |
|
---|
| 245 | //--------------------------------------------------------------------
|
---|
| 246 | } catch (PThrowable & exc) {
|
---|
| 247 | cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
| 248 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 249 | } catch (const std::exception & sex) {
|
---|
| 250 | cout<<"\ntsttoi2map: Catched std::exception \n"
|
---|
| 251 | <<(string)typeid(sex).name()<<endl;
|
---|
| 252 | } catch (...) {
|
---|
| 253 | cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
|
---|
| 254 | }
|
---|
| 255 | //--------------------------------------------------------------------
|
---|
| 256 |
|
---|
| 257 | exit(0);
|
---|
| 258 | }
|
---|