[798] | 1 | // Dominique YVON, CEA/DAPNIA/SPP 02/2000
|
---|
| 2 |
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 |
|
---|
| 6 | #include <math.h>
|
---|
| 7 | #include <iostream>
|
---|
| 8 | #include <fstream>
|
---|
| 9 |
|
---|
| 10 | #ifdef __MWERKS__
|
---|
| 11 | #include "mwerksmath.h"
|
---|
| 12 | #include "unixmac.h"
|
---|
| 13 | #include "macenvvariables.h"
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 | #include "nbrandom.h"
|
---|
| 17 | #include "lightgalaxresol.h"
|
---|
| 18 | #include "numrecipes.h"
|
---|
| 19 | #include "integ.h"
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | LightGalaxResol::LightGalaxResol(int_4 nside) {
|
---|
| 23 | sprintf(Name, "Galaxies Resolues");
|
---|
| 24 | nlat=nside;
|
---|
| 25 | resolution=2*M_PI/4./nlat; // Radians
|
---|
| 26 | nbFreq=31;
|
---|
| 27 | nbPointSource=2711;
|
---|
| 28 | PtSourceS=true;
|
---|
| 29 |
|
---|
| 30 | pNR=new NumRecipes;
|
---|
| 31 | LastFreqIndex=1;
|
---|
| 32 |
|
---|
| 33 | // Calcul des frquences des cartes guiderdonni
|
---|
| 34 | dataFreq=new r_8[nbFreq];
|
---|
| 35 | dataFreqDegueux= new float[nbFreq];
|
---|
| 36 |
|
---|
| 37 | double fmin=15.e9;
|
---|
| 38 | double fmax=15.e12;
|
---|
| 39 | double dLogFreq=log10(fmax/fmin)/(nbFreq-1);
|
---|
| 40 |
|
---|
| 41 | for(int i=0; i<nbFreq; i++)
|
---|
| 42 | {
|
---|
| 43 | dataFreq[i]=fmin*pow(10,i*dLogFreq);
|
---|
| 44 | dataFreqDegueux[i]=(float)dataFreq[i]; // Pour la NR
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | // Booking of skymap of index
|
---|
| 48 | try { pLightMap= new SphereGorski<uint_2> (nlat); }
|
---|
| 49 | catch(bad_alloc){
|
---|
| 50 | cerr<<"Erreur Reservation de memoire classe LightGalacResol, nlat= "<<nlat<<endl;
|
---|
| 51 | exit(-1);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | nbPixelLight=pLightMap->NbPixels();
|
---|
| 55 | int size=sizeof(uint_2)*nbPixelLight;
|
---|
| 56 | cout<<"Objet LightGalaxResol: "<<endl;
|
---|
| 57 | cout<<"Vous avez reserv: "<<size<<"Octets de mmoire vive"<<endl;
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | // La sphere est initialise nbPointSource+1, cad pas de sources
|
---|
| 61 | int_2 bidon=nbPointSource+1;
|
---|
| 62 | for(int i=0; i<nbPixelLight; i++) (*pLightMap)(i)=bidon;
|
---|
| 63 |
|
---|
| 64 | // On distribue les sources uniformement sur le ciel
|
---|
| 65 | int_4 skyIndex;
|
---|
| 66 | for(int_2 i=0; i<nbPointSource; i++)
|
---|
| 67 | {
|
---|
| 68 | skyIndex=(int)(MyRan()*nbPixelLight);
|
---|
| 69 | if ( (*pLightMap)(skyIndex)==(nbPointSource+1)) (*pLightMap)(skyIndex)=i;
|
---|
| 70 | else
|
---|
| 71 | {
|
---|
| 72 | while(! ((*pLightMap)(skyIndex) == (nbPointSource+1)) )
|
---|
| 73 | {
|
---|
| 74 | // float test;
|
---|
| 75 | // test= MyRan(); // frand01() ne fonctionne pas au 05/12/99 sur Mac
|
---|
| 76 | skyIndex=(int)(MyRan()*nbPixelLight);
|
---|
| 77 | }
|
---|
| 78 | (*pLightMap)(skyIndex)=i;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | // _____________ On lit les parametres des sources _______________________________________
|
---|
| 84 |
|
---|
| 85 | // Reservation de l'espace memoire de stockage
|
---|
| 86 | try {
|
---|
| 87 | ppPointSourceData= new float* [nbPointSource];
|
---|
| 88 | for(int i=0; i<nbPointSource; i++) ppPointSourceData[i]= new float[nbFreq];
|
---|
| 89 | }
|
---|
| 90 | catch(bad_alloc) {
|
---|
| 91 | cerr<<" Memory booking error in LightGalaxResol: ppskyData "<<endl;
|
---|
| 92 | exit(-1);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | // Lecture des fichiers
|
---|
| 96 | char filename[150];
|
---|
| 97 | double DumStarNb;
|
---|
| 98 | char DumChaine[20];
|
---|
| 99 | r_4 thisdata;
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | #ifndef __MWERKS__
|
---|
| 103 | char* PATHDataLScr=getenv("PATHDataLScr");
|
---|
| 104 | #endif
|
---|
| 105 |
|
---|
| 106 | for(int NoFreq=0; NoFreq<nbFreq; NoFreq++)
|
---|
| 107 | {
|
---|
| 108 | // cout<<"NoFreq :"<<NoFreq<<"Frequence: "<<dataFreq[NoFreq]<<endl;
|
---|
| 109 | // On genere le bon nom de fichier
|
---|
| 110 | sprintf(filename,"%seran102_441_%08imhz.s_rare",PATHDataLScr,(int)(dataFreq[NoFreq]/1.e6+.5));
|
---|
| 111 |
|
---|
| 112 | ifstream InFile(filename,ios::in); // Fichier Ouvert!
|
---|
| 113 |
|
---|
| 114 | #ifdef __MWERKS__
|
---|
| 115 | if (!InFile.is_open()) // cxx DEC est trop con pour comprendre is_open()
|
---|
| 116 | #else
|
---|
| 117 | if (!InFile)
|
---|
| 118 | #endif
|
---|
| 119 | { cerr<<"erreur a l'ouverture du fichier de donnees: "<<filename<<endl;
|
---|
| 120 | exit(-1);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | InFile>>DumStarNb;
|
---|
| 125 | if(DumStarNb!=nbPointSource) {
|
---|
| 126 | cerr<<"ya une bogue dans le nb de galaxptsources."<<endl;
|
---|
| 127 | cerr<<"fichier: "<< filename<<"nb sources annoncees:"<< DumStarNb<<endl;
|
---|
| 128 | }
|
---|
| 129 | InFile>>DumChaine;
|
---|
| 130 |
|
---|
| 131 | for(long noPtSource=0; noPtSource<nbPointSource; noPtSource++)
|
---|
| 132 | {
|
---|
| 133 | InFile>> thisdata;
|
---|
| 134 | ppPointSourceData [noPtSource] [NoFreq] =thisdata;
|
---|
| 135 | // cout<<noPtSource<<'\t'<<ppPointSourceData [noPtSource] [NoFreq]<<endl;
|
---|
| 136 | }
|
---|
| 137 | InFile.close();
|
---|
| 138 | }
|
---|
| 139 | /* for (int NoFreq=0; NoFreq<nbFreq; NoFreq ++)
|
---|
| 140 | cout<< NoFreq <<'\t'<< ppPointSourceData [] [NoFreq]<< endl;
|
---|
| 141 | */
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | LightGalaxResol::~LightGalaxResol()
|
---|
| 146 | {
|
---|
| 147 | // Librons la mmoire!! Bientt mai!
|
---|
| 148 | for(int i=0; i<nbPointSource; i++) delete[] ppPointSourceData[i];
|
---|
| 149 | delete[] ppPointSourceData;
|
---|
| 150 | delete pLightMap;
|
---|
| 151 | delete[] dataFreqDegueux;
|
---|
| 152 | delete[] dataFreq;
|
---|
| 153 | delete pNR;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | double LightGalaxResol::powSpecDens(double theta, double phi, double freq)
|
---|
| 157 | //(Watt/m2/Hz)
|
---|
| 158 | {
|
---|
| 159 | long pixelNo= pLightMap->PixIndexSph(theta, phi);
|
---|
| 160 | int_2 NoSource=(*pLightMap)(pixelNo);
|
---|
| 161 |
|
---|
| 162 | if ( NoSource==(nbPointSource+1)) return 0.; // Pas de source
|
---|
| 163 | else
|
---|
| 164 | {
|
---|
| 165 | float* binSpectre=(ppPointSourceData[NoSource]);
|
---|
| 166 | float InterpRes;
|
---|
| 167 | float InterpResErr;
|
---|
| 168 |
|
---|
| 169 | float thisFreq=freq;
|
---|
| 170 |
|
---|
| 171 | //Ou est la frequence dans le tableau?
|
---|
| 172 | pNR->hunt(dataFreqDegueux-1,(unsigned long) nbFreq, thisFreq, &LastFreqIndex);
|
---|
| 173 | if((LastFreqIndex==0)||(LastFreqIndex==nbFreq))
|
---|
| 174 | { cerr<<"Appel a powSpecDens dans LightGalaxResol hors limites de frequence"<<endl;
|
---|
| 175 | LastFreqIndex=1;
|
---|
| 176 | return 0;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | // On interpole 3 eme ordre. Num Reciepies fonction.
|
---|
| 181 | pNR->polint(dataFreqDegueux-1+LastFreqIndex,binSpectre-1+LastFreqIndex,
|
---|
| 182 | 2,thisFreq,&InterpRes,&InterpResErr);
|
---|
| 183 | // InterpRes en Jansky:10-26 W/m2/Hz
|
---|
| 184 | return (double) (InterpRes*10.e-26); // W/m2/Hz
|
---|
| 185 | // RMQ: Le Jansky est une unite de source ponctuelle !
|
---|
| 186 | // Pas de steradian dans les homogeneites.
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | static double randMax=RAND_MAX;
|
---|
| 191 | double LightGalaxResol::MyRan() {
|
---|
| 192 | return rand()/randMax;
|
---|
| 193 | }
|
---|
| 194 |
|
---|