Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_IO_GRID_MATLAB_WRITE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_IO_GRID_MATLAB_WRITE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <iostream>
00013 #include <fstream>
00014 #include <string>
00015
00016 namespace OpenTissue
00017 {
00018 namespace grid
00019 {
00020
00029 template <typename grid_type>
00030 inline bool matlab_write(std::string const & mfile, grid_type const & grid)
00031 {
00032 typedef typename grid_type::value_type value_type;
00033 typedef typename grid_type::math_types math_types;
00034 typedef typename math_types::vector3_type vector3_type;
00035 typedef typename math_types::real_type real_type;
00036
00037 std::ofstream file(mfile.c_str());
00038 file.precision(30);
00039
00040 value_type * value = grid.data();
00041 for (size_t k=0; k<grid.K(); ++k)
00042 {
00043 file << "mfile(:,:," << k+1 << ") = [ " ;
00044 for (size_t j=0; j<grid.J(); ++j)
00045 {
00046 file << "[ " ;
00047
00048 for (size_t i=0; i<grid.I()-1; ++i, value++)
00049 {
00050 file << static_cast<double>(*value) << ", " ;
00051 }
00052 file << static_cast<double>(*value++) << "];" << std::endl;
00053 }
00054 file << "];" << std::endl;
00055 }
00056 file.flush();
00057 file.close();
00058 return true;
00059 }
00060
00061 }
00062 }
00063
00064
00065 #endif