Skip to content

File Write_netcdf.h

FileList > src > Write_netcdf.h

Go to the source code of this file

  • #include "General.h"
  • #include "Param.h"
  • #include "Write_txtlog.h"
  • #include "ReadInput.h"
  • #include "MemManagement.h"
  • #include "Util_CPU.h"
  • #include "Arrays.h"

Public Functions

Type Name
void InitSave2Netcdf (Param & XParam, Model< T > & XModel)
Initialize NetCDF output files for the model. Initializes NetCDF output files for the model based on the provided parameters and model configuration. If output variables are specified in the parameters, it creates the necessary NetCDF files and defines the variables to be saved.
void Save2Netcdf (Param XParam, Loop< T > XLoop, Model< T > & XModel)
Save model output to NetCDF files at specified output times. Saves model output to NetCDF files at specified output times based on the provided parameters. It checks if the current output time matches the next scheduled output time for each output zone, and if so, writes the relevant variables to the corresponding NetCDF files.
void create2dnc (char * filename, int nx, int ny, double * xx, double * yy, double * var, char * varname)
Create a NetCDF file containing a 2D variable, for testing for example. Creates a NetCDF file containing a 2D variable with the specified dimensions and data. If the file already exists, it will be overwritten.
void create3dnc (char * name, int nx, int ny, int nt, double * xx, double * yy, double * theta, double * var, char * varname)
Create a NetCDF file containing a 3D variable, for testing for example. Creates a NetCDF file containing a 3D variable with the specified dimensions and data. If the file already exists, it will be overwritten.
void creatncfileBUQ (Param & XParam, int * activeblk, int * level, T * blockxo, T * blockyo, outzoneB & Xzone)
Create a NetCDF file for BG-Flood output. Creates a NetCDF file for BG-Flood output based on the provided parameters and zone information.
void creatncfileBUQ (Param & XParam, BlockP< T > & XBlock)
Create NetCDF files for all output zones in a block. Creates NetCDF files for all output zones defined in the block using the provided parameters and block information.
void defncvarBUQ (Param XParam, int * activeblk, int * level, T * blockxo, T * blockyo, std::string varst, int vdim, T * var, outzoneB Xzone)
Define a NetCDF variable for BG-Flood output. Defines a NetCDF variable for BG-Flood output based on the provided parameters, block information and zone information.
void handle_ncerror (int status)
Handle NetCDF errors.
void write2dvarnc (int nx, int ny, double totaltime, double * var)
Write a time step of a 2D variable to an existing NetCDF file, for testing for example. Writes a time step of a 2D variable to an existing NetCDF file by appending the provided variable data at the next available time index.
void write3dvarnc (int nx, int ny, int nt, double totaltime, double * var)
Write a time step of a 3D variable to an existing NetCDF file, for testing for example. Writes a time step of a 3D variable to an existing NetCDF file by appending the provided variable data at the next available time index.
void writenctimestep (std::string outfile, double totaltime)
Write the current time step to a NetCDF file. Writes the current time step to a NetCDF file by updating the "time" variable with the provided total time value.
void writencvarstepBUQ (Param XParam, int vdim, int * activeblk, int * level, T * blockxo, T * blockyo, std::string varst, T * var, outzoneB Xzone)
Write a time step of a NetCDF variable for BG-Flood output. Writes a time step of a NetCDF variable for BG-Flood output based on the provided parameters, block information, variable data, and zone information.

Public Functions Documentation

function InitSave2Netcdf

Initialize NetCDF output files for the model. Initializes NetCDF output files for the model based on the provided parameters and model configuration. If output variables are specified in the parameters, it creates the necessary NetCDF files and defines the variables to be saved.

template<class T>
void InitSave2Netcdf (
    Param & XParam,
    Model < T > & XModel
) 

Parameters:

  • XParam The parameter object containing grid settings and model parameters.
  • XModel The model object containing block information and output variable mappings.

Note:

This is a templated function that can handle different data types for the model (e.g., float, double).

See also: creatncfileBUQ for creating the NetCDF file and defining variables.


function Save2Netcdf

Save model output to NetCDF files at specified output times. Saves model output to NetCDF files at specified output times based on the provided parameters. It checks if the current output time matches the next scheduled output time for each output zone, and if so, writes the relevant variables to the corresponding NetCDF files.

template<class T>
void Save2Netcdf (
    Param XParam,
    Loop < T > XLoop,
    Model < T > & XModel
) 

Parameters:

  • XParam The parameter object containing grid settings and model parameters.
  • XLoop The loop object containing time-stepping information.
  • XModel The model object containing block information and output variable mappings.

Note:

This is a templated function that can handle different data types for the model (e.g., float, double).

See also: writenctimestep for writing the time step to the NetCDF file.


function create2dnc

Create a NetCDF file containing a 2D variable, for testing for example. Creates a NetCDF file containing a 2D variable with the specified dimensions and data. If the file already exists, it will be overwritten.

void create2dnc (
    char * filename,
    int nx,
    int ny,
    double * xx,
    double * yy,
    double * var,
    char * varname
) 

Parameters:

  • filename The name of the NetCDF file to be created.
  • nx The number of grid points in the x-direction.
  • ny The number of grid points in the y-direction.
  • xx Pointer to an array containing the x-coordinates of the grid points.
  • yy Pointer to an array containing the y-coordinates of the grid points.
  • var Pointer to an array containing the 2D variable data to be stored in the NetCDF file.
  • varname The name of the variable to be stored in the NetCDF file.

Note:

This function uses the NetCDF C library to create and write to the NetCDF file.


function create3dnc

Create a NetCDF file containing a 3D variable, for testing for example. Creates a NetCDF file containing a 3D variable with the specified dimensions and data. If the file already exists, it will be overwritten.

void create3dnc (
    char * name,
    int nx,
    int ny,
    int nt,
    double * xx,
    double * yy,
    double * theta,
    double * var,
    char * varname
) 

Parameters:

  • name The name of the NetCDF file to be created.
  • nx The number of grid points in the x-direction.
  • ny The number of grid points in the y-direction.
  • nt The number of time steps.
  • xx Pointer to an array containing the x-coordinates of the grid points.
  • yy Pointer to an array containing the y-coordinates of the grid points.
  • theta Pointer to an array containing the time values.
  • var Pointer to an array containing the 3D variable data to be stored in the NetCDF file.
  • varname The name of the variable to be stored in the NetCDF file.

Note:

This function uses the NetCDF C library to create and write to the NetCDF file.


function creatncfileBUQ

Create a NetCDF file for BG-Flood output. Creates a NetCDF file for BG-Flood output based on the provided parameters and zone information.

template<class T>
void creatncfileBUQ (
    Param & XParam,
    int * activeblk,
    int * level,
    T * blockxo,
    T * blockyo,
    outzoneB & Xzone
) 

Parameters:

  • XParam The parameter object containing grid settings and model parameters.
  • activeblk Pointer to an array of active block indices.
  • level Pointer to an array of block levels.
  • blockxo Pointer to an array of block x-coordinates.
  • blockyo Pointer to an array of block y-coordinates.
  • Xzone The output zone object defining the area and settings for the NetCDF file.

function creatncfileBUQ

Create NetCDF files for all output zones in a block. Creates NetCDF files for all output zones defined in the block using the provided parameters and block information.

template<class T>
void creatncfileBUQ (
    Param & XParam,
    BlockP < T > & XBlock
) 

Parameters:

  • XParam The parameter object containing grid settings and model parameters.
  • XBlock The block object containing block information and output zones.

function defncvarBUQ

Define a NetCDF variable for BG-Flood output. Defines a NetCDF variable for BG-Flood output based on the provided parameters, block information and zone information.

template<class T>
void defncvarBUQ (
    Param XParam,
    int * activeblk,
    int * level,
    T * blockxo,
    T * blockyo,
    std::string varst,
    int vdim,
    T * var,
    outzoneB Xzone
) 

Parameters:

  • XParam The parameter object containing grid settings and model parameters.
  • activeblk Pointer to an array of active block indices.
  • level Pointer to an array of block levels.
  • blockxo Pointer to an array of block x-coordinates.
  • blockyo Pointer to an array of block y-coordinates.
  • varst The base name of the variable to be defined.
  • vdim The number of dimensions of the variable (2 or 3).
  • var Pointer to the array containing the variable data.
  • Xzone The output zone object defining the area and settings for the NetCDF variable.

Note:

This is an overloaded function that provides a simpler interface when longname, stdname, and unit are not needed.


function handle_ncerror

Handle NetCDF errors.

void handle_ncerror (
    int status
) 

function write2dvarnc

Write a time step of a 2D variable to an existing NetCDF file, for testing for example. Writes a time step of a 2D variable to an existing NetCDF file by appending the provided variable data at the next available time index.

void write2dvarnc (
    int nx,
    int ny,
    double totaltime,
    double * var
) 

Parameters:

  • nx The number of grid points in the x-direction.
  • ny The number of grid points in the y-direction.
  • totaltime The total time value to be written to the "time" variable.
  • var Pointer to an array containing the 2D variable data to be appended to the NetCDF file.

Note:

This function assumes that the NetCDF file "3Dvar.nc" already exists and is open for writing.


function write3dvarnc

Write a time step of a 3D variable to an existing NetCDF file, for testing for example. Writes a time step of a 3D variable to an existing NetCDF file by appending the provided variable data at the next available time index.

void write3dvarnc (
    int nx,
    int ny,
    int nt,
    double totaltime,
    double * var
) 

Parameters:

  • nx The number of grid points in the x-direction.
  • ny The number of grid points in the y-direction.
  • nt The number of time steps.
  • totaltime The total time value to be written to the "time" variable.
  • var Pointer to an array containing the 3D variable data to be appended to the NetCDF file.

Note:

This function assumes that the NetCDF file "3Dvar.nc" already exists and is open for writing.


function writenctimestep

Write the current time step to a NetCDF file. Writes the current time step to a NetCDF file by updating the "time" variable with the provided total time value.

void writenctimestep (
    std::string outfile,
    double totaltime
) 

Parameters:

  • outfile The name of the NetCDF output file.
  • totaltime The total time value to be written to the "time" variable.

function writencvarstepBUQ

Write a time step of a NetCDF variable for BG-Flood output. Writes a time step of a NetCDF variable for BG-Flood output based on the provided parameters, block information, variable data, and zone information.

template<class T>
void writencvarstepBUQ (
    Param XParam,
    int vdim,
    int * activeblk,
    int * level,
    T * blockxo,
    T * blockyo,
    std::string varst,
    T * var,
    outzoneB Xzone
) 

Parameters:

  • XParam The parameter object containing grid settings and model parameters.
  • vdim The number of dimensions of the variable (2 or 3).
  • activeblk Pointer to an array of active block indices.
  • level Pointer to an array of block levels.
  • blockxo Pointer to an array of block x-coordinates.
  • blockyo Pointer to an array of block y-coordinates.
  • varst The base name of the variable to be written.
  • var Pointer to the array containing the variable data.
  • Xzone The output zone object defining the area and settings for the NetCDF variable.

Note:

This is a templated function that can handle different data types for the variable (e.g., float, double).



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