writeDMAT.cpp 984 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "writeDMAT.h"
  2. #include <cstdio>
  3. #include <Eigen/Dense>
  4. template <class Mat>
  5. IGL_INLINE bool igl::writeDMAT(const std::string file_name, const Mat & W)
  6. {
  7. FILE * fp = fopen(file_name.c_str(),"w");
  8. if(fp == NULL)
  9. {
  10. fprintf(stderr,"IOError: writeDMAT() could not open %s...",file_name.c_str());
  11. return false;
  12. }
  13. // first line contains number of rows and number of columns
  14. fprintf(fp,"%d %d\n",(int)W.cols(),(int)W.rows());
  15. // Loop over columns slowly
  16. for(int j = 0;j < W.cols();j++)
  17. {
  18. // loop over rows (down columns) quickly
  19. for(int i = 0;i < W.rows();i++)
  20. {
  21. fprintf(fp,"%lg\n",(double)W(i,j));
  22. }
  23. }
  24. fclose(fp);
  25. return true;
  26. }
  27. #ifndef IGL_HEADER_ONLY
  28. // Explicit template specialization
  29. // generated by autoexplicit.sh
  30. template bool igl::writeDMAT<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&);
  31. #endif