writeDMAT.cpp 735 B

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