| 1 | // Dominique YVON, CEA/DAPNIA/SPP 02/2000 | 
|---|
| 2 |  | 
|---|
| 3 | #include <iomanip.h> | 
|---|
| 4 | #include <new> | 
|---|
| 5 |  | 
|---|
| 6 | # define ERROR_LABEL -32768 | 
|---|
| 7 |  | 
|---|
| 8 | #include "makebolotimeline.h" | 
|---|
| 9 | //#include "fitsioserver.h" | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | MakeBoloTimeline::MakeBoloTimeline(char file[], AbsLightSource& LSrc, | 
|---|
| 13 | AbsLobeNoPolar& Lobe, SpectralResponse& Filter, Normalisation Norm) | 
|---|
| 14 | {       IsSigCalctool=true; | 
|---|
| 15 | IsPtSrcInBandtool=false; | 
|---|
| 16 | pSigCalcTool=new SigCalcTool(&LSrc,&Lobe,&Filter); | 
|---|
| 17 | MakeBoloTimeline(file,*pSigCalcTool,Norm); | 
|---|
| 18 | } | 
|---|
| 19 |  | 
|---|
| 20 | MakeBoloTimeline::MakeBoloTimeline(char file[], LightPtSrcLevSInBand& LSrc, | 
|---|
| 21 | MeanFreqLobe& Lobe, LevSPanckBand band, Normalisation Norm) | 
|---|
| 22 | {       IsSigCalctool=false; | 
|---|
| 23 | IsPtSrcInBandtool=true; | 
|---|
| 24 |  | 
|---|
| 25 | pPtSrcInBandCalTools=new PtSrcInBandCalTools(&LSrc,&Lobe,band); | 
|---|
| 26 | MakeBoloTimeline(file,*pPtSrcInBandCalTools,Norm); | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | MakeBoloTimeline::MakeBoloTimeline(char file[], AbsCalcTool& Tool, Normalisation Norm) | 
|---|
| 30 | :NormMethode(Norm), ptool(&Tool) | 
|---|
| 31 | { | 
|---|
| 32 |  | 
|---|
| 33 | #ifndef __MWERKS__ | 
|---|
| 34 | char* PATHResults=getenv("PATHResults"); | 
|---|
| 35 | #endif | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | NormRJ=ptool->NormKelvinRayleighJeans(); | 
|---|
| 39 | NormTCMB=ptool->NormKelvinCMB(); | 
|---|
| 40 | saveReadMe(file); | 
|---|
| 41 |  | 
|---|
| 42 | char filecur[150]; | 
|---|
| 43 | sprintf(filecur,"%s.dat",file); | 
|---|
| 44 |  | 
|---|
| 45 | pMystr= new ofstream(filecur,ios::out|ios::trunc); | 
|---|
| 46 | //      pMystr->setf(ios::scientific); | 
|---|
| 47 | (*pMystr)<<setprecision(5); | 
|---|
| 48 |  | 
|---|
| 49 | #ifdef VisuIsActive | 
|---|
| 50 | // Visu de controle | 
|---|
| 51 | try | 
|---|
| 52 | {       pSphere=new SphereHEALPix<r_4>(64); | 
|---|
| 53 | pSphereInt=new SphereHEALPix<uint_2>(64); | 
|---|
| 54 | } | 
|---|
| 55 | catch (bad_alloc) | 
|---|
| 56 | {       cerr<<"bad alloc in MakeBoloTimeline:"<<file<<endl; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | sprintf(Name, "%s%s",file,".visu"); | 
|---|
| 60 | #endif | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | MakeBoloTimeline::~MakeBoloTimeline() | 
|---|
| 65 | { | 
|---|
| 66 | (*pMystr)<<flush; | 
|---|
| 67 | pMystr->close(); | 
|---|
| 68 | delete pMystr; | 
|---|
| 69 |  | 
|---|
| 70 | if(IsSigCalctool) delete pSigCalcTool; | 
|---|
| 71 | if(IsPtSrcInBandtool) delete pPtSrcInBandCalTools; | 
|---|
| 72 |  | 
|---|
| 73 | #ifdef VisuIsActive | 
|---|
| 74 | for(long index=0; index<(*pSphere).NbPixels();index++) | 
|---|
| 75 | if ((*pSphereInt).PixVal(index)!=0) | 
|---|
| 76 | (*pSphere).PixVal(index)=(*pSphere).PixVal(index)/(*pSphereInt).PixVal(index); | 
|---|
| 77 |  | 
|---|
| 78 | //      FitsIoServer FitsServer; | 
|---|
| 79 | #ifndef __MWERKS__ | 
|---|
| 80 | char* PATHResults=getenv("PATHResults"); | 
|---|
| 81 | #endif | 
|---|
| 82 |  | 
|---|
| 83 | //      FitsServer.Mollweide_picture_projection((*pSphere),Name);  // BUGG XXXXXXXXX | 
|---|
| 84 |  | 
|---|
| 85 | delete pSphere; | 
|---|
| 86 | delete pSphereInt; | 
|---|
| 87 | #endif | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | void MakeBoloTimeline::addToStreamArchTOI(double theta,double phi) | 
|---|
| 91 | {       //       Theta en heures, Phi en degres, systeme RA Dec | 
|---|
| 92 | if((theta==ERROR_LABEL)||(phi==ERROR_LABEL)) return; | 
|---|
| 93 |  | 
|---|
| 94 | // On passe en Radian | 
|---|
| 95 | double thetaRad=theta*15./180*M_PI; | 
|---|
| 96 | double phiRad=phi/180.*M_PI; | 
|---|
| 97 |  | 
|---|
| 98 | // Go to Galactic ccordinates | 
|---|
| 99 | double lgalax=0.; | 
|---|
| 100 | double bgalax=0.; | 
|---|
| 101 | kmg_eulerRad(thetaRad,phiRad,1,&lgalax,&bgalax); | 
|---|
| 102 |  | 
|---|
| 103 | // Add to time line | 
|---|
| 104 | addToStream(lgalax,bgalax); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | void MakeBoloTimeline::addToStream(double lgalax,double bgalax) | 
|---|
| 108 | {       // lgalax et bgalax en Radian, Systeme coord Galactique J2000 | 
|---|
| 109 |  | 
|---|
| 110 | double theta=M_PI/2.-bgalax;    // Coordonnees Spheriques galactiques | 
|---|
| 111 | double phi=lgalax; | 
|---|
| 112 | double value; | 
|---|
| 113 |  | 
|---|
| 114 | switch (NormMethode) | 
|---|
| 115 | { | 
|---|
| 116 | case RayleighJeans:     // Value en TempeRJ | 
|---|
| 117 | {       value= NormRJ*ptool->compPixelQD(theta,phi); | 
|---|
| 118 | break; | 
|---|
| 119 | } | 
|---|
| 120 | case TempeCMB:  // Value en tempeCMB | 
|---|
| 121 | {       value= NormTCMB*ptool->compPixelQD(theta,phi); | 
|---|
| 122 | break; | 
|---|
| 123 | } | 
|---|
| 124 | default:                // Value en power | 
|---|
| 125 | {       value   =ptool->compPixelQD(theta,phi); | 
|---|
| 126 | break; | 
|---|
| 127 | } | 
|---|
| 128 | } | 
|---|
| 129 | (*pMystr)<<lgalax<<'\t'<<bgalax<<'\t'<<value<<'\n'; | 
|---|
| 130 |  | 
|---|
| 131 | long PixelNumb=(*pSphere).PixIndexSph(theta,phi); | 
|---|
| 132 | (*pSphere).PixVal(PixelNumb)+=value; | 
|---|
| 133 | (*pSphereInt).PixVal(PixelNumb)++; | 
|---|
| 134 |  | 
|---|
| 135 | return; | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | void  MakeBoloTimeline::saveReadMe(char File[]) | 
|---|
| 139 | {       char filecur[150]; | 
|---|
| 140 | // Fill Header file for ascii output | 
|---|
| 141 | sprintf(filecur,"%s.ReadMe",File); | 
|---|
| 142 | cout<<filecur<<endl; | 
|---|
| 143 | ofstream ReadMe(filecur,ios::out|ios::trunc); | 
|---|
| 144 |  | 
|---|
| 145 | ReadMe<<" Fichier de timeline pour:"<<endl; | 
|---|
| 146 | ptool->print(ReadMe); | 
|---|
| 147 |  | 
|---|
| 148 |  | 
|---|
| 149 | ReadMe<< setprecision(3); | 
|---|
| 150 | ReadMe<<" Constantes de normalisation"<<endl; | 
|---|
| 151 | ReadMe<<" RayleighJeans: "<<NormRJ<< " KelvinRJ/(W/m2)"<<endl; | 
|---|
| 152 | ReadMe<<" TempeCMB: "<<NormTCMB<< " Kelvin CMB/(W/m2)"<<endl; | 
|---|
| 153 |  | 
|---|
| 154 | ReadMe<<"Cette carte est en unit: "; | 
|---|
| 155 | switch(NormMethode) | 
|---|
| 156 | { | 
|---|
| 157 | case TempeCMB: | 
|---|
| 158 | {       ReadMe<< "Kelvin CMB"<<endl; | 
|---|
| 159 | break; | 
|---|
| 160 | } | 
|---|
| 161 | case RayleighJeans: | 
|---|
| 162 | {       ReadMe<< "Kelvin RayleighJeans"<<endl; | 
|---|
| 163 | break; | 
|---|
| 164 | } | 
|---|
| 165 | default: ReadMe<< "Watt/m2 effectif de mirroir"<<endl; | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | ReadMe<<"Fichier coordones galactique J2000ecrit selon le format"<<endl; | 
|---|
| 169 | ReadMe<<"l_galax(Radian)\tb_galax(Radian)\tAbove Unit"<<endl; | 
|---|
| 170 |  | 
|---|
| 171 | // J'espere que c'est assez | 
|---|
| 172 | ReadMe.close(); | 
|---|
| 173 |  | 
|---|
| 174 | return; | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|