MCPcopy Create free account
hub / github.com/Kitware/VTK / ValidateDimensions

Method ValidateDimensions

IO/NetCDF/vtkMPASReader.cxx:287–349  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Returns true if the dimensions in var match the expected args, or prints a warning and returns false if any are incorrect. ndims is the number of dimensions, and the variatic args must be C-strings identifying the expected dimensions. If silent is true, no warnings are printed. ------------------------------------------

Source from the content-addressed store, hash-verified

285// If silent is true, no warnings are printed.
286//------------------------------------------------------------------------------
287bool vtkMPASReader::Internal::ValidateDimensions(int nc_var, bool silent, int ndims, ...) const
288{
289 int nc_ndims;
290 if (nc_err(nc_inq_varndims(ncFile, nc_var, &nc_ndims)))
291 {
292 return false;
293 }
294
295 if (nc_ndims != ndims)
296 {
297 if (!silent)
298 {
299 char name[NC_MAX_NAME + 1];
300 if (nc_err(nc_inq_varname(ncFile, nc_var, name)))
301 {
302 return false;
303 }
304 vtkWarningWithObjectMacro(reader, << "Expected variable '" << name << "' to have " << ndims
305 << " dimension(s), but it has " << nc_ndims << ".");
306 }
307 return false;
308 }
309
310 int dims[NC_MAX_VAR_DIMS];
311 if (nc_err(nc_inq_vardimid(ncFile, nc_var, dims)))
312 {
313 return false;
314 }
315
316 va_list args;
317 va_start(args, ndims);
318
319 for (int i = 0; i < ndims; ++i)
320 {
321 char nc_name[NC_MAX_NAME + 1];
322 if (nc_err(nc_inq_dimname(ncFile, dims[i], nc_name)))
323 {
324 va_end(args);
325 return false;
326 }
327 std::string dimName(va_arg(args, const char*));
328 if (dimName != nc_name)
329 {
330 if (!silent)
331 {
332 char name[NC_MAX_NAME + 1];
333 if (nc_err(nc_inq_varname(ncFile, nc_var, name)))
334 {
335 return false;
336 }
337 vtkWarningWithObjectMacro(reader, << "Expected variable '" << name << "' to have '"
338 << dimName << "' at dimension index " << i << ", not '"
339 << nc_name << "'.");
340 }
341 va_end(args);
342 return false;
343 }
344 }

Callers 4

AllocPlanarGeometryMethod · 0.80
LoadTimeFieldDataMethod · 0.80

Calls 4

nc_inq_varndimsFunction · 0.85
nc_inq_varnameFunction · 0.85
nc_inq_vardimidFunction · 0.85
nc_inq_dimnameFunction · 0.85

Tested by

no test coverage detected