Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdf2plt.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
34 #include <cstdlib>
35 #include <cassert>
36 #include <fstream>
37 #include <iomanip>
38 #include <iostream>
39 #include <sstream>
40 #include <string>
41 #include <cstring>
42 
43 #include "roccom.h"
44 
45 #define SwitchOnDataType(dType, funcCall) \
46  switch (dType) { \
47  case COM_CHAR: \
48  case COM_BYTE: \
49  { typedef char TT; \
50  funcCall; } \
51  break; \
52  case COM_UNSIGNED_CHAR: \
53  { typedef unsigned char TT; \
54  funcCall; } \
55  break; \
56  case COM_SHORT: \
57  { typedef short TT; \
58  funcCall; } \
59  break; \
60  case COM_UNSIGNED_SHORT: \
61  { typedef unsigned short TT; \
62  funcCall; } \
63  break; \
64  case COM_INT: \
65  { typedef int TT; \
66  funcCall; } \
67  break; \
68  case COM_UNSIGNED: \
69  { typedef unsigned int TT; \
70  funcCall; } \
71  break; \
72  case COM_LONG: \
73  { typedef long TT; \
74  funcCall; } \
75  break; \
76  case COM_UNSIGNED_LONG: \
77  { typedef unsigned long TT; \
78  funcCall; } \
79  break; \
80  case COM_FLOAT: \
81  { typedef float TT; \
82  funcCall; } \
83  break; \
84  case COM_DOUBLE: \
85  { typedef double TT; \
86  funcCall; } \
87  break; \
88  case COM_LONG_DOUBLE: \
89  { typedef long double TT; \
90  funcCall; } \
91  break; \
92  }
93 
94 struct AttrInfo {
95  std::string m_name;
96  char m_location;
97  int m_dataType;
98  int m_numComp;
99  std::string m_units;
100 };
101 
102 struct ConnInfo {
103  std::string m_name;
104  std::string m_type;
105  int m_numElements;
106  int m_numGhost;
107 };
108 
109 namespace HDF2PLT
110 {
111 
112  struct Patch
113  {
116  int L1BEGIN;
117  int L1END;
118  int L2BEGIN;
119  int L2END;
126  int coupled;
127  };
128 
129  struct Block
130  {
133  int Ni;
134  int Nj;
135  int Nk;
136  std::vector< Patch > pathces;
137  };
138 
139  struct SGStr
140  {
142  std::map< int, Block > blocks;
143  } StructuredGrid;
144 
145 } // End Namespace HDF2PLT
146 
147 
154 inline int getBlockNumber( const int zonenumber, const int NBlocks )
155 {
156  std::stringstream iss;
157  iss << zonenumber;
158  std::string s = iss.str( );
159  bool found = false;
160  int reduceFactor = 4;
161  int B = -1;
162  while( !found )
163  {
164  s.resize( reduceFactor );
165  B = std::atoi( s.c_str( ) );
166  if( B <= NBlocks )
167  {
168  found = true;
169  }
170  --reduceFactor;
171  }
172  return( B );
173 }
174 
175 inline void resolveConnectivity( )
176 {
177  // TODO: implement this
178 }
179 
180 inline void readBlock( std::ifstream &ifs )
181 {
182  std::string dummyline;
183  int N;
184 
185  if( !ifs.is_open( ) )
186  {
187  std::cerr << "Error opening reading file!"<< std::endl;
188  std::cerr << "FILE: " << __FILE__ << std::endl;
189  std::cerr << "LINE: " << __LINE__ << std::endl;
190  exit( -1 );
191  }
192 
193  HDF2PLT::Block b;
194  ifs >> b.blockNumber >> b.gridLevels;
195 // std::cout << "# " << b.blockNumber << " ";
196 
197  std::getline( ifs, dummyline );
198 
199  ifs >> N >> b.Ni >> b.Nj >> b.Nk;
200 // std::cout << b.Ni << " " << b.Nj << " " << b.Nk << std::endl;
201 
202  std::getline( ifs,dummyline );
203 
204  b.pathces.resize( N );
205  for( int i=0; i < N; ++i )
206  {
207  HDF2PLT::Patch p;
208  ifs >> p.boundaryCondition;
209  ifs >> p.localBlockFaceNumer;
210  ifs >> p.L1BEGIN;
211  ifs >> p.L1END;
212  ifs >> p.L2BEGIN;
213  ifs >> p.L2END;
214  ifs >> p.remoteBlockNumber;
215  ifs >> p.remoteBlockFaceNumber;
216  ifs >> p.remoteL1BEGIN;
217  ifs >> p.remoteL1END;
218  ifs >> p.remoteL2BEGIN;
219  ifs >> p.remoteL2END;
220  ifs >> p.coupled;
221  std::getline( ifs, dummyline );
222  b.pathces[ i ] = p;
223  }
224 
225  assert( HDF2PLT::StructuredGrid.blocks.find( b.blockNumber ) ==
228 
229 
230 }
231 
232 inline void readTopFile( const std::string file )
233 {
234  std::ifstream ifs;
235  std::string dummyline;
236 
237  ifs.open( file.c_str( ) );
238 
239  if( !ifs.is_open( ) )
240  {
241  std::cerr << "Error opening file " << file << std::endl;
242  std::cerr << "FILE: " << __FILE__ << std::endl;
243  std::cerr << "LINE: " << __LINE__ << std::endl;
244  exit( -1 );
245  }
246 
247  std::getline( ifs, dummyline );
248  std::getline( ifs, dummyline );
249 
251 
252  std::getline( ifs, dummyline );
253 
254  int blockId;
255 
256  for( int i=0; i < HDF2PLT::StructuredGrid.numBlocks; ++i )
257  readBlock( ifs );
258 
259  ifs.close( );
260 }
261 
262 template <typename TT>
263 void PrintStructured(const TT* pData, const int ndims, const int* dims_nodes,
264  int ghost, char loc, std::ostream& out)
265 {
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};
269 
270  const int last[3] = { dims[0] - ghost,
271  ndims>=2 ? dims[1] - ghost : 0,
272  ndims>=3 ? dims[2] - ghost : 0};
273  int count = 0;
274 
275  if ( ndims==3)
276  {
277  for (int k=ghost; k<last[2]; ++k)
278  {
279  for (int j=ghost; j<last[1]; ++j)
280  {
281  for (int i=ghost; i<last[0]; ++i,++count)
282  {
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;
288  }
289  }
290  }
291  }
292  else if (ndims==2)
293  {
294  for (int j=ghost; j<last[1]; ++j)
295  {
296  for (int i=ghost; i<last[0]; ++i,++count)
297  {
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;
302  }
303  }
304 
305  }
306  else
307  {
308  for (int i=ghost; i<last[0]; ++i,++count)
309  {
310  out << " " << std::scientific << (!pData ? (TT)-987654321 : (loc=='p' ? pData[0] : pData[i]));
311  if (count % 10 == 9)
312  out << std::endl;
313  }
314  }
315  out << std::endl;
316 }
317 
318 template <typename TT>
319 void PrintUnstructured(const TT* pData, int size, bool panel, std::ostream& out)
320 {
321  int i;
322  for (i=0; i<size; ++i) {
323  out << " " << std::scientific << (!pData ? (TT)-987654321
324  : (panel ? pData[0]
325  : pData[i]));
326  if (i % 10 == 9) out << std::endl;
327  }
328  out << std::endl;
329 }
330 
331 void PrintConn(const int* pConn, const ConnInfo& ci, char type,
332  std::ostream& out)
333 {
334  int nn;
335  std::istringstream sin(ci.m_type.substr(1));
336  sin >> nn;
337 
338  int elem;
339  for (elem=0; elem<ci.m_numElements-ci.m_numGhost; ++elem) {
340  switch (type) {
341  case 't': // The overall type is 't', so all the tables must be 't'
342  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
343  << " " << pConn[elem+2*ci.m_numElements] << std::endl;
344  break;
345 
346  case 'q':
347  if (ci.m_type[0] == 't')
348  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
349  << " " << pConn[elem+2*ci.m_numElements] << " "
350  << pConn[elem+2*ci.m_numElements] << std::endl;
351  else // must be q4, q8 or q9.
352  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
353  << " " << pConn[elem+2*ci.m_numElements] << " "
354  << pConn[elem+3*ci.m_numElements] << std::endl;
355  break;
356 
357  case 'T': // The overall type is 'T', so all the tables must be 'T'
358  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
359  << " " << pConn[elem+2*ci.m_numElements] << " "
360  << pConn[elem+3*ci.m_numElements] << std::endl;
361  break;
362 
363  case 'B':
364  if (ci.m_type[0] == 'T')
365  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
366  << " " << pConn[elem+2*ci.m_numElements] << " "
367  << pConn[elem+2*ci.m_numElements] << " "
368  << pConn[elem+3*ci.m_numElements] << " "
369  << pConn[elem+3*ci.m_numElements] << " "
370  << pConn[elem+3*ci.m_numElements] << " "
371  << pConn[elem+3*ci.m_numElements] << std::endl;
372  else if (ci.m_type == "P5")
373  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
374  << " " << pConn[elem+2*ci.m_numElements] << " "
375  << pConn[elem+3*ci.m_numElements] << " "
376  << pConn[elem+4*ci.m_numElements] << " "
377  << pConn[elem+4*ci.m_numElements] << " "
378  << pConn[elem+4*ci.m_numElements] << " "
379  << pConn[elem+4*ci.m_numElements] << std::endl;
380  else if (ci.m_type == "P6" || ci.m_type == "W6")
381  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
382  << " " << pConn[elem+2*ci.m_numElements] << " "
383  << pConn[elem+2*ci.m_numElements] << " "
384  << pConn[elem+3*ci.m_numElements] << " "
385  << pConn[elem+4*ci.m_numElements] << " "
386  << pConn[elem+5*ci.m_numElements] << " "
387  << pConn[elem+5*ci.m_numElements] << std::endl;
388  else
389  out << " " << pConn[elem] << " " << pConn[elem+ci.m_numElements]
390  << " " << pConn[elem+2*ci.m_numElements] << " "
391  << pConn[elem+3*ci.m_numElements] << " "
392  << pConn[elem+4*ci.m_numElements] << " "
393  << pConn[elem+5*ci.m_numElements] << " "
394  << pConn[elem+6*ci.m_numElements] << " "
395  << pConn[elem+7*ci.m_numElements] << std::endl;
396  break;
397  }
398  }
399 }
400 
401 void COM_print_window(const std::string& wName, const std::string& timeStr,
402  std::ostream& out, bool with_ghost, bool useTopFile )
403 {
404 
405  if( useTopFile )
406  {
407  std::cout << "Resolving inter-partition connectivity....";
409  std::cout << "[DONE]\n";
410  }
411 
412  // Obtain the list of panes
413  int nPanes;
414  int* paneIds;
415  COM_get_panes(wName.c_str(), &nPanes, &paneIds);
416 
417  // Obtain the list of attributes
418  int nAttrs; // Number of attributes
419  char* attrStr; // names of attributes separated by spaces
420  COM_get_attributes(wName.c_str(), &nAttrs, &attrStr);
421 
422  // First get the nodal coordinate info.
423  int i;
424  std::string name;
425  std::vector<AttrInfo> attrs(nAttrs+1);
426  attrs[0].m_name = "nc";
427  COM_get_attribute((wName + '.' + attrs[0].m_name).c_str(),
428  &(attrs[0].m_location), &(attrs[0].m_dataType),
429  &(attrs[0].m_numComp), &(attrs[0].m_units));
430 
431  // Then get the basic attribute info.
432  {
433  std::istringstream sin(attrStr);
434  for (i=1; i<nAttrs+1; ++i) {
435  sin >> attrs[i].m_name;
436  COM_get_attribute((wName + '.' + attrs[i].m_name).c_str(),
437  &(attrs[i].m_location), &(attrs[i].m_dataType),
438  &(attrs[i].m_numComp), &(attrs[i].m_units));
439  }
440  }
441 
442  if ( nPanes > 0 )
443  {
444  out << "TITLE=\"" << wName << ". Time: " << timeStr << ".\"" << std::endl;
445  out << "VARIABLES= \"x\", \"y\", \"z\"";
446  }
447 
448  // Eliminate window and pane attributes, note element attributes.
449  // EDIT: pane attributes with one item are used as element data.
450  // We might as well get rid of vectors and tensors, too.
451  std::vector<int> elemCentered;
452  int var = 4;
453  std::vector<AttrInfo>::iterator p = attrs.begin();
454  ++p;
455  while (p != attrs.end()) {
456  if ((*p).m_location == 'w') {
457  p = attrs.erase(p);
458  continue;
459  }
460 
461  if ((*p).m_location == 'p') {
462  bool okay = true;
463  int nItems, nGItems;
464  for (i=0; i<nPanes && okay; ++i) {
465  COM_get_size((wName + '.' + (*p).m_name).c_str(), paneIds[i], &nItems,
466  &nGItems);
467  if (nItems - nGItems != 1)
468  okay = false;
469  }
470  if (!okay) {
471  p = attrs.erase(p);
472  continue;
473  }
474  }
475 
476  if ((*p).m_numComp == 1)
477  {
478  out << ", \"" << (*p).m_name << '"';
479  if ((*p).m_location != 'n')
480  elemCentered.push_back(var);
481  ++var;
482  }
483  else {
484  int x;
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);
489  ++var;
490  }
491  }
492  ++p;
493  }
494  out << std::endl;
495 
496  // Loop through the panes to find the meshes
497  for ( i=0; i < nPanes; ++i )
498  {
499 
500  int nElems, ngElems;
501  name = wName + ".conn";
502  COM_get_size(name.c_str(), paneIds[i], &nElems, &ngElems);
503  if ( with_ghost) ngElems = 0;
504  if ( nElems-ngElems==0) continue; // Skip empty panes
505 
506  out << "ZONE T=\"" << std::setw(5) << std::setfill('0')
507  << paneIds[i] << "\", ";
508 
509  // Obtain the size of nodes
510  int nNodes; // total number of nodes
511  int ghost; // Number of ghost nodes
512  name = wName + ".nc";
513  COM_get_size(name.c_str(), paneIds[i], &nNodes, &ghost);
514  if ( with_ghost) ghost=0;
515 
516  // Obtain pane connectivity
517 // int nPcon; // total number of pane connectivities
518 // name = wName +".pconn";
519 // COM_get_size( name.c_str( ), paneIds[ i ], &nPcon );
520 // // Obtain a reference to the pconn array.
521 // const int* pconnArray = NULL;
522 // COM_get_array_const( pConnName.c_str( ), paneIds[ i ], &pconnArray );
523 
524  // Obtain the connectivity tables
525  int nConn; // Number of connectivity tables
526  char* connNames; // Names of connectivity tables separated by space
527  COM_get_connectivities(wName.c_str(), paneIds[i], &nConn, &connNames);
528 
529  int ndims;
530  const int* dims = NULL;
531  char elemType = '\0';
532  int eTotal = 0;
533  std::vector<ConnInfo> connInfo(nConn);
534  if (nConn == 1 && std::strncmp(connNames, ":st", 3) == 0)
535  {
536  // Structured mesh
537 
538  connInfo.clear();
539 
540  name = wName + '.' + connNames;
541  COM_get_size(name.c_str(), paneIds[i], &ndims, &ghost);
542  if ( with_ghost) ghost=0;
543 
544  // Obtain the dimensions (must be a const array) of the pane
545  COM_get_array_const(name.c_str(), paneIds[i], &dims);
546 
547 // // Obtain the size of the pconn array
548 // std::string pConnName = wName + ".pconn";
549 // int pconnsize;
550 // COM_get_size( pConnName.c_str( ), paneIds[ i ], &pconnsize );
551 //
552 // std::cout << "Here is the pane connectivity size: " << pconnsize << std::endl;
553 // // Obtain a reference to the pconn array.
554 // const int* pconnArray = NULL;
555 // COM_get_array_const( pConnName.c_str( ), paneIds[ i ], &pconnArray );
556 //
557 // for( int panecon=0; panecon < pconnsize; panecon++ )
558 // {
559 // std::cout << pconnArray[ panecon ] << "\n";
560 // }
561 
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;
565 
566  out << ", ZONETYPE=ORDERED, ";
567 
568  if( useTopFile )
569  {
570  std::cout << "Processing paneId: " << paneIds[ i ] << std::endl;
571  int blockNum = getBlockNumber( paneIds[ i ], HDF2PLT::StructuredGrid.numBlocks );
572  std::cout << "Here is the block number: " << blockNum << std::endl;
573  assert( HDF2PLT::StructuredGrid.blocks.find( blockNum ) != HDF2PLT::StructuredGrid.blocks.end( ) );
575  std::cout << dims[ 0 ] << " == " << HDF2PLT::StructuredGrid.blocks[ blockNum ].Ni+7 << std::endl;
576  std::cout << dims[ 1 ] << " == " << HDF2PLT::StructuredGrid.blocks[ blockNum ].Nj+7 << std::endl;
577  std::cout << dims[ 2 ] << " == " << HDF2PLT::StructuredGrid.blocks[ blockNum ].Nk+7 << std::endl;
578  }
579 
580  }
581  else
582  { // Unstructured mesh
583  // Obtain the sizes of connectivity tables
584  std::istringstream sin(connNames);
585  std::vector<ConnInfo>::iterator c;
586  for (c=connInfo.begin(); c!=connInfo.end(); ++c)
587  {
588  sin >> (*c).m_type;
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);
594 
595  COM_get_size((*c).m_name.c_str(), paneIds[i], &((*c).m_numElements),
596  &((*c).m_numGhost));
597  if ( with_ghost) (*c).m_numGhost = 0;
598  eTotal += (*c).m_numElements - (*c).m_numGhost;
599 
600  // Tecplot can't do mixed elements, so we have to use the biggest
601  // and fudge the rest.
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];
607  }
608  out << "N=" << nNodes - ghost << ", E=" << eTotal << ", ZONETYPE=";
609  switch (elemType) {
610  case 't':
611  out << "FETRIANGLE, ";
612  break;
613 
614  case 'q':
615  out << "FEQUADRILATERAL, ";
616  break;
617 
618  case 'T':
619  out << "FETETRAHEDRON, ";
620  break;
621 
622  case 'P':
623  case 'W':
624  case 'H':
625  elemType = 'B';
626  // Intentional fall-through
627 
628  case 'B':
629  out << "FEBRICK, ";
630  break;
631  }
632 
633  // free the buffer of connNames
634  COM_free_buffer(&connNames);
635  }
636 
637  out << "DATAPACKING=BLOCK";
638  if (!elemCentered.empty()) {
639  std::vector<int>::iterator cv = elemCentered.begin();
640  out << ", VARLOCATION=([" << *cv;
641  ++cv;
642  while (cv != elemCentered.end()) {
643  out << ',' << *cv;
644  ++cv;
645  }
646  out << "]=CELLCENTERED)";
647  }
648  out << std::endl;
649 
650  for (p=attrs.begin(); p!=attrs.end(); ++p)
651  {
652  const void* pArray = NULL;
653  if ((*p).m_numComp == 1)
654  {
655  out << "# Begin " << (*p).m_name << std::endl;
656  COM_get_array_const((wName + '.' + (*p).m_name).c_str(), paneIds[i],
657  &pArray);
658  if (dims != NULL)
659  { // Structured
660  SwitchOnDataType((*p).m_dataType,
661  PrintStructured((TT*)pArray, ndims, dims, ghost,
662  (*p).m_location, out));
663  }
664  else
665  {
666  SwitchOnDataType((*p).m_dataType,
667  PrintUnstructured((TT*)pArray,
668  ((*p).m_location != 'n' ? eTotal
669  : nNodes - ghost),
670  (*p).m_location == 'p', out));
671  }
672 
673  } // End if m_numComp == 1
674  else
675  {
676  int comp;
677  for (comp=1; comp<=(*p).m_numComp; ++comp)
678  {
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);
683  if (dims != NULL) { // Structured
684  SwitchOnDataType((*p).m_dataType,
685  PrintStructured((TT*)pArray, ndims, dims, ghost,
686  (*p).m_location, out));
687  }
688  else
689  {
690  SwitchOnDataType((*p).m_dataType,
691  PrintUnstructured((TT*)pArray,
692  ((*p).m_location != 'n' ? eTotal
693  : nNodes - ghost),
694  (*p).m_location == 'p', out));
695  }
696 
697  }// End for comp
698 
699  } // End else
700 
701  } // End for attrs.begin
702 
703  if (!connInfo.empty( ) )
704  {
705  std::vector<ConnInfo>::iterator c = connInfo.begin();
706  while (c != connInfo.end())
707  {
708  const int* pConn = NULL;
709  COM_get_array_const((*c).m_name.c_str(), paneIds[i], &pConn);
710  PrintConn(pConn, *c, elemType, out);
711  ++c;
712  }
713 
714  }
715 
716  } // for all panes
717 
718  // Free buffers for pane ids and attribute names
719  COM_free_buffer(&paneIds);
720  COM_free_buffer(&attrStr);
721 
722 }
723 
725 
727 inline static void remove_arg( int *argc, char ***argv, int i) {
728  for ( int j=i; j<*argc-1; ++j) (*argv)[j]=(*argv)[j+1];
729  --*argc;
730 }
731 
735 struct globarg
736 {
737  bool useTopFile;
738  bool withGhost;
740  std::string cntrlfile;
741  std::string topfile;
742  std::string fileregx;
743  std::string outputfile;
744 
745  inline void printInfo( )
746  {
747  std::cout << __DATE__ << std::endl;
748 
749  if( readControlFile )
750  {
751  std::cout << "Read control file: yes\n";
752  std::cout << "Control file: " << cntrlfile << std::endl;
753  }
754  else
755  {
756  std::cout << "Read control file: no\n";
757  std::cout << "File(s): " << fileregx << std::endl;
758  }
759 
760  if( useTopFile )
761  {
762  std::cout << "Use *.top connectivity file: yes\n";
763  std::cout << "Top file: " << topfile << std::endl;
764  }
765  else
766  {
767  std::cout << "Use *.top connectivity file: no\n";
768  }
769 
770  std::cout << "Use ghost nodes: ";
771  (withGhost)? std::cout << "yes\n" : std::cout << "no\n";
772 
773  if( outputfile == "" )
774  std::cout << "Output file: standard out\n";
775  else
776  std::cout << "Output file: " << outputfile << std::endl;
777 
778  }
779 
780 } Program;
781 
785 void showUsage( )
786 {
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";
797  std::cout.flush( );
798 }
799 
805 void parseArguments( int argc, char **argv )
806 {
807  Program.useTopFile = false;
808  Program.withGhost = false;
809  Program.readControlFile = false;
810 
811  Program.cntrlfile = "";
812  Program.topfile = "";
813  Program.fileregx = "";
814 
815  for( int i=1; i < argc; ++i )
816  {
817  if( std::strcmp( argv[ i ], "-top" ) == 0 )
818  {
819  Program.useTopFile = true;
820  Program.topfile = std::string( argv[ ++i ] );
821  }
822  else if( std::strcmp( argv[ i ], "-g" ) == 0 )
823  {
824  Program.withGhost = true;
825  }
826  else if( std::strcmp( argv[ i ], "-c" ) == 0 )
827  {
828  Program.readControlFile = true;
829  Program.cntrlfile = std::string( argv[ ++i ] );
830  }
831  else if( std::strcmp( argv[ i ], "-o" ) == 0 )
832  {
833  Program.outputfile = std::string( argv[ ++i ] );
834  }
835  else if( std::strcmp( argv[ i ], "-regex") == 0 )
836  {
837  Program.fileregx = std::string( argv[ ++i ] );
838  }
839  else if( std::strcmp( argv[ i ], "-h") == 0 )
840  {
841  showUsage( );
842  exit( 0 );
843  }
844 
845  }
846 
847  if( Program.cntrlfile == "" && Program.fileregx == "" )
848  {
849  std::cerr << "Error parsing command line input!\n";
850  showUsage( );
851  exit( -1 );
852  }
853 
854 }
855 
863 int main(int argc, char* argv[])
864 {
865  /* Parse the command line arguments */
866  parseArguments( argc, argv );
867 
868  Program.printInfo( );
869 
870  /* Initialize the COM Environment */
871  COM_init(&argc, &argv);
872 
873  /* Load Rocin for reading the HDF files */
875 
876  std::cout << "Reading top file: " << Program.topfile << "...";
877  if( Program.useTopFile )
878  readTopFile( Program.topfile );
879  std::cout << "[DONE]\n";
880 
881  /* Obtain function handle to the obtain attribute function */
882  int IN_obtain = COM_get_function_handle("IN.obtain_attribute");
883 
884  std::string win_in;
885  if( Program.readControlFile )
886  win_in = Program.cntrlfile;
887  else
888  win_in = Program.fileregx;
889 
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)
895  win_in.erase(st);
896 
897  // Initialize an empty time string
898  int len = 15;
899  char timeStr[16];
900  timeStr[0] = '\0';
901 
902  if( Program.readControlFile )
903  {
904  std::cout << "Reading by control file " << Program.cntrlfile << " into window " << win_in << "...";
905 
906  int IN_read = COM_get_function_handle("IN.read_by_control_file");
907  COM_call_function(IN_read,
908  Program.cntrlfile.c_str(),
909  win_in.c_str(),
910  NULL,
911  timeStr,
912  &len);
913 
914  std::cout << "[DONE]\n";
915 
916  }
917  else
918  {
919  std::cout << "Reading HDF file(s) " << Program.fileregx << " into window " << win_in << "...";
920 
921  int IN_read = COM_get_function_handle("IN.read_window");
922  COM_call_function(IN_read,
923  Program.fileregx.c_str(),
924  win_in.c_str(),
925  NULL,
926  NULL,
927  timeStr,
928  &len);
929 
930  std::cout << "[DONE]\n";
931 
932  }
933 
934  std::string win_all(win_in + ".all");
935  int IN_all = COM_get_attribute_handle(win_all.c_str());
936 
937  std::cout << "Obtaining data attributes for window " << win_in << "...";
938  COM_call_function(IN_obtain, &IN_all, &IN_all);
939  std::cout << "[DONE]\n";
940 
941  if( Program.outputfile == "" )
942  {
943  std::cout << "Writing window out to standard output " << "...";
944  COM_print_window(win_in, timeStr, std::cout, Program.withGhost, Program.useTopFile );
945  std::cout << "[DONE]\n";
946  }
947  else
948  {
949  std::cout << "Writing window out to " << Program.outputfile << "...";
950  std::ofstream fout( Program.outputfile.c_str( ) );
951  COM_print_window(win_in, timeStr, fout, Program.withGhost, Program.useTopFile );
952  std::cout << "[DONE]\n";
953  }
954 
955  // COM_UNLOAD_MODULE_STATIC_DYNAMIC(Rocin);
956 
957  COM_finalize();
958  return 0;
959 }
960 
961 
std::map< int, Block > blocks
Definition: hdf2plt.C:142
void printInfo()
Definition: hdf2plt.C:745
void parseArguments(int argc, char **argv)
Parses the command line arguments.
Definition: hdf2plt.C:805
void readTopFile(const std::string file)
Definition: hdf2plt.C:232
void PrintConn(const int *pConn, const ConnInfo &ci, std::ostream &out)
Definition: cgns2smf.C:232
j indices k indices k
Definition: Indexing.h:6
void COM_get_attribute(const std::string wa_str, char *loc, int *type, int *ncomp, std::string *unit)
Definition: roccom_c++.h:269
double s
Definition: blastest.C:80
static void remove_arg(int *argc, char ***argv, int i)
Remove an argument from the argument list.
Definition: hdf2plt.C:727
int m_numGhost
Definition: cgns2smf.C:140
void PrintUnstructured(const TT **pData, int nComp, int size, std::ostream &out)
Definition: cgns2smf.C:221
std::string topfile
Filename for the top file.
Definition: hdf2plt.C:741
int m_dataType
Definition: cgns2smf.C:131
This file contains the prototypes for Roccom API.
int remoteBlockFaceNumber
The remote block face number that is connecting with this block.
Definition: hdf2plt.C:121
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.
Definition: printin.C:64
void PrintStructured(const TT **pData, int nComp, int ndims, const int *dims_nodes, int ghost, char loc, std::ostream &out)
Definition: cgns2smf.C:176
int remoteBlockNumber
The remote block number.
Definition: hdf2plt.C:120
int remoteL2BEGIN
The remote block&#39;s patch l2 begin coordinate.
Definition: hdf2plt.C:124
std::string m_name
Definition: cgns2smf.C:137
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void readBlock(std::ifstream &ifs)
Definition: hdf2plt.C:180
int remoteL2END
The remote block&#39;s patch l2 end coordinate.
Definition: hdf2plt.C:125
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
Definition: roccom_c++.h:363
int boundaryCondition
Patch boundary condition number.
Definition: hdf2plt.C:114
std::vector< Patch > pathces
Definition: hdf2plt.C:136
Holds some global program arguments.
Definition: hdf2plt.C:735
int remoteL1BEGIN
The remote block&#39;s patch l1 begin coordinate.
Definition: hdf2plt.C:122
std::string outputfile
The filename of the output file.
Definition: hdf2plt.C:743
std::string m_units
Definition: cgns2smf.C:133
bool useTopFile
A flag to specify that a top file needs to be read.
Definition: hdf2plt.C:737
void COM_get_attributes(const char *wname, int *na, std::string &names)
Definition: roccom_c++.h:360
void COM_finalize()
Definition: roccom_c++.h:59
int getBlockNumber(const int zonenumber, const int NBlocks)
Gets the block number by parsing the leading significant digits.
Definition: hdf2plt.C:154
std::string m_type
Definition: cgns2smf.C:138
NT & sin
int L2BEGIN
The local patch l2 begin coordinate.
Definition: hdf2plt.C:118
Definition: Rocin.h:64
#define SwitchOnDataType(dType, funcCall)
Definition: hdf2plt.C:45
blockLoc i
Definition: read.cpp:79
struct globarg Program
void int int REAL * x
Definition: read.cpp:74
std::string cntrlfile
Filename of the control file.
Definition: hdf2plt.C:740
int L1END
The local patch l1 end coordinate.
Definition: hdf2plt.C:117
int L1BEGIN
The local patch l1 begin coordinate.
Definition: hdf2plt.C:116
void showUsage()
Prints usage and examples to STDOUT.
Definition: hdf2plt.C:785
std::string m_name
Definition: cgns2smf.C:129
void COM_get_size(const char *wa_str, int pane_id, int *size, int *ng=0)
Get the sizes of an attribute.
Definition: roccom_c++.h:274
bool withGhost
A flag that specifies that ghost nodes need to be included.
Definition: hdf2plt.C:738
int localBlockFaceNumer
The local block face number.
Definition: hdf2plt.C:115
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
bool blocks
Input data is block-structured grid.
Definition: hdf2pltV2.C:51
void resolveConnectivity()
Definition: hdf2plt.C:175
int main(int argc, char *argv[])
Definition: blastest.C:94
int m_numComp
Definition: cgns2smf.C:132
int L2END
The local patch l2 end coordinate.
Definition: hdf2plt.C:119
int remoteL1END
The remote block&#39;s patch l1 end coordinate.
Definition: hdf2plt.C:123
struct HDF2PLT::SGStr StructuredGrid
bool readControlFile
A flag that specifies that a control file needs to be read.
Definition: hdf2plt.C:739
j indices j
Definition: Indexing.h:6
char m_location
Definition: cgns2smf.C:130
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
std::string fileregx
Regular expression that describes the files that need to be read.
Definition: hdf2plt.C:742
int m_numElements
Definition: cgns2smf.C:139
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
void COM_free_buffer(int **buf)
Definition: roccom_c++.h:397
int gridLevels
Definition: hdf2plt.C:132
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
int coupled
A flag to the external solver.
Definition: hdf2plt.C:126
int blockNumber
Definition: hdf2plt.C:131
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116
std::vector< int > paneIds
Array of paneIds.
Definition: hdf2pltV2.C:60