Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
printin.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  *********************************************************************/
29 #include "Rocin.h"
30 #include "roccom.h"
31 
32 #include <stdio.h>
33 #include <iostream>
34 #include <cstring>
35 #include <string>
36 #include <cstdlib>
37 #include <cstdio>
38 #include <sstream>
39 #include <fstream>
40 
41 // #define DEBUG_FILE_DUMP "/turing/home/jnorris/temp/"
42 
44 std::string COM_get_type(int type) {
45  switch (type) {
46  case COM_DOUBLE: return "COM_DOUBLE";
47  case COM_DOUBLE_PRECISION: return "COM_DOUBLE_PRECISION";
48  case COM_INT: return "COM_INT";
49  case COM_INTEGER: return "COM_INTEGER";
50  case COM_FLOAT: return "COM_FLOAT";
51  case COM_BYTE: return "COM_BYTE";
52  case COM_REAL: return "COM_REAL";
53  case COM_CHAR: return "COM_CHAR";
54  case COM_VOID: return "COM_VOID";
55  };
56  char buf[100];
57  std::sprintf(buf,"COM datatype %d",type);
58  return buf;
59 }
60 
64 void COM_print_window(const char *wName, std::ostream &ostr) {
65  std::string w(wName); w+=".";
66 
67  // Obtain the list of panes
68  int np, *pane_ids;
69  COM_get_panes( wName, &np, &pane_ids);
70 
71  int nnodes = 0; // total number of nodes
72  int nelems = 0; // total number of elems
73 
74  // Loop through the panes to find the meshes
75  for ( int i=0; i<np; ++i) {
76  int nconn; // Number of connectivity tables
77  char *cnames; // Names of connectivity tables separated by space
78  ostr << "Pane "<<pane_ids[i]<< " ";
79 
80  // Obtain the connectivity tables
81  COM_get_connectivities( wName, pane_ids[i], &nconn, &cnames);
82 
83  if ( nconn == 1 && strncmp(cnames,":st",3)==0) { // Structured mesh
84  int ndims; // Number of dimensions
85  int nglayers; // Number of ghost layers.
86  COM_get_size( (w+cnames).c_str(), pane_ids[i], &ndims, &nglayers);
87 
88  // Obtain the dimensions (must be a const array) of the pane and set them
89  const int *dims;
90  COM_get_array_const((w+cnames).c_str(), pane_ids[i], &dims);
91 
92  ostr << "Structured mesh: "
93  << ndims << "-D (" << nglayers << " ghost layers);"
94  <<" grid is " << dims[0];
95  nnodes = dims[0];
96  nelems = std::max(1, dims[0] - 1);
97  if ( ndims>1) {
98  ostr << "x" << dims[1];
99  nnodes *= dims[1];
100  nelems *= std::max(1, dims[1] - 1);
101  }
102  if ( ndims>2) {
103  ostr << "x" << dims[2];
104  nnodes *= dims[2];
105  nelems *= std::max(1, dims[2] - 1);
106  }
107  ostr << std::endl;
108  }
109  else { // Unstructured mesh
110  int ngnodes; // Number of ghost nodes
111 
112  // Obtain the size of nodes
113  COM_get_size((w+"nc").c_str(), pane_ids[i], &nnodes, &ngnodes);
114  ostr << "Unstructured mesh: "
115  << nnodes << " nodes (" << ngnodes << " ghosts)";
116 
117  // Obtain the sizes of connectivity tables
118  if ( nconn>0) {
119  std::istringstream is( cnames);
120  for ( int c=0; c<nconn; ++c) {
121  std::string cname;
122  is >> cname;
123  int ne, ng;
124  COM_get_size((w+cname).c_str(), pane_ids[i], &ne, &ng);
125  nelems += ne;
126  if (nconn>1)
127  ostr << "\n Connectivity table " << c << " has ";
128  else ostr<<" / ";
129  ostr << ne << " elements (" << ng << " ghosts)";
130  }
131  }
132  ostr<<std::endl;
133 
134  // free the buffer of cnames
135  COM_free_buffer( &cnames);
136  }
137  }
138  ostr<<std::endl;
139 
140  // Obtain the list of attributes
141  int na; // Number of attributes
142  char *atts; // names of attributes separated by spaces
143  COM_get_attributes( wName, &na, &atts);
144 
145  std::istringstream is(atts);
146  for ( int i=0; i<na; ++i) {
147  // Obtain the attribute name
148  std::string aname; is >> aname;
149  char loc;
150  int type, ncomp;
151  std::string units;
152 
153  COM_get_attribute( (w+aname).c_str(), &loc, &type, &ncomp, &units);
154  ostr << "" << aname << " ("<<units<<") " << ncomp << " x " << COM_get_type(type) <<" ";
155 
156  int nitems;
157  if ( loc == 'w') { /* window attribute */
158  int ng;
159  COM_get_size((w+aname).c_str(), 0, &nitems, &ng);
160  ostr << " Window: " << nitems << " items ("<<ng<<" ghosts)";
161  }
162  else if (loc=='p') { /* panel attribute */
163  for ( int i=0; i<np; ++i) {
164  // Obtain the size for a panel attribute.
165  int ng;
166  COM_get_size((w+aname).c_str(), pane_ids[i], &nitems, &ng);
167  ostr << "\n Panel("<<pane_ids[i]<<"): "<<nitems<<" items ("<<ng<<" ghosts)";
168  }
169  }
170  else if (loc=='e') { /* element attribute */
171  nitems = nelems;
172  ostr << " Element";
173  }
174  else if (loc=='n') { /* node attribute */
175  nitems = nnodes;
176  ostr << " Node";
177  }
178  else {
179  ostr << " (Unrecognized attribute location "<<loc<<")";
180  }
181  ostr << std::endl;
182 
183 #ifdef DEBUG_FILE_DUMP
184  std::ofstream fout(( DEBUG_FILE_DUMP + aname + ".txt").c_str());
185  const void* data;
186  int strd, cap;
187  for (int c=0; c<ncomp; ++c) {
188  if (ncomp == 1)
189  COM_get_array_const((w + aname).c_str(), pane_ids[i], &data, &strd,
190  &cap);
191  else
192  COM_get_array_const((w + (char)('1' + c) + '-' + aname).c_str(),
193  pane_ids[i], &data, &strd, &cap);
194  if (data == NULL)
195  fout << "NULL\n##################################################\n";
196  else {
197  int j;
198  switch (type) {
199  case COM_CHAR:
200  case COM_CHARACTER:
201  for (j=0; j<nitems; ++j) {
202  fout << (int)((const char*)data)[j];
203  if ((j + 1) % 8 == 0)
204  fout << '\n';
205  else
206  fout << ' ';
207  }
208  break;
209  case COM_INT:
210  case COM_INTEGER:
211  for (j=0; j<nitems; ++j) {
212  fout << ((const int*)data)[j];
213  if ((j + 1) % 8 == 0)
214  fout << '\n';
215  else
216  fout << ' ';
217  }
218  break;
219  case COM_FLOAT:
220  case COM_REAL:
221  for (j=0; j<nitems; ++j) {
222  fout << ((const float*)data)[j];
223  if ((j + 1) % 8 == 0)
224  fout << '\n';
225  else
226  fout << ' ';
227  }
228  break;
229  case COM_DOUBLE:
231  for (j=0; j<nitems; ++j) {
232  fout << ((const double*)data)[j];
233  if ((j + 1) % 8 == 0)
234  fout << '\n';
235  else
236  fout << ' ';
237  }
238  break;
239  }
240  fout << "\n##################################################\n";
241  }
242  }
243  fout.close();
244 #endif // DEBUG_FILE_DUMP
245  }
246 
247  // Free buffers for pane ids and attribute names
248  COM_free_buffer( &pane_ids);
249  COM_free_buffer( &atts);
250 }
251 
253 
254 int main(int argc, char *argv[]) {
255  COM_init( &argc, &argv);
256 
257  if (argc<2) {
258  std::cerr<<"Usage: printtest <hdf file to print>\n";
259  std::exit(1);
260  }
261 
263 
264  int IN_read = COM_get_function_handle( "IN.read_windows");
265  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
266 
267  COM_set_verbose(0);
269 
270  const char *hdf_in = argv[1];
271 
272  const char *win_in = "random_window";
273  std::string w(win_in); w+=".";
274 
275  COM_call_function( IN_read, hdf_in, win_in, "");
276 
277  int IN_all = COM_get_attribute_handle((w+"all").c_str());
278  COM_call_function(IN_obtain, &IN_all, &IN_all);
279 
280  printf("Analysis of file '%s':\n",hdf_in);
281  COM_print_window(win_in,std::cout);
282 
283  COM_finalize();
284  return 0;
285 }
286 
287 
288 
289 
290 
291 
void COM_get_attribute(const std::string wa_str, char *loc, int *type, int *ncomp, std::string *unit)
Definition: roccom_c++.h:269
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
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.
Definition: printin.C:64
C/C++ Data types.
Definition: roccom_basic.h:129
void COM_set_verbose(int i)
Definition: roccom_c++.h:543
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
Definition: roccom_c++.h:363
std::string COM_get_type(int type)
Use Rocin to read an HDF file, and print out a human-readable text listing of everything in the file...
Definition: printin.C:44
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
Definition: Rocin.h:64
blockLoc i
Definition: read.cpp:79
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
void COM_set_profiling(int i)
Definition: roccom_c++.h:550
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
Rocin creates a series of Roccom windows by reading in a list of files.
int main(int argc, char *argv[])
Definition: blastest.C:94
j indices j
Definition: Indexing.h:6
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
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
Fortran Data types.
Definition: roccom_basic.h:133
#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
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116