Skip to content

File ReadForcing.h

FileList > src > ReadForcing.h

Go to the source code of this file

  • #include "General.h"
  • #include "Input.h"
  • #include "Param.h"
  • #include "Write_txtlog.h"
  • #include "Read_netcdf.h"
  • #include "Forcing.h"
  • #include "Util_CPU.h"
  • #include "Setup_GPU.h"
  • #include "Poly.h"

Public Functions

Type Name
std::vector< std::string > DelimLine (std::string line, int n, char delim)
Split a string into a vector of substrings based on a specified delimiter.
std::vector< std::string > DelimLine (std::string line, int n)
Split a string into a vector of substrings based on common delimiters (tab, space, comma). Tries tab, space, and comma as delimiters and returns the first successful split with the expected number of elements.
void InitDynforcing (bool gpgpu, Param & XParam, DynForcingP< float > & Dforcing)
Initialize dynamic forcing data (Rain, wind, Atm pressure).
void InterpstepCPU (int nx, int ny, int hdstep, float totaltime, float hddt, T *& Ux, T * Uo, T * Un)
void clampedges (int nx, int ny, T clamp, T * z)
Clamp the edges of a 2D array to a specified value. Sets the values at the edges of a 2D array to a specified clamp value.
void denan (int nx, int ny, float denanval, int * z)
void denan (int nx, int ny, float denanval, T * z)
Replace NaN values in a 2D array with a specified value. Iterates through a 2D array and replaces any NaN values with the specified denanval.
void readDynforcing (bool gpgpu, double totaltime, DynForcingP< float > & Dforcing)
Deprecated function (!!!) to read dynamic forcing data for a given time.
std::vector< Flowin > readFlowfile (std::string Flowfilename, std::string & refdate)
Read flow data from a specified file, for river forcing for example. Reads flow data from a specified file and extracts time and flow rate information. Applies reference date adjustment if provided.
std::vector< Windin > readINfileUNI (std::string filename, std::string & refdate)
Read rain/atmospheric pressure data from a specified file for spatially uniform forcing. Reads rain/atmospheric pressure data from a specified file and extracts time and wind speed information. Applies reference date adjustment if provided.
std::vector< SLTS > readNestfile (std::string ncfile, std::string varname, int hor, double eps, double bndxo, double bndxmax, double bndy)
Read boundary nesting data from a NetCDF file. Reads boundary nesting data from a specified NetCDF file and variable name. Supports both horizontal and vertical boundaries.
Polygon readPolygon (std::string filename)
Read polygon from a specified file. Reads polygon vertices from a specified file and ensures the polygon is closed. Calculates bounding box of the polygon.
std::vector< SLTS > readWLfile (std::string WLfilename, std::string & refdate)
Read water level boundary file. Reads water level boundary file and extracts time and water level data. Applies reference date adjustment if provided.
std::vector< Windin > readWNDfileUNI (std::string filename, std::string & refdate, double grdalpha)
Read wind data from a specified file for spatially uniform forcing. Reads wind data from a specified file and extracts time, wind speed, wind direction, and calculates u and v wind components. Applies reference date adjustment if provided. __
void readXBbathy (std::string filename, int nx, int ny, T *& zb)
Read bathymetry data from an XBeach-style .bot/.dep file into a provided array. Parses the file format and fills the provided array with bathymetry values.
void readbathyASCHead (std::string filename, int & nx, int & ny, double & dx, double & xo, double & yo, double & grdalpha)
Read header information from an ASC (bathymetry) file. Extracts grid size (nx, ny), grid spacing (dx), origin (xo, yo), and grid rotation angle (grdalpha). Adjusts origin if the file uses corner registration.
void readbathyASCzb (std::string filename, int nx, int ny, T *& zb)
Read (bathymetry) data from an ASC file into a provided array. Parses the ASC file format and fills the provided array with bathymetry values.
void readbathyHeadMD (std::string filename, int & nx, int & ny, double & dx, double & grdalpha)
Read header information from an MD bathymetry file (or other MD input map). Extracts grid size (nx, ny), grid spacing (dx), and grid rotation angle (grdalpha).
void readbathyMD (std::string filename, T *& zb)
Read bathymetry data from an MD file into a provided array. Parses the MD file format and fills the provided array with bathymetry values. __
std::vector< SLTS > readbndfile (std::string filename, Param & XParam)
Read boundary forcing files (water levels or nest files).
Polygon readbndpolysegment (bndsegment bnd, Param XParam)
Read boundary polygon segment and create polygon structure.
void readforcing (Param & XParam, Forcing< T > & XForcing)
Wrapping function for reading all the forcing data.
void readforcingdata (int step, T forcing)
Read static forcing data from various file formats based on the file extension. Supports reading from .md, .nc, .bot/.dep, and .asc files.
void readforcingdata (double totaltime, DynForcingP< float > & forcing)
Read dynamic forcing data from a NetCDF file based on the current simulation time. Interpolates between time steps to obtain the current forcing values. Handles NaN values and clamps edges if specified.
DynForcingP< float > readforcinghead (DynForcingP< float > Fmap, Param XParam)
Read dynamic forcing metadata/header from a NetCDF file. Extracts grid size, spacing, origin, and time information.
T readforcinghead (T Fmap)
Read static forcing metadata/header from various file formats based on the file extension. Supports reading from .md, .nc, .bot/.dep, and .asc files. Extracts grid size, spacing, origin, and other relevant information. __
void readstaticforcing (T & Sforcing)
Single parameter version of readstaticforcing(int step, T& Sforcing).
void readstaticforcing (int step, T & Sforcing)
Allocate and read static (i.e. not varying in time) forcing data. Used for Bathymetry, roughness, deformation, etc.

Public Functions Documentation

function DelimLine

Split a string into a vector of substrings based on a specified delimiter.

std::vector< std::string > DelimLine (
    std::string line,
    int n,
    char delim
) 

Parameters:

  • s The input string to be split
  • delim The delimiter character used for splitting

Returns:

Vector of substrings


function DelimLine

Split a string into a vector of substrings based on common delimiters (tab, space, comma). Tries tab, space, and comma as delimiters and returns the first successful split with the expected number of elements.

std::vector< std::string > DelimLine (
    std::string line,
    int n
) 

Parameters:

  • line The input string to be split
  • n The expected number of elements after splitting

Returns:

Vector of substrings if successful; empty vector otherwise


function InitDynforcing

Initialize dynamic forcing data (Rain, wind, Atm pressure).

void InitDynforcing (
    bool gpgpu,
    Param & XParam,
    DynForcingP < float > & Dforcing
) 

Reads dynamic forcing header and allocates memory for dynamic forcing arrays.

Parameters:

  • gpgpu Use GPU acceleration
  • XParam Model parameters
  • Dforcing Dynamic forcing structure

function InterpstepCPU

template<class T>
void InterpstepCPU (
    int nx,
    int ny,
    int hdstep,
    float totaltime,
    float hddt,
    T *& Ux,
    T * Uo,
    T * Un
) 

function clampedges

Clamp the edges of a 2D array to a specified value. Sets the values at the edges of a 2D array to a specified clamp value.

template<class T>
void clampedges (
    int nx,
    int ny,
    T clamp,
    T * z
) 

Parameters:

  • nx Number of grid points in the x-direction
  • ny Number of grid points in the y-direction
  • clamp Value to set at the edges
  • z Pointer to the 2D array (flattened as 1D) to be modified

function denan

void denan (
    int nx,
    int ny,
    float denanval,
    int * z
) 

function denan

Replace NaN values in a 2D array with a specified value. Iterates through a 2D array and replaces any NaN values with the specified denanval.

template<class T>
void denan (
    int nx,
    int ny,
    float denanval,
    T * z
) 

Parameters:

  • nx Number of grid points in the x-direction
  • ny Number of grid points in the y-direction
  • denanval Value to replace NaN values with
  • z Pointer to the 2D array (flattened as 1D) to be modified

function readDynforcing

Deprecated function (!!!) to read dynamic forcing data for a given time.

void readDynforcing (
    bool gpgpu,
    double totaltime,
    DynForcingP < float > & Dforcing
) 

Reads and allocates dynamic forcing arrays for the specified time.

Parameters:

  • gpgpu Use GPU acceleration
  • totaltime Current simulation time
  • Dforcing Dynamic forcing structure

This is a deprecated function! See InitDynforcing() instead


function readFlowfile

Read flow data from a specified file, for river forcing for example. Reads flow data from a specified file and extracts time and flow rate information. Applies reference date adjustment if provided.

std::vector< Flowin > readFlowfile (
    std::string Flowfilename,
    std::string & refdate
) 

Parameters:

  • Flowfilename Name of the flow data file
  • refdate Reference date for time adjustment

Returns:

Vector of Flowin structures containing time and flow rate data


function readINfileUNI

Read rain/atmospheric pressure data from a specified file for spatially uniform forcing. Reads rain/atmospheric pressure data from a specified file and extracts time and wind speed information. Applies reference date adjustment if provided.

std::vector< Windin > readINfileUNI (
    std::string filename,
    std::string & refdate
) 

Parameters:

  • filename Name of the rain/atmospheric pressure data file
  • refdate Reference date for time adjustment

Returns:

Vector of Windin structures containing time and wind speed data


function readNestfile

Read boundary nesting data from a NetCDF file. Reads boundary nesting data from a specified NetCDF file and variable name. Supports both horizontal and vertical boundaries.

std::vector< SLTS > readNestfile (
    std::string ncfile,
    std::string varname,
    int hor,
    double eps,
    double bndxo,
    double bndxmax,
    double bndy
) 

Parameters:

  • ncfile Name of the NetCDF file
  • varname Name of the variable to read
  • hor If 1, read horizontal boundary (top/bottom); if 0 read vertical boundary (left/right)
  • eps Small value to avoid numerical issues
  • bndxo Starting coordinate of the boundary
  • bndxmax Ending coordinate of the boundary
  • bndy Fixed coordinate of the boundary

Returns:

Vector of SLTS structures containing time and water level data


function readPolygon

Read polygon from a specified file. Reads polygon vertices from a specified file and ensures the polygon is closed. Calculates bounding box of the polygon.

Polygon readPolygon (
    std::string filename
) 

Parameters:

  • filename Name of the polygon file

Returns:

Polygon structure containing vertices and bounding box information


function readWLfile

Read water level boundary file. Reads water level boundary file and extracts time and water level data. Applies reference date adjustment if provided.

std::vector< SLTS > readWLfile (
    std::string WLfilename,
    std::string & refdate
) 

Parameters:

  • WLfilename Name of the water level boundary file
  • refdate Reference date for time adjustment

Returns:

Vector of SLTS structures containing time and water level data


function readWNDfileUNI

Read wind data from a specified file for spatially uniform forcing. Reads wind data from a specified file and extracts time, wind speed, wind direction, and calculates u and v wind components. Applies reference date adjustment if provided. __

std::vector< Windin > readWNDfileUNI (
    std::string filename,
    std::string & refdate,
    double grdalpha
) 

Parameters:

  • filename Name of the wind data file
  • refdate Reference date for time adjustment
  • grdalpha Grid rotation angle in radians

Returns:

Vector of Windin structures containing time, wind speed, wind direction, and u/v components


function readXBbathy

Read bathymetry data from an XBeach-style .bot/.dep file into a provided array. Parses the file format and fills the provided array with bathymetry values.

template<class T>
void readXBbathy (
    std::string filename,
    int nx,
    int ny,
    T *& zb
) 

Parameters:

  • filename Name of the XBeach-style bathymetry file
  • nx Number of grid points in the x-direction
  • ny Number of grid points in the y-direction
  • zb Reference to the array to store bathymetry values

function readbathyASCHead

Read header information from an ASC (bathymetry) file. Extracts grid size (nx, ny), grid spacing (dx), origin (xo, yo), and grid rotation angle (grdalpha). Adjusts origin if the file uses corner registration.

void readbathyASCHead (
    std::string filename,
    int & nx,
    int & ny,
    double & dx,
    double & xo,
    double & yo,
    double & grdalpha
) 

Parameters:

  • filename Name of the ASC bathymetry file
  • nx Reference to store the number of grid points in the x-direction
  • ny Reference to store the number of grid points in the y-direction
  • dx Reference to store the grid spacing in the x-direction
  • xo Reference to store the x-coordinate of the grid origin
  • yo Reference to store the y-coordinate of the grid origin
  • grdalpha Reference to store the grid rotation angle in radians

function readbathyASCzb

Read (bathymetry) data from an ASC file into a provided array. Parses the ASC file format and fills the provided array with bathymetry values.

template<class T>
void readbathyASCzb (
    std::string filename,
    int nx,
    int ny,
    T *& zb
) 

Parameters:

  • filename Name of the ASC bathymetry file
  • nx Number of grid points in the x-direction
  • ny Number of grid points in the y-direction
  • zb Reference to the array to store bathymetry values

function readbathyHeadMD

Read header information from an MD bathymetry file (or other MD input map). Extracts grid size (nx, ny), grid spacing (dx), and grid rotation angle (grdalpha).

void readbathyHeadMD (
    std::string filename,
    int & nx,
    int & ny,
    double & dx,
    double & grdalpha
) 

Parameters:

  • filename Name of the MD bathymetry file
  • nx Reference to store the number of grid points in the x-direction
  • ny Reference to store the number of grid points in the y-direction
  • dx Reference to store the grid spacing
  • grdalpha Reference to store the grid rotation angle in radians

function readbathyMD

Read bathymetry data from an MD file into a provided array. Parses the MD file format and fills the provided array with bathymetry values. __

template<class T>
void readbathyMD (
    std::string filename,
    T *& zb
) 

Parameters:

  • filename Name of the MD bathymetry file
  • zb Reference to the array to store bathymetry values

function readbndfile

Read boundary forcing files (water levels or nest files).

std::vector< SLTS > readbndfile (
    std::string filename,
    Param & XParam
) 

Reads boundary forcing files based on their extension (.nc for nest files, others for water level files). Applies zsoffset correction if specified in model parameters.

Parameters:

  • filename Name of the boundary forcing file
  • XParam Model parameters

Returns:

Vector of SLTS structures containing boundary information


function readbndpolysegment

Read boundary polygon segment and create polygon structure.

Polygon readbndpolysegment (
    bndsegment bnd,
    Param XParam
) 

Reads boundary polygon segment based on specified keywords or file input.

Parameters:

  • bnd Boundary segment structure
  • XParam Model parameters

Returns:

Polygon structure representing the boundary segment


function readforcing

Wrapping function for reading all the forcing data.

template<class T>
void readforcing (
    Param & XParam,
    Forcing < T > & XForcing
) 

Reads bathymetry and other forcing data into the provided Forcing structure.

Template parameters:

  • T Data type

Parameters:

wrapping function for reading all the forcing data


function readforcingdata

Read static forcing data from various file formats based on the file extension. Supports reading from .md, .nc, .bot/.dep, and .asc files.

template<class T>
void readforcingdata (
    int step,
    T forcing
) 

Template parameters:

  • T Type of the forcing parameter structure (e.g., StaticForcingP<float>, deformmap<float>, etc.)

Parameters:

  • step Current time step for reading time-dependent data (if applicable)
  • forcing Forcing parameter structure containing file information and data storage

function readforcingdata

Read dynamic forcing data from a NetCDF file based on the current simulation time. Interpolates between time steps to obtain the current forcing values. Handles NaN values and clamps edges if specified.

void readforcingdata (
    double totaltime,
    DynForcingP < float > & forcing
) 

Parameters:

  • totaltime Current simulation time
  • forcing Dynamic forcing parameter structure containing file information and data storage

function readforcinghead

Read dynamic forcing metadata/header from a NetCDF file. Extracts grid size, spacing, origin, and time information.

DynForcingP < float > readforcinghead (
    DynForcingP < float > Fmap,
    Param XParam
) 

Parameters:

  • Fmap Dynamic forcing parameter structure containing file information
  • XParam Simulation parameters (used for reference date)

Returns:

Updated dynamic forcing parameter structure with metadata


function readforcinghead

Read static forcing metadata/header from various file formats based on the file extension. Supports reading from .md, .nc, .bot/.dep, and .asc files. Extracts grid size, spacing, origin, and other relevant information. __

template<class T>
T readforcinghead (
    T Fmap
) 

Template parameters:

  • T Type of the forcing parameter structure (e.g., StaticForcingP<float>, deformmap<float>, etc.)

Parameters:

  • ForcingParam Forcing parameter structure containing file information

Returns:

Updated forcing parameter structure with metadata


function readstaticforcing

Single parameter version of readstaticforcing(int step, T& Sforcing).

template<class T>
void readstaticforcing (
    T & Sforcing
) 

Calls readstaticforcing with step set to 0.

Template parameters:

  • T Data type

Parameters:

  • Sforcing Static forcing structure to be read and allocated

single parameter version of readstaticforcing(int step,T& Sforcing) readstaticforcing(0, Sforcing);


function readstaticforcing

Allocate and read static (i.e. not varying in time) forcing data. Used for Bathymetry, roughness, deformation, etc.

template<class T>
void readstaticforcing (
    int step,
    T & Sforcing
) 

Parameters:

  • step Time step (usually 0 for static data)
  • Sforcing Static forcing structure to be read and allocated

Allocate and read static (i.e. not varying in time) forcing Used for Bathy, roughness, deformation



The documentation for this class was generated from the following file src/ReadForcing.h