Loading...
Searching...
No Matches
qe.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * QEBinaryRecordFormat — Fortran unformatted sequential record I/O.
5 *
6 * Each record is framed as: [4-byte length prefix][data bytes][4-byte length suffix].
7 * Matches Quantum ESPRESSO's Fortran I/O (FORM='UNFORMATTED', ACCESS='SEQUENTIAL').
8 */
9
11
12namespace q3 {
13
15 public:
16 void write_record(std::ofstream& output_file,
17 const void* data,
18 int32_t number_of_bytes) const override {
19 output_file.write(reinterpret_cast<const char*>(&number_of_bytes), 4);
20 output_file.write(reinterpret_cast<const char*>(data), number_of_bytes);
21 output_file.write(reinterpret_cast<const char*>(&number_of_bytes), 4);
22 }
23
24 void
25 read_record(std::ifstream& input_file, void* data, int32_t number_of_bytes) const override {
26 int32_t prefix_length;
27 int32_t suffix_length;
28 input_file.read(reinterpret_cast<char*>(&prefix_length), 4);
29 if (prefix_length != number_of_bytes) {
30 input_file.setstate(std::ios::failbit);
31 return;
32 }
33 input_file.read(reinterpret_cast<char*>(data), number_of_bytes);
34 input_file.read(reinterpret_cast<char*>(&suffix_length), 4);
35 if (suffix_length != prefix_length) {
36 input_file.setstate(std::ios::failbit);
37 }
38 }
39};
40
41} // namespace q3
void read_record(std::ifstream &input_file, void *data, int32_t number_of_bytes) const override
Definition qe.hpp:25
void write_record(std::ofstream &output_file, const void *data, int32_t number_of_bytes) const override
Definition qe.hpp:16