Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
shambase::FortranIOFile Class Reference

Class for reading and writing Fortran-style binary files. More...

#include <shambase/include/shambase/fortran_io.hpp>

Public Types

using fort_real = f64
 Fortran real type.
 
using fort_int = int
 Fortran int type.
 

Public Member Functions

 FortranIOFile (std::basic_stringstream< byte > &&data_in, u64 length)
 Construct a new FortranIOFile object.
 
std::basic_stringstream< byte > & get_internal_buf ()
 Get a reference to the internal buffer.
 
template<class... Args>
void write (Args &...args)
 Write a list of arguments to the internal buffer.
 
template<class... Args>
void read (Args &...args)
 Read a list of arguments from the internal buffer.
 
void read_fixed_string (std::string &s, u32 len)
 Read a fixed-length string from the buffer.
 
void write_fixed_string (std::string &s, u32 len)
 Write a fixed-length string to the buffer.
 
void read_string_array (std::vector< std::string > &svec, u32 strlen, u32 str_count)
 Read a fixed-length string array from the buffer.
 
void write_string_array (std::vector< std::string > &svec, u32 strlen, u32 str_count)
 Write a fixed-length string array to the buffer.
 
template<class T >
void read_val_array (std::vector< T > &vec, u32 val_count)
 Read an array of values from the buffer.
 
template<class T >
void write_val_array (std::vector< T > &vec, u32 val_count)
 Write an array of values to the buffer.
 
bool finished_read ()
 Check if the end of the file has been reached.
 
void write_to_file (std::string fname)
 Write the Fortran formatted file to disk.
 

Detailed Description

Class for reading and writing Fortran-style binary files.

Definition at line 36 of file fortran_io.hpp.

Member Typedef Documentation

◆ fort_int

Fortran int type.

Definition at line 136 of file fortran_io.hpp.

◆ fort_real

Fortran real type.

Definition at line 133 of file fortran_io.hpp.

Constructor & Destructor Documentation

◆ FortranIOFile()

shambase::FortranIOFile::FortranIOFile ( std::basic_stringstream< byte > &&  data_in,
u64  length 
)
inlineexplicit

Construct a new FortranIOFile object.

Parameters
[in]data_inThe input buffer to be used for reading and writing
[in]lengthThe length of the input buffer

Definition at line 144 of file fortran_io.hpp.

Member Function Documentation

◆ finished_read()

bool shambase::FortranIOFile::finished_read ( )
inline

Check if the end of the file has been reached.

This function returns true if the end of the file has been reached, i.e. if all the data in the file has been read.

Returns
true if the end of the file has been reached

Definition at line 369 of file fortran_io.hpp.

◆ get_internal_buf()

std::basic_stringstream< byte > & shambase::FortranIOFile::get_internal_buf ( )
inline

Get a reference to the internal buffer.

Returns
std::basic_stringstream<byte>& A reference to the internal buffer

Definition at line 158 of file fortran_io.hpp.

◆ read()

template<class... Args>
void shambase::FortranIOFile::read ( Args &...  args)
inline

Read a list of arguments from the internal buffer.

This function reads a list of arguments from the internal buffer using the Fortran-like serialization format. The arguments are serialized in the following way: first the size of all arguments in bytes, then the arguments, and finally again the size of all arguments in bytes.

Template Parameters
Argsthe types of the arguments to be read
Parameters
[out]argsthe arguments to be read

Definition at line 195 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ read_fixed_string()

void shambase::FortranIOFile::read_fixed_string ( std::string &  s,
u32  len 
)
inline

Read a fixed-length string from the buffer.

This function reads a fixed-length string from the buffer using the Fortran-like serialization format. The string is serialized in the following way: first the size of the string in bytes, then the string itself, and finally again the size of the string in bytes.

Parameters
[out]sthe string to be read
lenthe length of the string to be read

Definition at line 216 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ read_string_array()

void shambase::FortranIOFile::read_string_array ( std::vector< std::string > &  svec,
u32  strlen,
u32  str_count 
)
inline

Read a fixed-length string array from the buffer.

This function reads a fixed-length string array from the buffer using the Fortran-like serialization format. The array is serialized in the following way: first the size of the array in bytes, then the array itself, and finally again the size of the array in bytes.

Parameters
[out]svecthe output array of strings
[in]strlenthe length of each string in the array
[in]str_countthe number of strings in the array

Definition at line 255 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ read_val_array()

template<class T >
void shambase::FortranIOFile::read_val_array ( std::vector< T > &  vec,
u32  val_count 
)
inline

Read an array of values from the buffer.

This function reads an array of values of type T from the buffer using the Fortran-like serialization format. The array is serialized in the following way: first the size of the array in bytes, then the array itself, and finally again the size of the array in bytes.

Template Parameters
TThe type in use
Parameters
[out]vecthe output array
[in]val_countthe number of values in the array

Definition at line 312 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ write()

template<class... Args>
void shambase::FortranIOFile::write ( Args &...  args)
inline

Write a list of arguments to the internal buffer.

This function writes a list of arguments to the internal buffer using the Fortran-like serialization format. The arguments are serialized in the following way: first the size of all arguments in bytes, then the arguments, and finally again the size of all arguments in bytes. This format is used by the Fortran standard for I/O.

Template Parameters
Argsthe types of the arguments to be written
Parameters
[in]argsthe arguments to be written

Definition at line 176 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ write_fixed_string()

void shambase::FortranIOFile::write_fixed_string ( std::string &  s,
u32  len 
)
inline

Write a fixed-length string to the buffer.

This function writes a fixed-length string to the buffer using the Fortran-like serialization format. The string is serialized in the following way: first the size of the string in bytes, then the string itself, and finally again the size of the string in bytes.

Parameters
[out]sthe string to be written
[in]lenthe length of the string to be written

Definition at line 237 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ write_string_array()

void shambase::FortranIOFile::write_string_array ( std::vector< std::string > &  svec,
u32  strlen,
u32  str_count 
)
inline

Write a fixed-length string array to the buffer.

This function writes a fixed-length string array to the buffer using the Fortran-like serialization format. The array is serialized in the following way: first the size of the array in bytes, then the array itself, and finally again the size of the array in bytes.

Parameters
[in]svecthe array of strings to write
[in]strlenthe length of each string in the array
[in]str_countthe number of strings in the array

Definition at line 285 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ write_to_file()

void shambase::FortranIOFile::write_to_file ( std::string  fname)
inline

Write the Fortran formatted file to disk.

Parameters
fnameFilename to write to
Exceptions
runtime_errorif the file could not be opened for writing

Definition at line 378 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ write_val_array()

template<class T >
void shambase::FortranIOFile::write_val_array ( std::vector< T > &  vec,
u32  val_count 
)
inline

Write an array of values to the buffer.

This function writes an array of values of type T to the buffer using the Fortran-like serialization format. The array is serialized in the following way: first the size of the array in bytes, then the array itself, and finally again the size of the array in bytes.

Parameters
vecThe input array to be written
val_countThe number of values in the array
Exceptions
std::invalid_argumentif val_count is larger than vec.size()

Definition at line 346 of file fortran_io.hpp.

+ Here is the call graph for this function:

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