FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetcdfHandler Class Reference

#include <netcdf_handler.h>

Public Member Functions

void readNCFile (const char *filename)
 
int cacheCurrentField ()
 
void closeNCFile ()
 Close the NetCDF file and release the file handle.
 
void getDomainBounds (float *bounds)
 
int getVar (char *name)
 
int getCurrentSpeedAt (float x, float y, float z, float *value)
 
int calculateDescriptorValues (float *values)
 
bool isProfileFile ()
 

Detailed Description

Handler for reading NetCDF current field files.

Provides methods for opening NetCDF files, caching current velocity data, and looking it up at query positions. Two layouts are read, selected from the variable and dimension names found in the file:

  • Grid (U_V_W_FILE): dimensions and coordinate variables zc, yc and xc, and velocity variables u, v and w on (zc, yc, xc).
  • Profile (Z_PROFILE_FILE): no xc dimension; a zc dimension and coordinate variable, and u and v on (zc).

xc is NED north, yc NED east and zc depth, positive down; u, v and w are the north, east and down components. The cell size is taken from the first two coordinates of each axis, so the coordinates must be uniformly spaced. A position is given the value of the node at the lower corner of its cell, without interpolation.

Member Function Documentation

◆ cacheCurrentField()

int NetcdfHandler::cacheCurrentField ( )

Cache the entire current velocity field in memory.

Returns
0 on success, non-zero error code on failure.

◆ calculateDescriptorValues()

int NetcdfHandler::calculateDescriptorValues ( float *  values)

Compute min, mean, and max velocity magnitude statistics.

Parameters
[out]valuesArray of at least 3 floats: [minVal, meanVal, maxVal] [m/s].
Returns
0 on success.

◆ getCurrentSpeedAt()

int NetcdfHandler::getCurrentSpeedAt ( float  x,
float  y,
float  z,
float *  value 
)

Get interpolated current velocity at a position.

Parameters
[in]xX (xc, north) coordinate [m].
[in]yY (yc, east) coordinate [m].
[in]zZ (zc, depth) coordinate [m].
[out]valueInterpolated velocity components [u, v, w] [m/s].
Returns
0 on success.

◆ getDomainBounds()

void NetcdfHandler::getDomainBounds ( float *  bounds)

Get the spatial domain bounds of the loaded field.

Parameters
[out]boundsArray of at least 6 floats [xmin, xmax, ymin, ymax, zmin, zmax] [m].

◆ getVar()

int NetcdfHandler::getVar ( char *  name)

Get a NetCDF variable ID by name.

Parameters
[in]nameVariable name string.
Returns
NetCDF variable ID, or a negative error code if not found.

◆ isProfileFile()

bool NetcdfHandler::isProfileFile ( )

Check whether the file is a depth-profile layout.

Returns
True if the file type is Z_PROFILE_FILE.

◆ readNCFile()

void NetcdfHandler::readNCFile ( const char *  filename)

Open and parse a NetCDF file.

Parameters
[in]filenamePath to NetCDF file.

Determines the file layout type from the variable and dimension names present in the file and loads the grid coordinate arrays.

Exceptions
std::runtime_errorIf the file cannot be opened, is not one of the two layouts read, or has an axis of fewer than two coordinates.

The documentation for this class was generated from the following file: