Initfile.cpp 2.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#define AMDIS_NO_EXTERN_INITFILE
#include "Initfile.hpp"
#undef AMDIS_NO_EXTERN_INITFILE

#include <string>
#ifdef _MSC_VER
#include <io.h>			// _access
#else
#include <unistd.h>
#endif

12
#include <dune/common/parametertreeparser.hh>
13
14

// a parser for arithmetic expressions
15
// #include <muParser.h>
16

17
#include <dune/amdis/Output.hpp>
18
19
20
21
22
23
24
25
26
27
28
29
30
31

namespace AMDiS
{
  /// check for file existence
  inline bool file_exists(std::string const& filename)
  {
#ifdef _MSC_VER
    return _access(filename.c_str(), 0) == 0;
#else
    return access(filename.c_str(), F_OK) == 0;
#endif
  }


32
33
34
35
36
37
38
//   namespace detail
//   {
//     double mu_parser_eval(std::string const& valStr)
//     {
//       mu::Parser parser;
//       parser.DefineConst(_T("M_PI"), m_pi);
//       parser.DefineConst(_T("M_E"), m_e);
39
//
40
41
42
43
//       parser.SetExpr(valStr);
//       return parser.Eval();
//     }
//   }
44
45
46
47

  /// initialize singleton object an global parameters
  void Initfile::init(std::string in)
  {
48
49
    singlett().read(in);
    singlett().getInternalParameters();
50
51
52
53
54
55
  }


  /// Fill an initfile from a file with filename fn
  void Initfile::read(std::string fn, bool /*force*/)
  {
56
57
    test_exit(file_exists(fn),
              "init-file '", fn, "' cannot be opened for reading");
58

59
    Dune::ParameterTreeParser::readINITree(fn, pt);
60
61
62
63
64
65
66
  }


  /// read standard values for output and information of parameter-values
  void Initfile::getInternalParameters()
  {
    int val = 0;
67
    get("level of information", val);
68
69
70
    msgInfo = val;

    val = 1;
71
    get("parameter information", val);
72
73
74
    paramInfo = val;

    val = 0;
75
    get("break on missing tag", val);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    breakOnMissingTag = val;

    if (msgInfo == 0)
      paramInfo = 0;
  }


  /// print all parameters to std::cout
  void Initfile::printParameters()
  {
    // TODO: implement printing of all parameters
  }

  // explicit template instatiation
90
91
92
  template void Initfile::get(std::string, int&);
  template void Initfile::get(std::string, double&);
  template void Initfile::get(std::string, std::string&);
93
94
95


} // end namespace AMDiS