31 #pragma warning(disable : 4244 4275)
43 #ifdef BORNAGAIN_TIFF_SUPPORT
46 file_name, [](std::istream& s) {
return OutputDataReadWriteTiff().readOutputData(s); });
63 std::unique_ptr<OutputData<double>> data(
readOutputData(file_name));
65 throw std::runtime_error(
"Could not read " + file_name);
70 const std::string& file_name)
75 #ifdef BORNAGAIN_TIFF_SUPPORT
78 OutputDataReadWriteTiff().writeOutputData(data, s);
88 std::function<
void(std::ostream&)> writeData)
93 std::ios_base::openmode openmode = std::ios::out;
95 openmode = std::ios::out | std::ios_base::binary;
100 fout.open(file_name, openmode);
104 throw std::runtime_error(
"IntensityDataIOFactory::writeOutputData() -> Error. "
106 + file_name +
"' for writing.");
108 throw std::runtime_error(
"IntensityDataIOFactory::writeOutputData() -> Error! "
109 "File is not good, probably it is a directory.");
110 std::stringstream ss;
113 boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered;
115 input_filtered.push(boost::iostreams::gzip_compressor());
117 input_filtered.push(boost::iostreams::bzip2_compressor());
118 input_filtered.push(ss);
120 boost::iostreams::copy(input_filtered, fout);
126 const std::string& file_name)
133 const std::string& file_name)
135 auto data = result.
data();
148 std::ifstream input_stream;
149 std::ios_base::openmode openmode = std::ios::in;
151 openmode = std::ios::in | std::ios_base::binary;
156 input_stream.open(file_name, openmode);
159 if (!input_stream.is_open())
160 throw std::runtime_error(
161 "IntensityDataIOFactory::getFromFilteredStream() -> Error. Can't open file '"
162 + file_name +
"' for reading.");
163 if (!input_stream.good())
164 throw std::runtime_error(
"IntensityDataIOFactory::getFromFilteredStream() -> Error! "
165 "File is not good, probably it is a directory.");
167 boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered;
169 input_filtered.push(boost::iostreams::gzip_decompressor());
171 input_filtered.push(boost::iostreams::bzip2_decompressor());
172 input_filtered.push(input_stream);
174 std::stringstream str;
175 boost::iostreams::copy(input_filtered, str);
177 return readData(str);
Defines namespace FileSystemUtils.
Defines interface IHistogram.
Defines class IntensityDataIOFactory.
Defines OutputDataReadReflectometry.
Defines OutputDataReadWriteINT.
Defines OutputDataReadWriteNumpyTXT.
Defines class OutputDataReadWriteTiff.
Defines class SimulationResult.
Contains boost streams related headers.
Base class for 1D and 2D histograms holding values of double type.
OutputData< double > * createOutputData(DataType dataType=DataType::INTEGRAL) const
creates new OutputData with histogram's shape and values corresponding to DataType
static IHistogram * createHistogram(const OutputData< double > &source)
static OutputData< double > * readOutputData(const std::string &file_name)
Reads file and returns newly created OutputData object.
static void writeOutputData(const OutputData< double > &data, const std::string &file_name)
Writes OutputData in file.
static IHistogram * readIntensityData(const std::string &file_name)
Reads file and returns newly created Histogram object.
static void writeIntensityData(const IHistogram &histogram, const std::string &file_name)
Writes histogram in file.
static OutputData< double > * readReflectometryData(const std::string &file_name)
static void writeSimulationResult(const SimulationResult &result, const std::string &file_name)
Writes OutputData contained in the given SimulationResult object.
Class for reading reflectometry data from ASCII file.
OutputData< double > * readOutputData(std::istream &input_stream)
Class for reading and writing BornAgain native IntensityData from ASCII file.
OutputData< double > * readOutputData(std::istream &input_stream)
void writeOutputData(const OutputData< double > &data, std::ostream &output_stream)
Class for reading and writing OutputData from simple ASCII file with the layout as in numpy....
void writeOutputData(const OutputData< double > &data, std::ostream &output_stream)
OutputData< double > * readOutputData(std::istream &input_stream)
Wrapper around OutputData<double> that also provides unit conversions.
std::unique_ptr< OutputData< double > > data(Axes::Units units=Axes::Units::DEFAULT) const
std::wstring convert_utf8_to_utf16(const std::string &str)
Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
bool IsFileExists(const std::string &path)
Returns true if file with given name exists on disk.