//! More...
Classes | |
class | diskio |
class for saving and loading matrices and fields More... | |
Enumerations | |
enum | file_type { auto_detect, raw_ascii, arma_ascii, arma_binary, pgm_binary, ppm_binary } |
file types supported by Armadillo More... | |
Functions | |
template<typename eT > | |
static std::string | diskio::gen_txt_header (const Mat< eT > &x) |
Generate the first line of the header used for saving matrices in text format. //! Format: "ARMA_MAT_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). / B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. | |
template<typename eT > | |
static std::string | diskio::gen_bin_header (const Mat< eT > &x) |
Generate the first line of the header used for saving matrices in binary format. //! Format: "ARMA_MAT_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. | |
template<typename eT > | |
static std::string | diskio::gen_txt_header (const Cube< eT > &x) |
Generate the first line of the header used for saving cubes in text format. //! Format: "ARMA_CUB_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. | |
template<typename eT > | |
static std::string | diskio::gen_bin_header (const Cube< eT > &x) |
Generate the first line of the header used for saving cubes in binary format. //! Format: "ARMA_CUB_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). // B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. | |
static char | diskio::conv_to_hex_char (const u8 x) |
static void | diskio::conv_to_hex (char *out, const u8 x) |
static std::string | diskio::gen_tmp_name (const std::string &x) |
Append a quasi-random string to the given filename. //! The rand() function is deliberately not used, //! as rand() has an internal state that changes //! from call to call. Such states should not be //! modified in scientific applications, where the results should be reproducable and not affected //! by saving data. | |
static bool | diskio::safe_rename (const std::string &old_name, const std::string &new_name) |
Safely rename a file. //! Before renaming, test if we can write to the final file. //! This should prevent: //! (i) overwriting files that have been write protected, //! (ii) overwriting directories. | |
template<typename eT > | |
static bool | diskio::save_raw_ascii (const Mat< eT > &x, const std::string &final_name) |
Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. | |
template<typename eT > | |
static bool | diskio::save_raw_ascii (const Mat< eT > &x, std::ostream &f) |
Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. | |
template<typename eT > | |
static bool | diskio::save_arma_ascii (const Mat< eT > &x, const std::string &final_name) |
Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_arma_ascii (const Mat< eT > &x, std::ostream &f) |
Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_arma_binary (const Mat< eT > &x, const std::string &final_name) |
Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_arma_binary (const Mat< eT > &x, std::ostream &f) |
Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_pgm_binary (const Mat< eT > &x, const std::string &final_name) |
Save a matrix as a PGM greyscale image. | |
template<typename eT > | |
static bool | diskio::save_pgm_binary (const Mat< eT > &x, std::ostream &f) |
Save a matrix as a PGM greyscale image. | |
template<typename T > | |
static bool | diskio::save_pgm_binary (const Mat< std::complex< T > > &x, const std::string &final_name) |
Save a matrix as a PGM greyscale image. | |
template<typename T > | |
static bool | diskio::save_pgm_binary (const Mat< std::complex< T > > &x, std::ostream &f) |
Save a matrix as a PGM greyscale image. | |
template<typename eT > | |
static bool | diskio::load_raw_ascii (Mat< eT > &x, const std::string &name, std::string &err_msg) |
Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header. | |
template<typename eT > | |
static bool | diskio::load_raw_ascii (Mat< eT > &x, std::istream &f, std::string &err_msg) |
Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header. | |
template<typename eT > | |
static bool | diskio::load_arma_ascii (Mat< eT > &x, const std::string &name, std::string &err_msg) |
Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_arma_ascii (Mat< eT > &x, std::istream &f, std::string &err_msg) |
Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_arma_binary (Mat< eT > &x, const std::string &name, std::string &err_msg) |
Load a matrix in binary format, //! with a header that indicates the matrix type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_arma_binary (Mat< eT > &x, std::istream &f, std::string &err_msg) |
static void | diskio::pnm_skip_comments (std::istream &f) |
template<typename eT > | |
static bool | diskio::load_pgm_binary (Mat< eT > &x, const std::string &name, std::string &err_msg) |
Load a PGM greyscale image as a matrix. | |
template<typename eT > | |
static bool | diskio::load_pgm_binary (Mat< eT > &x, std::istream &is, std::string &err_msg) |
Load a PGM greyscale image as a matrix. | |
template<typename T > | |
static bool | diskio::load_pgm_binary (Mat< std::complex< T > > &x, const std::string &name, std::string &err_msg) |
Load a PGM greyscale image as a matrix. | |
template<typename T > | |
static bool | diskio::load_pgm_binary (Mat< std::complex< T > > &x, std::istream &is, std::string &err_msg) |
Load a PGM greyscale image as a matrix. | |
template<typename eT > | |
static bool | diskio::load_auto_detect (Mat< eT > &x, const std::string &name, std::string &err_msg) |
Try to load a matrix by automatically determining its type. | |
template<typename eT > | |
static bool | diskio::load_auto_detect (Mat< eT > &x, std::istream &f, std::string &err_msg) |
Try to load a matrix by automatically determining its type. | |
template<typename eT > | |
static bool | diskio::save_raw_ascii (const Cube< eT > &x, const std::string &name) |
Save a cube as raw text (no header, human readable). | |
template<typename eT > | |
static bool | diskio::save_raw_ascii (const Cube< eT > &x, std::ostream &f) |
Save a cube as raw text (no header, human readable). | |
template<typename eT > | |
static bool | diskio::save_arma_ascii (const Cube< eT > &x, const std::string &name) |
Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_arma_ascii (const Cube< eT > &x, std::ostream &f) |
Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_arma_binary (const Cube< eT > &x, const std::string &name) |
Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::save_arma_binary (const Cube< eT > &x, std::ostream &f) |
Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_raw_ascii (Cube< eT > &x, const std::string &name, std::string &err_msg) |
Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header. | |
template<typename eT > | |
static bool | diskio::load_raw_ascii (Cube< eT > &x, std::istream &f, std::string &err_msg) |
Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header. | |
template<typename eT > | |
static bool | diskio::load_arma_ascii (Cube< eT > &x, const std::string &name, std::string &err_msg) |
Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_arma_ascii (Cube< eT > &x, std::istream &f, std::string &err_msg) |
Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_arma_binary (Cube< eT > &x, const std::string &name, std::string &err_msg) |
Load a cube in binary format, //! with a header that indicates the cube type as well as its dimensions. | |
template<typename eT > | |
static bool | diskio::load_arma_binary (Cube< eT > &x, std::istream &f, std::string &err_msg) |
template<typename eT > | |
static bool | diskio::load_auto_detect (Cube< eT > &x, const std::string &name, std::string &err_msg) |
Try to load a cube by automatically determining its type. | |
template<typename eT > | |
static bool | diskio::load_auto_detect (Cube< eT > &x, std::istream &f, std::string &err_msg) |
Try to load a cube by automatically determining its type. | |
template<typename T1 > | |
static bool | diskio::save_arma_binary (const field< T1 > &x, const std::string &name) |
template<typename T1 > | |
static bool | diskio::save_arma_binary (const field< T1 > &x, std::ostream &f) |
template<typename T1 > | |
static bool | diskio::load_arma_binary (field< T1 > &x, const std::string &name, std::string &err_msg) |
template<typename T1 > | |
static bool | diskio::load_arma_binary (field< T1 > &x, std::istream &f, std::string &err_msg) |
static bool | diskio::save_std_string (const field< std::string > &x, const std::string &name) |
static bool | diskio::save_std_string (const field< std::string > &x, std::ostream &f) |
static bool | diskio::load_std_string (field< std::string > &x, const std::string &name, std::string &err_msg) |
static bool | diskio::load_std_string (field< std::string > &x, std::istream &f, std::string &err_msg) |
template<typename T1 > | |
static bool | diskio::load_auto_detect (field< T1 > &x, const std::string &name, std::string &err_msg) |
Try to load a field by automatically determining its type. | |
template<typename T1 > | |
static bool | diskio::load_auto_detect (field< T1 > &x, std::istream &f, std::string &err_msg) |
Try to load a field by automatically determining its type. | |
template<typename eT > | |
bool | diskio::load_ppm_binary (Cube< eT > &x, const std::string &name, std::string &err_msg) |
template<typename eT > | |
bool | diskio::load_ppm_binary (Cube< eT > &x, std::istream &f, std::string &err_msg) |
template<typename eT > | |
bool | diskio::save_ppm_binary (const Cube< eT > &x, const std::string &final_name) |
template<typename eT > | |
bool | diskio::save_ppm_binary (const Cube< eT > &x, std::ostream &f) |
template<typename T1 > | |
static bool | diskio::load_ppm_binary (field< T1 > &x, const std::string &final_name, std::string &err_msg) |
template<typename T1 > | |
static bool | diskio::load_ppm_binary (field< T1 > &x, std::istream &f, std::string &err_msg) |
template<typename T1 > | |
static bool | diskio::save_ppm_binary (const field< T1 > &x, const std::string &final_name) |
template<typename T1 > | |
static bool | diskio::save_ppm_binary (const field< T1 > &x, std::ostream &f) |
//!
enum file_type |
file types supported by Armadillo
Definition at line 99 of file forward_proto.hpp.
{ auto_detect, //!< Automatically detect the file type (file must be one of the following types) raw_ascii, //!< ASCII format (text), without any other information. arma_ascii, //!< Armadillo ASCII format (text), with information about matrix type and size arma_binary, //!< Armadillo binary format pgm_binary, //!< Portable Grey Map (greyscale image) ppm_binary //!< Portable Pixel Map (colour image), used by the field and cube classes };
std::string diskio::gen_txt_header | ( | const Mat< eT > & | x | ) | [inline, static, inherited] |
Generate the first line of the header used for saving matrices in text format. //! Format: "ARMA_MAT_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). / B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes.
Definition at line 30 of file diskio_meat.hpp.
Referenced by load_arma_ascii(), and save_arma_ascii().
{ arma_type_check<diskio::is_supported_type<eT>::value == false>::apply(); if(is_u8<eT>::value == true) { return std::string("ARMA_MAT_TXT_IU001"); } else if(is_s8<eT>::value == true) { return std::string("ARMA_MAT_TXT_IS001"); } else if(is_u16<eT>::value == true) { return std::string("ARMA_MAT_TXT_IU002"); } else if(is_s16<eT>::value == true) { return std::string("ARMA_MAT_TXT_IS002"); } else if(is_u32<eT>::value == true) { return std::string("ARMA_MAT_TXT_IU004"); } else if(is_s32<eT>::value == true) { return std::string("ARMA_MAT_TXT_IS004"); } else if(is_float<eT>::value == true) { return std::string("ARMA_MAT_TXT_FN004"); } else if(is_double<eT>::value == true) { return std::string("ARMA_MAT_TXT_FN008"); } else if(is_complex_float<eT>::value == true) { return std::string("ARMA_MAT_TXT_FC008"); } else if(is_complex_double<eT>::value == true) { return std::string("ARMA_MAT_TXT_FC016"); } else { return std::string(); } }
std::string diskio::gen_bin_header | ( | const Mat< eT > & | x | ) | [inline, static, inherited] |
Generate the first line of the header used for saving matrices in binary format. //! Format: "ARMA_MAT_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes.
Definition at line 100 of file diskio_meat.hpp.
Referenced by load_arma_binary(), and save_arma_binary().
{ arma_type_check<diskio::is_supported_type<eT>::value == false>::apply(); if(is_u8<eT>::value == true) { return std::string("ARMA_MAT_BIN_IU001"); } else if(is_s8<eT>::value == true) { return std::string("ARMA_MAT_BIN_IS001"); } else if(is_u16<eT>::value == true) { return std::string("ARMA_MAT_BIN_IU002"); } else if(is_s16<eT>::value == true) { return std::string("ARMA_MAT_BIN_IS002"); } else if(is_u32<eT>::value == true) { return std::string("ARMA_MAT_BIN_IU004"); } else if(is_s32<eT>::value == true) { return std::string("ARMA_MAT_BIN_IS004"); } else if(is_float<eT>::value == true) { return std::string("ARMA_MAT_BIN_FN004"); } else if(is_double<eT>::value == true) { return std::string("ARMA_MAT_BIN_FN008"); } else if(is_complex_float<eT>::value == true) { return std::string("ARMA_MAT_BIN_FC008"); } else if(is_complex_double<eT>::value == true) { return std::string("ARMA_MAT_BIN_FC016"); } else { return std::string(); } }
std::string diskio::gen_txt_header | ( | const Cube< eT > & | x | ) | [inline, static, inherited] |
Generate the first line of the header used for saving cubes in text format. //! Format: "ARMA_CUB_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes.
Definition at line 170 of file diskio_meat.hpp.
{ arma_type_check<diskio::is_supported_type<eT>::value == false>::apply(); if(is_u8<eT>::value == true) { return std::string("ARMA_CUB_TXT_IU001"); } else if(is_s8<eT>::value == true) { return std::string("ARMA_CUB_TXT_IS001"); } else if(is_u16<eT>::value == true) { return std::string("ARMA_CUB_TXT_IU002"); } else if(is_s16<eT>::value == true) { return std::string("ARMA_CUB_TXT_IS002"); } else if(is_u32<eT>::value == true) { return std::string("ARMA_CUB_TXT_IU004"); } else if(is_s32<eT>::value == true) { return std::string("ARMA_CUB_TXT_IS004"); } else if(is_float<eT>::value == true) { return std::string("ARMA_CUB_TXT_FN004"); } else if(is_double<eT>::value == true) { return std::string("ARMA_CUB_TXT_FN008"); } else if(is_complex_float<eT>::value == true) { return std::string("ARMA_CUB_TXT_FC008"); } else if(is_complex_double<eT>::value == true) { return std::string("ARMA_CUB_TXT_FC016"); } else { return std::string(); } }
std::string diskio::gen_bin_header | ( | const Cube< eT > & | x | ) | [inline, static, inherited] |
Generate the first line of the header used for saving cubes in binary format. //! Format: "ARMA_CUB_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). // B is one of: U (for unsigned types), S (for signed types), N (for not appliable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes.
Definition at line 240 of file diskio_meat.hpp.
{ arma_type_check<diskio::is_supported_type<eT>::value == false>::apply(); if(is_u8<eT>::value == true) { return std::string("ARMA_CUB_BIN_IU001"); } else if(is_s8<eT>::value == true) { return std::string("ARMA_CUB_BIN_IS001"); } else if(is_u16<eT>::value == true) { return std::string("ARMA_CUB_BIN_IU002"); } else if(is_s16<eT>::value == true) { return std::string("ARMA_CUB_BIN_IS002"); } else if(is_u32<eT>::value == true) { return std::string("ARMA_CUB_BIN_IU004"); } else if(is_s32<eT>::value == true) { return std::string("ARMA_CUB_BIN_IS004"); } else if(is_float<eT>::value == true) { return std::string("ARMA_CUB_BIN_FN004"); } else if(is_double<eT>::value == true) { return std::string("ARMA_CUB_BIN_FN008"); } else if(is_complex_float<eT>::value == true) { return std::string("ARMA_CUB_BIN_FC008"); } else if(is_complex_double<eT>::value == true) { return std::string("ARMA_CUB_BIN_FC016"); } else { return std::string(); } }
char diskio::conv_to_hex_char | ( | const u8 | x | ) | [inline, static, inherited] |
Definition at line 304 of file diskio_meat.hpp.
Referenced by conv_to_hex().
{ char out; switch(x) { case 0: out = '0'; break; case 1: out = '1'; break; case 2: out = '2'; break; case 3: out = '3'; break; case 4: out = '4'; break; case 5: out = '5'; break; case 6: out = '6'; break; case 7: out = '7'; break; case 8: out = '8'; break; case 9: out = '9'; break; case 10: out = 'a'; break; case 11: out = 'b'; break; case 12: out = 'c'; break; case 13: out = 'd'; break; case 14: out = 'e'; break; case 15: out = 'f'; break; default: out = '-'; break; } return out; }
void diskio::conv_to_hex | ( | char * | out, | |
const u8 | x | |||
) | [inline, static, inherited] |
Definition at line 336 of file diskio_meat.hpp.
References conv_to_hex_char().
Referenced by gen_tmp_name().
{ const u8 a = x / 16; const u8 b = x - 16*a; out[0] = conv_to_hex_char(a); out[1] = conv_to_hex_char(b); }
std::string diskio::gen_tmp_name | ( | const std::string & | x | ) | [inline, static, inherited] |
Append a quasi-random string to the given filename. //! The rand() function is deliberately not used, //! as rand() has an internal state that changes //! from call to call. Such states should not be //! modified in scientific applications, where the results should be reproducable and not affected //! by saving data.
Definition at line 356 of file diskio_meat.hpp.
References conv_to_hex(), and sum().
Referenced by save_arma_ascii(), save_arma_binary(), save_pgm_binary(), save_ppm_binary(), save_raw_ascii(), and save_std_string().
{ const std::string* ptr_x = &x; const u8* ptr_ptr_x = reinterpret_cast<const u8*>(&ptr_x); const char* extra = ".tmp_"; const u32 extra_size = 5; const u32 tmp_size = 2*sizeof(u8*) + 2*2; char tmp[tmp_size]; u32 char_count = 0; for(u32 i=0; i<sizeof(u8*); ++i) { conv_to_hex(&tmp[char_count], ptr_ptr_x[i]); char_count += 2; } const u32 x_size = x.size(); u8 sum = 0; for(u32 i=0; i<x_size; ++i) { sum += u8(x[i]); } conv_to_hex(&tmp[char_count], sum); char_count += 2; conv_to_hex(&tmp[char_count], u8(x_size)); std::string out; out.resize(x_size + extra_size + tmp_size); for(u32 i=0; i<x_size; ++i) { out[i] = x[i]; } for(u32 i=0; i<extra_size; ++i) { out[x_size + i] = extra[i]; } for(u32 i=0; i<tmp_size; ++i) { out[x_size + extra_size + i] = tmp[i]; } return out; }
bool diskio::safe_rename | ( | const std::string & | old_name, | |
const std::string & | new_name | |||
) | [inline, static, inherited] |
Safely rename a file. //! Before renaming, test if we can write to the final file. //! This should prevent: //! (i) overwriting files that have been write protected, //! (ii) overwriting directories.
Definition at line 420 of file diskio_meat.hpp.
Referenced by save_arma_ascii(), save_arma_binary(), save_pgm_binary(), save_ppm_binary(), save_raw_ascii(), and save_std_string().
{ std::fstream f(new_name.c_str(), std::fstream::out | std::fstream::app); f.put(' '); bool save_okay = f.good(); f.close(); if(save_okay == true) { std::remove(new_name.c_str()); const int mv_result = std::rename(old_name.c_str(), new_name.c_str()); save_okay = (mv_result == 0); } return save_okay; }
bool diskio::save_raw_ascii | ( | const Mat< eT > & | x, | |
const std::string & | final_name | |||
) | [inline, static, inherited] |
Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements.
Definition at line 447 of file diskio_meat.hpp.
References gen_tmp_name(), and safe_rename().
Referenced by Mat< eT >::save(), Cube< eT >::save(), and save_raw_ascii().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_raw_ascii | ( | const Mat< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements.
Definition at line 480 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), Mat< eT >::n_cols, Mat< eT >::n_rows, and Mat< eT >::row().
{ arma_extra_debug_sigprint(); u32 cell_width; // TODO: need sane values for complex numbers if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.setf(ios::scientific); f.precision(8); cell_width = 16; } for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.width(cell_width); } f << x.at(row,col); } f.put('\n'); } return f.good(); }
bool diskio::save_arma_ascii | ( | const Mat< eT > & | x, | |
const std::string & | final_name | |||
) | [inline, static, inherited] |
Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions.
Definition at line 522 of file diskio_meat.hpp.
References gen_tmp_name(), and safe_rename().
Referenced by Mat< eT >::save(), Cube< eT >::save(), and save_arma_ascii().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_arma_ascii | ( | const Mat< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions.
Definition at line 555 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), gen_txt_header(), Mat< eT >::n_cols, Mat< eT >::n_rows, and Mat< eT >::row().
{ arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); f << diskio::gen_txt_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n'; u32 cell_width; // TODO: need sane values for complex numbers if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.setf(ios::scientific); f.precision(8); cell_width = 16; } for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.width(cell_width); } f << x.at(row,col); } f.put('\n'); } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; }
bool diskio::save_arma_binary | ( | const Mat< eT > & | x, | |
const std::string & | final_name | |||
) | [inline, static, inherited] |
Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions.
Definition at line 606 of file diskio_meat.hpp.
References gen_tmp_name(), and safe_rename().
Referenced by Mat< eT >::save(), field_aux::save(), Cube< eT >::save(), and save_arma_binary().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_arma_binary | ( | const Mat< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions.
Definition at line 639 of file diskio_meat.hpp.
References gen_bin_header(), Mat< eT >::mem, Mat< eT >::n_cols, Mat< eT >::n_elem, and Mat< eT >::n_rows.
{ arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n'; f.write(reinterpret_cast<const char*>(x.mem), x.n_elem*sizeof(eT)); return f.good(); }
bool diskio::save_pgm_binary | ( | const Mat< eT > & | x, | |
const std::string & | final_name | |||
) | [inline, static, inherited] |
Save a matrix as a PGM greyscale image.
Definition at line 657 of file diskio_meat.hpp.
References gen_tmp_name(), and safe_rename().
Referenced by Mat< eT >::save(), and save_pgm_binary().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_pgm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_pgm_binary | ( | const Mat< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a matrix as a PGM greyscale image.
Definition at line 694 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), podarray< eT >::mem, Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::row().
{ arma_extra_debug_sigprint(); f << "P5" << '\n'; f << x.n_cols << ' ' << x.n_rows << '\n'; f << 255 << '\n'; const u32 n_elem = x.n_rows * x.n_cols; podarray<u8> tmp(n_elem); u32 i = 0; for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { tmp[i] = u8( x.at(row,col) ); // TODO: add round() ? ++i; } } f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); return f.good(); }
bool diskio::save_pgm_binary | ( | const Mat< std::complex< T > > & | x, | |
const std::string & | final_name | |||
) | [inline, static, inherited] |
Save a matrix as a PGM greyscale image.
Definition at line 727 of file diskio_meat.hpp.
References save_pgm_binary().
{ arma_extra_debug_sigprint(); const uchar_mat tmp = conv_to<uchar_mat>::from(x); return diskio::save_pgm_binary(tmp, final_name); }
bool diskio::save_pgm_binary | ( | const Mat< std::complex< T > > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a matrix as a PGM greyscale image.
Definition at line 742 of file diskio_meat.hpp.
References save_pgm_binary().
{ arma_extra_debug_sigprint(); const uchar_mat tmp = conv_to<uchar_mat>::from(x); return diskio::save_pgm_binary(tmp, f); }
bool diskio::load_raw_ascii | ( | Mat< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header.
Definition at line 759 of file diskio_meat.hpp.
Referenced by Mat< eT >::load(), Cube< eT >::load(), load_auto_detect(), and load_raw_ascii().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_ascii(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_raw_ascii | ( | Mat< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header.
Definition at line 785 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), Mat< eT >::n_cols, Mat< eT >::n_rows, Mat< eT >::row(), and Mat< eT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; //std::fstream::pos_type start = f.tellg(); // // work out the size u32 f_n_rows = 0; u32 f_n_cols = 0; bool f_n_cols_found = false; std::string line_string; std::string token; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) break; std::stringstream line_stream(line_string); u32 line_n_cols = 0; while (line_stream >> token) line_n_cols++; if(f_n_cols_found == false) { f_n_cols = line_n_cols; f_n_cols_found = true; } else { if(line_n_cols != f_n_cols) { err_msg = "inconsistent number of columns in "; load_okay = false; } } ++f_n_rows; } if(load_okay == true) { f.clear(); f.seekg(0, ios::beg); //f.seekg(start); x.set_size(f_n_rows, f_n_cols); eT val; for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { // f >> token; // x.at(row,col) = eT( strtod(token.c_str(), 0) ); f >> val; x.at(row,col) = val; } } } if(f.good() == false) { load_okay = false; } return load_okay; }
bool diskio::load_arma_ascii | ( | Mat< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions.
Definition at line 871 of file diskio_meat.hpp.
Referenced by Mat< eT >::load(), Cube< eT >::load(), load_arma_ascii(), and load_auto_detect().
{ arma_extra_debug_sigprint(); std::ifstream f(name.c_str()); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_ascii(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_arma_ascii | ( | Mat< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions.
Definition at line 895 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), gen_txt_header(), Mat< eT >::n_cols, Mat< eT >::n_rows, Mat< eT >::row(), and Mat< eT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; u32 f_n_rows; u32 f_n_cols; f >> f_header; f >> f_n_rows; f >> f_n_cols; if(f_header == diskio::gen_txt_header(x)) { x.set_size(f_n_rows, f_n_cols); for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f >> x.at(row,col); } } load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; }
bool diskio::load_arma_binary | ( | Mat< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a matrix in binary format, //! with a header that indicates the matrix type as well as its dimensions.
Definition at line 939 of file diskio_meat.hpp.
Referenced by Mat< eT >::load(), field_aux::load(), Cube< eT >::load(), load_arma_binary(), and load_auto_detect().
{ arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_arma_binary | ( | Mat< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 962 of file diskio_meat.hpp.
References gen_bin_header(), Mat< eT >::memptr(), Mat< eT >::n_elem, and Mat< eT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; u32 f_n_rows; u32 f_n_cols; f >> f_header; f >> f_n_rows; f >> f_n_cols; if(f_header == diskio::gen_bin_header(x)) { //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows,f_n_cols); f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT)); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; }
void diskio::pnm_skip_comments | ( | std::istream & | f | ) | [inline, static, inherited] |
Definition at line 999 of file diskio_meat.hpp.
Referenced by load_pgm_binary(), and load_ppm_binary().
{ while( isspace(f.peek()) ) { while( isspace(f.peek()) ) { f.get(); } if(f.peek() == '#') { while( (f.peek() != '\r') && (f.peek()!='\n') ) { f.get(); } } } }
bool diskio::load_pgm_binary | ( | Mat< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a PGM greyscale image as a matrix.
Definition at line 1024 of file diskio_meat.hpp.
Referenced by Mat< eT >::load(), load_auto_detect(), and load_pgm_binary().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_pgm_binary(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_pgm_binary | ( | Mat< eT > & | x, | |
std::istream & | is, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a PGM greyscale image as a matrix.
Definition at line 1048 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), podarray< eT >::memptr(), Mat< eT >::n_elem, pnm_skip_comments(), Mat< eT >::row(), and Mat< eT >::set_size().
{ bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P5") { u32 f_n_rows = 0; u32 f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(f_n_rows,f_n_cols); if(f_maxval <= 255) { const u32 n_elem = f_n_cols*f_n_rows; podarray<u8> tmp(n_elem); f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); u32 i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(u32 row=0; row < f_n_rows; ++row) { for(u32 col=0; col < f_n_cols; ++col) { x.at(row,col) = eT(tmp[i]); ++i; } } } else { const u32 n_elem = f_n_cols*f_n_rows; podarray<u16> tmp(n_elem); f.read( reinterpret_cast<char *>(tmp.memptr()), n_elem*2); u32 i = 0; for(u32 row=0; row < f_n_rows; ++row) { for(u32 col=0; col < f_n_cols; ++col) { x.at(row,col) = eT(tmp[i]); ++i; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; }
bool diskio::load_pgm_binary | ( | Mat< std::complex< T > > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a PGM greyscale image as a matrix.
Definition at line 1146 of file diskio_meat.hpp.
References load_pgm_binary().
{ arma_extra_debug_sigprint(); uchar_mat tmp; const bool load_okay = diskio::load_pgm_binary(tmp, name, err_msg); x = conv_to< Mat< std::complex<T> > >::from(tmp); return load_okay; }
bool diskio::load_pgm_binary | ( | Mat< std::complex< T > > & | x, | |
std::istream & | is, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a PGM greyscale image as a matrix.
Definition at line 1164 of file diskio_meat.hpp.
References load_pgm_binary().
{ arma_extra_debug_sigprint(); uchar_mat tmp; const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg); x = conv_to< Mat< std::complex<T> > >::from(tmp); return load_okay; }
bool diskio::load_auto_detect | ( | Mat< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Try to load a matrix by automatically determining its type.
Definition at line 1182 of file diskio_meat.hpp.
Referenced by Mat< eT >::load(), field_aux::load(), Cube< eT >::load(), and load_auto_detect().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_auto_detect | ( | Mat< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Try to load a matrix by automatically determining its type.
Definition at line 1206 of file diskio_meat.hpp.
References load_arma_ascii(), load_arma_binary(), load_pgm_binary(), and load_raw_ascii().
{ arma_extra_debug_sigprint(); static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT"; static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; static const std::string P5 = "P5"; podarray<char> raw_header(ARMA_MAT_TXT.length() + 1); std::streampos pos = f.tellg(); f.read(raw_header.memptr(), ARMA_MAT_TXT.length()); raw_header[ARMA_MAT_TXT.length()] = '\0'; f.clear(); f.seekg(pos); const std::string header = raw_header.mem; if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) { return load_arma_ascii(x, f, err_msg); } else if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P5 == header.substr(0,P5.length())) { return load_pgm_binary(x, f, err_msg); } else { return load_raw_ascii(x, f, err_msg); } }
bool diskio::save_raw_ascii | ( | const Cube< eT > & | x, | |
const std::string & | name | |||
) | [inline, static, inherited] |
Save a cube as raw text (no header, human readable).
Definition at line 1256 of file diskio_meat.hpp.
References gen_tmp_name(), safe_rename(), and save_raw_ascii().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = save_raw_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_raw_ascii | ( | const Cube< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a cube as raw text (no header, human readable).
Definition at line 1288 of file diskio_meat.hpp.
References Cube< eT >::at(), Mat< eT >::col(), Cube< eT >::n_cols, Cube< eT >::n_rows, Cube< eT >::n_slices, and Mat< eT >::row().
{ arma_extra_debug_sigprint(); u32 cell_width; // TODO: need sane values for complex numbers if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.setf(ios::scientific); f.precision(8); cell_width = 16; } for(u32 slice=0; slice < x.n_slices; ++slice) { for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.width(cell_width); } f << x.at(row,col,slice); } f.put('\n'); } } return f.good(); }
bool diskio::save_arma_ascii | ( | const Cube< eT > & | x, | |
const std::string & | name | |||
) | [inline, static, inherited] |
Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions.
Definition at line 1333 of file diskio_meat.hpp.
References gen_tmp_name(), safe_rename(), and save_arma_ascii().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_arma_ascii | ( | const Cube< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions.
Definition at line 1366 of file diskio_meat.hpp.
References Cube< eT >::at(), Mat< eT >::col(), gen_txt_header(), Cube< eT >::n_cols, Cube< eT >::n_rows, Cube< eT >::n_slices, and Mat< eT >::row().
{ arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); f << diskio::gen_txt_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; u32 cell_width; // TODO: need sane values for complex numbers if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.setf(ios::scientific); f.precision(8); cell_width = 16; } for(u32 slice=0; slice < x.n_slices; ++slice) { for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float<eT>::value == true) || (is_double<eT>::value == true) ) { f.width(cell_width); } f << x.at(row,col,slice); } f.put('\n'); } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; }
bool diskio::save_arma_binary | ( | const Cube< eT > & | x, | |
const std::string & | name | |||
) | [inline, static, inherited] |
Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions.
Definition at line 1420 of file diskio_meat.hpp.
References gen_tmp_name(), safe_rename(), and save_arma_binary().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_arma_binary | ( | const Cube< eT > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions.
Definition at line 1453 of file diskio_meat.hpp.
References gen_bin_header(), Cube< eT >::mem, Cube< eT >::n_cols, Cube< eT >::n_elem, Cube< eT >::n_rows, and Cube< eT >::n_slices.
bool diskio::load_raw_ascii | ( | Cube< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header.
Definition at line 1472 of file diskio_meat.hpp.
References load_raw_ascii(), Mat< eT >::n_cols, Mat< eT >::n_rows, Cube< eT >::n_slices, Cube< eT >::set_size(), and Cube< eT >::slice().
bool diskio::load_raw_ascii | ( | Cube< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header.
Definition at line 1500 of file diskio_meat.hpp.
References load_raw_ascii(), Mat< eT >::n_cols, Mat< eT >::n_rows, Cube< eT >::n_slices, Cube< eT >::set_size(), and Cube< eT >::slice().
bool diskio::load_arma_ascii | ( | Cube< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions.
Definition at line 1528 of file diskio_meat.hpp.
References load_arma_ascii().
{ arma_extra_debug_sigprint(); std::ifstream f(name.c_str()); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_ascii(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_arma_ascii | ( | Cube< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions.
Definition at line 1552 of file diskio_meat.hpp.
References Cube< eT >::at(), Mat< eT >::col(), gen_txt_header(), Cube< eT >::n_cols, Cube< eT >::n_rows, Cube< eT >::n_slices, Mat< eT >::row(), and Cube< eT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; u32 f_n_rows; u32 f_n_cols; u32 f_n_slices; f >> f_header; f >> f_n_rows; f >> f_n_cols; f >> f_n_slices; if(f_header == diskio::gen_txt_header(x)) { x.set_size(f_n_rows, f_n_cols, f_n_slices); for(u32 slice=0; slice < x.n_slices; ++slice) { for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f >> x.at(row,col,slice); } } } load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; }
bool diskio::load_arma_binary | ( | Cube< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Load a cube in binary format, //! with a header that indicates the cube type as well as its dimensions.
Definition at line 1601 of file diskio_meat.hpp.
References load_arma_binary().
{ arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_arma_binary | ( | Cube< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 1624 of file diskio_meat.hpp.
References gen_bin_header(), Cube< eT >::memptr(), Cube< eT >::n_elem, and Cube< eT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; u32 f_n_rows; u32 f_n_cols; u32 f_n_slices; f >> f_header; f >> f_n_rows; f >> f_n_cols; f >> f_n_slices; if(f_header == diskio::gen_bin_header(x)) { //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows, f_n_cols, f_n_slices); f.read( reinterpret_cast<char *>(x.memptr()), x.n_elem*sizeof(eT)); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; }
bool diskio::load_auto_detect | ( | Cube< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Try to load a cube by automatically determining its type.
Definition at line 1665 of file diskio_meat.hpp.
References load_auto_detect().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_auto_detect | ( | Cube< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Try to load a cube by automatically determining its type.
Definition at line 1689 of file diskio_meat.hpp.
References load_arma_ascii(), load_arma_binary(), load_ppm_binary(), and load_raw_ascii().
{ arma_extra_debug_sigprint(); static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT"; static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; static const std::string P6 = "P6"; podarray<char> raw_header(ARMA_CUB_TXT.length() + 1); std::streampos pos = f.tellg(); f.read(raw_header.memptr(), ARMA_CUB_TXT.length()); raw_header[ARMA_CUB_TXT.length()] = '\0'; f.clear(); f.seekg(pos); const std::string header = raw_header.mem; if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) { return load_arma_ascii(x, f, err_msg); } else if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P6 == header.substr(0, P6.length())) { return load_ppm_binary(x, f, err_msg); } else { return load_raw_ascii(x, f, err_msg); } }
bool diskio::save_arma_binary | ( | const field< T1 > & | x, | |
const std::string & | name | |||
) | [inline, static, inherited] |
Definition at line 1740 of file diskio_meat.hpp.
References gen_tmp_name(), safe_rename(), and save_arma_binary().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_arma_binary | ( | const field< T1 > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Definition at line 1771 of file diskio_meat.hpp.
References field< oT >::n_cols, field< oT >::n_elem, field< oT >::n_rows, and save_arma_binary().
{ arma_extra_debug_sigprint(); arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == false) >::apply(); f << "ARMA_FLD_BIN" << '\n'; f << x.n_rows << '\n'; f << x.n_cols << '\n'; bool save_okay = true; for(u32 i=0; i<x.n_elem; ++i) { save_okay = diskio::save_arma_binary(x[i], f); if(save_okay == false) { break; } } return save_okay; }
bool diskio::load_arma_binary | ( | field< T1 > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 1801 of file diskio_meat.hpp.
References load_arma_binary().
{ arma_extra_debug_sigprint(); std::ifstream f( name.c_str(), std::fstream::binary ); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_arma_binary | ( | field< T1 > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 1823 of file diskio_meat.hpp.
References load_arma_binary(), field< oT >::n_elem, and field< oT >::set_size().
{ arma_extra_debug_sigprint(); arma_type_check< (is_Mat<T1>::value == false) && (is_Cube<T1>::value == false) >::apply(); bool load_okay = true; std::string f_type; f >> f_type; if(f_type != "ARMA_FLD_BIN") { load_okay = false; err_msg = "unsupported field type in "; } else { u32 f_n_rows; u32 f_n_cols; f >> f_n_rows; f >> f_n_cols; x.set_size(f_n_rows, f_n_cols); f.get(); for(u32 i=0; i<x.n_elem; ++i) { load_okay = diskio::load_arma_binary(x[i], f, err_msg); if(load_okay == false) { break; } } } return load_okay; }
bool diskio::save_std_string | ( | const field< std::string > & | x, | |
const std::string & | name | |||
) | [inline, static, inherited] |
Definition at line 1869 of file diskio_meat.hpp.
References gen_tmp_name(), and safe_rename().
Referenced by field_aux::save().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_std_string(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_std_string | ( | const field< std::string > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Definition at line 1899 of file diskio_meat.hpp.
References field< oT >::at(), Mat< eT >::col(), field< oT >::n_cols, field< oT >::n_rows, and Mat< eT >::row().
bool diskio::load_std_string | ( | field< std::string > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 1925 of file diskio_meat.hpp.
Referenced by field_aux::load().
{ arma_extra_debug_sigprint(); std::ifstream f( name.c_str() ); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_std_string(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_std_string | ( | field< std::string > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 1946 of file diskio_meat.hpp.
References field< oT >::at(), Mat< eT >::col(), field< oT >::n_cols, field< oT >::n_rows, Mat< eT >::row(), and field< oT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; // // work out the size u32 f_n_rows = 0; u32 f_n_cols = 0; bool f_n_cols_found = false; std::string line_string; std::string token; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) break; std::stringstream line_stream(line_string); u32 line_n_cols = 0; while (line_stream >> token) line_n_cols++; if(f_n_cols_found == false) { f_n_cols = line_n_cols; f_n_cols_found = true; } else { if(line_n_cols != f_n_cols) { load_okay = false; err_msg = "inconsistent number of columns in "; } } ++f_n_rows; } if(load_okay == true) { f.clear(); f.seekg(0, ios::beg); //f.seekg(start); x.set_size(f_n_rows, f_n_cols); for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { f >> x.at(row,col); } } } if(f.good() == false) { load_okay = false; } return load_okay; }
bool diskio::load_auto_detect | ( | field< T1 > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Try to load a field by automatically determining its type.
Definition at line 2023 of file diskio_meat.hpp.
References load_auto_detect().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_auto_detect | ( | field< T1 > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Try to load a field by automatically determining its type.
Definition at line 2047 of file diskio_meat.hpp.
References load_arma_binary(), and load_ppm_binary().
{ arma_extra_debug_sigprint(); arma_type_check<is_Mat<T1>::value == false>::apply(); static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; static const std::string P6 = "P6"; podarray<char> raw_header(ARMA_FLD_BIN.length() + 1); std::streampos pos = f.tellg(); f.read(raw_header.memptr(), ARMA_FLD_BIN.length()); f.clear(); f.seekg(pos); raw_header[ARMA_FLD_BIN.length()] = '\0'; const std::string header = raw_header.mem; if(ARMA_FLD_BIN == header.substr(0, ARMA_FLD_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P6 == header.substr(0, P6.length())) { return load_ppm_binary(x, f, err_msg); } else { err_msg = "unsupported header in "; return false; } }
bool diskio::load_ppm_binary | ( | Cube< eT > & | x, | |
const std::string & | name, | |||
std::string & | err_msg | |||
) | [inline, inherited] |
Definition at line 2094 of file diskio_meat.hpp.
References load_ppm_binary().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_ppm_binary(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_ppm_binary | ( | Cube< eT > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, inherited] |
Definition at line 2117 of file diskio_meat.hpp.
References Cube< eT >::at(), Mat< eT >::col(), podarray< eT >::memptr(), Mat< eT >::n_elem, pnm_skip_comments(), Mat< eT >::row(), and Cube< eT >::set_size().
{ arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P6") { u32 f_n_rows = 0; u32 f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(f_n_rows, f_n_cols, 3); if(f_maxval <= 255) { const u32 n_elem = 3*f_n_cols*f_n_rows; podarray<u8> tmp(n_elem); f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); u32 i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(u32 row=0; row < f_n_rows; ++row) { for(u32 col=0; col < f_n_cols; ++col) { x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,1) = eT(tmp[i+1]); x.at(row,col,2) = eT(tmp[i+2]); i+=3; } } } else { const u32 n_elem = 3*f_n_cols*f_n_rows; podarray<u16> tmp(n_elem); f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); u32 i = 0; for(u32 row=0; row < f_n_rows; ++row) { for(u32 col=0; col < f_n_cols; ++col) { x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,1) = eT(tmp[i+1]); x.at(row,col,2) = eT(tmp[i+2]); i+=3; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; }
bool diskio::save_ppm_binary | ( | const Cube< eT > & | x, | |
const std::string & | final_name | |||
) | [inline, inherited] |
Definition at line 2222 of file diskio_meat.hpp.
References gen_tmp_name(), safe_rename(), and save_ppm_binary().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_ppm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_ppm_binary | ( | const Cube< eT > & | x, | |
std::ostream & | f | |||
) | [inline, inherited] |
Definition at line 2253 of file diskio_meat.hpp.
References Cube< eT >::at(), Mat< eT >::col(), podarray< eT >::mem, Cube< eT >::n_cols, Mat< eT >::n_elem, Cube< eT >::n_rows, Cube< eT >::n_slices, Mat< eT >::row(), and access::tmp_real().
{ arma_extra_debug_sigprint(); arma_debug_check( (x.n_slices != 3), "diskio::save_ppm_binary(): given cube must have exactly 3 slices" ); const u32 n_elem = 3 * x.n_rows * x.n_cols; podarray<u8> tmp(n_elem); u32 i = 0; for(u32 row=0; row < x.n_rows; ++row) { for(u32 col=0; col < x.n_cols; ++col) { tmp[i+0] = u8( access::tmp_real( x.at(row,col,0) ) ); tmp[i+1] = u8( access::tmp_real( x.at(row,col,1) ) ); tmp[i+2] = u8( access::tmp_real( x.at(row,col,2) ) ); i+=3; } } f << "P6" << '\n'; f << x.n_cols << '\n'; f << x.n_rows << '\n'; f << 255 << '\n'; f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); return f.good(); }
bool diskio::load_ppm_binary | ( | field< T1 > & | x, | |
const std::string & | final_name, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 2295 of file diskio_meat.hpp.
References load_ppm_binary().
{ arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_ppm_binary(x, f, err_msg); f.close(); } return load_okay; }
bool diskio::load_ppm_binary | ( | field< T1 > & | x, | |
std::istream & | f, | |||
std::string & | err_msg | |||
) | [inline, static, inherited] |
Definition at line 2318 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), podarray< eT >::memptr(), Mat< eT >::n_elem, pnm_skip_comments(), Mat< eT >::row(), Mat< eT >::set_size(), and field< oT >::set_size().
{ arma_extra_debug_sigprint(); arma_type_check<is_Mat<T1>::value == false>::apply(); typedef typename T1::elem_type eT; bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P6") { u32 f_n_rows = 0; u32 f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(3); Mat<eT>& R = x(0); Mat<eT>& G = x(1); Mat<eT>& B = x(2); R.set_size(f_n_rows,f_n_cols); G.set_size(f_n_rows,f_n_cols); B.set_size(f_n_rows,f_n_cols); if(f_maxval <= 255) { const u32 n_elem = 3*f_n_cols*f_n_rows; podarray<u8> tmp(n_elem); f.read( reinterpret_cast<char*>(tmp.memptr()), n_elem); u32 i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(u32 row=0; row < f_n_rows; ++row) { for(u32 col=0; col < f_n_cols; ++col) { R.at(row,col) = eT(tmp[i+0]); G.at(row,col) = eT(tmp[i+1]); B.at(row,col) = eT(tmp[i+2]); i+=3; } } } else { const u32 n_elem = 3*f_n_cols*f_n_rows; podarray<u16> tmp(n_elem); f.read( reinterpret_cast<char *>(tmp.memptr()), 2*n_elem); u32 i = 0; for(u32 row=0; row < f_n_rows; ++row) { for(u32 col=0; col < f_n_cols; ++col) { R.at(row,col) = eT(tmp[i+0]); G.at(row,col) = eT(tmp[i+1]); B.at(row,col) = eT(tmp[i+2]); i+=3; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; }
bool diskio::save_ppm_binary | ( | const field< T1 > & | x, | |
const std::string & | final_name | |||
) | [inline, static, inherited] |
Definition at line 2433 of file diskio_meat.hpp.
References gen_tmp_name(), safe_rename(), and save_ppm_binary().
{ arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_ppm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; }
bool diskio::save_ppm_binary | ( | const field< T1 > & | x, | |
std::ostream & | f | |||
) | [inline, static, inherited] |
Definition at line 2463 of file diskio_meat.hpp.
References Mat< eT >::at(), Mat< eT >::col(), podarray< eT >::mem, Mat< eT >::n_cols, Mat< eT >::n_elem, field< oT >::n_elem, Mat< eT >::n_rows, Mat< eT >::row(), and access::tmp_real().
{ arma_extra_debug_sigprint(); arma_type_check<is_Mat<T1>::value == false>::apply(); typedef typename T1::elem_type eT; arma_debug_check( (x.n_elem != 3), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); bool same_size = true; for(u32 i=1; i<3; ++i) { if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) ) { same_size = false; break; } } arma_debug_check( (same_size != true), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); const Mat<eT>& R = x(0); const Mat<eT>& G = x(1); const Mat<eT>& B = x(2); f << "P6" << '\n'; f << R.n_cols << '\n'; f << R.n_rows << '\n'; f << 255 << '\n'; const u32 n_elem = 3 * R.n_rows * R.n_cols; podarray<u8> tmp(n_elem); u32 i = 0; for(u32 row=0; row < R.n_rows; ++row) { for(u32 col=0; col < R.n_cols; ++col) { tmp[i+0] = u8( access::tmp_real( R.at(row,col) ) ); tmp[i+1] = u8( access::tmp_real( G.at(row,col) ) ); tmp[i+2] = u8( access::tmp_real( B.at(row,col) ) ); i+=3; } } f.write(reinterpret_cast<const char*>(tmp.mem), n_elem); return f.good(); }