1#ifndef DUNE_GRID_IO_FILE_TEST_CHECKVTKFILE_HH
2#define DUNE_GRID_IO_FILE_TEST_CHECKVTKFILE_HH
20inline std::string pyq(
const std::string &s)
22 std::ostringstream result;
23 for(std::size_t i = 0; i < s.size(); ++i)
27 case '\'': result <<
"\\'";
break;
28 case '\\': result <<
"\\\\";
break;
29 case '\n': result <<
"\\n";
break;
31 if(c < 32 || c >= 127)
32 result <<
"\\x" << std::hex << std::setfill(
'0') << std::setw(2)
33 <<
static_cast<int>(c);
43inline std::string shq(
const std::string &s)
45 std::ostringstream result;
47 for(std::size_t i = 0; i < s.size(); ++i)
52 "Can't pass \\0 through the shell");
53 case '\'': result << (pend ?
"" :
"'") <<
"\\'"; pend =
true;
break;
54 default: result << (pend ?
"'" :
"") << c; pend =
false;
break;
57 if(pend) result <<
"'";
61inline int runShell(
const std::string &code)
63 int result = std::system(code.c_str());
68 return WEXITSTATUS(result);
69 if(WIFSIGNALED(result))
70 return WTERMSIG(result) + 256;
75inline int runPython(
const std::string &code)
77 return runShell(
"python -c '"+shq(code)+
"'");
80inline bool is_suffix(
const std::string &s,
const std::string &suffix)
82 return s.size() >= suffix.size() &&
83 s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0;
86inline int checkVTKFile(
const std::string &name)
88 static const bool havePythonVTK = (runPython(
"from vtk import *") == 0);
91 std::cerr <<
"warning: python or python vtk module not available"
93 std::cerr <<
"skip: " << name << std::endl;
98 if (is_suffix(name,
".vtu")) reader =
"vtkXMLUnstructuredGridReader";
99 else if(is_suffix(name,
".pvtu")) reader =
"vtkXMLPUnstructuredGridReader";
100 else if(is_suffix(name,
".vtp")) reader =
"vtkXMLPolyDataReader";
101 else if(is_suffix(name,
".pvtp")) reader =
"vtkXMLPPolyDataReader";
103 "Unknown vtk file extension: " << name);
105 std::cout <<
"Loading " << name <<
" using python vtk" << std::endl;
109 "reader = "+reader+
"();"
110 "reader.SetFileName('"+pyq(name)+
"');"
113 "sys.exit(not (reader.GetOutput().GetNumberOfCells() > 0));";
114 int result = runPython(pycode);
115 std::cout << (result == 0 ?
"pass: " :
"fail: ") << name << std::endl;
Default exception for dummy implementations.
Definition: exceptions.hh:288
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243