Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ghostbuster.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:
24 
25 #include "Roccom_base.h"
26 #include "roccom.h"
27 #include "roccom_devel.h"
28 
29 
30 #include <iostream>
31 #include <cstring>
32 #include <string>
33 #include <cstdlib>
34 #include <cassert>
35 #include <map>
36 #include <sstream>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <cgnslib.h>
40 #include "Rocout.h"
41 
42 using namespace std;
43 
44 #define CG_CHECK(routine, args) \
45 { \
46  int ier = routine args; \
47  if (ier != 0) { \
48  cerr << "ghostbuster: " #routine " (line " << __LINE__ << " in " \
49  << __FILE__ << ") failed: " << cg_get_error() << std::endl; \
50  return -1; \
51  } \
52 }
53 
54 class AutoCloser
55 {
56  public:
57  inline AutoCloser(int fn)
58  : m_fn(fn) {}
59  inline ~AutoCloser() { cg_close(m_fn); }
60  private:
61  int m_fn;
62 };
63 
66 
67 int main(int argc, char *argv[]) {
68  if ( argc < 2) {
69  cout << "Usage: " << argv[0] << " <inputfile>" << endl;
70  return -1;
71  }
72 
73  // Determine true material names. There's no clean ROCCOM way to do this.
74  vector<string> wins;
75  string materials;
76  string file_in(argv[1]);
77  string::size_type c = file_in.length();
78  if (file_in.substr(c - 5) == ".cgns") {
79  int fn;
80  CG_CHECK(cg_open, (file_in.c_str(), MODE_READ, &fn));
81  AutoCloser auto1(fn);
82 
83  int nBases;
84  CG_CHECK(cg_nbases, (fn, &nBases));
85 
86  int B, cellDim, physDim;
87  char baseName[33];
88  for (B=1; B<=nBases; ++B) {
89  CG_CHECK(cg_base_read, (fn, B, baseName, &cellDim, &physDim));
90  std::string name(baseName);
91  c = name.length();
92  if (c <= 7 || name.substr(c - 7) != "_ridges") {
93  wins.push_back(name);
94  materials += name + ' ';
95  }
96  }
97  if (!materials.empty())
98  materials.erase(materials.size() - 1);
99  } else {
100  cout << "Error: " << argv[0] << " only handles CGNS files at this time."
101  << endl;
102  return -1;
103  }
104 
105  std::cout << "Found materials: " << materials << std::endl;
106 
107  string file_out(file_in);
108  c = file_out.rfind('/');
109  if (c != string::npos)
110  file_out.replace(0, c + 1, "gb_");
111  else
112  file_out.insert(0, "gb_");
113 
114  COM_init( &argc, &argv);
115 
118 
119  int IN_read = COM_get_function_handle( "IN.read_windows");
120  int OUT_set = COM_get_function_handle( "OUT.set_option");
121  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
122 
123  COM_call_function( OUT_set, "format", "CGNS");
124  COM_call_function( OUT_set, "ghosthandle", "ignore");
125 
126  char time_level[33] = "";
127  int length = 32;
128  vector<string>::iterator w;
129  for (w=wins.begin(); w!=wins.end(); ++w) {
130  COM_call_function( IN_read, file_in.c_str(), wins[0].c_str(), NULL, NULL,
131  NULL, time_level, &length);
132 
133  int IN_all = COM_get_attribute_handle((*w+".all").c_str());
134 
135  COM_call_function( OUT_write, file_out.c_str(), &IN_all, (*w).c_str(),
136  time_level);
137 
138  COM_call_function( OUT_set, "mode", "a");
139  }
140 
143 
144  COM_finalize();
145 
146  return 0;
147 }
148 
149 
150 
151 
152 
153 
AutoCloser(int fn)
Definition: ghostbuster.C:57
This file contains the prototypes for Roccom API.
Automatically close open files, datasets, etc.
Definition: Rocin.C:179
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
double length(Vector3D *const v, int n)
Rocout creates a series of Roccom windows by reading in a list of files.
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
#define CG_CHECK(routine, args)
Definition: ghostbuster.C:44
void COM_finalize()
Definition: roccom_c++.h:59
Definition: Rocin.h:64
Definition: Rocout.h:81
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
int main(int argc, char *argv[])
Definition: blastest.C:94
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
#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
Contains declaration of the base class for Roccom implementations.