23 #ifndef COM_DAFER45_TBTK_EXPORTER
24 #define COM_DAFER45_TBTK_EXPORTER
27 #include "TBTK/MultiCounter.h"
28 #include "TBTK/Property/AbstractProperty.h"
30 #include "TBTK/SpinMatrix.h"
136 enum class Format {RowMajor, ColumnMajor};
149 template<
typename DataType>
152 const std::string &filename
165 template<
typename DataType>
168 const Index &pattern,
169 const std::string &filename
176 template<
typename DataType>
179 const std::string &filename
191 template<
typename DataType>
192 void write(std::ofstream &stream,
const DataType &value)
const;
196 format = Format::RowMajor;
199 template<
typename DataType>
202 const std::string &filename
207 save(annotatedArray, filename);
210 template<
typename DataType>
213 const Index &pattern,
214 const std::string &filename
219 save(annotatedArray, filename);
222 template<
typename DataType>
225 const std::string &filename
229 case Format::RowMajor:
232 case Format::ColumnMajor:
238 "Unknown format '" <<
static_cast<int>(format) <<
"'.",
243 std::ofstream fout(filename);
247 "Unable to open file '" << filename <<
"'.",
251 const std::vector<unsigned int> &ranges = outputArray.
getRanges();
252 std::vector<unsigned int> begin = ranges;
253 std::vector<unsigned int> end = ranges;
254 std::vector<unsigned int> increment = ranges;
255 for(
unsigned int n = 0; n < begin.size(); n++){
260 for(counter.
reset(); !counter.
done(); ++counter)
261 write(fout, outputArray[counter]);
266 this->format = format;
269 template<
typename DataType>
270 void Exporter::write(std::ofstream &stream,
const DataType &value)
const{
271 stream << value <<
"\n";
275 inline void Exporter::write<std::complex<double>>(
276 std::ofstream &stream,
277 const std::complex<double> &value
279 stream << real(value) <<
"\n";
280 stream << imag(value) <<
"\n";
284 inline void Exporter::write<SpinMatrix>(
285 std::ofstream &stream,
286 const SpinMatrix &value
289 case Format::RowMajor:
290 write(stream, value.at(0, 0));
291 write(stream, value.at(0, 1));
292 write(stream, value.at(1, 0));
293 write(stream, value.at(1, 1));
295 case Format::ColumnMajor:
296 write(stream, value.at(0, 0));
297 write(stream, value.at(1, 0));
298 write(stream, value.at(0, 1));
299 write(stream, value.at(1, 1));
304 "This should never happen, contact the developer.",