-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMeteorologicalData.cpp
More file actions
108 lines (90 loc) · 2.83 KB
/
MeteorologicalData.cpp
File metadata and controls
108 lines (90 loc) · 2.83 KB
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
#include "StdAfx.h"
#include "meteorologicaldata.h"
/** The global instance of meterological data */
CMeteorologicalData g_metData;
CMeteorologicalData::CMeteorologicalData(void)
{
m_scannerNum = 0;
m_wfReader = NULL;
}
CMeteorologicalData::~CMeteorologicalData(void)
{
if(m_wfReader != NULL){
delete m_wfReader;
m_wfReader = NULL;
}
}
/** Set the wind field for a scanner */
int CMeteorologicalData::SetWindField(const CString &serialNumber, const CWindFieldAndPlumeHeight &windField){
int i;
for(i = 0; i < m_scannerNum; ++i){
if(Equals(serialNumber, m_scanner[i])){
m_windFieldAtScanner[i] = windField;
return 0;
}
}
// scanner not found
if(m_scannerNum == MAX_NUMBER_OF_SCANNING_INSTRUMENTS){
// array full
return 1;
}
// insert a scanner
m_scanner[m_scannerNum].Format("%s", serialNumber);
m_windFieldAtScanner[m_scannerNum] = windField;
++m_scannerNum;
return 0;
}
/** Get the wind field for a scanner */
int CMeteorologicalData::GetWindField(const CString &serialNumber, const CDateTime &dt, CWindFieldAndPlumeHeight &windField){
int scannerIndex = -1;
// Find the index of the scanner
for(scannerIndex = 0; scannerIndex < m_scannerNum; ++scannerIndex){
if(Equals(serialNumber, m_scanner[scannerIndex])){
break;
}
}
// 1. Try to read the wind from the wind-field file reader
if(m_wfReader != NULL){
if(SUCCESS == m_wfReader->InterpolateWindField(dt, windField)){
// Check if the file contains the wind-speed, the wind-direction and/or the plume height
if(!m_wfReader->m_containsWindDirection && scannerIndex >= 0){
windField.SetWindDirection(m_windFieldAtScanner[scannerIndex].GetWindDirection(), MET_USER);
}
if(!m_wfReader->m_containsWindSpeed){
windField.SetWindSpeed(m_windFieldAtScanner[scannerIndex].GetWindSpeed(), MET_USER);
}
if(!m_wfReader->m_containsPlumeHeight){
windField.SetPlumeHeight(m_windFieldAtScanner[scannerIndex].GetPlumeHeight(), MET_USER);
}
return 0; // wind-field found...
}
}
// 2. No wind field found in the reader, use the user-supplied or default...
if(scannerIndex >= 0){
windField = m_windFieldAtScanner[scannerIndex];
return 0;
}
// scanner not found
return 1;
}
/** Tries to read in a wind-field from a file. If this is successfull
then all wind-data returned will be first searched for in the wind-field
file and secondly from the user given or default values.
@return 0 on success */
int CMeteorologicalData::ReadWindFieldFromFile(const CString &fileName){
// Completely reset the data in the existing file-reader
if(m_wfReader != NULL){
delete m_wfReader;
}
m_wfReader = new FileHandler::CWindFileReader();
// Set the path to the file
m_wfReader->m_windFile.Format(fileName);
// Read the wind-file
if(SUCCESS != m_wfReader->ReadWindFile()){
delete m_wfReader;
m_wfReader = NULL;
return 1;
}else{
return 0;
}
}