26 #include <tensor/tensor.h>
30 using namespace tensor;
32 bool file_exists(
const std::string &filename);
33 bool delete_file(
const std::string &filename);
34 bool rename_file(
const std::string &orig,
const std::string &dest,
35 bool overwrite =
true);
36 bool isdir(
const std::string &filename);
37 bool make_directory(
const std::string &dirname,
int mode = 0777);
44 TAG_RTENSOR_VECTOR = 2,
45 TAG_CTENSOR_VECTOR = 3
50 LITTLE_ENDIAN_FILE = 1
60 static const size_t var_name_size = 64;
62 std::string _actual_filename;
63 std::string _filename;
64 std::string _lock_filename;
68 static const enum endianness endian;
70 DataFile(
const std::string &a_filename,
int flags = SDF_SHARED);
72 const char *tag_to_name(
size_t tag);
74 bool is_open() {
return _open; }
75 bool is_locked() {
return _lock; }
76 const std::string &actual_filename() {
return _actual_filename; }
81 class OutDataFile :
public DataFile {
85 OutDataFile(
const std::string &a_filename,
int flags = SDF_SHARED);
88 void dump(
const int r,
const std::string &name =
"");
89 void dump(
const size_t r,
const std::string &name =
"");
90 void dump(
const double r,
const std::string &name =
"");
91 void dump(
const cdouble r,
const std::string &name =
"");
92 void dump(
const RTensor &t,
const std::string &name =
"");
93 void dump(
const CTensor &t,
const std::string &name =
"");
94 void dump(
const std::vector<RTensor> &t,
const std::string &name =
"");
95 void dump(
const std::vector<CTensor> &t,
const std::string &name =
"");
101 std::ofstream _stream;
103 void write_raw(
const char *data,
size_t n);
104 void write_raw(
const int *data,
size_t n);
105 void write_raw(
const long *data,
size_t n);
106 void write_raw(
const size_t *data,
size_t n);
107 void write_raw(
const double *data,
size_t n);
108 void write_raw(
const cdouble *data,
size_t n);
110 template<
typename t>
void write_raw(t v) {
114 template<
class Vector>
void dump_vector(
const Vector &v);
117 void write_variable_name(
const std::string &name);
118 void write_tag(
const std::string &name,
size_t tag);
121 class InDataFile :
public DataFile {
125 InDataFile(
const std::string &a_filename,
int flags = SDF_SHARED);
127 void load(
int *r,
const std::string &name =
"");
128 void load(
size_t *r,
const std::string &name =
"");
129 void load(
double *r,
const std::string &name =
"");
130 void load(cdouble *r,
const std::string &name =
"");
131 void load(
RTensor *t,
const std::string &name =
"");
132 void load(
CTensor *t,
const std::string &name =
"");
133 void load(std::vector<RTensor> *m,
const std::string &name =
"");
134 void load(std::vector<CTensor> *m,
const std::string &name =
"");
140 std::ifstream _stream;
142 void read_raw(
char *data,
size_t n);
143 void read_raw(
int *data,
size_t n);
144 void read_raw(
size_t *data,
size_t n);
145 void read_raw(
long *data,
size_t n);
146 void read_raw(
double *data,
size_t n);
147 void read_raw(cdouble *data,
size_t n);
149 template<
typename t>
void read_raw(t &v) {
153 template<
class Vector>
const Vector load_vector();
155 size_t read_tag_code();
156 std::string read_variable_name();
159 void read_tag(
const std::string &record_name,
size_t tag);
Real Tensor with elements of type "double".
Complex Tensor with elements of type "cdouble".