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,
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.",
const std::vector< unsigned int > & getRanges() const
Definition: Array.h:1228
static AnnotatedArray< DataType, Subindex > convert(const Property::AbstractProperty< DataType > &abstractProperty)
Definition: PropertyConverter.h:114
void setFormat(Format format)
Definition: Exporter.h:265
Converts Properties to AnnotatedArrays.
void reset()
Definition: MultiCounter.h:174
Multi-dimensional array.
Definition: Array.h:98
Array with additional information about its axes.
Definition: AnnotatedArray.h:41
Exporter()
Definition: Exporter.h:195
Abstract Property class.
Definition: AbstractProperty.h:101
Physical index.
Definition: Index.h:44
Array with additional information about its axes.
Array< DataType > getArrayWithReversedIndices() const
Definition: Array.h:1169
Format
Definition: Exporter.h:136
Helper class for flattening nested loops.
Definition: MultiCounter.h:42
void save(const Property::AbstractProperty< DataType > &abstractProperty, const std::string &filename) const
Definition: Exporter.h:200
bool done() const
Definition: MultiCounter.h:179
Exports data on human readable format.
Definition: Exporter.h:133
Matrix containing information about a spin.
Definition: SpinMatrix.h:82