// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ian Cullinan // Written by Ryan Curtin // Written by Szabolcs Horvat //! \addtogroup diskio //! @{ //! class for saving and loading matrices and fields class diskio { public: template inline static std::string gen_txt_header(const Mat& x); template inline static std::string gen_bin_header(const Mat& x); template inline static std::string gen_bin_header(const SpMat& x); template inline static std::string gen_txt_header(const Cube& x); template inline static std::string gen_bin_header(const Cube& x); inline static file_type guess_file_type(std::istream& f); inline arma_cold static std::string gen_tmp_name(const std::string& x); inline arma_cold static bool safe_rename(const std::string& old_name, const std::string& new_name); template inline static bool convert_naninf(eT& val, const std::string& token); template inline static bool convert_naninf(std::complex& val, const std::string& token); // // matrix saving template inline static bool save_raw_ascii (const Mat& x, const std::string& final_name); template inline static bool save_raw_binary (const Mat& x, const std::string& final_name); template inline static bool save_arma_ascii (const Mat& x, const std::string& final_name); template inline static bool save_csv_ascii (const Mat& x, const std::string& final_name); template inline static bool save_arma_binary(const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat< std::complex >& x, const std::string& final_name); template inline static bool save_hdf5_binary(const Mat& x, const std::string& final_name); template inline static bool save_raw_ascii (const Mat& x, std::ostream& f); template inline static bool save_raw_binary (const Mat& x, std::ostream& f); template inline static bool save_arma_ascii (const Mat& x, std::ostream& f); template inline static bool save_csv_ascii (const Mat& x, std::ostream& f); template inline static bool save_arma_binary(const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat< std::complex >& x, std::ostream& f); // // matrix loading template inline static bool load_raw_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, std::istream& is, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, std::istream& is, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, std::istream& f, std::string& err_msg); inline static void pnm_skip_comments(std::istream& f); // // sparse matrix saving template inline static bool save_coord_ascii(const SpMat& x, const std::string& final_name); template inline static bool save_arma_binary(const SpMat& x, const std::string& final_name); template inline static bool save_coord_ascii(const SpMat& x, std::ostream& f); template inline static bool save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f); template inline static bool save_arma_binary(const SpMat& x, std::ostream& f); // // sparse matrix loading template inline static bool load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg); template inline static bool load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg); // // cube saving template inline static bool save_raw_ascii (const Cube& x, const std::string& name); template inline static bool save_raw_binary (const Cube& x, const std::string& name); template inline static bool save_arma_ascii (const Cube& x, const std::string& name); template inline static bool save_arma_binary(const Cube& x, const std::string& name); template inline static bool save_hdf5_binary(const Cube& x, const std::string& name); template inline static bool save_raw_ascii (const Cube& x, std::ostream& f); template inline static bool save_raw_binary (const Cube& x, std::ostream& f); template inline static bool save_arma_ascii (const Cube& x, std::ostream& f); template inline static bool save_arma_binary(const Cube& x, std::ostream& f); // // cube loading template inline static bool load_raw_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, std::istream& f, std::string& err_msg); // // field saving and loading template inline static bool save_arma_binary(const field& x, const std::string& name); template inline static bool save_arma_binary(const field& x, std::ostream& f); template inline static bool load_arma_binary( field& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary( field& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect( field& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect( field& x, std::istream& f, std::string& err_msg); inline static bool save_std_string(const field& x, const std::string& name); inline static bool save_std_string(const field& x, std::ostream& f); inline static bool load_std_string( field& x, const std::string& name, std::string& err_msg); inline static bool load_std_string( field& x, std::istream& f, std::string& err_msg); // // handling of PPM images by cubes template inline static bool save_ppm_binary(const Cube& x, const std::string& final_name); template inline static bool save_ppm_binary(const Cube& x, std::ostream& f); template inline static bool load_ppm_binary( Cube& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( Cube& x, std::istream& f, std::string& err_msg); // // handling of PPM images by fields template inline static bool save_ppm_binary(const field& x, const std::string& final_name); template inline static bool save_ppm_binary(const field& x, std::ostream& f); template inline static bool load_ppm_binary( field& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( field& x, std::istream& f, std::string& err_msg); }; //! @}