22#include <unordered_map>
46 std::vector<std::pair<std::string, T>>
entries;
62 void add(std::string s, T val) {
63 s = shambase::format(
"{:16s}", s);
80 inline std::optional<T>
fetch(std::string s)
const {
81 std::optional<T> ret = {};
83 for (
auto [key, val] :
entries) {
101 for (
auto [key, val] :
entries) {
113 template<
class Tconv>
114 inline void add_to_map(std::unordered_map<std::string, Tconv> &map) {
115 for (
auto [key, val] :
entries) {
166 void fill_vec(std::string field_name, std::vector<Tb> &vec) {
167 if (
tag == field_name) {
307 void fill_vec(std::string field_name, std::vector<T> &vec) {
309 field_name = shambase::format(
"{:16s}", field_name);
312 tmp.fill_vec(field_name, vec);
315 tmp.fill_vec(field_name, vec);
318 tmp.fill_vec(field_name, vec);
321 tmp.fill_vec(field_name, vec);
324 tmp.fill_vec(field_name, vec);
327 tmp.fill_vec(field_name, vec);
330 tmp.fill_vec(field_name, vec);
333 tmp.fill_vec(field_name, vec);
438 s = shambase::format(
"{:16s}", s);
480 s = shambase::format(
"{:16s}", s);
493 "the entry cannot be found : " + s);
507 std::vector<T> vec{};
509 s = shambase::format(
"{:16s}", s);
530 s = shambase::format(
"{:16s}", s);
563 std::vector<T> vec{};
565 s = shambase::format(
"{:16s}", s);
double f64
Alias for double.
std::uint64_t u64
64 bit unsigned integer
std::int64_t i64
64 bit integer
Class for reading and writing Fortran-style binary files.
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for the sph model
bool compare_phantom_dumps(PhantomDump &dump1, PhantomDump &dump2)
Compare two phantom dumps and report offenses.
A helper class to represent a single block of data in a Phantom dump.
void write(shambase::FortranIOFile &phfile, i64 tot_count)
Writes a block to a file.
std::string tag
The tag of the block.
void print_state()
Prints the state of the block.
void fill_vec(std::string field_name, std::vector< Tb > &vec)
Fills a vector with the values of a given field name.
std::vector< T > vals
The values of the block.
static PhantomDumpBlockArray from_file(shambase::FortranIOFile &phfile, i64 tot_count)
Reads a block from a file.
A class to represent a single block of data in a Phantom dump.
std::vector< PhantomDumpBlockArray< fort_int > > blocks_fort_int
The blocks of values of type fort_int.
static PhantomDumpBlock from_file(shambase::FortranIOFile &phfile, i64 tot_count, std::array< i32, 8 > numarray)
Reads a block from a file.
u64 get_ref_f32(std::string s)
Gets the index of a block of type f32 with the given name.
u64 get_ref_i16(std::string s)
Gets the index of a block of type i16 with the given name.
std::vector< PhantomDumpBlockArray< i16 > > blocks_i16
The blocks of values of type i16.
std::vector< PhantomDumpBlockArray< i8 > > blocks_i8
The blocks of values of type i8.
std::vector< PhantomDumpBlockArray< f64 > > blocks_f64
The blocks of values of type f64.
std::vector< PhantomDumpBlockArray< i64 > > blocks_i64
The blocks of values of type i64.
u64 get_ref_fort_int(std::string s)
Gets the index of a block of type fort_int with the given name.
void write(shambase::FortranIOFile &phfile, i64 tot_count, std::array< i32, 8 > numarray)
Writes a block to a file.
void fill_vec(std::string field_name, std::vector< T > &vec)
Fills a vector with the values of a given field name.
u64 get_ref_fort_real(std::string s)
Gets the index of a block of type fort_real with the given name.
f64 fort_real
The type for Phantom's real type.
std::vector< PhantomDumpBlockArray< i32 > > blocks_i32
The blocks of values of type i32.
int fort_int
The type for Phantom's integer type.
u64 get_ref_i64(std::string s)
Gets the index of a block of type i64 with the given name.
u64 get_ref_f64(std::string s)
Gets the index of a block of type f64 with the given name.
i64 tot_count
The total number of values in the block.
std::vector< PhantomDumpBlockArray< fort_real > > blocks_fort_real
The blocks of values of type fort_real.
std::vector< PhantomDumpBlockArray< f32 > > blocks_f32
The blocks of values of type f32.
void print_state()
Prints the state of the block.
u64 get_ref_i8(std::string s)
Gets the index of a block of type i8 with the given name.
u64 get_ref_i32(std::string s)
Gets the index of a block of type i32 with the given name.
Class representing a Phantom dump file.
std::vector< T > read_header_floats(std::string s)
Reads multiple float values from the table headers based on the given string.
PhantomDumpTableHeader< i16 > table_header_i16
Table header for signed 16-bit integer data.
int fort_int
Integer type used in the phantom dump format.
fort_int i3
Magic number used in the phantom dump format.
T read_header_float(std::string s) const
Retrieves a floating-point value from the table headers.
void override_magic_number()
Overrides the magic numbers used in the PhantomDump struct.
void check_magic_numbers()
Checks if the magic numbers in the PhantomDump struct match the expected values.
PhantomDumpTableHeader< fort_int > table_header_fort_int
Table header for integer data.
std::string fileid
Magic number used in the phantom dump format.
fort_int i1
Magic number used in the phantom dump format.
PhantomDumpTableHeader< f32 > table_header_f32
Table header for 32-bit floating-point data.
bool has_header_entry(std::string s) const
Checks if a given string is present in any of the table headers.
PhantomDumpTableHeader< i64 > table_header_i64
Table header for signed 64-bit integer data.
PhantomDumpTableHeader< i32 > table_header_i32
Table header for signed 32-bit integer data.
T read_header_int(std::string s) const
Retrieves an integer value from the table headers.
f64 fort_real
Floating-point type used in the phantom dump format.
static PhantomDump from_file(shambase::FortranIOFile &phfile)
Reads a Phantom dump file and returns a PhantomDump object.
shambase::FortranIOFile gen_file()
Generates a Phantom dump file from the current state of the object.
fort_int i2
Magic number used in the phantom dump format.
std::vector< PhantomDumpBlock > blocks
List of blocks in the Phantom dump file.
std::vector< T > read_header_ints(std::string s)
Retrieves multiple integer values from the table headers based on the given string.
PhantomDumpTableHeader< fort_real > table_header_fort_real
Table header for floating-point data.
PhantomDumpTableHeader< f64 > table_header_f64
Table header for 64-bit floating-point data.
fort_int iversion
Magic number used in the phantom dump format.
void print_state()
Print current state of the data stored in the class.
PhantomDumpTableHeader< i8 > table_header_i8
Table header for signed 8-bit integer data.
fort_real r1
Magic number used in the phantom dump format.