Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
im2hdf.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  *********************************************************************/
23 // $Id: im2hdf.C,v 1.6 2008/12/06 08:43:24 mtcampbe Exp $
24 // Converting a .im file to .hdf.
25 
26 #include "IM_Reader.h"
27 #include "roccom.h"
28 #include <iostream>
29 #include <sstream>
30 
31 using namespace std;
32 
34 
35 int main(int argc, char *argv[]) {
36  COM_init( &argc, &argv);
37 
38  if ( argc < 2) {
39  cout << "Usage: " << argv[0] << " <im_file> [hdf_prefix] " << endl
40  << "\tWrite each pane into a separate HDF file." << std::endl;
41  cout << "Usage: " << argv[0] << " <im_file> [hdf_name] " << endl
42  << "\tWrite all panes into one HDF file." << std::endl;
43  exit(-1);
44  }
45 
46  char *firstdot=strchr( argv[1], '.');
47  const string wname(argv[1], firstdot? firstdot-argv[1]: strlen( argv[1]));
48 
49  std::cout << "Reading surface mesh file \"" << argv[1] << '"' << endl;
50 
51  COM_new_window( wname.c_str());
52  IM_Reader().read_mesh( argv[1], wname, NULL);
53  COM_window_init_done( wname.c_str());
54 
55  // Output mesh
57 
58  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
59  int mesh = COM_get_attribute_handle_const( (wname+".mesh").c_str());
60 
61 
62  std::string fname;
63  if ( argc>2) fname = argv[2]; else fname = wname+".hdf";
64 
65  int separate_files = fname.find( ".hdf") == string::npos;
66 
67  if ( !separate_files) {
68  std::cout << "Writing HDF file(s) " << fname << endl;
69 
70  COM_call_function( OUT_write, fname.c_str(), &mesh, (char*)wname.c_str(), "000");
71  }
72  else {
73  int npanes, *paneIDs;
74  COM_get_panes( wname.c_str(), &npanes, &paneIDs);
75 
76  for ( int i=0; i<npanes; ++i) {
77  std::ostringstream ostr;
78 
79  ostr << fname;
80  ostr.fill('0'); ostr.width(5);
81  ostr << paneIDs[i] << ".hdf";
82 
83  std::cout << "Writing HDF file(s) " << ostr.str() << endl;
84 
85  COM_call_function( OUT_write, ostr.str().c_str(), &mesh,
86  (char*)wname.c_str(),
87  "000", NULL, NULL, &paneIDs[i]);
88  }
89 
90  COM_free_buffer( &paneIDs);
91  }
92 
93  COM_finalize();
94 }
95 
96 
97 
98 
99 
100 
This file contains the prototypes for Roccom API.
void COM_finalize()
Definition: roccom_c++.h:59
int read_mesh(const char *fname, const std::string &wname, Func_ptr is_local)
Definition: IM_Reader.h:102
Definition: Rocout.h:81
blockLoc i
Definition: read.cpp:79
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
int COM_get_attribute_handle_const(const char *waname)
Definition: roccom_c++.h:420
int main(int argc, char *argv[])
Definition: blastest.C:94
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
#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