forked from NOVACProject/MobileDOAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flux1.cpp
675 lines (578 loc) · 21 KB
/
Flux1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
// Flux1.cpp: implementation of the CFlux class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DMSpec.h"
#include "Flux1.h"
#include "Common.h"
#include <math.h>
#include <vector>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
using namespace Flux;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFlux::CFlux(){
m_curTraverse = 0;
m_traverseNum = 0;
// allocate space for one traverse...
m_traverse.SetAtGrow(0, new CTraverse());
m_windField = nullptr;
m_useWindField = false;
m_windSpeed = 5;
m_windAngle = 210;
plumeWidth = 0;
traverseLength = 0;
spectraInPlume = 0;
fCreateAdditionalLog = false;
}
CFlux::~CFlux()
{
if(m_windField != nullptr){
delete(m_windField);
m_windField = nullptr;
}
for(int i = 0; i < m_traverse.GetCount(); ++i){
CTraverse *tr = m_traverse.GetAt(i);
if(tr != nullptr){
delete tr;
}
}
}
/**Calculate flux and record every calculated flux value in "postFluxRecord.txt" file
*
*/
double CFlux::GetTotalFlux()
{
if(fCreateAdditionalLog){
additionalLogName.Format("AdditionalFluxLog.txt");
m_traverse[m_curTraverse]->m_fCreateAdditionalLog = &fCreateAdditionalLog;
m_traverse[m_curTraverse]->m_additionalLogName = &additionalLogName;
}
// ----------------------- CALCULATING THE FLUX -------------------------
// Calculate the flux
if(m_traverse[m_curTraverse]->m_useWindField)
m_totalFlux = m_traverse[m_curTraverse]->GetTotalFlux();
else
m_totalFlux = m_traverse[m_curTraverse]->GetTotalFlux(m_windSpeed, m_windAngle);
// save some more data
this->plumeWidth = m_traverse[m_curTraverse]->m_plumeWidth;
this->traverseLength = m_traverse[m_curTraverse]->m_traverseLength;
// -------------------- ESTIMATING THE ERROR IN FLUX -----------------------
CTraverse *upperTraverse = new CTraverse();
CTraverse *lowerTraverse = new CTraverse();
CTraverse *curTraverse = m_traverse.GetAt(m_curTraverse);
*upperTraverse = *curTraverse;
*lowerTraverse = *curTraverse;
// Get the offset that the user has chosen
double userOffset = curTraverse->m_Offset;
// Find the average column error
double avgColErr = Average(curTraverse->columnError, curTraverse->m_recordNum);
int k;
// Go through the traverse, for each data point with a column value less than
// (offset + avgColErr) decrease the column value with its column error
// and for each data point with a column value higher than (offset + avgColErr)
// increase the column value with its column error.
for(k = 0; k < curTraverse->m_recordNum; ++k){
if(curTraverse->columnArray[k] < (userOffset + avgColErr)){
lowerTraverse->columnArray[k] = curTraverse->columnArray[k] + curTraverse->columnError[k];
upperTraverse->columnArray[k] = curTraverse->columnArray[k] - curTraverse->columnError[k];
}else{
lowerTraverse->columnArray[k] = curTraverse->columnArray[k] - curTraverse->columnError[k];
upperTraverse->columnArray[k] = curTraverse->columnArray[k] + curTraverse->columnError[k];
}
}
// correct the offsets
lowerTraverse->m_Offset = userOffset + avgColErr;
upperTraverse->m_Offset = userOffset - avgColErr;
// Calculate the fluxes
if(m_traverse[m_curTraverse]->m_useWindField){
m_totalFlux_Low = lowerTraverse->GetTotalFlux();
m_totalFlux_High = upperTraverse->GetTotalFlux();
}else{
m_totalFlux_Low = lowerTraverse->GetTotalFlux(m_windSpeed, m_windAngle);
m_totalFlux_High = upperTraverse->GetTotalFlux(m_windSpeed, m_windAngle);
}
delete upperTraverse;
delete lowerTraverse;
return m_totalFlux;
}
/* called when reading a new evaluation log */
long CFlux::ReadLogFile(CString filePath, CString fileName, int nChannels, double fileVersion){
return ReadLogFile(filePath, fileName, m_traverseNum, nChannels, fileVersion);
}
/* called when re-reading an old evaluation log */
long CFlux::ReadLogFile(CString filePath, CString fileName, long fileIndex, int nChannels, double fileVersion){
char buf[4096];
int n = 0;
FILE *f = fopen(fileName, "r");
if(nullptr == f){
f = fopen(TEXT(filePath + "\\" + fileName), "r");
if(nullptr == f){
MessageBox(NULL,TEXT("Can not read log file"),TEXT("Error"),MB_OK);
return FALSE;
}
}
m_traverse[fileIndex]->m_hasGPS = false;
if(nChannels > 1){
m_traverse[fileIndex+1]->m_hasGPS = false;
}
double fValue[3];
int i = 0;
// Read the data from the evaluation file into the correct columns
while(fgets(buf, 4095, f)){ // fgets reads until the next newline character
char* szToken = buf;
i = 0;
while(szToken = strtok(szToken,"\t")){
if(strstr(szToken, ":")){
if(sscanf(szToken, "%lf:%lf:%lf", &fValue[0], &fValue[1], &fValue[2]) != 3)
break;
}else{
if(sscanf(szToken, "%lf", &fValue[0]) != 1)
break;
}
AssignValueToColumn(fileIndex, i, n, fValue, nChannels, fileVersion);
++i;
szToken = NULL;
}
if(i != 0)
++n;
if(n == MAX_TRAVERSELENGTH){
CString message;
message.Format("Traverses longer than %d data points cannot be read fully. Reading stopped at datapoint %d.", MAX_TRAVERSELENGTH, MAX_TRAVERSELENGTH);
MessageBox(NULL, message, "Too long traverse", MB_OK);
break;
}
}
fclose(f);
if(n == 0){
nChannels = 1;
return 0;
}
/* Remove all backslashes in the given fileName, if any */
int stringIndex = fileName.ReverseFind('\\');
if(stringIndex != -1)
fileName.Format(fileName.Right(strlen(fileName) - stringIndex - 1));
for(int k = 0; k < nChannels; ++k){
m_traverse[fileIndex + k]->m_recordNum = n;
//hasValidGPS(fileIndex);
m_traverse[fileIndex + k]->m_gasFactor = m_traverse[fileIndex]->m_gasFactor;
if(strlen(m_specieName[k]) == 0){
m_traverse[fileIndex + k]->m_fileName.Format("%s", (LPCTSTR)fileName);
}else{
m_traverse[fileIndex + k]->m_fileName.Format("%s * %s", (LPCTSTR)m_specieName[k], (LPCTSTR)fileName);
if(0 == _strnicmp(m_specieName[k], "SO2", 3*sizeof(char)))
m_traverse[fileIndex + k]->m_gasFactor = GASFACTOR_SO2;
if(0 == _strnicmp(m_specieName[k], "O3", 2*sizeof(char)))
m_traverse[fileIndex + k]->m_gasFactor = GASFACTOR_O3;
if(0 == _strnicmp(m_specieName[k], "NO2", 3*sizeof(char)))
m_traverse[fileIndex + k]->m_gasFactor = GASFACTOR_NO2;
}
m_traverse[fileIndex + k]->m_filePath.Format("%s", (LPCTSTR)filePath);
m_traverse[fileIndex + k]->CalculateOffset();
// for files with several channels the fitregion is only read into the first channel
m_traverse[fileIndex + k]->m_fitRegion[0] = m_traverse[fileIndex]->m_fitRegion[0];
m_traverse[fileIndex + k]->m_fitRegion[1] = m_traverse[fileIndex]->m_fitRegion[1];
m_traverse[fileIndex + k]->m_dynRange = m_lastDynamicRange;
}
if(fileIndex == m_traverseNum){
m_traverseNum += nChannels;
m_curTraverse = m_traverseNum - nChannels;
}
return n;
}
/**Get all information about the plume center
*@maxBuffer 0 - column in the center - where max column locates
*@maxBuffer 1 - latitude - where max column locates
*@maxBuffer 2 - longitude - where max column locates
*@maxBuffer 3 - wind angle - where max column locates
*@avBuffer 0 - column in the center - where average column locates
*@avBuffer 1 - latitude - where average column locates
*@avBuffer 2 - longitude - where average column locates
*@avBuffer 3 - wind angle - where average column locates
*/
int CFlux::GetPlumeCenter(double srclat,double srclon,double *maxBuffer,double *avBuffer)
{
return m_traverse[m_curTraverse]->GetPlumeCenter(srclat, srclon, maxBuffer, avBuffer);
}
long CFlux::GetColumn(double *pBuffer)
{
memcpy((void*)pBuffer,(void*)m_traverse[m_curTraverse]->columnArray,sizeof(double)*m_traverse[m_curTraverse]->m_recordNum);
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetTime(double *pBuffer){
for(long k = 0; k < m_traverse[m_curTraverse]->m_recordNum; ++k){
Time &t = m_traverse[m_curTraverse]->time[k];
pBuffer[k] = 3600 * t.hour + 60 * t.minute + t.second;
if (k > 0) {
if (pBuffer[k] < pBuffer[k - 1]) {
pBuffer[k] += 3600 * 24;
}
}
}
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetColumnError(double *pBuffer)
{
memcpy((void*)pBuffer,(void*)m_traverse[m_curTraverse]->columnError,sizeof(double)*m_traverse[m_curTraverse]->m_recordNum);
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetIntensity(double *pBuffer)
{
memcpy((void*)pBuffer,(void*)m_traverse[m_curTraverse]->intensArray,sizeof(double)*m_traverse[m_curTraverse]->m_recordNum);
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetAltitude(double *pBuffer)
{
memcpy((void*)pBuffer,(void*)m_traverse[m_curTraverse]->altitude,sizeof(double)*m_traverse[m_curTraverse]->m_recordNum);
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetLon(double *pBuffer)
{
memcpy((void*)pBuffer,(void*)m_traverse[m_curTraverse]->longitude,sizeof(double)*m_traverse[m_curTraverse]->m_recordNum);
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetLat(double *pBuffer)
{
memcpy((void*)pBuffer,(void*)m_traverse[m_curTraverse]->latitude,sizeof(double)*m_traverse[m_curTraverse]->m_recordNum);
return m_traverse[m_curTraverse]->m_recordNum;
}
long CFlux::GetDynamicRange(){
return m_traverse[m_curTraverse]->m_dynRange;
}
void CFlux::SetParams(double pSpeed, double pAngle, double pLat, double pLon, long pLowIndex,long pHighIndex,double pOffset)
{
m_windSpeed = pSpeed;
m_windAngle = pAngle;
m_srcLatitude = pLat*DEGREETORAD;
m_srcLongitude = pLon*DEGREETORAD;
m_traverse[m_curTraverse]->m_lowIndex = pLowIndex;
m_traverse[m_curTraverse]->m_highIndex = pHighIndex;
m_traverse[m_curTraverse]->m_Offset = pOffset;
}
int CFlux::ReadSettingFile(CString filename,int &nChannels, double &fileVersion){
return ReadSettingFile(filename, m_traverseNum, nChannels, fileVersion);
}
int CFlux::ReadSettingFile(CString filename, long fileIndex, int &nChannels, double &fileVersion){
char *pt;
char txt[256];
char nl[2]={ 0x0a, 0 };
char lf[2]={ 0x0d, 0 };
int nofSpecies = 0;
bool hasMasterChannelData = false;
CString knownSpecie[] = {"SO2", "NO2", "O3", "O4", "HCHO", "RING", "H2O", "CLO", "BRO", "CHOCHO", "Glyoxal", "Formaldehyde", "FraunhoferRef"};
int nKnownSpecies = 13;
CString columnLabel;
// reset the 'm_specieName' buffer
for (int i = 0; i < 20; ++i) {
m_specieName[i].Format("");
}
char msg[200];
nChannels = 1;
m_lastRefFileNum = 0;
int result=0;
FILE* fil = fopen(filename, "r");
if(fil<(FILE *)1)
{
sprintf(msg,"Could not open file %s",(LPCTSTR)filename);
MessageBox(NULL,msg,TEXT("Error"),MB_OK);
return 0;
}
while(fgets(txt,sizeof(txt)-1,fil) ){
if(strlen(txt)>4 && txt[0]!='%'){
pt = txt;
if(pt=strstr(txt,nl))
pt[0]=0;
pt=txt;
if(pt=strstr(txt,lf))
pt[0]=0;
if(pt=strstr(txt,"GASFACTOR="))
{
pt=strstr(txt,"=");
sscanf(&pt[1],"%lf",&m_lastGasFactor);
}
if(pt = strstr(txt, "DYNAMICRANGE="))
{
pt=strstr(txt,"=");
sscanf(&pt[1],"%ld",&m_lastDynamicRange);
}
if((pt = strstr(txt, "FITFROM=")) || (pt = strstr(txt, "FitFrom")))
{
pt = strstr(txt,"=");
sscanf(&pt[1],"%ld",&m_lastFitFrom);
}
if((pt = strstr(txt, "FITTO=")) || (pt = strstr(txt, "FitTo")))
{
pt = strstr(txt,"=");
sscanf(&pt[1],"%ld",&m_lastFitTo);
}
if(pt = strstr(txt, "REFFILE="))
{
char buffer[4096];
pt = strstr(txt,"=");
if(0 < sscanf(&pt[1],"%4095s",&buffer)){
char *lastBackslash = strrchr(buffer, '\\');
if(lastBackslash == nullptr)
m_lastRefFile[m_lastRefFileNum++].Format("%s", buffer);
else
m_lastRefFile[m_lastRefFileNum++].Format("%s", lastBackslash+1);
}
}
if(pt=strstr(txt,"VERSION="))
{
pt=strstr(txt,"=");
sscanf(&pt[1],"%lf",&fileVersion);
}
if(pt=strstr(txt,"FILETYPE=")){
pt=strstr(txt,"=");
sscanf(pt+1,"%99s",m_FileType);
result = 1; /* the file is a correct evaluation log */
}
pt = txt;
while(pt = strstr(pt, "Master_Column_")){
if(Equals(pt+14, "SO2", 3)){
m_specieName[nofSpecies].Format("Master_SO2");
}else if(Equals(pt+14, "NO2", 3)){
m_specieName[nofSpecies].Format("Master_NO2");
}else if(Equals(pt+14, "O3", 2)){
m_specieName[nofSpecies].Format("Master_O3");
}else if(Equals(pt+14, "RING", 4)){
m_specieName[nofSpecies].Format("Master_Ring");
}else if(Equals(pt+14, "O4", 2)){
m_specieName[nofSpecies].Format("Master_O4");
}else if(Equals(pt+14, "HCHO", 4)){
m_specieName[nofSpecies].Format("Master_HCHO");
}
++nofSpecies;
++pt;
}
pt = txt;
while(pt = strstr(pt, "Slave_Column_")){
if(Equals(pt+14, "SO2", 3)){
m_specieName[nofSpecies].Format("Slave_SO2");
}else if(Equals(pt+14, "NO2", 3)){
m_specieName[nofSpecies].Format("Slave_NO2");
}else if(Equals(pt+14, "O3", 2)){
m_specieName[nofSpecies].Format("Slave_O3");
}else if(Equals(pt+14, "RING", 4)){
m_specieName[nofSpecies].Format("Slave_Ring");
}else if(Equals(pt+14, "O4", 2)){
m_specieName[nofSpecies].Format("Slave_O4");
}else if(Equals(pt+14, "HCHO", 4)){
m_specieName[nofSpecies].Format("Slave_HCHO");
}
++nofSpecies;
++pt;
}
if (nullptr != (pt = strstr(txt, "Column(Master)")) || nullptr != (pt = strstr(txt, "Master_Column"))) {
hasMasterChannelData = true;
}
if(hasMasterChannelData && (nullptr != (pt = strstr(txt, "Column(Slave)")) || nullptr != (pt = strstr(txt, "Slave_Column")))) {
nChannels = 2; /* if there are several channels */
m_specieName[0].Format("Master");
m_specieName[1].Format("Slave");
m_traverse.SetAtGrow(1, new CTraverse());
}
if(pt = strstr(txt, "nSpecies=")){
pt = strstr(txt, "=");
sscanf(&pt[1], "%d", &nChannels);
}
// Search for known species
for(int k = 0; k < nKnownSpecies; ++k){
columnLabel.Format("%s(column)", (LPCTSTR)knownSpecie[k]);
pt = txt;
while(pt = strstr(pt, columnLabel)){
m_specieName[nofSpecies].Format(knownSpecie[k]);
++nofSpecies;
++pt;
}
}
}
}
fclose(fil);
if (nofSpecies > 1)
{
for (int ii = 1; ii < nofSpecies; ++ii)
{
m_traverse.SetAtGrow(ii, new CTraverse());
}
}
return result;
}
void CFlux::Reset()
{
/* memset((void*)columnArray, 0, sizeof(double)*2*65536);
memset((void*)latArray, 0, sizeof(double)*2*65536);
memset((void*)longitude, 0, sizeof(double)*2*65536);
memset((void*)altArray, 0, sizeof(double)*2*65536);*/
}
bool CFlux::hasValidGPS(int file){
if(file == -1)
file = m_curTraverse;
if(m_traverse[file]->m_hasGPS)
return true;
for(int k = 0; k < m_traverse[file]->m_recordNum; ++k){
if(m_traverse[file]->latitude[k] != 0 || m_traverse[file]->longitude[k] != 0){
m_traverse[file]->m_hasGPS = true;
return true;
}
}
return false;
}
// used when parsing the log files
bool CFlux::AssignValueToColumn(long fileIndex, int column, int row, double value[3], int nChannels, double fileVersion){
// first make sure that this is not a reevaluation log, they are different
if(0 == strncmp(m_FileType, "ReEvaluationlog", 15))
return AssignValueToColumn_ReEvaluationLog(fileIndex, column, row, value, nChannels, fileVersion);
// the columns that are same for all versions of ev.logs.
switch(column){
case 0:
for(int k = 0; k < nChannels; ++k){
m_traverse[fileIndex + k]->time[row].hour = (char)value[0];
m_traverse[fileIndex + k]->time[row].minute = (char)value[1];
m_traverse[fileIndex + k]->time[row].second = (char)value[2];
}
return true;
case 1:
for(int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->latitude[row] = value[0];
return true;
case 2:
for(int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->longitude[row] = value[0];
return true;
}
// the version specific
if(fileVersion < 4.0){
switch(column){
case 3: m_traverse[fileIndex]->intensArray[row] = value[0]; return true;
case 4: m_traverse[fileIndex]->m_nSpectra = (long)value[0]; return true;
case 5: m_traverse[fileIndex]->columnArray[row] = value[0]; return true;
case 6: m_traverse[fileIndex]->m_expTime = (long)value[0]; return true;
}
}else if(fileVersion == 4.0){
switch(column){
case 3:
for(int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->altitude[row] = value[0];
return true;
case 4: m_traverse[fileIndex]->m_nSpectra = (long)value[0]; return true;
case 5: m_traverse[fileIndex]->m_expTime = (long)value[0]; return true;
case 6: m_traverse[fileIndex]->intensArray[row] = value[0]; return true;
case 7: m_traverse[fileIndex]->columnArray[row] = value[0]; return true;
case 8: m_traverse[fileIndex + 1]->intensArray[row] = value[0]; return true;
case 9: m_traverse[fileIndex + 1]->columnArray[row] = value[0]; return true;
}
}else if(fileVersion >= 4.1){// || fileVersion == 4.2){
switch(column){
case 3:
for(int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->altitude[row] = value[0];
return true;
case 4: m_traverse[fileIndex]->m_nSpectra = (long)value[0]; return true;
case 5: m_traverse[fileIndex]->m_expTime = (long)value[0]; return true;
case 6: m_traverse[fileIndex]->intensArray[row] = value[0]; return true;
case 7: m_traverse[fileIndex]->columnArray[row] = value[0]; return true;
case 8: m_traverse[fileIndex]->columnError[row] = value[0]; return true;
case 9: m_traverse[fileIndex + 1]->intensArray[row] = value[0]; return true;
case 10: m_traverse[fileIndex + 1]->columnArray[row] = value[0]; return true;
case 11: m_traverse[fileIndex + 1]->columnError[row] = value[0]; return true;
}
}
// no column found
return false;
}
bool CFlux::AssignValueToColumn_ReEvaluationLog(long fileIndex, int column, int row, double value[3], int nChannels, double fileVersion){
const int nCommonColumns = 7;
const int nColumnsPerSpecie = 6;
/* if any of the common columns */
switch(column){
case 0:
for (int k = 0; k < nChannels; ++k) {
m_traverse[fileIndex + k]->time[row].hour = (char)value[0];
m_traverse[fileIndex + k]->time[row].minute = (char)value[1];
m_traverse[fileIndex + k]->time[row].second = (char)value[2];
}
return true;
case 1:
for (int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->latitude[row] = value[0];
return true;
case 2:
for (int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->longitude[row] = value[0];
return true;
case 3:
for (int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->altitude[row] = value[0];
return true;
case 4:
for (int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->m_nSpectra = (long)value[0];
return true;
case 5:
for (int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->m_expTime = (long)value[0];
return true;
case 6:
for (int k = 0; k < nChannels; ++k)
m_traverse[fileIndex + k]->intensArray[row] = value[0];
return true;
}
/* this column is a description of one specie.
There are six columns for every specie; COLUMN, COLUMN_ERRROR, SHIFT, SHIFT_ERROR, SQUEEZE, SQUEEZE_ERROR */
int specieNumber = (column - nCommonColumns) / nColumnsPerSpecie;
int columnType = (column - nCommonColumns) % nColumnsPerSpecie;
switch(columnType){
case 0: m_traverse[fileIndex + specieNumber]->columnArray[row] = value[0];
return true;
case 1: m_traverse[fileIndex + specieNumber]->columnError[row] = value[0];
return true;
case 2:
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
}
return false;
}
long CFlux::GetCurrentFileName(CString &str){
char buffer[4096];
sprintf(buffer, "%s", (LPCTSTR)m_traverse[m_curTraverse]->m_fileName);
char *pt = strchr(buffer, '*');
if(pt != 0)
pt += 2;
else
pt = buffer;
str.Format("%s\\%s", (LPCTSTR)m_traverse[m_curTraverse]->m_filePath, pt);
return 0;
}
void CFlux::InterpolateWindField(int layer){
if(m_curTraverse < 0 || m_traverseNum <= 0)
return;
if(m_windField == nullptr || m_useWindField == false)
return;
CTraverse *tr = m_traverse[m_curTraverse];
std::vector<double> ws(tr->m_recordNum, 0);
std::vector<double> wd(tr->m_recordNum, 0);
// do the actual interpolation
int nPoints = m_windField->Interpolate(tr->latitude, tr->longitude, tr->time, layer, tr->m_recordNum,
ws.data(), wd.data(), CWindField::INTERPOLATION_NEAREST);
if(nPoints < tr->m_recordNum){
MessageBox(NULL, "Failed to interpolate all points in the traverse", "Error", MB_OK);
return;
}
// save the result
for(int i = 0; i < tr->m_recordNum; ++i){
tr->m_windDirection[i] = wd[i];
tr->m_windSpeed[i] = ws[i];
}
tr->m_useWindField = true;
}