[801] | 1 | // Dominique YVON, CEA/DAPNIA/SPP 02/2000
|
---|
| 2 |
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 | #include <stddef.h>
|
---|
| 6 | #include <string.h>
|
---|
| 7 | #include <math.h>
|
---|
| 8 | #include <iostream>
|
---|
| 9 | //#include "machine.h"
|
---|
| 10 | #include "nbconst.h"
|
---|
| 11 | #include "cimage.h"
|
---|
| 12 | #include "cartelobe.h"
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | static NumRecipes NR; // pour avoir acces au librairies NR
|
---|
| 16 |
|
---|
| 17 | // Tout cet Objet est programme dans le philosophie des tableaux NR
|
---|
| 18 | // J'essaye d'etre coherent
|
---|
| 19 |
|
---|
| 20 | // Last Index used Value member
|
---|
| 21 | long lastXIndex, lastYIndex;
|
---|
| 22 |
|
---|
| 23 | CarteLobe::CarteLobe(char fileRoot[], double frequence, int_4 NbPixelX, int_4 NbPixelY){
|
---|
| 24 | freq=frequence;
|
---|
| 25 | NbPixX=(long)NbPixelX;
|
---|
| 26 | NbPixY=(long)NbPixelY;
|
---|
| 27 | XMin=XMax=YMin=YMax=1.;
|
---|
| 28 | lastXIndex=lastYIndex=1;
|
---|
| 29 |
|
---|
| 30 | pCarte=NR.matrix(1,NbPixX,1,NbPixY);
|
---|
| 31 | // On Reserve l'espace memoire pour stocker la carte. Librairie NR
|
---|
| 32 | pAxeX= NR.vector(1,NbPixX);
|
---|
| 33 | pAxeY= NR.vector(1,NbPixY);
|
---|
| 34 | // La suite a-t-elle un sens avec les fonction de la NR?
|
---|
| 35 | if ((pCarte==NULL)||(pAxeX==NULL)||(pAxeY==NULL)) {
|
---|
| 36 | cerr<<"erreur memoire dans constructeur pCarte"<<endl;
|
---|
| 37 | cerr<<"espace demand: "<<NbPixX*NbPixY*4<<" Octets"<<endl;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | FILE* pfile;
|
---|
| 41 | char fileCur[150];
|
---|
| 42 |
|
---|
| 43 | // On lit le tableau des abscisses
|
---|
| 44 | sprintf(fileCur,"%s",fileRoot);
|
---|
| 45 | strcat(fileCur,"_U.txt");
|
---|
| 46 | pfile=fopen(fileCur,"r");
|
---|
| 47 | if (pfile==NULL){
|
---|
| 48 | cerr<< "Erreur a l'ouverture du fichier de donnees :"<<fileCur<< endl;
|
---|
| 49 | exit(-1);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | double PixCur=0.;
|
---|
| 53 | char dumChar;
|
---|
| 54 | for (int_4 i=1; i<(NbPixX+1); i++) {
|
---|
| 55 | fscanf(pfile,"%le%c",&PixCur,&dumChar);
|
---|
| 56 | pAxeX[i]=(r_4)PixCur;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | XMin=XMax=pAxeX[1];
|
---|
| 60 | for (int_4 i=2; i<(NbPixX+1); i++){
|
---|
| 61 | if (XMin>pAxeX[i]) XMin=pAxeX[i];
|
---|
| 62 | if (XMax<pAxeX[i]) XMax=pAxeX[i];
|
---|
| 63 | }
|
---|
| 64 | fclose(pfile);
|
---|
| 65 |
|
---|
| 66 | // On lit le tableau des ordonnees
|
---|
| 67 | sprintf(fileCur,"%s",fileRoot);
|
---|
| 68 | strcat(fileCur,"_V.txt");
|
---|
| 69 |
|
---|
| 70 | pfile=fopen(fileCur,"r");
|
---|
| 71 | if (pfile==NULL){
|
---|
| 72 | cerr<< "Erreur a l'ouverture du fichier de donnees :"<< fileCur<< endl;
|
---|
| 73 | exit(-1);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | for (int_4 j=1; j<(NbPixY+1); j++) {
|
---|
| 77 | fscanf(pfile,"%le%c",&PixCur,&dumChar);
|
---|
| 78 | pAxeY[j]=(r_4)PixCur;
|
---|
| 79 | for (int_4 i=0; i<(NbPixX-1); i++) {
|
---|
| 80 | fscanf(pfile,"%le%c",&PixCur,&dumChar);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | YMin=YMax=pAxeY[1];
|
---|
| 85 | for (int_4 i=0; i<NbPixY; i++){
|
---|
| 86 | if (YMin>pAxeY[i]) YMin=pAxeY[i];
|
---|
| 87 | if (YMax<pAxeY[i]) YMax=pAxeY[i];
|
---|
| 88 | }
|
---|
| 89 | fclose (pfile);
|
---|
| 90 |
|
---|
| 91 | // On lit le contenu de la carte
|
---|
| 92 | sprintf(fileCur,"%s",fileRoot);
|
---|
| 93 | strcat(fileCur,"_PowdB.txt");
|
---|
| 94 |
|
---|
| 95 | pfile=fopen(fileCur,"r");
|
---|
| 96 | if (pfile==NULL){
|
---|
| 97 | cerr<< "Erreur a l'ouverture du fichier de donnees :"<< fileCur<< endl;
|
---|
| 98 | exit(-1);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | for (int j=1; j<(NbPixY+1); j++){
|
---|
| 102 | for(int i=1; i<(NbPixX+1); i++){
|
---|
| 103 | fscanf(pfile,"%le%c",&PixCur,&dumChar);
|
---|
| 104 | pCarte[i][j]=PixCur;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | resolution=CalcResol();
|
---|
| 108 | // C'est fini!
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | CarteLobe::~CarteLobe() {
|
---|
| 112 | NR.free_vector(pAxeX,1,NbPixX);
|
---|
| 113 | NR.free_vector(pAxeY,1,NbPixY);
|
---|
| 114 | NR.free_matrix(pCarte,1,NbPixX,1,NbPixY);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | double CarteLobe::Value(double XVal, double YVal) const {
|
---|
| 118 | // Value of lobe at coordinates
|
---|
| 119 | float X=(float) XVal;
|
---|
| 120 | float Y=(float) YVal;
|
---|
| 121 | float dBValue=0.;
|
---|
| 122 | float dBError=0.;
|
---|
| 123 |
|
---|
| 124 | if ((X<=XMin)||(X>=XMax)||(Y<=YMin)||(Y>=YMax)) return 0.;
|
---|
| 125 |
|
---|
| 126 | else {
|
---|
| 127 | unsigned long XIndex=lastXIndex;
|
---|
| 128 | unsigned long YIndex=lastYIndex;
|
---|
| 129 |
|
---|
| 130 | NR.hunt(pAxeX,NbPixX,X,&XIndex); // 0<X<NbPixX-1
|
---|
| 131 | NR.hunt(pAxeY,NbPixY,Y,&YIndex); // 0<Y<NbPixY-1
|
---|
| 132 |
|
---|
| 133 | lastXIndex=XIndex;
|
---|
| 134 | lastYIndex=YIndex;
|
---|
| 135 |
|
---|
| 136 | // Extrait le soustableau encadrant XIndex et YIndex
|
---|
| 137 | if(XIndex>(NbPixX-2)) XIndex=NbPixX-2;
|
---|
| 138 | if(YIndex>(NbPixY-2)) YIndex=NbPixY-2;
|
---|
| 139 | float ** ptableau= NR.submatrix(pCarte,XIndex,XIndex+2,YIndex,YIndex+2,1,1);
|
---|
| 140 |
|
---|
| 141 | // On interpole sous le soustableau
|
---|
| 142 | NR.polin2(pAxeX+XIndex-1,pAxeY+YIndex-1,ptableau,3,3,X,Y,&dBValue,&dBError);
|
---|
| 143 |
|
---|
| 144 | // On passe en echelle lineaire
|
---|
| 145 | return pow(10.,(double)(dBValue/10.));
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void CarteLobe::FitsVisu(char FitsFile[],long nx,long ny) {
|
---|
| 150 | Image<float>* img;
|
---|
| 151 | img = new Image<float>(nx,ny,1);
|
---|
| 152 | double xstep=(XMax-XMin)/nx;
|
---|
| 153 | double ystep=(YMax-YMin)/ny;
|
---|
| 154 | double yPos=YMin;
|
---|
| 155 | double xPos=XMin;
|
---|
| 156 |
|
---|
| 157 | for(int i=0; i<nx;i++){
|
---|
| 158 | xPos=XMin;
|
---|
| 159 | for(int j=0; j<ny; j++){
|
---|
| 160 | (*img)(i,j)=Value(xPos,yPos);
|
---|
| 161 | xPos+=xstep;
|
---|
| 162 | }
|
---|
| 163 | yPos+=ystep;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | (*img).Save(FitsFile); // BUGG XXXXXX
|
---|
| 167 | // Ne sauvegarde pas dans un format FITS pour le moment!!!
|
---|
| 168 | cerr<<"Ecriture fichier :"<<FitsFile<<endl;
|
---|
| 169 | delete img;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | void CarteLobe::UVToAng(double U, double V, double& alpha, double& beta) const {
|
---|
| 173 | // U=sin alpha cos beta
|
---|
| 174 | // V=sin alpha sin beta
|
---|
| 175 | double sinalpha=sqrt(U*U+V*V); // Approx des petits angles pour alpha
|
---|
| 176 | // Pas pour beta
|
---|
| 177 | if(U>=0) beta=asin(V/sinalpha);
|
---|
| 178 | else beta=Pi-asin(V/sinalpha);
|
---|
| 179 | alpha=asin(sinalpha);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | double CarteLobe::halfAngAperture(){
|
---|
| 183 | double alCentre=0.; double beCentre=0.;
|
---|
| 184 | UVToAng(UCentre(),VCentre(),alCentre,beCentre);
|
---|
| 185 | double alBord=0; double beBord=0;
|
---|
| 186 | UVToAng(XMin, YMin, alBord,beBord);
|
---|
| 187 | double CosAng=0.;
|
---|
| 188 | CosAng+=cos(alCentre)*cos(alBord);
|
---|
| 189 | CosAng+=sin(alCentre)*sin(beCentre)*sin(alBord)*sin(beBord);
|
---|
| 190 | CosAng+=sin(alCentre)*cos(beCentre)*sin(alBord)*cos(beBord);
|
---|
| 191 | return acos(CosAng);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | double CarteLobe::CalcResol(){
|
---|
| 195 | double halfAng=halfAngAperture();
|
---|
| 196 | double NbBin=sqrt(NbPixX*NbPixX+NbPixY*NbPixY);
|
---|
| 197 | return 2*halfAng/NbBin; // C'est delirament petit
|
---|
| 198 | // on prend
|
---|
| 199 | // return 1.e-3; // Debug XXXX
|
---|
| 200 | }
|
---|