DAS  3.1.6 - 18/09/2017
DOAS.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 #include <io.h>
4 #include <fcntl.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <time.h>
10 #include <sys/timeb.h>
11 #include <string.h>
12 #include <math.h>
13 #include "mgui.h"
14 #include "DAS_Spatram.h"
15 #include "dcl.h"
16 #include "dil.h"
17 #include "DOAS.h"
18 #include "bil.h"
19 
21 
26 int Pix2Wl(int mod, int pos, int spix, int epix, struct doas *pd)
27 {
28  int k, i, c = pos, t=0;
29 
30  for(i = 0;i< 18 ;i++)
31  {
32  if(pos == pd->wlc[i])
33  {
34  t = i;
35  }
36  }
37  // dl for wl at pix pixref
38  pd->lambda[pd->pixref[t]] = (2 * pd->wlref[t] - pd->k1[t]) / (2 - pd->k2[t]);
39 
40  // tot wl at pix pixref
41  pd->lambda[pd->pixref[t]] =
42  (pd->lambda[pd->pixref[t]]) + (pd->k1[t] - pd->k2[t] * pd->lambda[pd->pixref[t]]) * pd->dhg[t];
43 
44 
45  //Wavelenth series is build for decreasing pixel number
46  for(k = pd->pixref[t] - 1 ; k >= spix; k--)
47  pd->lambda[k] = ((2 + pd->k2[t]) * pd->lambda[k + 1] - 2 * pd->k1[t]) / (2 - pd->k2[t]);
48 
49  //Wavelenth series is build for increasing pixel number
50  for (k = pd->pixref[t] + 1; k <= epix +1; k++)
51  pd->lambda[k] = ((2 - pd->k2[t]) * pd->lambda[k - 1] + 2 * pd->k1[t]) / (2 + pd->k2[t]);
52 
53  return 0;
54 }
55 
56 
57 
58 
59  /* CalcSpectrumLimits(int mod, int pos, int spx, int epix, int refpix )
60  Pixel --> Wavelength
61  mod: dummy
62  pos: spectral position
63  spx: start pixel for wl series
64  epx: end pixel for wl series
65  refpix: referring pixel
66 */
67 void CalcSpectrumLimits(int mod, int pos, int spix, int epix, int refpix )
68 {
69 
70 /* Da calcoli di Giorgio
71 2773 0.675070513 -3.42932E-05
72 3312 0.608620686 -1.22438E-05
73 3840 0.513266027 9.38545E-06
74 4358 0.580417561 -8.00615E-06
75 4866 1.094769302 -1.17723E-04
76 5363 0.637981086 -2.18565E-05
77 5850 0.450432353 9.64196E-06
78 6237 0.926432179 -6.81376E-05
79 6795 0.509714198 -3.59181E-06
80 7253 0.961946259 -6.73045E-05
81 */
82 
83 /* Da calcoli di Danbo in DispersioneSPATRAM_EV.xls
84 
85  ATTENZIONE LA procedura di linearizzazione utilizza l'equazione: dl = K1 - K2 * l,
86  mentre la procedura di regressione di EXCEL utilizza (giustamente) dl = K1 + K2 * l,
87  quindi i valori di k2 in excel hanno il segno "-" mentre qui devono essere inseriti nel
88  vettore kk2 con il segno positivo.
89 
90 2823 dl = 2.35808044 - 0.000628126 * l
91 3337 dl = 0.767112208 - 4.67502E-05 * l
92 3850 dl = 0.824026577 - 5.67659E-05 * l
93 4358 dl = 3.011942876 - 0.000572933 * l
94 4861
95 5332
96 5814
97 6282
98 6734
99 7201
100 7677
101 8195
102 8622
103 9023
104 9405
105 9758
106 10066
107 10358
108 1.094769302 -1.17723E-04
109 
110 
111 
112 */
113 
114  int k, i, c = pos;
115 /* Da calcoli di Giorgio*/
116 // double kk1[] = {0.675070513,0.608620686,0.513266027,0.580417561,1.094769302,6,7,8,9,10,11,12,13,14,15,16,17,18};
117 // double kk2[] = {-3.42932E-05,-1.22438E-05,9.38545E-06,-8.00615E-06,-1.17723E-04,6,7,8,9,10,11,12,13,14,15,16,17,18};
118 
119 /* Da calcoli di Danbo*/
120 // double kk1[] = {2.35808044,0.767112208,0.824026577,3.011942876,1.094769302,1,1,1,1,1,1,1,1,1,1,1,1,1};
121 // double kk2[] = {0.000628126,4.67502E-05,5.67659E-05,0.000572933,1.17723E-04,1,1,1,1,1,1,1,1,1,1,1,1,1};
122 
123  double lm[1055];
124 
125  double k1,k2;
126 
127  for(i = 0;i< 18 ;i++)
128  {
129  if(pos == wl[i])
130  {
131 // k1 = kk1[i];
132 // k2 = kk2[i];
133  k1 = DOAS.k1[i];
134  k2 = DOAS.k2[i];
135  }
136  }
137 /*
138  DOAS.lambda[512] = (2 * pos - k1) / (2 - k2); // dl for wl at pix 512
139 
140  DOAS.lambda[512] = (DOAS.lambda[512]) + (k1 - k2 * DOAS.lambda[512]); // tot wl at pix 512
141 
142 
143  //Wavelenth series is build for decreasing pixel number
144  for(k = 511; k >= 0; k--)
145  DOAS.lambda[k] = ((2 + k2) * DOAS.lambda[k + 1] - 2 * k1) / (2 - k2);
146 
147  //Wavelenth series is build for increasing pixel number
148  for (k = 513; k <= IDX; k++)
149  DOAS.lambda[k] = ((2 - k2) * DOAS.lambda[k - 1] + 2 * k1) / (2 + k2);
150 */
151 
152  lm[refpix] = (2 * pos - k1) / (2 - k2); // dl for wl at pix pixref
153 
154  lm[refpix] = (lm[refpix]) + (k1 - k2 * lm[refpix]); // tot wl at pix pixref
155 
156 
157  //Wavelenth series is build for decreasing pixel number
158  for(k = refpix - 1 ; k >= spix; k--)
159  lm[k] = ((2 + k2) * lm[k + 1] - 2 * k1) / (2 - k2);
160 
161  //Wavelenth series is build for increasing pixel number
162  for (k = refpix + 1; k <= epix +1; k++)
163  lm[k] = ((2 - k2) * lm[k - 1] + 2 * k1) / (2 + k2);
164 
165  for(i = spix; i<=epix; i++)
166  DOAS.lambda[i] = lm[i];
167 
168 }
169 
170 void FixedStep(void)
171 {
172 
173 
174 }
175 
176 
177 
178 int BuildLogRatio(void)
179 {
180 
181  int x, y, BlindPix_1;
182  FILE *fd;
183  float low = 65535;
184  float high= -65535;
185 
186  IDY = IDY -1;
187 
188 
189  BlindPix_1 = 0;
190  if (BIL.SPH.ccdwx - (BIL.SPH.ccdex +1) != 0) // se i pixel del sensore sono piu' di quelli in param.ini
191  BlindPix_1 = BIL.SPH.ccdwx - (BIL.SPH.ccdex +1) ;
192 
193 
194 // FixedStep();
195 
196 
197 
198  DOAS.IoSmoothed = AllocFloatMat(IDX, IDY);
199  DOAS.IsSmoothed = AllocFloatMat(IDX, IDY);
200 
201  DOAS.LogRatioMat = AllocFloatMat(IDX, IDY);
202 
204 
205  DOAS.VarY = AllocFloatMat(IDX, IDY);
206 
207  FilterData(DOAS.IoMat, IDX, IDY, 5, BlindPix_1);
208  FilterData(BIL.DPLOT.ImatOrig, IDX, IDY, 5, BlindPix_1);
209 
210  SmoothData(DOAS.IoMat, DOAS.IoSmoothed, IDX, IDY, DOAS.FFTFilter, BlindPix_1);
211  SmoothData(BIL.DPLOT.ImatOrig, DOAS.IsSmoothed, IDX, IDY, DOAS.FFTFilter, BlindPix_1);
212 
213  for(x = 2; x < IDX - BlindPix_1; x++)
214  {
215 
216  for(y = 0; y < IDY; y++)
217  {
218  DOAS.LogRatioMat[y * IDX + x] = (float) log( DOAS.IoMat[y * IDX + x] / ( BIL.DPLOT.ImatOrig[y * IDX + x] * (DOAS.IoSmoothed[y * IDX + x] / DOAS.IsSmoothed[y * IDX + x])));
219  }
220  }
221 
222  SmoothFloatData(DOAS.LogRatioMat, DOAS.LogRatioSmoothed, IDX, IDY, DOAS.FFTFilter, BlindPix_1);
223 
224 // for(x = 2; x < IDX - BlindPix_1 + 1; x++)
225  for(x = 2; x < IDX - BlindPix_1; x++)
226  {
227 
228  for(y = 0; y < IDY; y++)
229  {
230  DOAS.VarY[y * IDX + x] = DOAS.LogRatioMat[y * IDX + x] - DOAS.LogRatioSmoothed[y * IDX + x];
231  }
232  }
233 
234 
235  fd = fopen("TestLogRatio.dat", "w");
236  if(fd < 0) return 1;
237 
238 
239 // for(x = 2; x < IDX - BlindPix_1 + 1; x++)
240  for(x = 2; x < IDX - BlindPix_1; x++)
241  {
242 
243  fprintf(fd, " %9.4lf", DOAS.lambda[x]);
244  for(y = 0; y < IDY; y++)
245  {
246 
247 
248 // DOAS.LogRatioMat[y * IDX + x] = log( DOAS.IoMat[y * IDX + x] / ( BIL.DPLOT.ImatOrig[y * IDX + x] * (DOAS.IoSmoothed[y * IDX + x] / DOAS.IsSmoothed[y * IDX + x])));
249  fprintf(fd, " %9.4lf", DOAS.VarY[y * IDX + x]);
250  }
251  fprintf(fd, "\n", NULL);
252  }
253  fprintf(fd, "\n", NULL);
254  fclose(fd);
255 
256 
257 
258 
259 
260 // for(x = 2; x < IDX - BlindPix_1 + 1; x++)
261  for(x = 2; x < IDX - BlindPix_1; x++)
262  {
263  for(y = 0; y < IDY; y++)
264  {
265  if(DOAS.VarY[y * IDX + x] < low) low = DOAS.VarY[y * IDX + x];
266  if(DOAS.VarY[y * IDX + x] > high) high = DOAS.VarY[y * IDX + x];
267  }
268  }
269 
270 
271 // for(x = 2; x < IDX - BlindPix_1 + 1; x++)
272  for(x = 2; x < IDX - BlindPix_1; x++)
273  {
274 
275  for(y = 0; y < IDY; y++)
276  {
277  BIL.DPLOT.ImatOrig[y * IDX + x] = (unsigned short)((DOAS.VarY[y * IDX + x] - low) * 100000);
278  }
279  }
280 
281 
282 
283 
284 
285 
286 // SwapMatrix((unsigned short *) DOAS.VarY, BIL.DPLOT.ImatOrig, IDX, IDY);
288 
289 /*
290  DOAS.IoSmoothed = DeallocFloatMat(DOAS.IoSmoothed);
291  DOAS.IsSmoothed = DeallocFloatMat(DOAS.IsSmoothed);
292 
293  DOAS.LogRatioMat = DeallocFloatMat(DOAS.LogRatioMat);
294 
295  DOAS.LogRatioSmoothed = DeallocFloatMat(DOAS.LogRatioSmoothed);
296 
297  DOAS.VarY = DeallocFloatMat(DOAS.VarY);
298 */
299  return 0;
300 
301 }
302 
303 
304 
int SmoothFloatData(float *source, float *destination, int horpix, int verpix, int filw, int bp)
Calc. the smoothed matrix of a float one. .
Definition: Save.c:890
double k2[20]
k2 dispersion parameter -slope (x stretch2
Definition: DOASdef.h:23
float * IsSmoothed
Smoothed measured spectrum.
Definition: DOASdef.h:29
void GrafoIMG(int mode)
Definition: Spat_Plot.c:1242
int IDX
Number of sensible horizontal pixels.
Definition: DAS_Spat.c:118
Definition: DOASdef.h:16
float * IoSmoothed
Smoothed ref spectrum.
Definition: DOASdef.h:28
void FixedStep(void)
Definition: DOAS.c:170
int FilterData(unsigned short *mat, int horpix, int verpix, int filw, int bp)
Definition: FFT.c:250
spectrumheader SPH
Spectrum Header Structure.
Definition: bildef.h:256
double wlref[20]
reference wavelength
Definition: DOASdef.h:20
int SmoothData(unsigned short *source, float *destination, int horpix, int verpix, int filw, int bp)
Calc. the smoothed matrix of an unsigned short one. .
Definition: Save.c:973
int pixref[20]
reference pixel
Definition: DOASdef.h:21
float * LogRatioSmoothed
Definition: DOASdef.h:32
unsigned short * ImatOrig
Definition: bildef.h:180
d_view DPLOT
Definition: bildef.h:254
double lambda[1055]
Wavelength series.
Definition: DOASdef.h:18
int ON_OFFLINEPLOT
Definition: DAS_Spat.c:117
double dhg[20]
shift parameter
Definition: DOASdef.h:24
float * VarY
Definition: DOASdef.h:31
double k1[20]
k1 dispersion parameter - intercept (x stretch1)
Definition: DOASdef.h:22
int IDY
Number of sensible vertical pixels.
Definition: DAS_Spat.c:119
int Pix2Wl(int mod, int pos, int spix, int epix, struct doas *pd)
Definition: DOAS.c:26
Function prototypes.
int FFTFilter
Fast Fourier Trasform Filter windows.
Definition: DOASdef.h:25
int BuildLogRatio(void)
first attempt to apply the DOAS algorithm (..on going!!!)
Definition: DOAS.c:178
Function prototypes.
bil BIL
Definition: 2DPlot.c:28
unsigned short * IoMat
Reference spectrum.
Definition: DOASdef.h:27
int wl[]
WaveLength definition - for SD_Grating.
Definition: DAS_Spat.c:182
int wlc[20]
Central wavelength.
Definition: DOASdef.h:19
doas DOAS
Definition: DOAS.c:20
void CalcSpectrumLimits(int mod, int pos, int spix, int epix, int refpix)
Definition: DOAS.c:67
float * AllocFloatMat(int hp, int vp)
Definition: Spat_Plot.c:2009
float * LogRatioMat
log of the ratio
Definition: DOASdef.h:30
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:44:08 for DAS - Rel. 3.1.6 - 18/09/2017.