[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
|
---|
| 22 | <<" fitsin_point fitsin_bolo fitsphout [fitsphwout]"<<endl
|
---|
| 23 | <<" -p lp : print level (def=0)"<<endl
|
---|
| 24 | <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
|
---|
| 25 | <<" -w data_window_size : window size for pipe (def=8192)"<<endl
|
---|
| 26 | <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
|
---|
| 27 | <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
|
---|
| 28 | <<" coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
|
---|
| 29 | <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
|
---|
| 30 | <<" -n nlat : nlat for Healpix sphere (def=128)"<<endl
|
---|
[1520] | 31 | <<" -i c,h : coordIn caracteristics (c=G/E h=H/D) (def=G,D)"<<endl
|
---|
| 32 | <<" -o c,h : idem -i for coordOut"<<endl
|
---|
[1516] | 33 | <<" fitsin_point : fits file for pointing"<<endl
|
---|
| 34 | <<" fitsin_bolo : fits file for bolo values"<<endl
|
---|
| 35 | <<" fitsphout : fits file for output Healpix sphere"<<endl
|
---|
| 36 | <<" fitsphwout : fits file for output Healpix nFilled sphere (def=no)"<<endl;
|
---|
[1463] | 37 | }
|
---|
| 38 |
|
---|
[1516] | 39 | unsigned long typecoord(char typc=' ',char hd=' ');
|
---|
| 40 | unsigned long typecoord(char typc,char hd)
|
---|
| 41 | // typc : G=galactiques, E=equatoriales, autres=galactiques
|
---|
| 42 | // hd : H=heure, D=degre, autres=(heure si typc==E, degre si typc==G)
|
---|
| 43 | {
|
---|
| 44 | if(typc!='G' && typc!='E') typc='G';
|
---|
| 45 | if(hd!='H' && hd!='D') {if(typc=='E') hd='H'; else hd='D';}
|
---|
| 46 | unsigned long rc=TypCoordUndef;
|
---|
| 47 | if(typc=='G') rc |= TypCoordGal;
|
---|
| 48 | else rc |= TypCoordEq;
|
---|
| 49 | if(hd=='D') rc |= TypCoordDD;
|
---|
| 50 | else rc |= TypCoordHD;
|
---|
| 51 | return rc;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[1463] | 54 | ////////////////////////////////////////////////////////////////
|
---|
| 55 | int main(int narg, char** arg) {
|
---|
| 56 |
|
---|
| 57 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 58 |
|
---|
| 59 | //-- Decodage arguments
|
---|
| 60 | int lp = 0, width = 8192;
|
---|
| 61 | int nlat = 128; // npixel = 12 * nlat^2
|
---|
[1498] | 62 | char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
|
---|
[1463] | 63 | long sdeb,sfin;
|
---|
[1516] | 64 | string fitsphwout = "";
|
---|
| 65 | unsigned long tcoorin=typecoord(), tcoorout=typecoord();
|
---|
| 66 | int c; char t=' ',h=' ';
|
---|
| 67 | while((c = getopt(narg,arg,"hp:s:w:a:d:b:n:i:o:")) != -1) {
|
---|
[1463] | 68 | switch (c) {
|
---|
| 69 | case 's' :
|
---|
| 70 | sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
|
---|
| 71 | cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
|
---|
| 72 | if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
|
---|
[1516] | 73 | else {cout<<"Bad sample interval "<<endl; exit(2);}
|
---|
[1463] | 74 | break;
|
---|
| 75 | case 'w' :
|
---|
| 76 | sscanf(optarg,"%d",&width);
|
---|
| 77 | if(width<=0) width=8192;
|
---|
| 78 | cout<<"Data window size "<<width<<endl;
|
---|
| 79 | break;
|
---|
| 80 | case 'p' :
|
---|
| 81 | sscanf(optarg,"%d",&lp);
|
---|
| 82 | if(lp<0) lp=0;
|
---|
| 83 | break;
|
---|
| 84 | case 'a' :
|
---|
[1498] | 85 | label_coord1 = optarg;
|
---|
[1463] | 86 | break;
|
---|
| 87 | case 'd' :
|
---|
[1498] | 88 | label_coord2 = optarg;
|
---|
[1463] | 89 | break;
|
---|
| 90 | case 'b' :
|
---|
| 91 | label_bolomuv = optarg;
|
---|
| 92 | break;
|
---|
| 93 | case 'n' :
|
---|
| 94 | sscanf(optarg,"%d",&nlat);
|
---|
| 95 | if(nlat<0) nlat=128;
|
---|
| 96 | break;
|
---|
[1516] | 97 | case 'i' :
|
---|
| 98 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
| 99 | tcoorin=typecoord(t,h);
|
---|
| 100 | break;
|
---|
| 101 | case 'o' :
|
---|
| 102 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
| 103 | tcoorout=typecoord(t,h);
|
---|
| 104 | break;
|
---|
[1463] | 105 | case 'h' :
|
---|
[1516] | 106 | default:
|
---|
| 107 | usage(); exit(1);
|
---|
[1463] | 108 | break;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
[1516] | 111 | if(optind+2>=narg) {usage(); exit(3);}
|
---|
[1498] | 112 |
|
---|
[1516] | 113 | char * fitsin_point = arg[optind];
|
---|
| 114 | char * fitsin_bolo = arg[optind+1];
|
---|
| 115 | string const fitsphout = arg[optind+2];
|
---|
| 116 | if(optind+3<narg) fitsphwout = arg[optind+3];
|
---|
[1463] | 117 |
|
---|
[1516] | 118 | {
|
---|
| 119 | unsigned long tg,te,hd,dd;
|
---|
[1463] | 120 | cout<<">>>> tsttoi2map:"<<endl
|
---|
[1516] | 121 | <<"Pipe Window Size "<<width<<endl
|
---|
| 122 | <<"Fits Infile Bolo "<<fitsin_bolo<<endl
|
---|
| 123 | <<" ...label_bolomuv "<<label_bolomuv<<endl;
|
---|
| 124 | tg = tcoorin&TypCoordGal; te = tcoorin&TypCoordEq;
|
---|
| 125 | hd = tcoorin&TypCoordHD; dd = tcoorin&TypCoordDD;
|
---|
[1520] | 126 | cout<<"Fits Infile Pointing "<<fitsin_point<<endl
|
---|
| 127 | <<" ...label_coord1 "<<label_coord1<<endl
|
---|
[1516] | 128 | <<" ...label_coord2 "<<label_coord2<<endl
|
---|
| 129 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
| 130 | tg = tcoorout&TypCoordGal; te = tcoorout&TypCoordEq;
|
---|
| 131 | hd = tcoorout&TypCoordHD; dd = tcoorout&TypCoordDD;
|
---|
| 132 | cout<<"Fits Healpix Sphere "<<fitsphout<<endl
|
---|
[1463] | 133 | <<" ...nlat "<<nlat<<endl
|
---|
[1516] | 134 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
| 135 | cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl;
|
---|
| 136 | }
|
---|
[1463] | 137 |
|
---|
| 138 | SophyaInit();
|
---|
| 139 | InitTim();
|
---|
| 140 |
|
---|
| 141 | //--------------------------------------------------------------------
|
---|
| 142 | try {
|
---|
| 143 | //--------------------------------------------------------------------
|
---|
| 144 |
|
---|
| 145 | // FITS reader
|
---|
[1498] | 146 | FITSTOIReader rfitsb(fitsin_bolo);
|
---|
| 147 | int ncolb = rfitsb.getNOut();
|
---|
| 148 | cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
|
---|
[1516] | 149 | if(ncolb<1) exit(-4);
|
---|
[1463] | 150 |
|
---|
[1498] | 151 | FITSTOIReader rfitsp(fitsin_point);
|
---|
| 152 | int ncolp = rfitsp.getNOut();
|
---|
| 153 | cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
|
---|
[1516] | 154 | if(ncolp<2) exit(-5);
|
---|
[1498] | 155 |
|
---|
[1463] | 156 | // Creation de la sphere Healpix
|
---|
| 157 | SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
|
---|
| 158 | cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
|
---|
| 159 | <<" Nombre de pixels : "<<sph->NbPixels()<<endl;
|
---|
| 160 |
|
---|
| 161 | // Creation de la sphere de poids Healpix
|
---|
| 162 | SphereHEALPix<r_8>* wsph = NULL;
|
---|
| 163 | if(fitsphwout.size()>0) {
|
---|
| 164 | wsph = new SphereHEALPix<r_8>;
|
---|
| 165 | cout<<"SphereHEALPix Weight: Type de map : "<<wsph->TypeOfMap()<<endl
|
---|
[1516] | 166 | <<" Nombre de pixels : "<<wsph->NbPixels()<<endl;
|
---|
[1463] | 167 | }
|
---|
| 168 |
|
---|
| 169 | // TOI Processor
|
---|
| 170 | TOI2Map toi2m(sph,wsph);
|
---|
| 171 | cout<<"TOI2Map created"<<endl;
|
---|
[1516] | 172 | toi2m.SetEquinox(2000.);
|
---|
| 173 | toi2m.SetCoorIn((TypAstroCoord) tcoorin);
|
---|
| 174 | toi2m.SetCoorOut((TypAstroCoord) tcoorout);
|
---|
[1463] | 175 |
|
---|
| 176 | // Definition des tuyaux
|
---|
[1498] | 177 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
[1516] | 178 | // toicoord1in->setDebugLevel(1);
|
---|
[1498] | 179 | rfitsp.addOutput(label_coord1,toicoord1in);
|
---|
| 180 | toi2m.addInput("Coord1In",toicoord1in);
|
---|
[1463] | 181 |
|
---|
[1498] | 182 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
[1516] | 183 | // toicoord2in->setDebugLevel(1);
|
---|
[1498] | 184 | rfitsp.addOutput(label_coord2,toicoord2in);
|
---|
| 185 | toi2m.addInput("Coord2In",toicoord2in);
|
---|
| 186 |
|
---|
[1463] | 187 | TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
|
---|
[1516] | 188 | // toibolin->setDebugLevel(1);
|
---|
[1498] | 189 | rfitsb.addOutput(label_bolomuv,toibolin);
|
---|
[1463] | 190 | toi2m.addInput("BoloIn",toibolin);
|
---|
| 191 |
|
---|
| 192 | // Run
|
---|
| 193 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
[1498] | 194 | rfitsp.PrintStatus(cout);
|
---|
| 195 | rfitsb.PrintStatus(cout);
|
---|
[1463] | 196 |
|
---|
| 197 | PrtTim("starting threads");
|
---|
[1498] | 198 | rfitsp.start();
|
---|
| 199 | rfitsb.start();
|
---|
[1463] | 200 | toi2m.start();
|
---|
| 201 |
|
---|
| 202 | if(lp>1)
|
---|
| 203 | for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
[1498] | 204 | cout<<*toicoord1in;
|
---|
[1463] | 205 | cout<<*toibolin;
|
---|
| 206 | sleep(2);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | mgr->joinAll();
|
---|
| 210 | PrtTim("End threads");
|
---|
| 211 |
|
---|
| 212 | // Ecriture de la sphere Healpix sur fits
|
---|
| 213 | {
|
---|
| 214 | FitsOutFile sfits(fitsphout);
|
---|
| 215 | cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
|
---|
| 216 | sfits << *sph;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | // Ecriture de la sphere Healpix sur fits
|
---|
| 220 | if(wsph) {
|
---|
| 221 | FitsOutFile swfits(fitsphwout);
|
---|
| 222 | cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
|
---|
| 223 | swfits << *wsph;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | // Nettoyage
|
---|
| 227 | delete sph;
|
---|
| 228 | if(wsph) delete wsph;
|
---|
| 229 |
|
---|
| 230 | //--------------------------------------------------------------------
|
---|
| 231 | } catch (PThrowable & exc) {
|
---|
| 232 | cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
| 233 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 234 | } catch (const std::exception & sex) {
|
---|
| 235 | cout<<"\ntsttoi2map: Catched std::exception \n"
|
---|
| 236 | <<(string)typeid(sex).name()<<endl;
|
---|
| 237 | } catch (...) {
|
---|
| 238 | cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
|
---|
| 239 | }
|
---|
| 240 | //--------------------------------------------------------------------
|
---|
| 241 |
|
---|
| 242 | exit(0);
|
---|
| 243 | }
|
---|