Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
write_parameter_file.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 #include <iostream>
24 #include <fstream>
25 #include <iomanip>
26 #include <cstdlib>
27 
28 #include "Rocout.h"
29 #include "roccom_c++.h"
30 
31 using namespace std;
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 USE_COM_NAME_SPACE
34 #endif
35 
36 void Rocout::write_parameter_file( const char* file_name,
37  const char* window_name,
38  const MPI_Comm *comm){
39 
40  // Check to see if the window exists
41  COM::Roccom_base * rbase = COM_get_roccom();
42  int whandle = COM_get_window_handle(window_name);
43  COM::Window* param_window = NULL;
44  if(whandle >0)
45  param_window = rbase->get_window_object(whandle);
46 
47  COM_assertion_msg(param_window,
48  "Parameter window does not exist");
49 
50  //open parameter file for output
51  std::ofstream param_file(file_name);
52  COM_assertion_msg(file_name,
53  "Specified parameter file can't be opened for writing.");
54 
55  // Get all the attributes of the window
56  std::vector<Attribute*> atts;
57  param_window->attributes(atts);
58 
59  // Loop through all the attributes
60  // print out those with the correct format.
61  for(uint i =0, ni = atts.size(); i<ni; ++i){
62  if(atts[i]->location()=='w'
63  && atts[i]->data_type() == COM_CHAR
64  && atts[i]->size_of_components() == 1){
65 
66  std::string option = atts[i]->name();
67  std::string value ("");
68  value.assign((const char*)atts[i]->pointer(),
69  atts[i]->size_of_items());
70 
71  param_file << option << " = ";
72 
73  if(value.find(" ") != std::string::npos)
74  param_file << "\"" << value << "\"\n";
75  else
76  param_file << value << "\n";
77  }
78  }
79 } // file closed automatically
80 
81 
82 
83 
84 
85 
Contains the wrapper routines for C++ binding of Roccom API.
void write_parameter_file(const char *file_name, const char *window_name, const MPI_Comm *comm=NULL)
Write out the parameters defined in the fiven window into a parameter file.
const char * option(const char *const name, const int argc, const char *const *const argv, const char *defaut, const char *const usage=0)
Definition: CImg.h:5604
#define COM_assertion_msg(EX, msg)
C/C++ Data types.
Definition: roccom_basic.h:129
Rocout creates a series of Roccom windows by reading in a list of files.
blockLoc i
Definition: read.cpp:79
int COM_get_window_handle(const char *wname)
Definition: roccom_c++.h:404
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
COM_END_NAME_SPACE COM::Roccom_base * COM_get_roccom()
Definition: Roccom_base.h:537