#include "machdefs.h" #include #include #include #include #include #include #include "timing.h" #include "sambainit.h" #include "pexceptions.h" #include "datacards.h" #include "fitsioserver.h" #include "spheregorski.h" #include "radspecvector.h" #include "blackbody.h" #include "nupower.h" #include "squarefilt.h" #include "trianglefilt.h" #include "specrespvector.h" #include "gaussfilt.h" // ------ Function declaration void addComponent(SpectralResponse& sr, PixelMap& finalMap, PixelMap& mapToAdd, RadSpectra& rs, double K=1.); void addComponent(SpectralResponse& sr, PixelMap& finalMap, PixelMap& mapToAdd, RadSpectra& rs, double K=1.); int CheckCards(DataCards & dc, string & msg); char * BuildFITSFileName(string const & fname); void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name); void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name); // ----- Variable globale ------------ static char mapPath[256]; // Path for input maps static int hp_nside = 32; // HealPix NSide static int nskycomp = 0; // Number of sky components static int debuglev = 0; // debuglevel // ------------------------------------------------------------------------- // main program // ------------------------------------------------------------------------- int main(int narg, char * arg[]) { if ((narg < 3) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) { cout << " Usage: skymixer parameterFile outputfitsname [outppfname]" << endl; exit(0); } InitTim(); string msg; int rc = 0; POutPersist * so = NULL; try { string dcard = arg[1]; cout << " Decoding parameters from file " << dcard << endl; DataCards dc(dcard); rc = CheckCards(dc, msg); if (rc) goto Fin; cout << " skymix/Info : NComp = " << nskycomp << " SphereGorski_NSide= " << hp_nside << endl; cout << " ... MapPath = " << (string)mapPath << " DbgLev= " << debuglev << endl; // We create an output persist file for writing debug objects if (debuglev > 0) so = new POutPersist("skymixdbg.ppf"); SphereGorski outgs(hp_nside); cout << " Output Gorski Map created - NbPixels= " << outgs.NbPixels() << endl; outgs.SetPixels(0.); // Decoding detection pass-band filter double nu0 = dc.DParam("FILTER", 0, 10.); double s = dc.DParam("FILTER", 1, 1.); double a = dc.DParam("FILTER", 2, 1.); double numin = dc.DParam("FILTER", 3, 0.1); double numax = dc.DParam("FILTER", 4, 9999); GaussianFilter filt(nu0, s, a, numin, numax); cout << " Filter decoded - Created " << endl; cout << filt << endl; // FOR debug if (debuglev > 0) SpectralResponse2Nt(filt, *so, "filter"); PrtTim(" After FilterCreation "); SphereGorski * ings = NULL; // Our input map FitsIoServer fios; // Our FITS IO Server char * flnm, buff[64]; string key; // Loop over sky component int sk; for(sk = 0; sk(hp_nside); sprintf(buff, "MAPFITSFILE%d", sk+1); key = buff; flnm = BuildFITSFileName(dc.SParam(key, 0)); cout << " Reading Input FITS map " << (string)flnm << endl; fios.load(*ings, flnm, 1); if (debuglev > 4) { // Writing tne input map to the outppf FIO_SphereGorski fiog(ings); fiog.Write(*so, key); } } } // End of try block catch (PException exc) { msg = exc.Msg(); cerr << " !!!! skymixer - Catched exception - Msg= " << exc.Msg() << endl; rc = 90; } Fin: if (so) delete so; // Closing the debug ppf file if (rc == 0) return(0); cerr << " Error condition -> Rc= " << rc << endl; cerr << " Msg= " << msg << endl; return(rc); } /* Nouvelle-Fonction */ int CheckCards(DataCards & dc, string & msg) // Function to check datacards { mapPath[0] = '\0'; hp_nside = 32; nskycomp = 0; debuglev = 0; int rc = 0; // Cheking datacards if ( (!dc.HasKey("SKYMIX")) || (!dc.HasKey("FILTER")) ) { rc = 71; msg = "Invalid parameters - NO @SKYMIX or @FILTER card "; return(rc); } // Decoding number of component and pixelisation parameter int mg = 32; int ncomp = 0; ncomp = dc.IParam("SKYMIX", 0, 0); mg = dc.IParam("SKYMIX", 1, 32); if (ncomp < 1) { msg = "Invalid parameters - Check datacards @SKYMIX "; rc = 72; return(rc); } // Checking input FITS file specifications int kc; string key, key2; char buff[256]; bool pb = false; for(kc=0; kc void addComponent(SpectralResponse& sr, PixelMap& finalMap, PixelMap& mapToAdd, RadSpectra& rs, double K) { // finalMap = finalMap + coeff* mapToAdd // coeff = convolution of sr and rs // compute the coefficient corresponding to mapToAdd if (finalMap.NbPixels() != mapToAdd.NbPixels()) throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels"); double coeff = rs.filteredIntegratedFlux(sr) * K; for(int i=0; i& finalMap, PixelMap& mapToAdd, RadSpectra& rs, double K) { // finalMap = finalMap + coeff* mapToAdd // coeff = convolution of sr and rs // compute the coefficient corresponding to mapToAdd if (finalMap.NbPixels() != mapToAdd.NbPixels()) throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels"); double coeff = rs.filteredIntegratedFlux(sr) * K; for(int i=0; i oiont(nt); oiont.Write(so, name); return; } /* Nouvelle-Fonction */ void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name) { char *ntn[2] = {"nu","tnu"}; NTuple nt(2,ntn); // Creation NTuple (AVEC new ) float xnt[2]; double nu; double numin = sr.minFreq(); double numax = sr.maxFreq(); int nmax = 500; double dnu = (numax-numin)/nmax; for(int k=0; k oiont(nt); oiont.Write(so, name); return; }