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