@@ -199,7 +199,11 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
199199 auto poBathymetryCoverage01 = poRootGroup->OpenGroupFromFullname (
200200 " /BathymetryCoverage/BathymetryCoverage.01" );
201201 if (!poBathymetryCoverage01)
202+ {
203+ CPLError (CE_Failure, CPLE_AppDefined,
204+ " S102: Cannot find /BathymetryCoverage/BathymetryCoverage.01" );
202205 return nullptr ;
206+ }
203207
204208 const bool bNorthUp = CPLTestBool (
205209 CSLFetchNameValueDef (poOpenInfo->papszOpenOptions , " NORTH_UP" , " YES" ));
@@ -225,18 +229,34 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
225229
226230 auto poGroup001 = poBathymetryCoverage01->OpenGroup (" Group_001" );
227231 if (!poGroup001)
232+ {
233+ CPLError (CE_Failure, CPLE_AppDefined,
234+ " S102: Cannot find "
235+ " /BathymetryCoverage/BathymetryCoverage.01/Group_001" );
228236 return nullptr ;
237+ }
229238 auto poValuesArray = poGroup001->OpenMDArray (" values" );
230239 if (!poValuesArray || poValuesArray->GetDimensionCount () != 2 )
240+ {
241+ CPLError (CE_Failure, CPLE_AppDefined,
242+ " S102: Cannot find "
243+ " /BathymetryCoverage/BathymetryCoverage.01/Group_001/values" );
231244 return nullptr ;
232-
245+ }
233246 const auto &oType = poValuesArray->GetDataType ();
234247 if (oType.GetClass () != GEDTC_COMPOUND)
248+ {
249+ CPLError (CE_Failure, CPLE_AppDefined,
250+ " S102: Wrong type for "
251+ " /BathymetryCoverage/BathymetryCoverage.01/Group_001/values" );
235252 return nullptr ;
253+ }
236254 const auto &oComponents = oType.GetComponents ();
237- if (oComponents.size () != 2 || oComponents[0 ]->GetName () != " depth" ||
238- oComponents[1 ]->GetName () != " uncertainty" )
255+ if (oComponents.size () == 0 || oComponents[0 ]->GetName () != " depth" )
239256 {
257+ CPLError (CE_Failure, CPLE_AppDefined,
258+ " S102: Wrong type for "
259+ " /BathymetryCoverage/BathymetryCoverage.01/Group_001/values" );
240260 return nullptr ;
241261 }
242262
@@ -288,11 +308,6 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
288308 }
289309 }();
290310
291- auto poUncertainty = poValuesArray->GetView (" [\" uncertainty\" ]" );
292- const double dfUncertaintyNoData = poUncertainty->GetNoDataValueAsDouble ();
293- auto poUncertaintyDS =
294- std::unique_ptr<GDALDataset>(poUncertainty->AsClassicDataset (1 , 0 ));
295-
296311 poDS->nRasterXSize = poDepthDS->GetRasterXSize ();
297312 poDS->nRasterYSize = poDepthDS->GetRasterYSize ();
298313
@@ -330,33 +345,46 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
330345
331346 poDS->SetBand (1 , poDepthBand);
332347
333- // Create uncertainty band
334- auto poUncertaintyBand = new S102RasterBand (std::move (poUncertaintyDS));
335- poUncertaintyBand->SetDescription (" uncertainty" );
336-
337- auto poMinimumUncertainty = poGroup001->GetAttribute (" minimumUncertainty" );
338- if (poMinimumUncertainty &&
339- poMinimumUncertainty->GetDataType ().GetClass () == GEDTC_NUMERIC)
348+ const bool bHasUncertainty =
349+ oComponents.size () >= 2 && oComponents[1 ]->GetName () == " uncertainty" ;
350+ if (bHasUncertainty)
340351 {
341- const double dfVal = poMinimumUncertainty->ReadAsDouble ();
342- if (dfVal != dfUncertaintyNoData)
352+ // Create uncertainty band
353+ auto poUncertainty = poValuesArray->GetView (" [\" uncertainty\" ]" );
354+ const double dfUncertaintyNoData =
355+ poUncertainty->GetNoDataValueAsDouble ();
356+ auto poUncertaintyDS =
357+ std::unique_ptr<GDALDataset>(poUncertainty->AsClassicDataset (1 , 0 ));
358+
359+ auto poUncertaintyBand = new S102RasterBand (std::move (poUncertaintyDS));
360+ poUncertaintyBand->SetDescription (" uncertainty" );
361+
362+ auto poMinimumUncertainty =
363+ poGroup001->GetAttribute (" minimumUncertainty" );
364+ if (poMinimumUncertainty &&
365+ poMinimumUncertainty->GetDataType ().GetClass () == GEDTC_NUMERIC)
343366 {
344- poUncertaintyBand->m_dfMinimum = dfVal;
367+ const double dfVal = poMinimumUncertainty->ReadAsDouble ();
368+ if (dfVal != dfUncertaintyNoData)
369+ {
370+ poUncertaintyBand->m_dfMinimum = dfVal;
371+ }
345372 }
346- }
347373
348- auto poMaximumUncertainty = poGroup001->GetAttribute (" maximumUncertainty" );
349- if (poMaximumUncertainty &&
350- poMaximumUncertainty->GetDataType ().GetClass () == GEDTC_NUMERIC)
351- {
352- const double dfVal = poMaximumUncertainty->ReadAsDouble ();
353- if (dfVal != dfUncertaintyNoData)
374+ auto poMaximumUncertainty =
375+ poGroup001->GetAttribute (" maximumUncertainty" );
376+ if (poMaximumUncertainty &&
377+ poMaximumUncertainty->GetDataType ().GetClass () == GEDTC_NUMERIC)
354378 {
355- poUncertaintyBand->m_dfMaximum = dfVal;
379+ const double dfVal = poMaximumUncertainty->ReadAsDouble ();
380+ if (dfVal != dfUncertaintyNoData)
381+ {
382+ poUncertaintyBand->m_dfMaximum = dfVal;
383+ }
356384 }
357- }
358385
359- poDS->SetBand (2 , poUncertaintyBand);
386+ poDS->SetBand (2 , poUncertaintyBand);
387+ }
360388
361389 poDS->GDALDataset ::SetMetadataItem (GDALMD_AREA_OR_POINT, GDALMD_AOP_POINT);
362390
0 commit comments