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:
ncidFile ID from open_file() or create_file()
function create_file
Create a new NetCDF file for writing.
static int emulator::EmulatorIO::create_file (
const std::string & filename
)
Parameters:
filenamePath 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:
ncidFile ID (must be in define mode)dimnameDimension namelengthDimension 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:
ncidFile ID (must be in define mode)varnameVariable namenctypeNetCDF type (e.g., NC_DOUBLE)dimidsVector 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:
ncidFile 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:
ncidFile IDdimnameDimension 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:
ncidFile IDvarnameVariable 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:
commMPI communicator for parallel I/Ocomp_nameComponent 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:
filenamePath 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:
ncidFile IDvarnameVariable namedataOutput buffer (must be pre-allocated)sizeNumber 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:
ncidFile IDvarnameVariable namedataOutput buffersizeNumber 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:
ncidFile IDvarnameVariable namedataOutput buffer (must be pre-allocated, row-major)nxSize in x dimensionnySize 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:
ncidFile IDvarnameVariable namedataOutput buffernxSize in x dimensionnySize in y dimensiontime_idxTime 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:
ncidFile 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:
ncidFile IDvarnameVariable name (must already exist)dataInput data buffersizeNumber 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:
ncidFile IDvarnameVariable name (must already exist)dataInput data buffer (row-major)nxSize in x dimensionnySize 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