[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
|
---|
| 31 | <<" -i c,h : coord1 caracteristics (c=G/E h=H/D) (def=G,D)"<<endl
|
---|
| 32 | <<" -o c,h : idem -i for coord2"<<endl
|
---|
| 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;
|
---|
| 126 | cout<<" ...label_coord1 "<<label_coord1<<endl
|
---|
| 127 | <<" ...label_coord2 "<<label_coord2<<endl
|
---|
| 128 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
| 129 | tg = tcoorout&TypCoordGal; te = tcoorout&TypCoordEq;
|
---|
| 130 | hd = tcoorout&TypCoordHD; dd = tcoorout&TypCoordDD;
|
---|
| 131 | cout<<"Fits Healpix Sphere "<<fitsphout<<endl
|
---|
[1463] | 132 | <<" ...nlat "<<nlat<<endl
|
---|
[1516] | 133 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
| 134 | cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl;
|
---|
| 135 | }
|
---|
[1463] | 136 |
|
---|
| 137 | SophyaInit();
|
---|
| 138 | InitTim();
|
---|
| 139 |
|
---|
| 140 | //--------------------------------------------------------------------
|
---|
| 141 | try {
|
---|
| 142 | //--------------------------------------------------------------------
|
---|
| 143 |
|
---|
| 144 | // FITS reader
|
---|
[1498] | 145 | FITSTOIReader rfitsb(fitsin_bolo);
|
---|
| 146 | int ncolb = rfitsb.getNOut();
|
---|
| 147 | cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
|
---|
[1516] | 148 | if(ncolb<1) exit(-4);
|
---|
[1463] | 149 |
|
---|
[1498] | 150 | FITSTOIReader rfitsp(fitsin_point);
|
---|
| 151 | int ncolp = rfitsp.getNOut();
|
---|
| 152 | cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
|
---|
[1516] | 153 | if(ncolp<2) exit(-5);
|
---|
[1498] | 154 |
|
---|
[1463] | 155 | // Creation de la sphere Healpix
|
---|
| 156 | SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
|
---|
| 157 | cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
|
---|
| 158 | <<" Nombre de pixels : "<<sph->NbPixels()<<endl;
|
---|
| 159 |
|
---|
| 160 | // Creation de la sphere de poids Healpix
|
---|
| 161 | SphereHEALPix<r_8>* wsph = NULL;
|
---|
| 162 | if(fitsphwout.size()>0) {
|
---|
| 163 | wsph = new SphereHEALPix<r_8>;
|
---|
| 164 | cout<<"SphereHEALPix Weight: Type de map : "<<wsph->TypeOfMap()<<endl
|
---|
[1516] | 165 | <<" Nombre de pixels : "<<wsph->NbPixels()<<endl;
|
---|
[1463] | 166 | }
|
---|
| 167 |
|
---|
| 168 | // TOI Processor
|
---|
| 169 | TOI2Map toi2m(sph,wsph);
|
---|
| 170 | cout<<"TOI2Map created"<<endl;
|
---|
[1516] | 171 | toi2m.SetEquinox(2000.);
|
---|
| 172 | toi2m.SetCoorIn((TypAstroCoord) tcoorin);
|
---|
| 173 | toi2m.SetCoorOut((TypAstroCoord) tcoorout);
|
---|
[1463] | 174 |
|
---|
| 175 | // Definition des tuyaux
|
---|
[1498] | 176 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
[1516] | 177 | // toicoord1in->setDebugLevel(1);
|
---|
[1498] | 178 | rfitsp.addOutput(label_coord1,toicoord1in);
|
---|
| 179 | toi2m.addInput("Coord1In",toicoord1in);
|
---|
[1463] | 180 |
|
---|
[1498] | 181 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
[1516] | 182 | // toicoord2in->setDebugLevel(1);
|
---|
[1498] | 183 | rfitsp.addOutput(label_coord2,toicoord2in);
|
---|
| 184 | toi2m.addInput("Coord2In",toicoord2in);
|
---|
| 185 |
|
---|
[1463] | 186 | TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
|
---|
[1516] | 187 | // toibolin->setDebugLevel(1);
|
---|
[1498] | 188 | rfitsb.addOutput(label_bolomuv,toibolin);
|
---|
[1463] | 189 | toi2m.addInput("BoloIn",toibolin);
|
---|
| 190 |
|
---|
| 191 | // Run
|
---|
| 192 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
[1498] | 193 | rfitsp.PrintStatus(cout);
|
---|
| 194 | rfitsb.PrintStatus(cout);
|
---|
[1463] | 195 |
|
---|
| 196 | PrtTim("starting threads");
|
---|
[1498] | 197 | rfitsp.start();
|
---|
| 198 | rfitsb.start();
|
---|
[1463] | 199 | toi2m.start();
|
---|
| 200 |
|
---|
| 201 | if(lp>1)
|
---|
| 202 | for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
[1498] | 203 | cout<<*toicoord1in;
|
---|
[1463] | 204 | cout<<*toibolin;
|
---|
| 205 | sleep(2);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | mgr->joinAll();
|
---|
| 209 | PrtTim("End threads");
|
---|
| 210 |
|
---|
| 211 | // Ecriture de la sphere Healpix sur fits
|
---|
| 212 | {
|
---|
| 213 | FitsOutFile sfits(fitsphout);
|
---|
| 214 | cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
|
---|
| 215 | sfits << *sph;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | // Ecriture de la sphere Healpix sur fits
|
---|
| 219 | if(wsph) {
|
---|
| 220 | FitsOutFile swfits(fitsphwout);
|
---|
| 221 | cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
|
---|
| 222 | swfits << *wsph;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | // Nettoyage
|
---|
| 226 | delete sph;
|
---|
| 227 | if(wsph) delete wsph;
|
---|
| 228 |
|
---|
| 229 | //--------------------------------------------------------------------
|
---|
| 230 | } catch (PThrowable & exc) {
|
---|
| 231 | cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
| 232 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
| 233 | } catch (const std::exception & sex) {
|
---|
| 234 | cout<<"\ntsttoi2map: Catched std::exception \n"
|
---|
| 235 | <<(string)typeid(sex).name()<<endl;
|
---|
| 236 | } catch (...) {
|
---|
| 237 | cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
|
---|
| 238 | }
|
---|
| 239 | //--------------------------------------------------------------------
|
---|
| 240 |
|
---|
| 241 | exit(0);
|
---|
| 242 | }
|
---|