45 #define SwitchOnDataType(dType, funcCall) \
52 case COM_UNSIGNED_CHAR: \
53 { typedef unsigned char TT; \
60 case COM_UNSIGNED_SHORT: \
61 { typedef unsigned short TT; \
69 { typedef unsigned int TT; \
76 case COM_UNSIGNED_LONG: \
77 { typedef unsigned long TT; \
85 { typedef double TT; \
88 case COM_LONG_DOUBLE: \
89 { typedef long double TT; \
156 std::stringstream iss;
158 std::string
s = iss.str( );
160 int reduceFactor = 4;
164 s.resize( reduceFactor );
165 B = std::atoi( s.c_str( ) );
182 std::string dummyline;
185 if( !ifs.is_open( ) )
187 std::cerr <<
"Error opening reading file!"<< std::endl;
188 std::cerr <<
"FILE: " << __FILE__ << std::endl;
189 std::cerr <<
"LINE: " << __LINE__ << std::endl;
197 std::getline( ifs, dummyline );
199 ifs >> N >> b.
Ni >> b.
Nj >> b.
Nk;
202 std::getline( ifs,dummyline );
205 for(
int i=0;
i < N; ++
i )
221 std::getline( ifs, dummyline );
235 std::string dummyline;
237 ifs.open( file.c_str( ) );
239 if( !ifs.is_open( ) )
241 std::cerr <<
"Error opening file " << file << std::endl;
242 std::cerr <<
"FILE: " << __FILE__ << std::endl;
243 std::cerr <<
"LINE: " << __LINE__ << std::endl;
247 std::getline( ifs, dummyline );
248 std::getline( ifs, dummyline );
252 std::getline( ifs, dummyline );
262 template <
typename TT>
264 int ghost,
char loc, std::ostream& out)
266 const int dims[3] = { dims_nodes[0] - (loc!=
'n'),
267 ndims>=2 ? dims_nodes[1] - (loc!=
'n') : 0,
268 ndims>=3 ? dims_nodes[2] - (loc!=
'n') : 0};
270 const int last[3] = { dims[0] - ghost,
271 ndims>=2 ? dims[1] - ghost : 0,
272 ndims>=3 ? dims[2] - ghost : 0};
277 for (
int k=ghost;
k<last[2]; ++
k)
279 for (
int j=ghost;
j<last[1]; ++
j)
281 for (
int i=ghost;
i<last[0]; ++
i,++count)
283 out <<
" " << std::scientific
284 << (!pData ? (TT)-987654321
285 : (loc==
'p' ? pData[0]
286 : pData[
i+
j*dims[0]+
k*dims[0]*dims[1]]));
287 if (count % 10 == 9) out << std::endl;
294 for (
int j=ghost;
j<last[1]; ++
j)
296 for (
int i=ghost;
i<last[0]; ++
i,++count)
298 out <<
" " << std::scientific
299 << (!pData ? (TT)-987654321
300 : (loc==
'p' ? pData[0] : pData[
i+
j*dims[0]]));
301 if (count % 10 == 9) out << std::endl;
308 for (
int i=ghost;
i<last[0]; ++
i,++count)
310 out <<
" " << std::scientific << (!pData ? (TT)-987654321 : (loc==
'p' ? pData[0] : pData[
i]));
318 template <
typename TT>
322 for (i=0; i<size; ++
i) {
323 out <<
" " << std::scientific << (!pData ? (TT)-987654321
326 if (i % 10 == 9) out << std::endl;
335 std::istringstream
sin(ci.
m_type.substr(1));
342 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
348 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
352 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
358 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
365 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
372 else if (ci.
m_type ==
"P5")
373 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
381 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
389 out <<
" " << pConn[elem] <<
" " << pConn[elem+ci.
m_numElements]
402 std::ostream& out,
bool with_ghost,
bool useTopFile )
407 std::cout <<
"Resolving inter-partition connectivity....";
409 std::cout <<
"[DONE]\n";
425 std::vector<AttrInfo> attrs(nAttrs+1);
426 attrs[0].m_name =
"nc";
428 &(attrs[0].m_location), &(attrs[0].m_dataType),
429 &(attrs[0].m_numComp), &(attrs[0].m_units));
433 std::istringstream
sin(attrStr);
434 for (i=1; i<nAttrs+1; ++
i) {
435 sin >> attrs[
i].m_name;
437 &(attrs[i].m_location), &(attrs[i].m_dataType),
438 &(attrs[i].m_numComp), &(attrs[i].m_units));
444 out <<
"TITLE=\"" << wName <<
". Time: " << timeStr <<
".\"" << std::endl;
445 out <<
"VARIABLES= \"x\", \"y\", \"z\"";
451 std::vector<int> elemCentered;
453 std::vector<AttrInfo>::iterator p = attrs.begin();
455 while (p != attrs.end()) {
456 if ((*p).m_location ==
'w') {
461 if ((*p).m_location ==
'p') {
464 for (i=0; i<nPanes && okay; ++
i) {
465 COM_get_size((wName +
'.' + (*p).m_name).c_str(), paneIds[
i], &nItems,
467 if (nItems - nGItems != 1)
476 if ((*p).m_numComp == 1)
478 out <<
", \"" << (*p).m_name <<
'"';
479 if ((*p).m_location !=
'n')
480 elemCentered.push_back(var);
485 for (x=1; x<=(*p).m_numComp; ++
x) {
486 out <<
", \"" << x <<
'-' << (*p).m_name <<
'"';
487 if ((*p).m_location !=
'n')
488 elemCentered.push_back(var);
497 for ( i=0; i < nPanes; ++
i )
501 name = wName +
".conn";
503 if ( with_ghost) ngElems = 0;
504 if ( nElems-ngElems==0)
continue;
506 out <<
"ZONE T=\"" << std::setw(5) << std::setfill(
'0')
507 << paneIds[
i] <<
"\", ";
512 name = wName +
".nc";
514 if ( with_ghost) ghost=0;
530 const int* dims = NULL;
531 char elemType =
'\0';
533 std::vector<ConnInfo> connInfo(nConn);
534 if (nConn == 1 && std::strncmp(connNames,
":st", 3) == 0)
540 name = wName +
'.' + connNames;
542 if ( with_ghost) ghost=0;
545 COM_get_array_const(name.c_str(), paneIds[
i], &dims);
562 out <<
"I=" << dims[0] - 2 * ghost;
563 if ( ndims>=2) out <<
", J=" << dims[1] - 2 * ghost;
564 if ( ndims>=3) out <<
", K=" << dims[2] - 2 * ghost;
566 out <<
", ZONETYPE=ORDERED, ";
570 std::cout <<
"Processing paneId: " << paneIds[
i ] << std::endl;
572 std::cout <<
"Here is the block number: " << blockNum << std::endl;
584 std::istringstream
sin(connNames);
585 std::vector<ConnInfo>::iterator c;
586 for (c=connInfo.begin(); c!=connInfo.end(); ++c)
589 (*c).m_name = wName +
'.' + (*c).m_type;
590 (*c).m_type.erase(0, 1);
591 std::string::size_type
x = (*c).m_type.find(
':', 2);
592 if (x != std::string::npos)
593 (*c).m_type.erase(x);
595 COM_get_size((*c).m_name.c_str(), paneIds[
i], &((*c).m_numElements),
597 if ( with_ghost) (*c).m_numGhost = 0;
598 eTotal += (*c).m_numElements - (*c).m_numGhost;
602 if (elemType ==
'\0' || elemType ==
't'
603 || ((elemType ==
'q' || elemType ==
'T')
604 && (*c).m_type[0] >
'A' && (*c).m_type[0] <
'Z')
605 || (*c).m_type[0] ==
'B' || (*c).m_type[0] ==
'H')
606 elemType = (*c).m_type[0];
608 out <<
"N=" << nNodes - ghost <<
", E=" << eTotal <<
", ZONETYPE=";
611 out <<
"FETRIANGLE, ";
615 out <<
"FEQUADRILATERAL, ";
619 out <<
"FETETRAHEDRON, ";
637 out <<
"DATAPACKING=BLOCK";
638 if (!elemCentered.empty()) {
639 std::vector<int>::iterator cv = elemCentered.begin();
640 out <<
", VARLOCATION=([" << *cv;
642 while (cv != elemCentered.end()) {
646 out <<
"]=CELLCENTERED)";
650 for (p=attrs.begin(); p!=attrs.end(); ++p)
652 const void* pArray = NULL;
653 if ((*p).m_numComp == 1)
655 out <<
"# Begin " << (*p).m_name << std::endl;
656 COM_get_array_const((wName +
'.' + (*p).m_name).c_str(), paneIds[
i],
662 (*p).m_location, out));
668 ((*p).m_location !=
'n' ? eTotal
670 (*p).m_location ==
'p', out));
677 for (comp=1; comp<=(*p).m_numComp; ++comp)
679 std::ostringstream sout;
680 sout << wName <<
'.' << comp <<
'-' << (*p).m_name;
681 out <<
"# Begin " << comp <<
'-' << (*p).m_name << std::endl;
682 COM_get_array_const(sout.str().c_str(), paneIds[
i], &pArray);
686 (*p).m_location, out));
692 ((*p).m_location !=
'n' ? eTotal
694 (*p).m_location ==
'p', out));
703 if (!connInfo.empty( ) )
705 std::vector<ConnInfo>::iterator c = connInfo.begin();
706 while (c != connInfo.end())
708 const int* pConn = NULL;
709 COM_get_array_const((*c).m_name.c_str(), paneIds[
i], &pConn);
728 for (
int j=i;
j<*argc-1; ++
j) (*argv)[
j]=(*argv)[
j+1];
747 std::cout << __DATE__ << std::endl;
751 std::cout <<
"Read control file: yes\n";
752 std::cout <<
"Control file: " <<
cntrlfile << std::endl;
756 std::cout <<
"Read control file: no\n";
757 std::cout <<
"File(s): " <<
fileregx << std::endl;
762 std::cout <<
"Use *.top connectivity file: yes\n";
763 std::cout <<
"Top file: " <<
topfile << std::endl;
767 std::cout <<
"Use *.top connectivity file: no\n";
770 std::cout <<
"Use ghost nodes: ";
771 (
withGhost)? std::cout <<
"yes\n" : std::cout <<
"no\n";
774 std::cout <<
"Output file: standard out\n";
776 std::cout <<
"Output file: " <<
outputfile << std::endl;
787 std::cout <<
"HDF2PLT OPTIONS:\n";
788 std::cout <<
"-regex \"{somestring}*.hdf\" : Specifies a set of hdf files\n";
789 std::cout <<
"-top {topfile} : Specifies a top file to use to resolve the connectivity\n";
790 std::cout <<
"-g : Enables ghost node inclusion in the output file\n";
791 std::cout <<
"-c {cntrlfile} : Specifies a control file to use\n";
792 std::cout <<
"-o {outputfile} : Specifies output file. Output is printed to STDOUT by default.\n";
793 std::cout <<
"-h : Prints this help menu.\n";
794 std::cout <<
"Examples:\n";
795 std::cout <<
"\thdf2plt -g -regex \"fluid*.hdf\" -o output.plt\n";
796 std::cout <<
"\thdf2plt -regex \"fluid*.hdf\" -top fluid.top -o output.plt\n";
809 Program.readControlFile =
false;
815 for(
int i=1;
i < argc; ++
i )
817 if( std::strcmp( argv[
i ],
"-top" ) == 0 )
820 Program.topfile = std::string( argv[ ++i ] );
822 else if( std::strcmp( argv[ i ],
"-g" ) == 0 )
826 else if( std::strcmp( argv[ i ],
"-c" ) == 0 )
828 Program.readControlFile =
true;
829 Program.cntrlfile = std::string( argv[ ++i ] );
831 else if( std::strcmp( argv[ i ],
"-o" ) == 0 )
833 Program.outputfile = std::string( argv[ ++i ] );
835 else if( std::strcmp( argv[ i ],
"-regex") == 0 )
837 Program.fileregx = std::string( argv[ ++i ] );
839 else if( std::strcmp( argv[ i ],
"-h") == 0 )
849 std::cerr <<
"Error parsing command line input!\n";
863 int main(
int argc,
char* argv[])
876 std::cout <<
"Reading top file: " <<
Program.topfile <<
"...";
879 std::cout <<
"[DONE]\n";
890 std::string::size_type st = win_in.find_last_of(
'/');
891 if (st != std::string::npos)
892 win_in.erase(0, st+1);
893 st = win_in.find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
894 if (st != std::string::npos)
904 std::cout <<
"Reading by control file " <<
Program.cntrlfile <<
" into window " << win_in <<
"...";
914 std::cout <<
"[DONE]\n";
919 std::cout <<
"Reading HDF file(s) " <<
Program.fileregx <<
" into window " << win_in <<
"...";
930 std::cout <<
"[DONE]\n";
934 std::string win_all(win_in +
".all");
937 std::cout <<
"Obtaining data attributes for window " << win_in <<
"...";
939 std::cout <<
"[DONE]\n";
943 std::cout <<
"Writing window out to standard output " <<
"...";
945 std::cout <<
"[DONE]\n";
949 std::cout <<
"Writing window out to " <<
Program.outputfile <<
"...";
950 std::ofstream fout(
Program.outputfile.c_str( ) );
952 std::cout <<
"[DONE]\n";
std::map< int, Block > blocks
void parseArguments(int argc, char **argv)
Parses the command line arguments.
void readTopFile(const std::string file)
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)
static void remove_arg(int *argc, char ***argv, int i)
Remove an argument from the argument list.
void PrintUnstructured(const TT **pData, int nComp, int size, std::ostream &out)
std::string topfile
Filename for the top file.
This file contains the prototypes for Roccom API.
int remoteBlockFaceNumber
The remote block face number that is connecting with this block.
A struct that holds all the global program data.
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)
int remoteBlockNumber
The remote block number.
int remoteL2BEGIN
The remote block's patch l2 begin coordinate.
int COM_get_attribute_handle(const char *waname)
void readBlock(std::ifstream &ifs)
int remoteL2END
The remote block's patch l2 end coordinate.
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
int boundaryCondition
Patch boundary condition number.
std::vector< Patch > pathces
Holds some global program arguments.
int remoteL1BEGIN
The remote block's patch l1 begin coordinate.
std::string outputfile
The filename of the output file.
bool useTopFile
A flag to specify that a top file needs to be read.
void COM_get_attributes(const char *wname, int *na, std::string &names)
int getBlockNumber(const int zonenumber, const int NBlocks)
Gets the block number by parsing the leading significant digits.
int L2BEGIN
The local patch l2 begin coordinate.
#define SwitchOnDataType(dType, funcCall)
std::string cntrlfile
Filename of the control file.
int L1END
The local patch l1 end coordinate.
int L1BEGIN
The local patch l1 begin coordinate.
void showUsage()
Prints usage and examples to STDOUT.
void COM_get_size(const char *wa_str, int pane_id, int *size, int *ng=0)
Get the sizes of an attribute.
bool withGhost
A flag that specifies that ghost nodes need to be included.
int localBlockFaceNumer
The local block face number.
void COM_call_function(const int wf, int argc,...)
bool blocks
Input data is block-structured grid.
void resolveConnectivity()
int main(int argc, char *argv[])
int L2END
The local patch l2 end coordinate.
int remoteL1END
The remote block's patch l1 end coordinate.
struct HDF2PLT::SGStr StructuredGrid
bool readControlFile
A flag that specifies that a control file needs to be read.
void COM_init(int *argc, char ***argv)
std::string fileregx
Regular expression that describes the files that need to be read.
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)
int coupled
A flag to the external solver.
#define COM_EXTERN_MODULE(moduleName)
std::vector< int > paneIds
Array of paneIds.