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