42 #define SwitchOnDataType(dType, funcCall) \
49 case COM_UNSIGNED_CHAR: \
50 { typedef unsigned char TT; \
57 case COM_UNSIGNED_SHORT: \
58 { typedef unsigned short TT; \
66 { typedef unsigned int TT; \
73 case COM_UNSIGNED_LONG: \
74 { typedef unsigned long TT; \
82 { typedef double TT; \
85 case COM_LONG_DOUBLE: \
86 { typedef long double TT; \
106 template <
typename TT>
108 int ghost,
char loc, std::ostream& out)
110 const int dims[3] = { dims_nodes[0] - (loc!=
'n'),
111 ndims>=2 ? dims_nodes[1] - (loc!=
'n') : 0,
112 ndims>=3 ? dims_nodes[2] - (loc!=
'n') : 0};
114 const int last[3] = { dims[0] - ghost,
115 ndims>=2 ? dims[1] - ghost : 0,
116 ndims>=3 ? dims[2] - ghost : 0};
119 for (
int k=ghost;
k<last[2]; ++
k)
120 for (
int j=ghost;
j<last[1]; ++
j)
121 for (
int i=ghost;
i<last[0]; ++
i) {
122 out <<
" " << std::scientific
123 << (!pData ? (TT)-987654321
124 : (loc==
'p' ? pData[0]
125 : pData[
i+
j*dims[0]+
k*dims[0]*dims[1]]));
126 if ((
i - ghost) % 10 == 9) out << std::endl;
130 for (
int j=ghost;
j<last[1]; ++
j)
131 for (
int i=ghost;
i<last[0]; ++
i) {
132 out <<
" " << std::scientific
133 << (!pData ? (TT)-987654321
134 : (loc==
'p' ? pData[0] : pData[
i+
j*dims[0]]));
135 if ((
i - ghost) % 10 == 9) out << std::endl;
140 for (
int i=ghost;
i<last[0]; ++
i) {
141 out <<
" " << std::scientific
142 << (!pData ? (TT)-987654321 : (loc==
'p' ? pData[0] : pData[
i]));
143 if ((i - ghost) % 10 == 9) out << std::endl;
150 template <
typename TT>
154 for (i=0; i<size; ++
i) {
155 out <<
" " << std::scientific << (!pData ? (TT)-987654321
158 if (i % 10 == 9) out << std::endl;
167 std::istringstream
sin(ci.
m_type.substr(1));
174 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
180 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
184 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
190 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
197 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
204 else if (ci.
m_type ==
"P5")
205 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
213 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
221 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
234 std::ostream& out,
bool with_ghost) {
248 std::vector<AttrInfo> attrs(nAttrs+1);
249 attrs[0].m_name =
"nc";
251 &(attrs[0].m_location), &(attrs[0].m_dataType),
252 &(attrs[0].m_numComp), &(attrs[0].m_units));
256 std::istringstream
sin(attrStr);
257 for (i=1; i<nAttrs+1; ++
i) {
258 sin >> attrs[
i].m_name;
260 &(attrs[i].m_location), &(attrs[i].m_dataType),
261 &(attrs[i].m_numComp), &(attrs[i].m_units));
266 out <<
"TITLE=\"" << wName <<
". Time: " << timeStr <<
".\"" << std::endl;
267 out <<
"VARIABLES= \"x\", \"y\", \"z\"";
273 std::vector<int> elemCentered;
275 std::vector<AttrInfo>::iterator p = attrs.begin();
277 while (p != attrs.end()) {
278 if ((*p).m_location !=
'n' ) {
283 if ((*p).m_numComp == 1) {
284 out <<
", \"" << (*p).m_name <<
'"';
288 for (x=1; x<=(*p).m_numComp; ++
x) {
289 out <<
", \"" << x <<
'-' << (*p).m_name <<
'"';
299 for (i=0; i<nPanes; ++
i) {
302 name = wName +
".conn";
304 if ( with_ghost) ngElems = 0;
305 if ( nElems-ngElems==0)
continue;
307 out <<
"ZONE T=\"" << std::setw(5) << std::setfill(
'0')
308 << paneIds[
i] <<
"\", ";
313 name = wName +
".nc";
315 if ( with_ghost) ghost=0;
323 const int* dims = NULL;
324 char elemType =
'\0';
326 std::vector<ConnInfo> connInfo(nConn);
327 if (nConn == 1 && strncmp(connNames,
":st", 3) == 0) {
330 name = wName +
'.' + connNames;
332 if ( with_ghost) ghost=0;
335 COM_get_array_const(name.c_str(), paneIds[
i], &dims);
337 out <<
"I=" << dims[0] - 2 * ghost;
338 if ( ndims>=2) out <<
", J=" << dims[1] - 2 * ghost;
339 if ( ndims>=3) out <<
", K=" << dims[2] - 2 * ghost;
341 out <<
", ZONETYPE=ORDERED, ";
344 std::istringstream
sin(connNames);
345 std::vector<ConnInfo>::iterator c;
346 for (c=connInfo.begin(); c!=connInfo.end(); ++c) {
348 (*c).m_name = wName +
'.' + (*c).m_type;
349 (*c).m_type.erase(0, 1);
350 std::string::size_type
x = (*c).m_type.find(
':', 2);
351 if (x != std::string::npos)
352 (*c).m_type.erase(x);
354 COM_get_size((*c).m_name.c_str(), paneIds[
i], &((*c).m_numElements),
356 if ( with_ghost) (*c).m_numGhost = 0;
357 eTotal += (*c).m_numElements - (*c).m_numGhost;
361 if (elemType ==
'\0' || elemType ==
't'
362 || ((elemType ==
'q' || elemType ==
'T')
363 && (*c).m_type[0] >
'A' && (*c).m_type[0] <
'Z')
364 || (*c).m_type[0] ==
'B' || (*c).m_type[0] ==
'H')
365 elemType = (*c).m_type[0];
367 out <<
"N=" << nNodes - ghost <<
", E=" << eTotal <<
", ZONETYPE=";
370 out <<
"FETRIANGLE, ";
374 out <<
"FEQUADRILATERAL, ";
378 out <<
"FETETRAHEDRON, ";
396 out <<
"DATAPACKING=BLOCK";
397 if (!elemCentered.empty()) {
398 std::vector<int>::iterator cv = elemCentered.begin();
399 out <<
", VARLOCATION=([" << *cv;
401 while (cv != elemCentered.end()) {
405 out <<
"]=CELLCENTERED)";
409 for (p=attrs.begin(); p!=attrs.end(); ++p) {
410 const void* pArray = NULL;
411 if ((*p).m_numComp == 1) {
412 out <<
"# Begin " << (*p).m_name << std::endl;
413 COM_get_array_const((wName +
'.' + (*p).m_name).c_str(), paneIds[
i],
418 (*p).m_location, out));
422 ((*p).m_location !=
'n' ? eTotal
424 (*p).m_location ==
'p', out));
428 for (comp=1; comp<=(*p).m_numComp; ++comp) {
429 std::ostringstream sout;
430 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
431 out <<
"# Begin " << comp <<
'-' << (*p).m_name << std::endl;
432 COM_get_array_const(sout.str().c_str(), paneIds[
i], &pArray);
436 (*p).m_location, out));
440 ((*p).m_location !=
'n' ? eTotal
442 (*p).m_location ==
'p', out));
448 if (!connInfo.empty()) {
449 std::vector<ConnInfo>::iterator c = connInfo.begin();
450 while (c != connInfo.end()) {
451 const int* pConn = NULL;
452 COM_get_array_const((*c).m_name.c_str(), paneIds[
i], &pConn);
461 int n;
COM_get_size( (wName+
".ridges").c_str(), paneIds[i], &n);
464 out <<
"ZONE T=\"fea" << std::setw(5) << std::setfill(
'0')
465 << paneIds[
i] <<
"\", N=" << nNodes - ghost
466 <<
", E=" << n <<
", ZONETYPE=FELINESEG, DATAPACKING=BLOCK\n";
467 out <<
"VARSHARELIST=([1-" << var <<
"]=" << zone_count <<
")" << std::endl;
470 COM_get_array( (wName+
".ridges").c_str(), paneIds[i], &pArray);
472 for (
int i=0; i<
n; ++
i) {
473 out <<
" " << pArray[
i] <<
" " << pArray[i+
n] << std::endl;
490 for (
int j=i;
j<*argc-1; ++
j) (*argv)[
j]=(*argv)[
j+1];
494 int main(
int argc,
char* argv[])
498 bool with_ghost = (argc>1 && std::strcmp(argv[1],
"-g")==0);
499 if ( with_ghost)
remove_arg( &argc, &argv, 1);
501 bool read_control = (argc>1 && std::strcmp(argv[1],
"-c")==0);
502 if ( read_control)
remove_arg( &argc, &argv, 1);
504 if (argc < 2 || argc > 3 ) {
505 std::cerr <<
"Usage: hdf2plt [-g] <hdf input files> [<output file>]" << std::endl;
506 std::cerr <<
" or: hdf2plt [-g] -c <Rocin control file> [<output file>]" << std::endl;
507 std::cerr <<
"\nOptions:\n\t -g: Includes ghost nodes and elements in output\n"
509 <<
"\thdf2plt -g \"surfmesh*.hdf\" output.plt\n"
510 <<
"\thdf2plt -g -c surfmesh.txt output.plt" << std::endl;
518 std::string file_in(argv[1]);
519 std::string win_in = file_in;
521 std::string::size_type st = win_in.find_last_of(
'/');
522 if (st != std::string::npos)
523 win_in.erase(0, st+1);
524 st = win_in.find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
525 if (st != std::string::npos)
534 std::cerr <<
"Reading by control file " << file_in
535 <<
" into window " << win_in << std::endl;
541 std::cerr <<
"Reading HDF file(s) " << file_in
542 <<
" into window " << win_in << std::endl;
549 std::string win_all(win_in +
".all");
552 std::cerr <<
"Obtaining data attributes for window " << win_in << std::endl;
556 std::cerr <<
"Writing window out to standard output " << std::endl;
559 std::cerr <<
"Writing window out to " << argv[2] << std::endl;
560 std::ofstream fout(argv[2]);
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)
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_get_array(const char *wa_str, int pane_id, void **addr, int *strd, int *cap)
Get the address for an attribute on a specific pane.
int COM_get_attribute_handle(const char *waname)
static void remove_arg(int *argc, char ***argv, int i)
Remove an argument from the argument list.
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
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_call_function(const int wf, int argc,...)
int main(int argc, char *argv[])
#define SwitchOnDataType(dType, funcCall)
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 COM_EXTERN_MODULE(moduleName)
std::vector< int > paneIds
Array of paneIds.