fileio.hpp
Go to the documentation of this file.
19// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
493 throw Exception("Failure during reading element " + ToString(static_cast<unsigned int>(i)) + " of array. "
841 error = "Error reading binary IBM float array. Trying to read 4*" + NRLib::ToString(n) + " elements when end-of-file was reached.\n";
Definition: exception.hpp:80 Definition: exception.hpp:34 static void Ieee2Ibm(unsigned int &in) Converts Ieee float (represented as 32-bit int) to IBM float. Definition: fileio.hpp:1129 static void Ibm2Ieee(unsigned int &in) Converts Ieee float (represented as 32-bit int) to IBM float. Definition: fileio.hpp:1109 not_this_one begin(...) Definition: fileio.hpp:355 void WriteIBMFloatBE(char *buffer, float f) Write IEEE double-precision float to big-endian buffer. Definition: fileio.hpp:1174 void ParseIEEEDoubleBE(const char *buffer, double &d) Parse IEEE double-precision float from big-endian buffer. Definition: fileio.hpp:1046 void WriteIBMFloatLE(char *buffer, float f) Write IEEE double-precision float to little-endian buffer. Definition: fileio.hpp:1187 void WriteUInt16BE(char *buffer, unsigned short us) Write unsigned 32-bit integer to big-endian buffer. Definition: fileio.hpp:917 void WriteUInt16LE(char *buffer, unsigned short us) Write unsigned 32-bit integer to little-endian buffer. Definition: fileio.hpp:925 void WriteIEEEFloatLE(char *buffer, float f) Write IEEE single-precision float to little-endian buffer. Definition: fileio.hpp:1031 void ParseIBMFloatLE(const char *buffer, float &f) Parse IEEE double-precision float from little-endian buffer. Definition: fileio.hpp:1159 void WriteIEEEFloatBE(char *buffer, float f) Write IEEE single-precision float to big-endian buffer. Definition: fileio.hpp:1020 void ParseIEEEFloatLE(const char *buffer, float &f) Parse IEEE single-precision float from little-endian buffer. Definition: fileio.hpp:1007 void ParseUInt16LE(const char *buffer, unsigned short &ui) Parse unsigned 32-bit integer from little-endian buffer. Definition: fileio.hpp:908 void ParseUInt32LE(const char *buffer, unsigned int &ui) Parse unsigned 32-bit integer from little-endian buffer. Definition: fileio.hpp:960 void WriteIEEEDoubleLE(char *buffer, double d) Write IEEE double-precision float to little-endian buffer. Definition: fileio.hpp:1086 void WriteIEEEDoubleBE(char *buffer, double d) Write IEEE double-precision float to big-endian buffer. Definition: fileio.hpp:1071 void ParseIEEEDoubleLE(const char *buffer, double &d) Parse IEEE double-precision float from little-endian buffer. Definition: fileio.hpp:1058 void WriteUInt32LE(char *buffer, unsigned int ui) Write unsigned 32-bit integer to little-endian buffer. Definition: fileio.hpp:981 void WriteUInt32BE(char *buffer, unsigned int ui) Write unsigned 32-bit integer to big-endian buffer. Definition: fileio.hpp:971 Definition: exception.hpp:31 void WriteBinaryShort(std::ostream &stream, short s, Endianess number_representation=END_BIG_ENDIAN) Write a 2-byte integer to a binary file. void WriteBinaryDouble(std::ostream &stream, double d, Endianess number_representation=END_BIG_ENDIAN) Write a 8-byte float on standard IEEE format. void RemoveFile(const std::string &filename) void WriteBinaryIbmFloatArray(std::ostream &stream, I begin, I end, Endianess number_representation=END_BIG_ENDIAN) Write an array of 4-byte floats on standard IEEE format. Definition: fileio.hpp:796 I ReadBinaryIbmFloatArray(std::istream &stream, I begin, size_t n, Endianess number_representation=END_BIG_ENDIAN) Read an array of 4-byte floats on standard IEEE format. Definition: fileio.hpp:828 void ParseUInt32BE(const char *buffer, unsigned int &ui) Parse unsigned 32-bit integer from big-endian buffer. Definition: fileio.hpp:949 std::istream & GetNextNonEmptyLine(std::istream &stream, int &line_num, std::string &line) Gets the next line that not only contains whitespace. Returns the stream. Stream will be bad if end-o... I ReadBinaryFloatArray(std::istream &stream, I begin, size_t n, Endianess number_representation=END_BIG_ENDIAN) Read an array of 4-byte floats on standard IEEE format. Definition: fileio.hpp:688 I ReadAsciiArrayFast(std::istream &stream, I begin, size_t n) Gets sequence with elements of type T from input stream. Does no type checking, and does not count li... Definition: fileio.hpp:481 void ParseUInt16BE(const char *buffer, unsigned short &ui) Parse unsigned 32-bit integer from big-endian buffer. Definition: fileio.hpp:899 I ParseAsciiArrayFast(std::string &s, I begin, size_t n) Not safe. Replaces whitespace in s with \0. Definition: stringtools.hpp:191 void WriteBinaryFloatArray(std::ostream &stream, I begin, I end, Endianess number_representation=END_BIG_ENDIAN) Write an array of 4-byte floats on standard IEEE format. Definition: fileio.hpp:657 void WriteBinaryIntArray(std::ostream &stream, I begin, I end, Endianess number_representation=END_BIG_ENDIAN) Write an array of binary 4-byte integers. Definition: fileio.hpp:587 void WriteBinaryFloat(std::ostream &stream, float f, Endianess number_representation=END_BIG_ENDIAN) Write a 4-byte float on standard IEEE format. T ReadNext(std::istream &stream, int &line) Gets next token from file, and parses it as type T Might be relatively slow, due to typechecking,... Definition: fileio.hpp:439 bool FileExists(const std::string &filename) void ReadNextQuoted(std::istream &stream, char quote, std::string &s, int &line) Reads the next, possibly quoted, string. I ReadBinaryDoubleArray(std::istream &stream, I begin, size_t n, Endianess number_representation=END_BIG_ENDIAN) Read an array of 8-byte floats on standard IEEE format. Definition: fileio.hpp:758 void CreateDirIfNotExists(const std::string &filename) void ParseIEEEFloatBE(const char *buffer, float &f) Parse IEEE single-precision float from big-endian buffer. Definition: fileio.hpp:995 void ParseInt16BE(const char *buffer, short &ui) Parse unsigned 32-bit integer from big-endian buffer. Definition: fileio.hpp:888 void WriteBinaryInt(std::ostream &stream, int i, Endianess number_representation=END_BIG_ENDIAN) Write a 4-byte integer to a binary file. void ParseInt32BE(const char *buffer, int &ui) Parse unsigned 32-bit integer from big-endian buffer. Definition: fileio.hpp:936 void ParseIBMFloatBE(const char *buffer, float &f) Parse IEEE double-precision float from big-endian buffer. Definition: fileio.hpp:1144 bool IgnoreComment(std::ifstream &file, char chin) float ReadBinaryFloat(std::istream &stream, Endianess number_representation=END_BIG_ENDIAN) Read a 4-byte float on standard IEEE format. short ReadBinaryShort(std::istream &stream, Endianess number_representation=END_BIG_ENDIAN) Read a 2-byte integer from a binary file. void DiscardRestOfLine(std::istream &stream, int &line_num, bool throw_if_non_whitespace) Reads and discard all characters until and including next newline. void CopyFile(const std::string &from_path, const std::string &to_path, bool allow_overwrite) void WriteBinaryShortArray(std::ostream &stream, I begin, I end, Endianess number_representation=END_BIG_ENDIAN) Write an array of binary 2-byte integers. Definition: fileio.hpp:517 I ReadBinaryShortArray(std::istream &stream, I begin, size_t n, Endianess number_representation=END_BIG_ENDIAN) Read an array of binary 2-byte integers. Definition: fileio.hpp:549 int ReadBinaryInt(std::istream &stream, Endianess number_representation=END_BIG_ENDIAN) Read a 4-byte integer from a binary file. I ReadAsciiArrayFastRestOfFile(std::istream &stream, I begin, size_t n) Gets sequence with elements of type T from input stream. Does no type checking, and does not count li... Definition: fileio.hpp:502 int FindGridFileType(const std::string &filename) Find type of file, for 3D grid files. std::istream & ReadNextToken(std::istream &stream, std::string &s, int &line) Read next white-space seperated token from file. Updates line number when new line is read in.... I ReadAsciiArray(std::istream &stream, I begin, size_t n, int &line) Gets sequence with elements of type T from input stream. Might be relatively slow,... Definition: fileio.hpp:469 float ReadBinaryIbmFloat(std::istream &stream, Endianess number_representation=END_BIG_ENDIAN) Read a 4-byte float on standard IEEE format. std::string FindLastNonEmptyLine(std::istream &stream, const std::ios::pos_type &max_line_len=1000) Returns last non-empty line in file. Stream will be at end of file. int Seek(FILE *file, long long offset, int origin) Seek to given position in file, works for large files. void WriteBinaryIbmFloat(std::ostream &stream, float f, Endianess number_representation=END_BIG_ENDIAN) Write a 4-byte float on standard IEEE format. double ReadBinaryDouble(std::istream &stream, Endianess number_representation=END_BIG_ENDIAN) Read a 8-byte float on standard IEEE format. bool CheckEndOfFile(std::istream &stream) Check if end of file is reached. Discards all whitespace before end of file or next token. void WriteBinaryDoubleArray(std::ostream &stream, I begin, I end, Endianess number_representation=END_BIG_ENDIAN) Write an array of 8-byte floats on standard IEEE format. Definition: fileio.hpp:726 void SkipComments(std::istream &stream, char comment_token, int &line_num) Returns next line that not only contains whitespace, or starts with the given comment token. void OpenWrite(std::ofstream &stream, const std::string &filename, std::ios_base::openmode mode=std::ios_base::out, bool create_dir=true) Open file for writing. void WriteAsciiArray(std::ostream &stream, I begin, I end, int n_per_line=6) Writes array. Definition: fileio.hpp:453 unsigned long long FindFileSize(const std::string &filename) Finds the size of a file. Throws IOError if file not found. void OpenRead(std::ifstream &stream, const std::string &filename, std::ios_base::openmode mode=std::ios_base::in) Open file for reading. std::string ToString(const T obj, int precision=-99999) Definition: stringtools.hpp:177 I ReadBinaryIntArray(std::istream &stream, I begin, size_t n, Endianess number_representation=END_BIG_ENDIAN) Read an array of binary 4-byte integers. Definition: fileio.hpp:619 Definition: fileio.hpp:365 Definition: fileio.hpp:360 |