Skip to content

Commit 17920eb

Browse files
Add support for loading multiple GRIB files.
Each file can be loaded and enabled/disabled independently. The GRIB files are structured in GRIB layers. Data interpolation occurs across GRIB layers. Add unit tests for the GRIB plugin.
1 parent 7898343 commit 17920eb

23 files changed

+1303
-277
lines changed

plugins/grib_pi/CMakeLists.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,66 @@ set(PACKAGE_NAME grib_pi)
3737
set(PLUGIN_SOURCE_DIR .)
3838
message(STATUS "*** Staging to build ${PACKAGE_NAME} ***")
3939

40+
# Define source files before tests so they're available to the test build
41+
set(SRC_GRIB
42+
src/grib_pi.h
43+
src/grib_pi.cpp
44+
src/grib_file.h
45+
src/grib_layer.h
46+
src/grib_layer.cpp
47+
src/grib_layer_set.h
48+
src/grib_layer_set.cpp
49+
src/grib_timeline_record_set.h
50+
src/GribOverlayFactory.cpp
51+
src/GribOverlayFactory.h
52+
src/GribUIDialogBase.cpp
53+
src/GribUIDialogBase.h
54+
src/GrabberWin.cpp
55+
src/GrabberWin.h
56+
src/GribUIDialog.cpp
57+
src/GribUIDialog.h
58+
src/CursorData.cpp
59+
src/CursorData.h
60+
src/GribSettingsDialog.cpp
61+
src/GribSettingsDialog.h
62+
src/GribRequestDialog.cpp
63+
src/GribRequestDialog.h
64+
src/XyGribPanel.h
65+
src/XyGribPanel.cpp
66+
src/XyGribModelDef.h
67+
src/XyGribModelDef.cpp
68+
src/icons.h
69+
src/msg.h
70+
src/email.h
71+
src/email.cpp
72+
src/GribTable.h
73+
src/GribTable.cpp
74+
src/CustomGrid.h
75+
src/CustomGrid.cpp
76+
src/icons.cpp
77+
src/GribReader.cpp
78+
src/GribRecord.cpp
79+
src/GribV1Record.cpp
80+
src/GribV2Record.cpp
81+
src/zuFile.cpp
82+
src/IsoLine.cpp
83+
src/pi_ocpndc.cpp
84+
src/pi_ocpndc.h
85+
)
86+
87+
# Enable testing
88+
enable_testing()
89+
90+
# Add tests subdirectory
91+
add_subdirectory(tests)
92+
93+
# Add plugin-specific test target
94+
add_custom_target(grib-pi-tests
95+
COMMAND ctest --output-on-failure
96+
COMMENT "Running GRIB plugin tests"
97+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
98+
)
99+
40100
# SET(CMAKE_BUILD_TYPE Debug) SET(CMAKE_VERBOSE_MAKEFILE ON)
41101
set(CMAKE_MACOSX_RPATH "ON")
42102

@@ -89,6 +149,12 @@ find_package(Gettext REQUIRED)
89149
set(SRC_GRIB
90150
src/grib_pi.h
91151
src/grib_pi.cpp
152+
src/grib_file.h
153+
src/grib_layer.h
154+
src/grib_layer.cpp
155+
src/grib_layer_set.h
156+
src/grib_layer_set.cpp
157+
src/grib_timeline_record_set.h
92158
src/GribOverlayFactory.cpp
93159
src/GribOverlayFactory.h
94160
src/GribUIDialogBase.cpp

plugins/grib_pi/src/CursorData.cpp

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,20 @@ void CursorData::PopulateTrackingControls(bool vertical) {
174174
vertical ? (bf ? dummy : m_tcWindSpeedBf) : m_tcWindDirection,
175175
vertical ? m_tcWindDirection : 0,
176176
m_gparent.m_pTimelineSet &&
177-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VX) !=
177+
m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_WIND_VX) !=
178178
wxNOT_FOUND &&
179-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VY) !=
179+
m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_WIND_VY) !=
180180
wxNOT_FOUND,
181181
vertical, wd, ws);
182182
AddTrackingControl(m_cbWindGust, m_tcWindGust, 0, 0,
183183
m_gparent.m_pTimelineSet &&
184-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
184+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
185185
Idx_WIND_GUST) != wxNOT_FOUND &&
186186
m_Altitude == 0,
187187
vertical, wn);
188188
AddTrackingControl(m_cbPressure, m_tcPressure, 0, 0,
189189
m_gparent.m_pTimelineSet &&
190-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
190+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
191191
Idx_PRESSURE) != wxNOT_FOUND &&
192192
m_Altitude == 0,
193193
vertical, wn);
@@ -197,10 +197,8 @@ void CursorData::PopulateTrackingControls(bool vertical) {
197197
m_tcWaveDirection, false, vertical, 0,
198198
0); // hide all waves's parameters
199199
if (m_gparent.m_pTimelineSet &&
200-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_HTSIGW) !=
201-
wxNOT_FOUND) {
202-
if (m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) !=
203-
wxNOT_FOUND)
200+
m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_HTSIGW) != wxNOT_FOUND) {
201+
if (m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_WVDIR) != wxNOT_FOUND)
204202
AddTrackingControl(m_cbWave, m_tcWaveHeight,
205203
vertical ? m_tcWavePeriode : m_tcWaveDirection,
206204
vertical ? m_tcWaveDirection : 0, m_Altitude == 0,
@@ -210,77 +208,76 @@ void CursorData::PopulateTrackingControls(bool vertical) {
210208
vertical, wn);
211209
} else {
212210
if (m_gparent.m_pTimelineSet &&
213-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) !=
214-
wxNOT_FOUND)
211+
m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_WVDIR) != wxNOT_FOUND)
215212
AddTrackingControl(m_cbWave, m_tcWaveDirection, 0, 0, m_Altitude == 0,
216213
vertical, wn);
217214
}
218215

219216
AddTrackingControl(m_cbCurrent, m_tcCurrentVelocity, m_tcCurrentDirection, 0,
220217
false, vertical, 0, 0); // hide all current's parameters
221-
AddTrackingControl(m_cbCurrent, m_tcCurrentVelocity,
222-
vertical ? dummy : m_tcCurrentDirection,
223-
vertical ? m_tcCurrentDirection : 0,
224-
m_gparent.m_pTimelineSet &&
225-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
226-
Idx_SEACURRENT_VX) != wxNOT_FOUND &&
227-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
228-
Idx_SEACURRENT_VY) != wxNOT_FOUND &&
229-
m_Altitude == 0,
230-
vertical, wn, ws);
218+
AddTrackingControl(
219+
m_cbCurrent, m_tcCurrentVelocity, vertical ? dummy : m_tcCurrentDirection,
220+
vertical ? m_tcCurrentDirection : 0,
221+
m_gparent.m_pTimelineSet &&
222+
m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_SEACURRENT_VX) !=
223+
wxNOT_FOUND &&
224+
m_gparent.m_LayerSet.GetGribIdxArray().Index(Idx_SEACURRENT_VY) !=
225+
wxNOT_FOUND &&
226+
m_Altitude == 0,
227+
vertical, wn, ws);
231228
AddTrackingControl(m_cbPrecipitation, m_tcPrecipitation, 0, 0,
232229
m_gparent.m_pTimelineSet &&
233-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
230+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
234231
Idx_PRECIP_TOT) != wxNOT_FOUND &&
235232
m_Altitude == 0,
236233
vertical, wn);
237234
AddTrackingControl(m_cbCloud, m_tcCloud, 0, 0,
238235
m_gparent.m_pTimelineSet &&
239-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
236+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
240237
Idx_CLOUD_TOT) != wxNOT_FOUND &&
241238
m_Altitude == 0,
242239
vertical, wn);
243240
AddTrackingControl(m_cbAirTemperature, m_tcAirTemperature, 0, 0,
244241
m_gparent.m_pTimelineSet &&
245-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
242+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
246243
Idx_AIR_TEMP) != wxNOT_FOUND &&
247244
m_Altitude == 0,
248245
vertical, wn);
249246
AddTrackingControl(m_cbSeaTemperature, m_tcSeaTemperature, 0, 0,
250247
m_gparent.m_pTimelineSet &&
251-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
248+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
252249
Idx_SEA_TEMP) != wxNOT_FOUND &&
253250
m_Altitude == 0,
254251
vertical, wn);
255252
AddTrackingControl(m_cbCAPE, m_tcCAPE, 0, 0,
256253
m_gparent.m_pTimelineSet &&
257-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
254+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
258255
Idx_CAPE) != wxNOT_FOUND &&
259256
m_Altitude == 0,
260257
vertical, wn);
261258
AddTrackingControl(m_cbReflC, m_tcReflC, 0, 0,
262259
m_gparent.m_pTimelineSet &&
263-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
260+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
264261
Idx_COMP_REFL) != wxNOT_FOUND &&
265262
m_Altitude == 0,
266263
vertical, wn);
267264
//
268265
// init and show extra parameters for altitude tracking if necessary
269266
AddTrackingControl(m_cbAltitude, m_tcAltitude, 0, 0,
270267
m_gparent.m_pTimelineSet &&
271-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
268+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
272269
Idx_GEOP_HGT + m_Altitude) != wxNOT_FOUND &&
273270
m_Altitude != 0,
274271
vertical, wn);
275272
AddTrackingControl(m_cbTemp, m_tcTemp, 0, 0,
276273
m_gparent.m_pTimelineSet &&
277-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
274+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
278275
Idx_AIR_TEMP + m_Altitude) != wxNOT_FOUND &&
279276
m_Altitude != 0,
280277
vertical, wn);
281278
AddTrackingControl(m_cbRelHumid, m_tcRelHumid, 0, 0,
282279
m_gparent.m_pTimelineSet &&
283-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
280+
m_gparent.m_LayerSet.GetGribIdxArray().Index(
284281
Idx_HUMID_RE + m_Altitude) != wxNOT_FOUND &&
285282
m_Altitude != 0,
286283
vertical, wn);
@@ -335,19 +332,18 @@ void CursorData::PopulateTrackingControls(bool vertical) {
335332
lev = m_gparent.m_OverlaySettings.CalibrateValue(
336333
GribOverlaySettings::GEO_ALTITUDE,
337334
2); // convert 2m in current altitude unit
338-
t.Printf(m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(
335+
t.Printf(m_gparent.m_LayerSet.GetGribIdxArray().Index(
339336
1000 + NORWAY_METNO) != wxNOT_FOUND
340337
? s[0] + s[2]
341338
: _T(" %1.*f ") + m_gparent.m_OverlaySettings.GetUnitSymbol(
342339
GribOverlaySettings::GEO_ALTITUDE),
343340
lev == (int)lev ? 0 : 1, lev);
344341
m_tcAirTemperature->SetToolTip(s[1] + t);
345342

346-
m_tcSeaTemperature->SetToolTip(
347-
m_gparent.m_bGRIBActiveFile->m_GribIdxArray.Index(1000 + NOAA_GFS) !=
348-
wxNOT_FOUND
349-
? s[1] + s[0] + s[2]
350-
: s[3]);
343+
m_tcSeaTemperature->SetToolTip(m_gparent.m_LayerSet.GetGribIdxArray().Index(
344+
1000 + NOAA_GFS) != wxNOT_FOUND
345+
? s[1] + s[0] + s[2]
346+
: s[3]);
351347
}
352348
dummy->Show(false);
353349
}

plugins/grib_pi/src/GribRecordSet.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* the same reference time. A record set combines multiple meteorological
2525
* (wind, pressure, waves, etc.) valid at a single forecast time.
2626
*/
27+
#ifndef GRIB_RECORD_SET_H
28+
#define GRIB_RECORD_SET_H
29+
2730
#include "GribRecord.h"
2831

2932
// These are indexes into the array
@@ -159,3 +162,7 @@ class GribRecordSet {
159162
// interpolated grib are not, keep track of them
160163
bool m_GribRecordUnref[Idx_COUNT];
161164
};
165+
166+
WX_DECLARE_OBJARRAY(GribRecordSet, ArrayOfGribRecordSets);
167+
168+
#endif // GRIB_RECORD_SET_H

plugins/grib_pi/src/GribTable.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
8787
1) if current unit is not bf ==> double speed display (current unit +
8888
bf) 2) create two lines for direction and speed and a third for gust if
8989
exists 3) these two or three lines will be part of the same block*/
90-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VX) !=
90+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_WIND_VX) !=
9191
wxNOT_FOUND &&
92-
m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_VY) !=
92+
m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_WIND_VY) !=
9393
wxNOT_FOUND) {
9494
nrows++;
9595
AddDataRow(nrows, i, _("Wind,Dir"), datarow);
@@ -105,7 +105,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
105105
else
106106
m_pGribTable->SetCellValue(nrows, i, GetWind(RecordArray, 3, wdir));
107107
m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
108-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WIND_GUST) !=
108+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_WIND_GUST) !=
109109
wxNOT_FOUND) {
110110
nrows++;
111111
AddDataRow(nrows, i, _("Wind,Gust"), datarow);
@@ -119,7 +119,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
119119
} // wind
120120

121121
// create and populate Pressure data rown
122-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRESSURE) !=
122+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_PRESSURE) !=
123123
wxNOT_FOUND) {
124124
nrows++;
125125
AddDataRow(nrows, i, _("Pressure"), datarow);
@@ -131,10 +131,10 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
131131
1) if significant height data exists then create a line for direction
132132
and height then a third for periode if data exists
133133
2) these two or three lines will be part of the same block*/
134-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_HTSIGW) !=
134+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_HTSIGW) !=
135135
wxNOT_FOUND) {
136136
double wdir;
137-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVDIR) !=
137+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_WVDIR) !=
138138
wxNOT_FOUND) {
139139
nrows++;
140140
AddDataRow(nrows, i, _("Waves,Dir"), datarow);
@@ -146,7 +146,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
146146
m_pGribTable->SetCellValue(nrows, i,
147147
GetWaves(RecordArray, Idx_HTSIGW, wdir));
148148
m_pGribTable->SetCellBackgroundColour(nrows, i, m_pDataCellsColour);
149-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_WVPER) !=
149+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_WVPER) !=
150150
wxNOT_FOUND) {
151151
nrows++;
152152
AddDataRow(nrows, i, _("Waves,Per"), datarow);
@@ -156,7 +156,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
156156
} // waves
157157

158158
// create and populate total rainfall data row
159-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_PRECIP_TOT) !=
159+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_PRECIP_TOT) !=
160160
wxNOT_FOUND) {
161161
nrows++;
162162
AddDataRow(nrows, i, _("Rainfall"), datarow);
@@ -165,7 +165,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
165165
} // rainfall
166166

167167
// create and populate total cloud control
168-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CLOUD_TOT) !=
168+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_CLOUD_TOT) !=
169169
wxNOT_FOUND) {
170170
nrows++;
171171
AddDataRow(nrows, i, _("Cloud Cover"), datarow);
@@ -174,7 +174,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
174174
} // cloud
175175

176176
// create and populate the Air Temperature data row
177-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_AIR_TEMP) !=
177+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_AIR_TEMP) !=
178178
wxNOT_FOUND) {
179179
nrows++;
180180
AddDataRow(nrows, i, _("Air Temp."), datarow);
@@ -183,7 +183,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
183183
} // air temp
184184

185185
// create and populate the Sea Surface Temperature data row
186-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_SEA_TEMP) !=
186+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_SEA_TEMP) !=
187187
wxNOT_FOUND) {
188188
nrows++;
189189
AddDataRow(nrows, i, _("Sea Temp."), datarow);
@@ -193,7 +193,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
193193

194194
// create and populate the Convective Available Potential Energy (CAPE) data
195195
// row
196-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_CAPE) !=
196+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_CAPE) !=
197197
wxNOT_FOUND) {
198198
nrows++;
199199
AddDataRow(nrows, i, _("CAPE"), datarow);
@@ -202,7 +202,7 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
202202
} // cape
203203

204204
// create and populate the Composite Reflectivity data row
205-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(Idx_COMP_REFL) !=
205+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_COMP_REFL) !=
206206
wxNOT_FOUND) {
207207
nrows++;
208208
AddDataRow(nrows, i, _("C. Reflect."), datarow);
@@ -213,10 +213,10 @@ void GRIBTable::InitGribTable(int zone, ArrayOfGribRecordSets *rsa,
213213
/*create and populate the current data rows
214214
1)create two lines for direction and speed
215215
2) these two or three lines will be part of the same block*/
216-
if (m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(
217-
Idx_SEACURRENT_VX) != wxNOT_FOUND &&
218-
m_pGDialog->m_bGRIBActiveFile->m_GribIdxArray.Index(
219-
Idx_SEACURRENT_VY) != wxNOT_FOUND) {
216+
if (m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_SEACURRENT_VX) !=
217+
wxNOT_FOUND &&
218+
m_pGDialog->m_LayerSet.GetGribIdxArray().Index(Idx_SEACURRENT_VY) !=
219+
wxNOT_FOUND) {
220220
double wdir;
221221
nrows++;
222222
AddDataRow(nrows, i, _("Current,Dir"), datarow);

0 commit comments

Comments
 (0)