Skip to content

Class emulator::EmulatorIO

ClassList > emulator > EmulatorIO

Static class providing parallel I/O using SCORPIO/PIO. More...

  • #include <emulator_io.hpp>

Public Static Functions

Type Name
void close_file (int ncid)
Close an open file.
int create_file (const std::string & filename)
Create a new NetCDF file for writing.
int define_dim (int ncid, const std::string & dimname, int length)
Define a new dimension in a NetCDF file.
int define_var (int ncid, const std::string & varname, int nctype, const std::vector< int > & dimids)
Define a new variable in a NetCDF file.
bool end_def (int ncid)
End define mode and switch to data mode.
void finalize ()
Finalize the PIO subsystem.
int get_dim_size (int ncid, const std::string & dimname)
Get the size of a dimension.
bool has_var (int ncid, const std::string & varname)
Check if a variable exists in the file.
void initialize (MPI_Comm comm, const std::string & comp_name)
Initialize the PIO subsystem.
bool is_initialized ()
Check if PIO is initialized.
int open_file (const std::string & filename)
Open an existing NetCDF file for reading.
bool read_var_1d (int ncid, const std::string & varname, double * data, int size)
Read a 1D double array from a NetCDF variable.
bool read_var_1d_int (int ncid, const std::string & varname, int * data, int size)
Read a 1D integer array from a NetCDF variable.
bool read_var_2d (int ncid, const std::string & varname, double * data, int nx, int ny)
Read a 2D double array from a NetCDF variable.
bool read_var_3d_slice (int ncid, const std::string & varname, double * data, int nx, int ny, int time_idx)
Read a 2D slice from a 3D variable (time, lat, lon).
void sync_file (int ncid)
Synchronize (flush) file contents to disk.
bool write_var_1d (int ncid, const std::string & varname, const double * data, int size)
Write a 1D double array to a NetCDF variable.
bool write_var_2d (int ncid, const std::string & varname, const double * data, int nx, int ny)
Write a 2D double array to a NetCDF variable.

Detailed Description

Public Static Functions Documentation

function close_file

Close an open file.

static void emulator::EmulatorIO::close_file (
    int ncid
) 

Parameters:


function create_file

Create a new NetCDF file for writing.

static int emulator::EmulatorIO::create_file (
    const std::string & filename
) 

Parameters:

  • filename Path to the new file

Returns:

NetCDF file ID (ncid), or -1 on failure


function define_dim

Define a new dimension in a NetCDF file.

static int emulator::EmulatorIO::define_dim (
    int ncid,
    const std::string & dimname,
    int length
) 

Parameters:

  • ncid File ID (must be in define mode)
  • dimname Dimension name
  • length Dimension length

Returns:

Dimension ID, or -1 on failure


function define_var

Define a new variable in a NetCDF file.

static int emulator::EmulatorIO::define_var (
    int ncid,
    const std::string & varname,
    int nctype,
    const std::vector< int > & dimids
) 

Parameters:

  • ncid File ID (must be in define mode)
  • varname Variable name
  • nctype NetCDF type (e.g., NC_DOUBLE)
  • dimids Vector of dimension IDs

Returns:

Variable ID, or -1 on failure


function end_def

End define mode and switch to data mode.

static bool emulator::EmulatorIO::end_def (
    int ncid
) 

Must be called after defining dimensions and variables, before writing data.

Parameters:

  • ncid File ID

Returns:

true on success


function finalize

Finalize the PIO subsystem.

static void emulator::EmulatorIO::finalize () 

Should be called before MPI_Finalize to release resources.


function get_dim_size

Get the size of a dimension.

static int emulator::EmulatorIO::get_dim_size (
    int ncid,
    const std::string & dimname
) 

Parameters:

  • ncid File ID
  • dimname Dimension name

Returns:

Dimension length, or -1 if not found


function has_var

Check if a variable exists in the file.

static bool emulator::EmulatorIO::has_var (
    int ncid,
    const std::string & varname
) 

Parameters:

  • ncid File ID
  • varname Variable name

Returns:

true if variable exists


function initialize

Initialize the PIO subsystem.

static void emulator::EmulatorIO::initialize (
    MPI_Comm comm,
    const std::string & comp_name
) 

Must be called once before any file operations. Typically called from EmulatorComp::create_instance().

Parameters:

  • comm MPI communicator for parallel I/O
  • comp_name Component name (for logging)

function is_initialized

Check if PIO is initialized.

static inline bool emulator::EmulatorIO::is_initialized () 

Returns:

true if initialize() has been called successfully


function open_file

Open an existing NetCDF file for reading.

static int emulator::EmulatorIO::open_file (
    const std::string & filename
) 

Parameters:

  • filename Path to the file

Returns:

NetCDF file ID (ncid), or -1 on failure


function read_var_1d

Read a 1D double array from a NetCDF variable.

static bool emulator::EmulatorIO::read_var_1d (
    int ncid,
    const std::string & varname,
    double * data,
    int size
) 

Parameters:

  • ncid File ID
  • varname Variable name
  • data Output buffer (must be pre-allocated)
  • size Number of elements to read

Returns:

true on success, false if variable not found or read failed


function read_var_1d_int

Read a 1D integer array from a NetCDF variable.

static bool emulator::EmulatorIO::read_var_1d_int (
    int ncid,
    const std::string & varname,
    int * data,
    int size
) 

Parameters:

  • ncid File ID
  • varname Variable name
  • data Output buffer
  • size Number of elements to read

Returns:

true on success


function read_var_2d

Read a 2D double array from a NetCDF variable.

static bool emulator::EmulatorIO::read_var_2d (
    int ncid,
    const std::string & varname,
    double * data,
    int nx,
    int ny
) 

Parameters:

  • ncid File ID
  • varname Variable name
  • data Output buffer (must be pre-allocated, row-major)
  • nx Size in x dimension
  • ny Size in y dimension

Returns:

true on success


function read_var_3d_slice

Read a 2D slice from a 3D variable (time, lat, lon).

static bool emulator::EmulatorIO::read_var_3d_slice (
    int ncid,
    const std::string & varname,
    double * data,
    int nx,
    int ny,
    int time_idx
) 

Parameters:

  • ncid File ID
  • varname Variable name
  • data Output buffer
  • nx Size in x dimension
  • ny Size in y dimension
  • time_idx Time index to read

Returns:

true on success


function sync_file

Synchronize (flush) file contents to disk.

static void emulator::EmulatorIO::sync_file (
    int ncid
) 

Parameters:

  • ncid File ID

function write_var_1d

Write a 1D double array to a NetCDF variable.

static bool emulator::EmulatorIO::write_var_1d (
    int ncid,
    const std::string & varname,
    const double * data,
    int size
) 

Parameters:

  • ncid File ID
  • varname Variable name (must already exist)
  • data Input data buffer
  • size Number of elements to write

Returns:

true on success


function write_var_2d

Write a 2D double array to a NetCDF variable.

static bool emulator::EmulatorIO::write_var_2d (
    int ncid,
    const std::string & varname,
    const double * data,
    int nx,
    int ny
) 

Parameters:

  • ncid File ID
  • varname Variable name (must already exist)
  • data Input data buffer (row-major)
  • nx Size in x dimension
  • ny Size in y dimension

Returns:

true on success



The documentation for this class was generated from the following file components/emulator_comps/common/src/emulator_io.hpp