#include "writeDMAT.h" #include #ifndef IGL_NO_EIGEN # include #endif template IGL_INLINE bool igl::writeDMAT(const std::string file_name, const Mat & W) { FILE * fp = fopen(file_name.c_str(),"w"); if(fp == NULL) { fprintf(stderr,"IOError: writeDMAT() could not open %s...",file_name.c_str()); return false; } // first line contains number of rows and number of columns fprintf(fp,"%d %d\n",(int)W.cols(),(int)W.rows()); // Loop over columns slowly for(int j = 0;j < W.cols();j++) { // loop over rows (down columns) quickly for(int i = 0;i < W.rows();i++) { fprintf(fp,"%0.17lg\n",(double)W(i,j)); } } fclose(fp); return true; } template IGL_INLINE bool igl::writeDMAT( const std::string file_name, const std::vector > W) { FILE * fp = fopen(file_name.c_str(),"w"); if(fp == NULL) { fprintf(stderr,"IOError: writeDMAT() could not open %s...",file_name.c_str()); return false; } int num_rows = (int)W.size(); int num_cols = 0; if(num_rows > 0) { num_cols = W[0].size(); } // first line contains number of columns and number of rows fprintf(fp,"%d %d\n",num_cols,num_rows); // Loop over columns slowly for(int j = 0;j < num_cols;j++) { // loop over rows (down columns) quickly for(int i = 0;i < num_rows;i++) { // better be rectangular assert((int)W[i].size() > j); fprintf(fp,"%0.15lf\n",(double)W[i][j]); } } fclose(fp); return true; } #ifndef IGL_HEADER_ONLY // Explicit template specialization // generated by autoexplicit.sh template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::Matrix const&); template bool igl::writeDMAT(std::basic_string, std::allocator >, std::vector >, std::allocator > > >); template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::Matrix const&); template bool igl::writeDMAT >(std::basic_string, std::allocator >, Eigen::Matrix const&); #endif