| [801] | 1 | // Dominique YVON, CEA/DAPNIA/SPP 02/2000 | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #include <stdio.h> | 
|---|
|  | 4 | #include <stdlib.h> | 
|---|
|  | 5 | #include <math.h> | 
|---|
|  | 6 | #ifdef __MWERKS__ | 
|---|
|  | 7 | #include "unixmac.h" | 
|---|
|  | 8 | #include "macenvvariables.h" | 
|---|
|  | 9 | #endif | 
|---|
|  | 10 | #include "nbrandom.h" | 
|---|
|  | 11 | #include "tmatrix.h" | 
|---|
|  | 12 | #include "numrecipes.h" | 
|---|
|  | 13 | #include "integ.h" | 
|---|
|  | 14 | #include "fitsioserver.h" | 
|---|
|  | 15 |  | 
|---|
| [1148] | 16 |  | 
|---|
| [801] | 17 | #include "lightgalaxnoresol.h" | 
|---|
|  | 18 |  | 
|---|
|  | 19 |  | 
|---|
|  | 20 | LightGalaxNoResol::LightGalaxNoResol(int_4 nside=512) | 
|---|
|  | 21 | { | 
|---|
|  | 22 |  | 
|---|
|  | 23 | /* cerr<< "LightGalaxNoResol en travaux, ne pas utiliser"<<endl; | 
|---|
|  | 24 | exit (-1); | 
|---|
|  | 25 | */ | 
|---|
|  | 26 | sprintf(Name,"Galaxies non resolues"); | 
|---|
|  | 27 | nlat=nside; | 
|---|
|  | 28 | if(nside!=2048) | 
|---|
|  | 29 | {  cerr<<" Warning : Donnees Guiderdonni compatible avec nlat=2048"<<endl; | 
|---|
|  | 30 | cerr<<" Vous avez choisi nlat= "<<nlat<<endl; | 
|---|
|  | 31 | } | 
|---|
|  | 32 | nbFreq=31;                       // Nbre de frequences calcules | 
|---|
|  | 33 | NbPixUnCote=441; | 
|---|
|  | 34 | nbPixel=NbPixUnCote*NbPixUnCote;    // Nbre de pixel cartes Guiderdonni | 
|---|
|  | 35 | nbPixelKept=65535;       // Ce que lon peut stocker dans un U2 | 
|---|
|  | 36 | pNR= new NumRecipes; | 
|---|
|  | 37 |  | 
|---|
|  | 38 | // Tableau des frquences auxquelles sont calcules les cartes guiderdonni | 
|---|
|  | 39 | dataFreq=new r_8[nbFreq]; | 
|---|
|  | 40 | dataFreqDegueux= new float[nbFreq]; | 
|---|
|  | 41 | // Calcul des frquences des cartes guiderdonni | 
|---|
|  | 42 | double fmin=15.e9; | 
|---|
|  | 43 | double fmax=15.e12; | 
|---|
|  | 44 | double dLogFreq=log10(fmax/fmin)/(nbFreq-1.); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | for(int i=0; i<nbFreq; i++) | 
|---|
|  | 47 | { | 
|---|
|  | 48 | dataFreq[i]=fmin*pow(10,i*dLogFreq); | 
|---|
|  | 49 | dataFreqDegueux[i]=(float)dataFreq[i]; | 
|---|
|  | 50 | } | 
|---|
|  | 51 | // Chaque pixel du ciel est caracterise par un spectre chantillonn | 
|---|
|  | 52 | //  nbfreq frequences extrait des cartes Guiderdonni. | 
|---|
|  | 53 | // On stocke le no de pixel de la carte guiderdonni correspondant au pixel ciel | 
|---|
|  | 54 |  | 
|---|
| [1148] | 55 | try {pSphereIndex=new SphereHEALPix<uint_2>(nlat); } | 
|---|
| [801] | 56 | catch(bad_alloc) { | 
|---|
|  | 57 | cerr<<"Memory booking error in LightGalaxNoResol: pSphereIndex"<<endl; | 
|---|
|  | 58 | exit(-1); | 
|---|
|  | 59 | } | 
|---|
|  | 60 | // Sphre faisant la correspondance ciel, no de pixel de carte guiderdonni | 
|---|
|  | 61 | nbPixelLight=pSphereIndex->NbPixels(); | 
|---|
|  | 62 | // On attribue a chaque pixel ciel un pixel carte Guiderdonni. | 
|---|
|  | 63 | for( long i=0; i< nbPixelLight; i++) | 
|---|
|  | 64 | { | 
|---|
|  | 65 | // double test= MyRan()*nbPixelKept; | 
|---|
|  | 66 | // bogue sur Mac frand01() retourne toujours la meme valeur. | 
|---|
|  | 67 | // On utilise ran() standard. | 
|---|
|  | 68 |  | 
|---|
|  | 69 | (*pSphereIndex)(i)= (int_2) (MyRan()*nbPixelKept); | 
|---|
|  | 70 | } | 
|---|
|  | 71 |  | 
|---|
|  | 72 | // Stockage des donnes Guiderdonni petites cartes | 
|---|
|  | 73 | // Rserve l'espace mmoire ncessaire au stockage des cartes partielles | 
|---|
|  | 74 | ppskyData= new r_4* [nbPixelKept]; | 
|---|
|  | 75 | // Un tableau pour chaque point du ciel | 
|---|
|  | 76 | try { | 
|---|
|  | 77 | for(int i=0; i<nbPixelKept; i++) ppskyData[i]= new r_4 [nbFreq]; | 
|---|
|  | 78 | } | 
|---|
|  | 79 | catch(bad_alloc) { | 
|---|
|  | 80 | cerr<<"Memory booking error in LightGalaxNoResol: ppskyData"<<endl; | 
|---|
|  | 81 | exit(-1); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 |  | 
|---|
|  | 85 | /*// ca ne marche plus. se renseigner de comment faire!. | 
|---|
|  | 86 | if(pSphereIndex==NULL){ | 
|---|
|  | 87 | cerr<<"Memory booking error LightGalaxNoResol constructor"<<endl; | 
|---|
|  | 88 | exit(-1); | 
|---|
|  | 89 | } | 
|---|
|  | 90 | */ | 
|---|
|  | 91 |  | 
|---|
|  | 92 | int_4 size=sizeof(r_4)*(nbFreq*nbPixelKept) + sizeof(uint_2)*nbPixelLight; | 
|---|
|  | 93 | cout<<"Objet LightGalaxNoResol: "<<endl; | 
|---|
|  | 94 | cout<<"Vous avez reserv: "<<size<<" Octets de mmoire vive"<<endl; | 
|---|
|  | 95 |  | 
|---|
|  | 96 | // Lit les cartes Guiderdonni:les charge dans dataTampon,puis dans skyData | 
|---|
|  | 97 | #ifndef __MWERKS__ | 
|---|
|  | 98 | char* PATHDataLScr=getenv("PATHDataLScr"); | 
|---|
|  | 99 | #endif | 
|---|
|  | 100 |  | 
|---|
|  | 101 | FitsIoServer FitsServer; | 
|---|
|  | 102 |  | 
|---|
|  | 103 | TMatrix<float> UneCarte(NbPixUnCote, NbPixUnCote); | 
|---|
|  | 104 |  | 
|---|
|  | 105 | long cartefreqMHz; | 
|---|
|  | 106 | char filename[150]; | 
|---|
|  | 107 | for(int noFreq=0; noFreq<nbFreq; noFreq++) | 
|---|
|  | 108 | { | 
|---|
|  | 109 | // Gnre le nom des cartes | 
|---|
|  | 110 | cartefreqMHz=(long)(dataFreq[noFreq]/1000000.+0.5); | 
|---|
|  | 111 | sprintf(filename,"%seran102_441_%08imhz.fits",PATHDataLScr,cartefreqMHz); | 
|---|
|  | 112 |  | 
|---|
|  | 113 | FitsServer.load(UneCarte,filename); | 
|---|
| [1148] | 114 |  | 
|---|
| [801] | 115 | //      cout<<"Carte Lue: "<<filename<<'\t'<<"Frquence: "<<dataFreq[noFreq]<<endl; | 
|---|
|  | 116 |  | 
|---|
|  | 117 | long indexUneCarte1=0; | 
|---|
|  | 118 | long indexUneCarte2=0; | 
|---|
|  | 119 |  | 
|---|
|  | 120 | // On remplit LightData | 
|---|
|  | 121 | for(int NoPixel=0;NoPixel<nbPixelKept;NoPixel++) | 
|---|
|  | 122 | { | 
|---|
|  | 123 | indexUneCarte1= (long) (NoPixel/NbPixUnCote);             // Division entiere | 
|---|
|  | 124 | indexUneCarte2= NoPixel%NbPixUnCote; | 
|---|
|  | 125 | ppskyData[NoPixel][noFreq]= UneCarte(indexUneCarte1,indexUneCarte2); | 
|---|
|  | 126 | cout <<"NoPixel: "<<NoPixel<<" Valeur: "; | 
|---|
|  | 127 | cout << ppskyData[NoPixel][noFreq]<<'\t'<<UneCarte(indexUneCarte1,indexUneCarte2)<<endl; | 
|---|
|  | 128 | } | 
|---|
|  | 129 |  | 
|---|
|  | 130 | }  // C'est dans la boite LightData | 
|---|
|  | 131 |  | 
|---|
|  | 132 | // C'est fini pour le constructeur | 
|---|
|  | 133 | } | 
|---|
|  | 134 |  | 
|---|
|  | 135 | LightGalaxNoResol::~LightGalaxNoResol(){ | 
|---|
|  | 136 | for(int i=0; i<nbPixelKept; i++) delete[] ppskyData[i]; | 
|---|
|  | 137 | delete[] ppskyData; | 
|---|
|  | 138 | delete pNR; | 
|---|
|  | 139 | delete[] dataFreq; | 
|---|
|  | 140 | delete[] dataFreqDegueux; | 
|---|
|  | 141 | delete[] pSphereIndex; | 
|---|
|  | 142 |  | 
|---|
|  | 143 | } | 
|---|
|  | 144 |  | 
|---|
|  | 145 | double LightGalaxNoResol::powSpecDens(double theta, double phi, double freq){ | 
|---|
|  | 146 | long index=pSphereIndex->PixIndexSph(theta,phi); | 
|---|
|  | 147 | int_2 pixNb=pSphereIndex->PixVal(index); | 
|---|
|  | 148 |  | 
|---|
|  | 149 | float* pbinSpectre= ppskyData[pixNb]; //10-26 W/m2/Hz/st | 
|---|
|  | 150 |  | 
|---|
|  | 151 | // On interpole au troisieme ordre. | 
|---|
|  | 152 | float InterpRes=0.; | 
|---|
|  | 153 | float InterpResErr=0.; | 
|---|
|  | 154 | pNR->polint(dataFreqDegueux-1,pbinSpectre-1,3,freq,&InterpRes,&InterpResErr); | 
|---|
|  | 155 |  | 
|---|
|  | 156 | return (double)InterpRes*1.e-26;  // W/m2/Hz/st | 
|---|
|  | 157 | } | 
|---|
|  | 158 |  | 
|---|
|  | 159 |  | 
|---|
|  | 160 | static double randMax=RAND_MAX; | 
|---|
|  | 161 |  | 
|---|
|  | 162 | double LightGalaxNoResol::MyRan() | 
|---|
|  | 163 | { | 
|---|
|  | 164 | return rand()/randMax; | 
|---|
|  | 165 | } | 
|---|
|  | 166 |  | 
|---|