| [931] | 1 | #include "pmixer.h" | 
|---|
| [761] | 2 |  | 
|---|
| [928] | 3 | /*! | 
|---|
| [931] | 4 | * \defgroup PMixer PMixer module | 
|---|
|  | 5 | * This module contains programs which: | 
|---|
|  | 6 | * <UL> | 
|---|
|  | 7 | * <LI> add several sky components, taking into account their | 
|---|
|  | 8 | * radiation spectra and convoluting them with a given filter | 
|---|
|  | 9 | * response : skymixer | 
|---|
|  | 10 | * <LI> create a map with point source : extractRS | 
|---|
|  | 11 | * <LI> generate sky components, radiation spectra and spectral | 
|---|
|  | 12 | * response (small generator of maps) : tgsky and tgrsr | 
|---|
|  | 13 | * </UL> | 
|---|
|  | 14 | * A detailed description may be found at: | 
|---|
|  | 15 | */ | 
|---|
| [928] | 16 | /*! | 
|---|
|  | 17 | * \ingroup PMixer | 
|---|
|  | 18 | * \file skymixer.cc | 
|---|
|  | 19 | *\brief   \b PROGRAM    \b skyMixer  <BR> | 
|---|
|  | 20 | *   add several sky components, taking into account their | 
|---|
|  | 21 | *radiation spectra and convoluting them with a given filter | 
|---|
|  | 22 | *response | 
|---|
| [931] | 23 | */ | 
|---|
| [928] | 24 |  | 
|---|
| [761] | 25 | // ----------------------------------------------------------------- | 
|---|
|  | 26 | // ------------- Function declaration ------------------------------ | 
|---|
|  | 27 | int CheckCards(DataCards & dc, string & msg); | 
|---|
|  | 28 | char * BuildFITSFileName(string const & fname); | 
|---|
|  | 29 | SpectralResponse * getSpectralResponse(DataCards & dc); | 
|---|
|  | 30 | RadSpectra * getEmissionSpectra(DataCards & dc, int nc); | 
|---|
| [1252] | 31 | void SKM_MergeFITSKeywords(char * flnm); | 
|---|
| [761] | 32 | void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name); | 
|---|
|  | 33 | void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name); | 
|---|
| [1252] | 34 |  | 
|---|
| [876] | 35 | // to add different sky components and corresponding tools | 
|---|
|  | 36 | //---------------------------------------------------------- | 
|---|
|  | 37 | template <class T> | 
|---|
|  | 38 | void addComponent(SpectralResponse&  sr, | 
|---|
|  | 39 | PixelMap<T>& finalMap, | 
|---|
|  | 40 | PixelMap<T>& mapToAdd, | 
|---|
|  | 41 | RadSpectra& rs, double K=1.); | 
|---|
|  | 42 | // | 
|---|
| [761] | 43 | template <class T> | 
|---|
| [880] | 44 | void addComponentBeta(SphereHEALPix<T>& finalMap, | 
|---|
|  | 45 | SphereHEALPix<T>& mapToAdd,SpectralResponse& sr, | 
|---|
|  | 46 | SphereHEALPix<T>& betaMap, double normFreq, double K); | 
|---|
| [876] | 47 | // | 
|---|
| [761] | 48 | template <class T> | 
|---|
| [876] | 49 | void integratedMap(SpectralResponse&  sr, | 
|---|
| [880] | 50 | SphereHEALPix<T>& betaMap, double normFreq, SphereHEALPix<T>& intBetaMap); | 
|---|
| [904] | 51 |  | 
|---|
|  | 52 | // | 
|---|
| [876] | 53 | template <class T> | 
|---|
| [880] | 54 | void addComponentBeta(SphereHEALPix<T>& finalMap, | 
|---|
|  | 55 | SphereHEALPix<T>& mapToAdd, | 
|---|
|  | 56 | SphereHEALPix<T>& intBetaMap, double K); | 
|---|
| [876] | 57 | // | 
|---|
| [904] | 58 | template <class T> | 
|---|
|  | 59 | void addDipole(SpectralResponse&  sr,  PixelMap<T>& finalMap, | 
|---|
|  | 60 | double theta,double phi,double amp,double temp); | 
|---|
|  | 61 | // | 
|---|
| [761] | 62 | // ----------------------------------------------------------------- | 
|---|
|  | 63 |  | 
|---|
|  | 64 | //  ----- Global (static) variables ------------ | 
|---|
|  | 65 | static bool rdmap = false;    // true -> Read map first | 
|---|
|  | 66 | static char mapPath[256];     // Path for input maps | 
|---|
|  | 67 | static int  hp_nside = 32;    // HealPix NSide | 
|---|
|  | 68 | static int  nskycomp = 0;     // Number of sky components | 
|---|
|  | 69 | static int  debuglev = 0;     // Debug Level | 
|---|
|  | 70 | static int  printlev = 0;     // Print Level | 
|---|
| [1252] | 71 | static POutPersist * so = NULL;    // Debug PPFOut file | 
|---|
|  | 72 | static DVList * dvl_fitskw = NULL; // Global DVList for all FITS Keywords | 
|---|
| [761] | 73 |  | 
|---|
| [1252] | 74 | // --------- SkyMixer Version -------------- | 
|---|
|  | 75 | static double skm_version = 1.4; | 
|---|
|  | 76 |  | 
|---|
| [761] | 77 | // ------------------------------------------------------------------------- | 
|---|
|  | 78 | //                             main program | 
|---|
|  | 79 | // ------------------------------------------------------------------------- | 
|---|
|  | 80 | int main(int narg, char * arg[]) | 
|---|
|  | 81 | { | 
|---|
|  | 82 | if ((narg < 3) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) { | 
|---|
|  | 83 | cout << "  Usage: skymixer parameterFile outputfitsname [outppfname]" << endl; | 
|---|
|  | 84 | exit(0); | 
|---|
|  | 85 | } | 
|---|
| [886] | 86 |  | 
|---|
| [904] | 87 | InitTim(); | 
|---|
|  | 88 |  | 
|---|
|  | 89 | string msg; | 
|---|
|  | 90 | int rc = 0; | 
|---|
|  | 91 | RadSpectra * es = NULL; | 
|---|
|  | 92 | SpectralResponse * sr = NULL; | 
|---|
|  | 93 | double moy, sig; | 
|---|
|  | 94 |  | 
|---|
|  | 95 | DataCards dc; | 
|---|
|  | 96 | so = NULL; | 
|---|
| [1252] | 97 | // DVList for merging all FITS keywords | 
|---|
|  | 98 | dvl_fitskw = new DVList; | 
|---|
| [904] | 99 |  | 
|---|
|  | 100 | try { | 
|---|
|  | 101 | string dcard = arg[1]; | 
|---|
|  | 102 | if(printlev > 1) cout << " Decoding parameters from file " << dcard << endl; | 
|---|
|  | 103 | dc.ReadFile(dcard); | 
|---|
|  | 104 |  | 
|---|
|  | 105 | rc = CheckCards(dc, msg); | 
|---|
|  | 106 | if (rc) { | 
|---|
|  | 107 | cerr << " Error condition -> Rc= " << rc << endl; | 
|---|
|  | 108 | cerr << " Msg= " << msg << endl; | 
|---|
|  | 109 | return(rc); | 
|---|
|  | 110 | } | 
|---|
|  | 111 | } | 
|---|
|  | 112 | catch (PException exc) { | 
|---|
|  | 113 | msg = exc.Msg(); | 
|---|
|  | 114 | cerr << " !!!! skymixer/ Readcard - Catched exception - Msg= " << exc.Msg() << endl; | 
|---|
|  | 115 | return(90); | 
|---|
|  | 116 | } | 
|---|
|  | 117 |  | 
|---|
|  | 118 |  | 
|---|
|  | 119 | cout << " skymix/Info : NComp = " <<  nskycomp << " SphereHEALPix_NSide= " << hp_nside << endl; | 
|---|
|  | 120 | cout << "  ... MapPath = " << (string)mapPath << "  DebugLev= " << debuglev | 
|---|
|  | 121 | << "  PrintLev= " << printlev << endl; | 
|---|
|  | 122 |  | 
|---|
|  | 123 | // We create an output persist file for writing debug objects | 
|---|
|  | 124 | if (debuglev > 0) so = new POutPersist("skymixdbg.ppf"); | 
|---|
|  | 125 |  | 
|---|
|  | 126 | SphereHEALPix<float> outgs(hp_nside); | 
|---|
|  | 127 | try{ | 
|---|
|  | 128 | if (rdmap) {  // Reading map from FITS file | 
|---|
|  | 129 | char ifnm[256]; | 
|---|
|  | 130 | strncpy(ifnm, dc.SParam("READMAP", 0).c_str(), 255); | 
|---|
|  | 131 | ifnm[255] = '\0'; | 
|---|
|  | 132 | cout << " Reading output HealPix map from FITS file " << (string)ifnm << endl; | 
|---|
|  | 133 | { | 
|---|
| [937] | 134 | FITS_SphereHEALPix<float> fios(&outgs); | 
|---|
| [1062] | 135 | fios.Read(ifnm,2); | 
|---|
| [1252] | 136 | //  Getting FITS keywords in primary header | 
|---|
|  | 137 | SKM_MergeFITSKeywords(ifnm); | 
|---|
| [904] | 138 | } | 
|---|
|  | 139 | if(printlev>0) | 
|---|
|  | 140 | cout << " Output HealPIx Map read - NbPixels= " << | 
|---|
|  | 141 | outgs.NbPixels() << endl; | 
|---|
| [886] | 142 | if (printlev > 0) { | 
|---|
|  | 143 | MeanSig(outgs.DataBlock(), moy, sig ); | 
|---|
| [899] | 144 | cout << " MeanSig for outpout map - Mean= " << | 
|---|
|  | 145 | moy << " Sigma= " << sig << endl; | 
|---|
| [886] | 146 | } | 
|---|
| [761] | 147 | } | 
|---|
| [886] | 148 | else { | 
|---|
| [899] | 149 | if(printlev>0) | 
|---|
|  | 150 | cout << " Output HealPix Map  created - NbPixels= " << | 
|---|
|  | 151 | outgs.NbPixels() << endl; | 
|---|
| [886] | 152 | outgs.SetPixels(0.); | 
|---|
|  | 153 | } | 
|---|
| [876] | 154 |  | 
|---|
| [886] | 155 | // Decoding detection pass-band filter | 
|---|
|  | 156 | sr = getSpectralResponse(dc); | 
|---|
|  | 157 | PrtTim(" After FilterCreation "); | 
|---|
| [876] | 158 |  | 
|---|
| [886] | 159 | char * flnm, buff[90]; | 
|---|
|  | 160 | string key; | 
|---|
| [876] | 161 |  | 
|---|
| [886] | 162 | double K = 1.; | 
|---|
|  | 163 | double freqOfMap = 1.; | 
|---|
|  | 164 | // Loop over sky component | 
|---|
|  | 165 | int sk; | 
|---|
|  | 166 | for(sk = 0; sk<nskycomp; sk++) { | 
|---|
| [899] | 167 | cout << "------------------------------------" << endl; | 
|---|
| [886] | 168 | cout << " Processing sky component No " << sk+1 << endl; | 
|---|
|  | 169 |  | 
|---|
| [904] | 170 |  | 
|---|
| [886] | 171 | sprintf(buff, "%d", sk+1); | 
|---|
| [904] | 172 | key = (string)"DIPOLE" + buff; | 
|---|
|  | 173 | // check for an eventual dipole | 
|---|
| [899] | 174 | if(dc.HasKey(key)) | 
|---|
|  | 175 | { | 
|---|
| [886] | 176 | if (es) { delete es; es = NULL; } | 
|---|
| [904] | 177 | double temp = -10.; | 
|---|
|  | 178 | double theta=  dc.DParam(key,1,1.); | 
|---|
|  | 179 | double phi  =  dc.DParam(key,2,1.); | 
|---|
|  | 180 | double amp  =  dc.DParam(key,3,1.); | 
|---|
|  | 181 | if(dc.NbParam(key)>3) | 
|---|
|  | 182 | { | 
|---|
|  | 183 | temp =  dc.DParam(key,4,1.); | 
|---|
|  | 184 | } | 
|---|
|  | 185 | cout << " creating dipole " << temp << " " << amp << " " << phi << " " << theta << " " << endl; | 
|---|
|  | 186 | addDipole(*sr, outgs,theta,phi,amp,temp); | 
|---|
| [886] | 187 | } | 
|---|
|  | 188 | else | 
|---|
|  | 189 | { | 
|---|
| [904] | 190 | sprintf(buff, "%d", sk+1); | 
|---|
|  | 191 | key = (string)"MAPFITSFILE" + buff; | 
|---|
| [886] | 192 | flnm = BuildFITSFileName(dc.SParam(key, 0)); | 
|---|
| [904] | 193 |  | 
|---|
|  | 194 | K = dc.DParam(key, 1, 1.); | 
|---|
|  | 195 |  | 
|---|
|  | 196 | cout << " Reading Input FITS map " << (string)flnm << endl; | 
|---|
|  | 197 | SphereHEALPix<float> ings(hp_nside); | 
|---|
| [899] | 198 | { | 
|---|
| [937] | 199 | FITS_SphereHEALPix<float> fiosIn(&ings); | 
|---|
| [1062] | 200 | fiosIn.Read(flnm,2); | 
|---|
| [1252] | 201 | //  Getting FITS keywords in primary header | 
|---|
|  | 202 | SKM_MergeFITSKeywords(flnm); | 
|---|
| [899] | 203 | } | 
|---|
|  | 204 | if (debuglev > 4) {  // Writing the input map to the outppf | 
|---|
| [904] | 205 | FIO_SphereHEALPix<float> fiog(ings); | 
|---|
|  | 206 | fiog.Write(*so, key); | 
|---|
| [899] | 207 | } | 
|---|
| [904] | 208 | if (printlev > 2) { | 
|---|
|  | 209 | MeanSig(ings.DataBlock(), moy, sig ); | 
|---|
|  | 210 | cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl; | 
|---|
|  | 211 | } | 
|---|
|  | 212 | bool mapDependentOfFreq = false; | 
|---|
|  | 213 | key = (string)"BETAFITSFILE"+ buff; | 
|---|
|  | 214 | if(dc.HasKey(key)) | 
|---|
|  | 215 | { | 
|---|
|  | 216 | mapDependentOfFreq = true; | 
|---|
|  | 217 | } | 
|---|
|  | 218 |  | 
|---|
|  | 219 | // getting Emission spectra | 
|---|
|  | 220 | if(!mapDependentOfFreq) | 
|---|
|  | 221 | { | 
|---|
|  | 222 | if (es) { delete es; es = NULL; } | 
|---|
|  | 223 | es = getEmissionSpectra(dc, sk); | 
|---|
|  | 224 | addComponent(*sr, outgs, ings, *es, K); | 
|---|
|  | 225 | } | 
|---|
| [886] | 226 | else | 
|---|
|  | 227 | { | 
|---|
| [904] | 228 | key = (string)"BETAFITSFILE"+ buff; | 
|---|
|  | 229 | //SphereHEALPix<float> betaMap; | 
|---|
|  | 230 | flnm = BuildFITSFileName(dc.SParam(key, 0)); | 
|---|
|  | 231 | double normFreq = dc.DParam(key, 1, 1.); | 
|---|
|  | 232 | if (printlev > 4) cout << "....BetaFits... normalization Freq = " << normFreq << endl; | 
|---|
|  | 233 | int nSideForInt = dc.DParam(key, 2, 1.); | 
|---|
|  | 234 | if (printlev > 4) cout << "....BetaFits... NSide for Integration map = " << nSideForInt << endl; | 
|---|
|  | 235 | cout << "....BetaFits...  Reading Beta FITS map " << (string)flnm << endl; | 
|---|
|  | 236 | SphereHEALPix<float> betaMap(hp_nside); | 
|---|
|  | 237 | { | 
|---|
| [937] | 238 | FITS_SphereHEALPix<float> fiosBM(&betaMap); | 
|---|
| [1062] | 239 | fiosBM.Read(flnm,2); | 
|---|
| [1252] | 240 | //  Getting FITS keywords in primary header | 
|---|
|  | 241 | SKM_MergeFITSKeywords(flnm); | 
|---|
| [904] | 242 | } | 
|---|
| [937] | 243 | if (printlev > 2) { | 
|---|
|  | 244 | MeanSig(betaMap.DataBlock(), moy, sig ); | 
|---|
|  | 245 | cout << " MeanSig for Beta map - Mean= " << moy << " Sigma= " << sig << endl; | 
|---|
|  | 246 | } | 
|---|
| [899] | 247 | if (debuglev > 4) {  // Writing the input map to the outppf | 
|---|
| [904] | 248 | FIO_SphereHEALPix<float> fiogs(betaMap); | 
|---|
|  | 249 | fiogs.Write(*so, key); | 
|---|
| [899] | 250 | } | 
|---|
| [904] | 251 |  | 
|---|
|  | 252 | if(nSideForInt<0) nSideForInt = sqrt((double)betaMap.NbPixels()/12); | 
|---|
|  | 253 | bool bydefault = true; | 
|---|
|  | 254 | if(!bydefault) | 
|---|
|  | 255 | addComponentBeta(outgs,ings,*sr,betaMap,normFreq, K); | 
|---|
|  | 256 | else | 
|---|
|  | 257 | { | 
|---|
|  | 258 | // integrate the betamap over the SpectralResponse | 
|---|
|  | 259 | SphereHEALPix<float> intBetaMap(nSideForInt); | 
|---|
|  | 260 | integratedMap(*sr, betaMap, normFreq, intBetaMap); | 
|---|
|  | 261 | if (debuglev > 4) {  // Writing the input map to the outppf | 
|---|
|  | 262 | FIO_SphereHEALPix<float> fiogs2(intBetaMap); | 
|---|
|  | 263 | fiogs2.Write(*so, "INTBETAMAP"); | 
|---|
|  | 264 | } | 
|---|
|  | 265 |  | 
|---|
|  | 266 | betaMap.Resize(8); | 
|---|
| [937] | 267 | if (printlev > 4) | 
|---|
|  | 268 | { | 
|---|
|  | 269 | MeanSig(intBetaMap.DataBlock(), moy, sig ); | 
|---|
|  | 270 | cout << "....BetaFits... MeanSig for intBetaMap - Mean= " | 
|---|
|  | 271 | << moy << " Sigma= " << sig << endl; | 
|---|
|  | 272 | } | 
|---|
| [904] | 273 | // add the integrated beta map | 
|---|
|  | 274 | addComponentBeta(outgs,ings,intBetaMap, K); | 
|---|
|  | 275 | } | 
|---|
| [886] | 276 | } | 
|---|
| [904] | 277 |  | 
|---|
|  | 278 | MeanSig(outgs.DataBlock(), moy, sig ); | 
|---|
|  | 279 | cout << " MeanSig for Sum map - Mean= " << moy << " Sigma= " << sig << endl; | 
|---|
|  | 280 | cout << "-------------------------------------------------" << endl; | 
|---|
|  | 281 |  | 
|---|
|  | 282 | sprintf(buff, "End of Processing Component %d ", sk+1); | 
|---|
|  | 283 | PrtTim(buff); | 
|---|
|  | 284 | } | 
|---|
|  | 285 | } | 
|---|
|  | 286 | } | 
|---|
|  | 287 | catch(PException exc) | 
|---|
|  | 288 | { | 
|---|
|  | 289 | cout << "catched PException" << endl; | 
|---|
|  | 290 | msg = exc.Msg(); | 
|---|
|  | 291 | cerr << " !!!! skymixer - Catched exception - Msg= " << exc.Msg() << endl; | 
|---|
|  | 292 | rc = 50; | 
|---|
|  | 293 | return(50); | 
|---|
| [886] | 294 | } | 
|---|
| [904] | 295 |  | 
|---|
| [986] | 296 | try { | 
|---|
| [886] | 297 | // Saving the output map in FITS format | 
|---|
| [986] | 298 | cout << "Output Map (SphereHEALPix<float>) written to FITS file " | 
|---|
|  | 299 | << (string)(arg[2]) << endl; | 
|---|
|  | 300 | { | 
|---|
| [1239] | 301 | FitsOutFile fios(arg[2]); | 
|---|
|  | 302 | fios.firstImageOnPrimaryHeader(false); // Use secondary header | 
|---|
| [1252] | 303 | DVList& dvl = (*dvl_fitskw); | 
|---|
|  | 304 | dvl["PDMTYPE"] = "COMPMAP"; | 
|---|
|  | 305 | dvl.SetComment("PDMTYPE", "Planck Data Model Type"); | 
|---|
|  | 306 | dvl["SOPHYVER"] =  SophyaVersion(); | 
|---|
|  | 307 | dvl.SetComment("SOPHYVER", "Sophya Version number"); | 
|---|
|  | 308 | dvl["SKYMVER"] =  skm_version; | 
|---|
|  | 309 | dvl.SetComment("SKYMVER", "skymixer Version number"); | 
|---|
|  | 310 | fios.DVListIntoPrimaryHeader(dvl); | 
|---|
| [1239] | 311 | fios << outgs ; | 
|---|
| [986] | 312 | } | 
|---|
|  | 313 | PrtTim("End of WriteFITS "); | 
|---|
|  | 314 | // Saving the output map in PPF format | 
|---|
|  | 315 | if (narg > 3) { | 
|---|
|  | 316 | POutPersist s(arg[3]); | 
|---|
|  | 317 | FIO_SphereHEALPix<float> fiog(&outgs) ; | 
|---|
|  | 318 | fiog.Write(s); | 
|---|
|  | 319 | cout << "Output Map (SphereHEALPix<float>) written to POutPersist file " | 
|---|
|  | 320 | << (string)(arg[3]) << endl; | 
|---|
|  | 321 | PrtTim("End of WritePPF "); | 
|---|
|  | 322 | } | 
|---|
| [899] | 323 | } | 
|---|
| [986] | 324 | catch(PException exc) | 
|---|
|  | 325 | { | 
|---|
|  | 326 | cout << "catched PException (2)" << endl; | 
|---|
|  | 327 | msg = exc.Msg(); | 
|---|
|  | 328 | cerr << " !!!! skymixer(2) - Catched exception - Msg= " << exc.Msg() << endl; | 
|---|
|  | 329 | rc = 55; | 
|---|
|  | 330 | return(55); | 
|---|
|  | 331 | } | 
|---|
|  | 332 |  | 
|---|
| [886] | 333 | if (so) delete so;  //  Closing the debug ppf file | 
|---|
|  | 334 | return(rc); | 
|---|
| [761] | 335 | } | 
|---|
|  | 336 |  | 
|---|
|  | 337 | /* Nouvelle-Fonction */ | 
|---|
|  | 338 | int CheckCards(DataCards & dc, string & msg) | 
|---|
|  | 339 | //   Function to check datacards | 
|---|
|  | 340 | { | 
|---|
|  | 341 | rdmap = false; | 
|---|
|  | 342 | mapPath[0] = '\0'; | 
|---|
|  | 343 | hp_nside = 32; | 
|---|
|  | 344 | nskycomp = 0; | 
|---|
|  | 345 | debuglev  = 0; | 
|---|
|  | 346 | printlev = 0; | 
|---|
|  | 347 |  | 
|---|
|  | 348 | int rc = 0; | 
|---|
| [904] | 349 | string key, key2,key3; | 
|---|
| [761] | 350 |  | 
|---|
|  | 351 | //  Cheking datacards | 
|---|
|  | 352 | if (dc.NbParam("SKYMIX") < 2)   { | 
|---|
|  | 353 | rc = 71; | 
|---|
|  | 354 | msg = "Invalid parameters  - Check @SKYMIX card "; | 
|---|
|  | 355 | return(rc); | 
|---|
|  | 356 | } | 
|---|
|  | 357 | key = "READMAP"; | 
|---|
|  | 358 | if (dc.HasKey(key)) { | 
|---|
|  | 359 | if (dc.NbParam(key) < 1) { | 
|---|
|  | 360 | rc = 72; | 
|---|
|  | 361 | msg = "Invalid parameters  - Check @READMAP card "; | 
|---|
|  | 362 | return(rc); | 
|---|
|  | 363 | } | 
|---|
|  | 364 | else rdmap = true; | 
|---|
|  | 365 | } | 
|---|
|  | 366 |  | 
|---|
|  | 367 | //  Checking detection filter specification | 
|---|
|  | 368 | key = "GAUSSFILTER"; | 
|---|
|  | 369 | key2 = "FILTERFITSFILE"; | 
|---|
| [904] | 370 | key3 = "DIPOLE"; | 
|---|
|  | 371 | if ( (dc.NbParam(key) < 5) && (dc.NbParam(key2) < 3) && (dc.NbParam(key3) < 3)) { | 
|---|
|  | 372 | msg = "Missing card or parameters : Check @GAUSSFILTER or @FILTERFITSFILE or @DIPOLE"; | 
|---|
| [761] | 373 | rc = 73;  return(rc); | 
|---|
|  | 374 | } | 
|---|
|  | 375 |  | 
|---|
|  | 376 | // Decoding number of component and pixelisation parameter | 
|---|
|  | 377 | int mg = 32; | 
|---|
|  | 378 | int ncomp = 0; | 
|---|
|  | 379 | ncomp = dc.IParam("SKYMIX", 0, 0); | 
|---|
|  | 380 | mg = dc.IParam("SKYMIX", 1, 32); | 
|---|
|  | 381 | if (ncomp < 1)  { | 
|---|
|  | 382 | msg = "Invalid parameters  - Check datacards @SKYMIX "; | 
|---|
|  | 383 | rc = 74; | 
|---|
|  | 384 | return(rc); | 
|---|
|  | 385 | } | 
|---|
|  | 386 |  | 
|---|
|  | 387 | // Checking detection filter specification | 
|---|
| [876] | 388 | //  Checking input FITS file specifications | 
|---|
| [761] | 389 | int kc; | 
|---|
|  | 390 | char buff[256]; | 
|---|
|  | 391 | bool pb = false; | 
|---|
| [876] | 392 | string key4; | 
|---|
|  | 393 | string key5; | 
|---|
| [904] | 394 | string key6; | 
|---|
| [761] | 395 | for(kc=0; kc<ncomp; kc++) { | 
|---|
|  | 396 | sprintf(buff, "MAPFITSFILE%d", kc+1); | 
|---|
|  | 397 | key = buff; | 
|---|
| [904] | 398 | sprintf(buff, "DIPOLE%d", kc+1); | 
|---|
|  | 399 | key3 = buff; | 
|---|
|  | 400 | if (dc.NbParam(key) < 1 && dc.NbParam(key3)<1) { | 
|---|
|  | 401 | msg = "Missing or invalid card : " + key + " " + key2 + " " + key3; | 
|---|
| [761] | 402 | pb = true;  break; | 
|---|
|  | 403 | } | 
|---|
|  | 404 | sprintf(buff, "SPECTRAFITSFILE%d", kc+1); | 
|---|
|  | 405 | key = buff; | 
|---|
|  | 406 | sprintf(buff, "BLACKBODY%d", kc+1); | 
|---|
|  | 407 | key2 = buff; | 
|---|
|  | 408 | sprintf(buff, "POWERLAWSPECTRA%d", kc+1); | 
|---|
|  | 409 | key3 = buff; | 
|---|
| [876] | 410 | sprintf(buff, "BETAFITSFILE%d", kc+1); | 
|---|
|  | 411 | key4 = buff; | 
|---|
|  | 412 | sprintf(buff, "DIPOLE%d", kc+1); | 
|---|
|  | 413 | key5 = buff; | 
|---|
| [904] | 414 | sprintf(buff, "DERIVBB%d", kc+1); | 
|---|
|  | 415 | key6 = buff; | 
|---|
| [876] | 416 | if ( (dc.NbParam(key) < 3) && (dc.NbParam(key2) < 1) && (dc.NbParam(key3) < 6) && (dc.NbParam(key4)<2) | 
|---|
| [904] | 417 | &&  (dc.NbParam(key6)<1) &&  (dc.NbParam(key5)<3))  { | 
|---|
| [876] | 418 | msg = "Missing card or invalid parameters : " + key + " " + key2 + " " + key3 + " " + key4+ " " + key5; | 
|---|
| [761] | 419 | pb = true;  break; | 
|---|
|  | 420 | } | 
|---|
|  | 421 |  | 
|---|
|  | 422 | } | 
|---|
|  | 423 |  | 
|---|
|  | 424 | if (pb)  { | 
|---|
|  | 425 | rc = 75; | 
|---|
|  | 426 | return(75); | 
|---|
|  | 427 | } | 
|---|
|  | 428 |  | 
|---|
|  | 429 |  | 
|---|
|  | 430 | // Initialiazing parameters | 
|---|
|  | 431 | rc = 0; | 
|---|
|  | 432 | msg = "OK"; | 
|---|
|  | 433 | nskycomp = ncomp; | 
|---|
|  | 434 | hp_nside = mg; | 
|---|
|  | 435 |  | 
|---|
|  | 436 | // Checking for PATH definition card | 
|---|
|  | 437 | key = "MAPPATH"; | 
|---|
|  | 438 | if (dc.NbParam(key) < 3)  strncpy(mapPath, dc.SParam(key, 0).c_str(), 255); | 
|---|
|  | 439 | mapPath[255] = '\0'; | 
|---|
|  | 440 | key = "DEBUGLEVEL"; | 
|---|
|  | 441 | debuglev =  dc.IParam(key, 0, 0); | 
|---|
|  | 442 | key = "PRINTLEVEL"; | 
|---|
|  | 443 | printlev =  dc.IParam(key, 0, 0); | 
|---|
|  | 444 | return(rc); | 
|---|
|  | 445 | } | 
|---|
|  | 446 |  | 
|---|
|  | 447 | static char buff_flnm[1024];   // Mal protege ! | 
|---|
|  | 448 | /* Nouvelle-Fonction */ | 
|---|
|  | 449 | char* BuildFITSFileName(string const & fname) | 
|---|
|  | 450 | { | 
|---|
|  | 451 | if (mapPath[0] != '\0') sprintf(buff_flnm, "%s/%s", mapPath, fname.c_str()); | 
|---|
|  | 452 | else sprintf(buff_flnm, "%s", fname.c_str()); | 
|---|
|  | 453 | return(buff_flnm); | 
|---|
|  | 454 | } | 
|---|
|  | 455 |  | 
|---|
|  | 456 | /* Nouvelle-Fonction */ | 
|---|
|  | 457 | SpectralResponse * getSpectralResponse(DataCards & dc) | 
|---|
|  | 458 | { | 
|---|
|  | 459 | SpectralResponse * filt = NULL; | 
|---|
|  | 460 |  | 
|---|
|  | 461 | string key = "FILTERFITSFILE"; | 
|---|
|  | 462 | string key2 = "GAUSSFILTER"; | 
|---|
|  | 463 | string ppfname = "filter"; | 
|---|
|  | 464 |  | 
|---|
|  | 465 | if (dc.HasKey(key) ) {      // Reading FITS filter file | 
|---|
|  | 466 | char ifnm[256]; | 
|---|
|  | 467 | strncpy(ifnm, dc.SParam(key, 1).c_str(), 255); | 
|---|
|  | 468 | ifnm[255] = '\0'; | 
|---|
| [1120] | 469 | Matrix mtx; | 
|---|
| [1239] | 470 | FitsInFile fiis(ifnm); | 
|---|
|  | 471 | fiis.firstImageOnPrimaryHeader(false); // Use secondary header HDU=2 | 
|---|
|  | 472 | fiis >> mtx ; | 
|---|
| [1252] | 473 | //  Getting FITS keywords in primary header | 
|---|
|  | 474 | SKM_MergeFITSKeywords(ifnm); | 
|---|
| [761] | 475 | double numin = dc.DParam(key, 2, 1.); | 
|---|
|  | 476 | double numax = dc.DParam(key, 3, 9999.); | 
|---|
|  | 477 | Vector nu(mtx.NCols()); | 
|---|
|  | 478 | Vector fnu(mtx.NCols()); | 
|---|
|  | 479 | for(int k=0; k<mtx.NCols(); k++) { | 
|---|
|  | 480 | nu(k) = mtx(0, k); | 
|---|
|  | 481 | fnu(k) = mtx(1, k); | 
|---|
|  | 482 | } | 
|---|
|  | 483 | filt = new SpecRespVec(nu, fnu, numin, numax); | 
|---|
|  | 484 | ppfname = key; | 
|---|
|  | 485 | } | 
|---|
|  | 486 | else if (dc.HasKey(key2) ) {   // creating GaussianFilter | 
|---|
|  | 487 | double nu0 = dc.DParam(key2, 0, 10.); | 
|---|
|  | 488 | double s = dc.DParam(key2, 1, 1.); | 
|---|
|  | 489 | double a = dc.DParam(key2, 2, 1.); | 
|---|
|  | 490 | double numin = dc.DParam(key2, 3, 0.1); | 
|---|
|  | 491 | double numax = dc.DParam(key2, 4, 9999); | 
|---|
|  | 492 | filt = new GaussianFilter(nu0, s, a, numin, numax); | 
|---|
|  | 493 | ppfname = key2; | 
|---|
|  | 494 | } | 
|---|
|  | 495 | if (filt == NULL) throw ParmError("datacard error ! No detection filter"); | 
|---|
| [899] | 496 | if(printlev>0) | 
|---|
|  | 497 | { | 
|---|
|  | 498 | cout << endl; | 
|---|
|  | 499 | cout << " Filter decoded - Created " << endl; | 
|---|
|  | 500 | cout << *filt << endl; | 
|---|
|  | 501 | } | 
|---|
|  | 502 | // for debug | 
|---|
| [761] | 503 | if (debuglev > 1)  SpectralResponse2Nt(*filt, *so, ppfname); | 
|---|
|  | 504 | return(filt); | 
|---|
|  | 505 | } | 
|---|
|  | 506 |  | 
|---|
|  | 507 | /* Nouvelle-Fonction */ | 
|---|
|  | 508 | RadSpectra * getEmissionSpectra(DataCards & dc, int nc) | 
|---|
|  | 509 | { | 
|---|
|  | 510 | char numb[16]; | 
|---|
|  | 511 | sprintf(numb, "%d", nc+1); | 
|---|
|  | 512 |  | 
|---|
|  | 513 | string key = (string)"SPECTRAFITSFILE" + numb; | 
|---|
|  | 514 | string key2 = (string)"BLACKBODY" + numb; | 
|---|
| [904] | 515 | string key5 = (string)"DERIVBB" + numb; | 
|---|
| [761] | 516 | string key3 = (string)"POWERLAWSPECTRA" + numb; | 
|---|
|  | 517 | string ppfname = "espectra"; | 
|---|
|  | 518 |  | 
|---|
|  | 519 | RadSpectra * rs = NULL; | 
|---|
|  | 520 | if (dc.HasKey(key) ) {    // Reading emission spectra from file | 
|---|
|  | 521 | char * ifnm = BuildFITSFileName(dc.SParam(key, 0)); | 
|---|
|  | 522 | cout << " Reading Input FITS spectra file " << (string)ifnm << endl; | 
|---|
| [1120] | 523 | Matrix mtx; | 
|---|
| [1239] | 524 | FitsInFile fiis(ifnm); | 
|---|
|  | 525 | fiis.firstImageOnPrimaryHeader(false); // Use secondary header HDU=2 | 
|---|
|  | 526 | fiis >> mtx ; | 
|---|
| [1252] | 527 | //  Getting FITS keywords in primary header | 
|---|
|  | 528 | SKM_MergeFITSKeywords(ifnm); | 
|---|
| [761] | 529 | double numin = dc.DParam(key, 2, 1.); | 
|---|
|  | 530 | double numax = dc.DParam(key, 3, 9999.); | 
|---|
|  | 531 | Vector nu(mtx.NCols()); | 
|---|
|  | 532 | Vector tnu(mtx.NCols()); | 
|---|
|  | 533 | for(int k=0; k<mtx.NCols(); k++) { | 
|---|
|  | 534 | nu(k) = mtx(0, k); | 
|---|
|  | 535 | tnu(k) = mtx(1, k); | 
|---|
|  | 536 | } | 
|---|
|  | 537 | rs = new RadSpectraVec(nu, tnu, numin, numax); | 
|---|
|  | 538 | ppfname = key; | 
|---|
|  | 539 | } | 
|---|
|  | 540 | else if (dc.HasKey(key2) ) { // Creating BlackBody emission spectra | 
|---|
|  | 541 | rs = new BlackBody(dc.DParam(key2, 0, 2.726)); | 
|---|
|  | 542 | ppfname = key2; | 
|---|
|  | 543 | } | 
|---|
| [876] | 544 | else if (dc.HasKey(key5) ) { // Creating Dipole | 
|---|
| [904] | 545 | rs = new DerivBlackBody(dc.DParam(key5, 0, 3.E-3)); | 
|---|
| [876] | 546 | ppfname = key5; | 
|---|
|  | 547 | } | 
|---|
| [761] | 548 | else if (dc.HasKey(key3) ) { // Creating PowerLaw emission spectra | 
|---|
|  | 549 | double a = dc.DParam(key3, 0, 1.); | 
|---|
|  | 550 | double nu0 = dc.DParam(key3, 1, 100.); | 
|---|
|  | 551 | double dnu = dc.DParam(key3, 2, 10.); | 
|---|
|  | 552 | double b = dc.DParam(key3, 3, 0.); | 
|---|
|  | 553 | double numin = dc.DParam(key3, 4, 0.1); | 
|---|
|  | 554 | double numax = dc.DParam(key3, 5, 9999); | 
|---|
|  | 555 | rs = new PowerLawSpectra(a, b, nu0, dnu, numin, numax); | 
|---|
|  | 556 | ppfname = key3; | 
|---|
|  | 557 | } | 
|---|
|  | 558 | if (rs == NULL) throw ParmError("datacard error ! missing Emission spectra"); | 
|---|
|  | 559 | cout << " Emission spectra decoded - Created (" << ppfname << ")" << endl; | 
|---|
|  | 560 | cout << *rs << endl; | 
|---|
|  | 561 | // for debug | 
|---|
|  | 562 | if (debuglev > 2)  RadSpec2Nt(*rs, *so, ppfname); | 
|---|
|  | 563 | return(rs); | 
|---|
|  | 564 | } | 
|---|
|  | 565 |  | 
|---|
|  | 566 |  | 
|---|
|  | 567 |  | 
|---|
|  | 568 |  | 
|---|
| [904] | 569 | template <class T> | 
|---|
|  | 570 | void addDipole(SpectralResponse&  sr,  PixelMap<T>& finalMap, | 
|---|
|  | 571 | double theta,double phi,double amp,double temp) | 
|---|
|  | 572 | { | 
|---|
|  | 573 | DerivBlackBody dbb; | 
|---|
|  | 574 | if(temp>0) dbb.setTemperature(temp); | 
|---|
|  | 575 | double coeff = dbb.filteredIntegratedFlux(sr) * amp; | 
|---|
|  | 576 | UnitVector vd(theta,phi); | 
|---|
|  | 577 | UnitVector vc(theta,phi); | 
|---|
|  | 578 |  | 
|---|
|  | 579 | for(int i=0; i<finalMap.NbPixels(); i++) | 
|---|
|  | 580 | { | 
|---|
|  | 581 | double thetar,phir; | 
|---|
|  | 582 | finalMap.PixThetaPhi(i,thetar,phir); | 
|---|
|  | 583 | vc.SetThetaPhi(thetar,  phir); | 
|---|
|  | 584 | finalMap(i) += vd.Psc(vc)*coeff; | 
|---|
|  | 585 | } | 
|---|
|  | 586 | if (debuglev > 4) {  // Writing the input map to the outppf | 
|---|
|  | 587 | SphereHEALPix<float> ings(sqrt((double)finalMap.NbPixels()/12)); | 
|---|
|  | 588 | for(int i=0; i<finalMap.NbPixels(); i++) | 
|---|
|  | 589 | { | 
|---|
|  | 590 | double thetar,phir; | 
|---|
|  | 591 | finalMap.PixThetaPhi(i,thetar,phir); | 
|---|
|  | 592 | vc.SetThetaPhi(thetar,  phir); | 
|---|
|  | 593 | ings(i) = vd.Psc(vc); | 
|---|
|  | 594 | } | 
|---|
|  | 595 | FIO_SphereHEALPix<float> fiog(ings); | 
|---|
|  | 596 | fiog.Write(*so, "dipole"); | 
|---|
|  | 597 | cout << "Debug the dipole map....saved in debug file !" << endl; | 
|---|
|  | 598 | } | 
|---|
|  | 599 | } | 
|---|
| [761] | 600 | /* Nouvelle-Fonction */ | 
|---|
|  | 601 | template <class T> | 
|---|
|  | 602 | void addComponent(SpectralResponse&  sr, PixelMap<T>& finalMap, | 
|---|
|  | 603 | PixelMap<T>& mapToAdd, RadSpectra& rs, double K) | 
|---|
|  | 604 | { | 
|---|
|  | 605 | // finalMap = finalMap + coeff* mapToAdd | 
|---|
|  | 606 | // coeff    =  convolution of sr and rs | 
|---|
|  | 607 | // compute the coefficient corresponding to mapToAdd | 
|---|
|  | 608 | if (finalMap.NbPixels() != mapToAdd.NbPixels()) | 
|---|
|  | 609 | throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels"); | 
|---|
|  | 610 | double coeff = rs.filteredIntegratedFlux(sr) * K; | 
|---|
|  | 611 | if (printlev > 1) | 
|---|
|  | 612 | cout << " addComponent - Coeff= " << coeff << " (K= " << K << ")" << endl; | 
|---|
|  | 613 | for(int i=0; i<finalMap.NbPixels(); i++) | 
|---|
|  | 614 | { | 
|---|
|  | 615 | finalMap(i) += coeff * mapToAdd(i); | 
|---|
|  | 616 | } | 
|---|
|  | 617 | } | 
|---|
| [876] | 618 | /* Nouvelle-Fonction */ | 
|---|
|  | 619 | template <class T> | 
|---|
| [880] | 620 | void addComponentBeta(SphereHEALPix<T>& finalMap, | 
|---|
|  | 621 | SphereHEALPix<T>& mapToAdd,SpectralResponse& sr, | 
|---|
|  | 622 | SphereHEALPix<T>& betaMap, double normFreq, double K) | 
|---|
| [876] | 623 | { | 
|---|
|  | 624 | // finalMap = finalMap + coeff* mapToAdd | 
|---|
|  | 625 | // coeff    =  convolution of sr and rs | 
|---|
|  | 626 | // compute the coefficient corresponding to mapToAdd | 
|---|
|  | 627 | // betaMap is the map of (beta(theta,phi)) | 
|---|
| [761] | 628 |  | 
|---|
| [876] | 629 | int nbpix = finalMap.NbPixels(); | 
|---|
|  | 630 | if (nbpix != mapToAdd.NbPixels()) | 
|---|
|  | 631 | throw SzMismatchError("addComponentBeta()/Error: Unequal number of Input/Output map pixels"); | 
|---|
|  | 632 | if (printlev > 1) | 
|---|
|  | 633 | { | 
|---|
|  | 634 | cout << "addComponentBeta - Coeff= "  << K  << endl; | 
|---|
|  | 635 | cout << "nb pixels: " << finalMap.NbPixels() << endl; | 
|---|
|  | 636 | } | 
|---|
| [885] | 637 | SphereHEALPix<T> bigBetaMap(sqrt((double)nbpix/12)); | 
|---|
| [876] | 638 | if(nbpix != betaMap.NbPixels()) | 
|---|
|  | 639 | { | 
|---|
|  | 640 | Sph2Sph(betaMap,bigBetaMap); | 
|---|
|  | 641 | } | 
|---|
|  | 642 | for(int i=0; i<finalMap.NbPixels(); i++) | 
|---|
|  | 643 | { | 
|---|
|  | 644 | // coeff = integration of (nu/normFreq)^(-beta(theta,phi)) in each pixels | 
|---|
|  | 645 | RadSpectra* rs =  new PowerLawSpectra | 
|---|
|  | 646 | (1.,-bigBetaMap(i), 0., normFreq, 0.01, 800.); | 
|---|
|  | 647 | double coeff = rs->filteredIntegratedFlux(sr); | 
|---|
|  | 648 | finalMap(i) += coeff*K*mapToAdd(i); | 
|---|
|  | 649 | } | 
|---|
|  | 650 | } | 
|---|
|  | 651 |  | 
|---|
|  | 652 | template <class T> | 
|---|
|  | 653 | void integratedMap(SpectralResponse&  sr, | 
|---|
| [880] | 654 | SphereHEALPix<T>& betaMap, | 
|---|
| [876] | 655 | double normFreq, | 
|---|
| [880] | 656 | SphereHEALPix<T>& intBetaMap) | 
|---|
| [876] | 657 | { | 
|---|
| [899] | 658 | PowerLawSpectra rs(1.,-2., 0., normFreq); | 
|---|
|  | 659 |  | 
|---|
|  | 660 | if(betaMap.NbPixels()!=intBetaMap.NbPixels()) | 
|---|
| [876] | 661 | { | 
|---|
| [899] | 662 | Sph2Sph(betaMap,intBetaMap); | 
|---|
|  | 663 | for(int i=0; i<intBetaMap.NbPixels(); i++) | 
|---|
|  | 664 | { | 
|---|
|  | 665 | rs.setExp(-intBetaMap(i)); | 
|---|
|  | 666 | double coeff = rs.filteredIntegratedFlux(sr); | 
|---|
|  | 667 | intBetaMap(i) = coeff; | 
|---|
|  | 668 | } | 
|---|
| [876] | 669 | } | 
|---|
| [899] | 670 | else | 
|---|
|  | 671 | { | 
|---|
|  | 672 | for(int i=0; i<intBetaMap.NbPixels(); i++) | 
|---|
|  | 673 | { | 
|---|
|  | 674 | rs.setExp(-betaMap(i)); | 
|---|
|  | 675 | double coeff = rs.filteredIntegratedFlux(sr); | 
|---|
|  | 676 | intBetaMap(i) = coeff; | 
|---|
|  | 677 | } | 
|---|
|  | 678 | } | 
|---|
| [876] | 679 | } | 
|---|
|  | 680 |  | 
|---|
|  | 681 | template <class T> | 
|---|
| [880] | 682 | void addComponentBeta(SphereHEALPix<T>& finalMap, | 
|---|
|  | 683 | SphereHEALPix<T>& mapToAdd,SphereHEALPix<T>& intBetaMap, double K) | 
|---|
| [876] | 684 | { | 
|---|
|  | 685 | // finalMap = finalMap + coeff* mapToAdd | 
|---|
|  | 686 | // coeff    =  convolution of sr and rs | 
|---|
|  | 687 | // compute the coefficient corresponding to mapToAdd | 
|---|
|  | 688 | // integBetaMap is the map of the integration (nu/normFreq)^(-beta(theta,phi)) over | 
|---|
|  | 689 | // the spectralResponse | 
|---|
|  | 690 | // different from addComponentBeta(PixelMap<T>& finalMap, | 
|---|
|  | 691 | //    PixelMap<T>& mapToAdd,SpectralResponse& sr, PixelMap<T>& betaMap, double normFreq, double K) | 
|---|
|  | 692 | //   since it permits to use a intBetaMap with a different number of pixels than | 
|---|
|  | 693 | //   the other maps | 
|---|
|  | 694 |  | 
|---|
|  | 695 | int nbpix = finalMap.NbPixels(); | 
|---|
|  | 696 | if (nbpix != mapToAdd.NbPixels()) | 
|---|
|  | 697 | throw SzMismatchError("addComponentBeta(PixelMap<T>&,PixelMap<T>&,PixelMap<T>&,double)/Error: Unequal number of Input/Output map pixels"); | 
|---|
|  | 698 | double coeff = K; | 
|---|
|  | 699 |  | 
|---|
|  | 700 | if(nbpix != intBetaMap.NbPixels()) | 
|---|
|  | 701 | { | 
|---|
|  | 702 | for(int i=0; i<finalMap.NbPixels();i++) | 
|---|
|  | 703 | { | 
|---|
| [899] | 704 | double teta,phi,val; | 
|---|
|  | 705 | finalMap.PixThetaPhi(i, teta, phi); | 
|---|
|  | 706 | int pixel = intBetaMap.PixIndexSph(teta,phi); | 
|---|
|  | 707 | val = intBetaMap.PixVal(pixel); | 
|---|
|  | 708 | finalMap(i) += coeff*mapToAdd(i)*val; | 
|---|
| [876] | 709 | } | 
|---|
|  | 710 | } | 
|---|
|  | 711 | else | 
|---|
|  | 712 | { | 
|---|
|  | 713 | for(int i=0; i<finalMap.NbPixels();i++) | 
|---|
|  | 714 | { | 
|---|
|  | 715 | finalMap(i) += coeff*mapToAdd(i)*intBetaMap(i); | 
|---|
|  | 716 | } | 
|---|
|  | 717 | } | 
|---|
|  | 718 | if (printlev > 1) | 
|---|
|  | 719 | { | 
|---|
|  | 720 | cout << "addComponentBeta(SG<T>,SG<T>,SG<T>,double) - Coeff= "  << K  << endl; | 
|---|
|  | 721 | } | 
|---|
|  | 722 | } | 
|---|
|  | 723 |  | 
|---|
|  | 724 |  | 
|---|
|  | 725 |  | 
|---|
|  | 726 |  | 
|---|
|  | 727 |  | 
|---|
|  | 728 | /* Nouvelle-Fonction */ | 
|---|
| [1252] | 729 | void SKM_MergeFITSKeywords(char * flnm) | 
|---|
|  | 730 | { | 
|---|
|  | 731 | DVList dvl; | 
|---|
|  | 732 | FitsFile::FitsExtensionType typeOfExtension; | 
|---|
|  | 733 | int naxis; | 
|---|
|  | 734 | vector<int> naxisn; | 
|---|
|  | 735 | FitsFile::FitsDataType dataType; | 
|---|
|  | 736 | FitsInFile::GetBlockType(flnm, 1, typeOfExtension, naxis, naxisn, dataType, dvl); | 
|---|
|  | 737 | // Cleaning the keywords | 
|---|
|  | 738 | #define SZexlst 21 | 
|---|
|  | 739 | char *exlst[SZexlst]= | 
|---|
|  | 740 | {"SIMPLE","BITPIX" ,"NAXIS" ,"NAXIS#" ,"PCOUNT","GCOUNT", | 
|---|
|  | 741 | "EXTEND","ORIGIN" ,"DATE*" ,"TFIELDS","TTYPE#","TFORM#", | 
|---|
|  | 742 | "TUNIT#","EXTNAME","CTYPE#","CRVAL#" ,"CRPIX#","CDELT#", | 
|---|
|  | 743 | "XTENSION","INSTRUME","TELESCOP"}; | 
|---|
|  | 744 | char  kwex[32]; | 
|---|
|  | 745 | int i,l; | 
|---|
|  | 746 | for (i=0; i<SZexlst; i++) { | 
|---|
|  | 747 | strncpy(kwex, exlst[i], 32); | 
|---|
|  | 748 | l = strlen(kwex)-1; | 
|---|
|  | 749 | if ((kwex[l] != '*') && (kwex[l] != '#')) { | 
|---|
|  | 750 | dvl.DeleteKey(kwex); | 
|---|
|  | 751 | } | 
|---|
|  | 752 | else { | 
|---|
|  | 753 | bool fgd = (kwex[l] == '#') ? true : false; | 
|---|
|  | 754 | list<string> lstsup; | 
|---|
|  | 755 | kwex[l] = '\0'; | 
|---|
|  | 756 | DVList::ValList::const_iterator it; | 
|---|
|  | 757 | for (it = dvl.Begin(); it != dvl.End(); it++) { | 
|---|
|  | 758 | if ((*it).first.substr(0,l) != kwex) continue; | 
|---|
|  | 759 | if (fgd && !isdigit((*it).first[l])) continue; | 
|---|
|  | 760 | lstsup.push_back((*it).first); | 
|---|
|  | 761 | } | 
|---|
|  | 762 | list<string>::iterator it2; | 
|---|
|  | 763 | for (it2 = lstsup.begin(); it2 != lstsup.end(); it2++) | 
|---|
|  | 764 | dvl.DeleteKey(*it2); | 
|---|
|  | 765 | } | 
|---|
|  | 766 | } | 
|---|
|  | 767 | dvl_fitskw->Merge(dvl); | 
|---|
|  | 768 | } | 
|---|
| [761] | 769 |  | 
|---|
|  | 770 | /* Nouvelle-Fonction */ | 
|---|
|  | 771 | void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name) | 
|---|
|  | 772 | { | 
|---|
|  | 773 | char *ntn[2] = {"nu","fnu"}; | 
|---|
|  | 774 | NTuple nt(2,ntn);  // Creation NTuple (AVEC new ) | 
|---|
|  | 775 | float xnt[2]; | 
|---|
|  | 776 | double nu; | 
|---|
|  | 777 | double numin = rs.minFreq(); | 
|---|
|  | 778 | double numax = rs.maxFreq(); | 
|---|
|  | 779 | int nmax = 500; | 
|---|
|  | 780 | double dnu = (numax-numin)/nmax; | 
|---|
|  | 781 | for(int k=0; k<nmax; k++) { | 
|---|
|  | 782 | nu = numin+k*dnu; | 
|---|
|  | 783 | xnt[0] = nu; | 
|---|
|  | 784 | xnt[1] = rs.flux(nu); | 
|---|
|  | 785 | nt.Fill(xnt); | 
|---|
|  | 786 | } | 
|---|
|  | 787 | ObjFileIO<NTuple> oiont(nt); | 
|---|
|  | 788 | oiont.Write(so, name); | 
|---|
|  | 789 | return; | 
|---|
|  | 790 | } | 
|---|
|  | 791 |  | 
|---|
|  | 792 | /* Nouvelle-Fonction */ | 
|---|
|  | 793 | void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name) | 
|---|
|  | 794 | { | 
|---|
|  | 795 | char *ntn[2] = {"nu","tnu"}; | 
|---|
|  | 796 | NTuple nt(2,ntn);  // Creation NTuple (AVEC new ) | 
|---|
|  | 797 | float xnt[2]; | 
|---|
|  | 798 | double nu; | 
|---|
|  | 799 | double numin = sr.minFreq(); | 
|---|
|  | 800 | double numax = sr.maxFreq(); | 
|---|
|  | 801 | int nmax = 500; | 
|---|
|  | 802 | double dnu = (numax-numin)/nmax; | 
|---|
|  | 803 | for(int k=0; k<nmax; k++) { | 
|---|
|  | 804 | nu = numin+k*dnu; | 
|---|
|  | 805 | xnt[0] = nu; | 
|---|
|  | 806 | xnt[1] = sr.transmission(nu); | 
|---|
|  | 807 | nt.Fill(xnt); | 
|---|
|  | 808 | } | 
|---|
|  | 809 | ObjFileIO<NTuple> oiont(nt); | 
|---|
|  | 810 | oiont.Write(so, name); | 
|---|
|  | 811 | return; | 
|---|
|  | 812 | } | 
|---|
|  | 813 |  | 
|---|