42 #define VTK_EMPTY_CELL 0
44 #define VTK_POLY_VERTEX 2
46 #define VTK_POLY_LINE 4
47 #define VTK_TRIANGLE 5
48 #define VTK_TRIANGLE_STRIP 6
54 #define VTK_HEXAHEDRON 12
56 #define VTK_PYRAMID 14
57 #define VTK_PENTAGONAL_PRISM 15
58 #define VTK_HEXAGONAL_PRISM 16
61 #define VTK_QUADRATIC_EDGE 21
62 #define VTK_QUADRATIC_TRIANGLE 22
63 #define VTK_QUADRATIC_QUAD 23
64 #define VTK_QUADRATIC_TETRA 24
65 #define VTK_QUADRATIC_HEXAHEDRON 25
66 #define VTK_QUADRATIC_WEDGE 26
67 #define VTK_QUADRATIC_PYRAMID 27
70 #define VTK_CONVEX_POINT_SET 41
73 #define VTK_PARAMETRIC_CURVE 51
74 #define VTK_PARAMETRIC_SURFACE 52
75 #define VTK_PARAMETRIC_TRI_SURFACE 53
76 #define VTK_PARAMETRIC_QUAD_SURFACE 54
77 #define VTK_PARAMETRIC_TETRA_REGION 55
78 #define VTK_PARAMETRIC_HEX_REGION 56
81 #define SwitchOnDataType(dType, funcCall) \
88 case COM_UNSIGNED_CHAR: \
89 { typedef unsigned char TT; \
96 case COM_UNSIGNED_SHORT: \
97 { typedef unsigned short TT; \
105 { typedef unsigned int TT; \
112 case COM_UNSIGNED_LONG: \
113 { typedef unsigned long TT; \
117 { typedef float TT; \
121 { typedef double TT; \
124 case COM_LONG_DOUBLE: \
125 { typedef long double TT; \
145 template <
typename TT>
147 const int* dims_nodes,
int ghost,
char loc,
150 const int dims[3] = { dims_nodes[0] - (loc ==
'e'),
151 ndims >= 2 ? dims_nodes[1] - (loc ==
'e') : 0,
152 ndims >= 3 ? dims_nodes[2] - (loc ==
'e') : 0 };
154 const int last[3] = { dims[0] - ghost,
155 ndims >= 2 ? dims[1] - ghost : 0,
156 ndims >= 3 ? dims[2] - ghost : 0 };
161 for (i=ghost; i<last[0]; ++
i) {
162 for (c=0; c<nComp; ++c)
163 out << (pData[c] ? pData[c][i] : (TT)-987654321) <<
' ';
169 for (j=ghost; j<last[1]; ++
j)
170 for (i=ghost; i<last[0]; ++
i) {
171 for (c=0; c<nComp; ++c)
172 out << (pData[c] ? pData[c][i+j*dims[0]] : (TT)-987654321) <<
' ';
178 for (k=ghost; k<last[2]; ++
k)
179 for (j=ghost; j<last[1]; ++
j)
180 for (i=ghost; i<last[0]; ++
i) {
181 for (c=0; c<nComp; ++c)
182 out << (pData[c] ? pData[c][i+j*dims[0]+k*dims[0]*dims[1]]
183 : (TT)-987654321) <<
' ';
190 template <
typename TT>
194 for (i=0; i<size; ++
i) {
195 for (c=0; c<nComp; ++c)
196 out << (pData[c] ? pData[c][i] : (TT)-987654321) <<
' ';
207 std::istringstream
sin(ci.
m_type.substr(1));
214 for (elem=0; elem<ne; ++elem) {
223 const std::string& file_in,
bool mesh_only)
225 static std::map<int, std::string> DataTypeAsString;
226 static std::map<std::string, int> COM2VTK;
227 if (DataTypeAsString.empty()) {
228 DataTypeAsString[
COM_CHAR] =
"char";
229 DataTypeAsString[
COM_BYTE] =
"char";
233 DataTypeAsString[
COM_INT] =
"int";
235 DataTypeAsString[
COM_LONG] =
"long";
242 if (COM2VTK.empty()) {
271 std::vector<AttrInfo> attrs(nAttrs+1);
272 attrs[0].m_name =
"nc";
274 &(attrs[0].m_location), &(attrs[0].m_dataType),
275 &(attrs[0].m_numComp), &(attrs[0].m_units));
279 std::istringstream
sin(attrStr);
280 for (i=1; i<nAttrs+1; ++
i) {
281 sin >> attrs[
i].m_name;
283 &(attrs[i].m_location), &(attrs[i].m_dataType),
284 &(attrs[i].m_numComp), &(attrs[i].m_units));
289 std::set<char> locset;
290 std::vector<AttrInfo>::iterator p = attrs.begin();
292 while (p != attrs.end()) {
293 char loc = (*p).m_location;
294 if (loc ==
'w' || loc ==
'p') {
303 for (i=0; i<nPanes; ++
i) {
306 std::string file_out(file_in.substr(0, file_in.rfind(
'.')) +
".vtk");
307 out.open(file_out.c_str());
309 std::ostringstream sout;
310 sout << wName <<
'_' << timeStr <<
"_"
311 << std::setw(4) << std::setfill(
'0') << i <<
".vtk";
312 out.open(sout.str().c_str());
315 out <<
"# vtk DataFile Version 2.0" << std::endl;
316 out <<
"Material=" << wName <<
", Block=" << i <<
", Time: " << timeStr
318 out <<
"ASCII" << std::endl;
323 name = wName +
".nc";
332 const int* dims = NULL;
333 int ndims, eTotal = 0, eSize = 0;
334 std::vector<ConnInfo> connInfo(nConn);
335 std::vector<std::pair<int, int> > cellTypes;
336 if (nConn == 1 && strncmp(connNames,
":st", 3) == 0) {
337 name = wName +
'.' + connNames;
341 COM_get_array_const(name.c_str(), paneIds[
i], &dims);
343 out <<
"DATASET STRUCTURED_GRID" << std::endl;
344 out <<
"DIMENSIONS " << dims[0] - 2 * ghost <<
" " << dims[1] - 2 * ghost
345 <<
" " << dims[2] - 2 * ghost << std::endl;
347 eTotal = (dims[0] - 2 * ghost > 1 ? dims[0] - 2 * ghost - 1 : 1)
348 * (dims[1] - 2 * ghost > 1 ? dims[1] - 2 * ghost - 1 : 1)
349 * (dims[2] - 2 * ghost > 1 ? dims[2] - 2 * ghost - 1 : 1);
351 out <<
"DATASET UNSTRUCTURED_GRID" << std::endl;
353 std::istringstream
sin(connNames);
354 std::vector<ConnInfo>::iterator c;
355 for (c=connInfo.begin(); c!=connInfo.end(); ++c) {
357 (*c).m_name = wName +
'.' + (*c).m_type;
358 (*c).m_type.erase(0, 1);
359 std::string::size_type
x = (*c).m_type.find(
':', 2);
360 if (x != std::string::npos)
361 (*c).m_type.erase(x);
363 COM_get_size((*c).m_name.c_str(), paneIds[
i], &((*c).m_numElements),
365 eTotal += (*c).m_numElements - (*c).m_numGhost;
368 if ((*c).m_type ==
"q9")
371 std::istringstream
sin((*c).m_type.substr(1));
374 eSize += ((*c).m_numElements - (*c).m_numGhost) * (nn + 1);
376 cellTypes.push_back(std::pair<int, int>(COM2VTK[(*c).m_type],
377 (*c).m_numElements - (*c).m_numGhost));
381 out <<
"POINTS " << nNodes <<
' ' << DataTypeAsString[attrs[0].m_dataType]
383 const void* pArray[9] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
387 for (comp=1; comp<=(*p).m_numComp; ++comp) {
388 std::ostringstream sout;
389 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
390 COM_get_array_const(sout.str().c_str(), paneIds[
i], &(pArray[comp-1]));
396 ndims, dims, ghost, (*p).m_location,
404 if (nConn != 1 || strncmp(connNames,
":st", 3) != 0) {
405 out <<
"CELLS " << eTotal <<
' ' << eSize << std::endl;
407 std::vector<ConnInfo>::iterator c;
408 for (c=connInfo.begin(); c!=connInfo.end(); ++c) {
409 const int* pConn = NULL;
410 COM_get_array_const((*c).m_name.c_str(), paneIds[
i], &pConn);
414 out <<
"CELL_TYPES " << eTotal << std::endl;
417 std::vector<std::pair<int, int> >::iterator t = cellTypes.begin();
418 while (t != cellTypes.end()) {
419 for (i=0; i<(*t).second; ++
i)
420 out << (*t).first << std::endl;
428 if (!mesh_only && locset.count(
'n') > 0) {
429 out <<
"POINT_DATA " << nNodes << std::endl;
430 for (p=attrs.begin(); p!=attrs.end(); ++p) {
431 if ((*p).m_location !=
'n')
434 if ((*p).m_numComp == 1) {
435 COM_get_array_const((wName +
'.' + (*p).m_name).c_str(), paneIds[
i],
440 for (comp=1; comp<=(*p).m_numComp; ++comp) {
441 std::ostringstream sout;
442 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
443 COM_get_array_const(sout.str().c_str(), paneIds[
i],
446 if ((*p).m_numComp == 3)
452 out << (*p).m_name <<
' ' << DataTypeAsString[(*p).m_dataType]
455 if ((*p).m_numComp == 1)
456 out <<
"LOOKUP_TABLE default" << std::endl;
461 ndims, dims, ghost, (*p).m_location,
471 if (!mesh_only && locset.count(
'e') > 0) {
472 out << std::endl <<
"CELL_DATA " << eTotal << std::endl;
473 for (p=attrs.begin(); p!=attrs.end(); ++p) {
474 if ((*p).m_location !=
'e')
477 if ((*p).m_numComp == 1) {
478 COM_get_array_const((wName +
'.' + (*p).m_name).c_str(), paneIds[
i],
483 for (comp=1; comp<=(*p).m_numComp; ++comp) {
484 std::ostringstream sout;
485 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
486 COM_get_array_const(sout.str().c_str(), paneIds[
i],
489 if ((*p).m_numComp == 3)
495 out << (*p).m_name <<
' ' << DataTypeAsString[(*p).m_dataType]
498 if ((*p).m_numComp == 1)
499 out <<
"LOOKUP_TABLE default" << std::endl;
504 ndims, dims, ghost, (*p).m_location,
522 int main(
int argc,
char* argv[])
526 bool mesh_only =
false, read_control =
false;
528 for (i=1; i<argc-1; ++
i) {
529 if (std::strcmp(argv[1],
"-c") == 0)
531 else if (std::strcmp(argv[1],
"-meshonly") == 0)
534 std::cerr <<
"Usage: hdf2vtk [-meshonly] <hdf file>" << std::endl;
535 std::cerr <<
" hdf2vtk [-meshonly] -c <control file>" << std::endl;
547 std::string file_in(argv[argc-1]);
548 std::string win_in(file_in);
549 std::string::size_type st = win_in.find_last_of(
'/');
550 if (st != std::string::npos)
551 win_in.erase(0, st+1);
552 st = win_in.find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
553 if (st != std::string::npos)
557 char timeStr[16] =
"";
560 std::cerr <<
"Reading by control file " << file_in
561 <<
" into window " << win_in << std::endl;
567 std::cerr <<
"Reading HDF file(s) " << file_in
568 <<
" into window " << win_in << std::endl;
#define VTK_QUADRATIC_TETRA
void PrintConn(const int *pConn, const ConnInfo &ci, std::ostream &out)
void COM_get_attribute(const std::string wa_str, char *loc, int *type, int *ncomp, std::string *unit)
#define VTK_QUADRATIC_TRIANGLE
void PrintUnstructured(const TT **pData, int nComp, int size, std::ostream &out)
This file contains the prototypes for Roccom API.
void COM_print_window(const char *wName, std::ostream &ostr)
Print a terse human-readable description of this window to this ostream.
void PrintStructured(const TT **pData, int nComp, int ndims, const int *dims_nodes, int ghost, char loc, std::ostream &out)
void COM_set_verbose(int i)
int COM_get_attribute_handle(const char *waname)
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
void COM_get_attributes(const char *wname, int *na, std::string &names)
void COM_get_size(const char *wa_str, int pane_id, int *size, int *ng=0)
Get the sizes of an attribute.
void COM_set_profiling(int i)
void COM_call_function(const int wf, int argc,...)
Rocin creates a series of Roccom windows by reading in a list of files.
#define SwitchOnDataType(dType, funcCall)
int main(int argc, char *argv[])
void COM_init(int *argc, char ***argv)
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
void COM_free_buffer(int **buf)
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
int COM_get_function_handle(const char *wfname)
#define VTK_QUADRATIC_HEXAHEDRON
#define VTK_QUADRATIC_QUAD
#define COM_EXTERN_MODULE(moduleName)
std::vector< int > paneIds
Array of paneIds.