@@ -114,6 +114,8 @@ void metdata::load_from_netcdf(const std::string& path,std::map<std::string, boo
114
114
// #pragma omp parallel for
115
115
// hangs, unclear why, critical sections around the json and gdal calls
116
116
// don't seem to help. Probably _dD_tree is not thread safe
117
+
118
+ int skipped = 0 ; // keep track of how many we skipped due to nans
117
119
for (size_t y = 0 ; y < _nc->get_ysize (); y++)
118
120
{
119
121
for (size_t x = 0 ; x < _nc->get_xsize (); x++)
@@ -130,23 +132,16 @@ void metdata::load_from_netcdf(const std::string& path,std::map<std::string, boo
130
132
131
133
// Some Netcdf files have NaN grid squares, For these cases we will just insert a nullptr station and
132
134
// don't add the station to the dD list which is the only way it ever gets to modules
133
- if ( std::isnan (latitude) &&
134
- std::isnan (longitude) )
135
+ if ( std::isnan (latitude) ||
136
+ std::isnan (longitude) ||
137
+ std::isnan (z))
135
138
{
136
139
_stations.at (index ) = nullptr ;
140
+ ++skipped;
137
141
continue ;
138
142
}
139
143
140
144
141
-
142
- if ( std::isnan (z))
143
- {
144
- CHM_THROW_EXCEPTION (forcing_error,
145
- " Elevation for x,y=" + std::to_string (x) + " ," + std::to_string (y)+
146
- " is NaN. Regardless of the timestep the model is started from, it looks for timestep = 0 to define the elevations. Ensure it is defined then." );
147
- }
148
-
149
-
150
145
std::string station_name = std::to_string (index ); // these don't really have names
151
146
152
147
// need to convert the input lat/long into the coordinate system our mesh is in
@@ -176,6 +171,14 @@ void metdata::load_from_netcdf(const std::string& path,std::map<std::string, boo
176
171
}
177
172
}
178
173
174
+ if ( skipped == _nstations)
175
+ {
176
+ CHM_THROW_EXCEPTION (forcing_error,
177
+ " All forcing grid cells were skipped due to being NaN values. Elevation and lat/lon,"
178
+ " regardless of the timestep the model is started from, are defined from timestep = 0 "
179
+ " . Ensure it is defined then." );
180
+ }
181
+
179
182
} catch (netCDF::exceptions::NcException& e)
180
183
{
181
184
OGRCoordinateTransformation::DestroyCT (coordTrans);
0 commit comments