ModFile.hh 5.43 KB
Newer Older
1
/*
2
 * Copyright (C) 2006-2014 Dynare Team
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _MOD_FILE_HH
#define _MOD_FILE_HH

using namespace std;

#include <ostream>
26
27
#include <ctime>

28
29
#include "SymbolTable.hh"
#include "NumericalConstants.hh"
30
#include "NumericalInitialization.hh"
sebastien's avatar
sebastien committed
31
32
#include "StaticModel.hh"
#include "DynamicModel.hh"
33
#include "SteadyStateModel.hh"
34
#include "Statement.hh"
35
#include "ExternalFunctionsTable.hh"
36
#include "ConfigFile.hh"
37
#include "WarningConsolidation.hh"
38
#include "FileOutputType.hh"
39
40
41
42
43

//! The abstract representation of a "mod" file
class ModFile
{
public:
44
  ModFile(WarningConsolidation &warnings_arg);
45
46
47
  ~ModFile();
  //! Symbol table
  SymbolTable symbol_table;
48
49
  //! External Functions table
  ExternalFunctionsTable external_functions_table;
50
51
52
53
  //! Numerical constants table
  NumericalConstants num_constants;
  //! Expressions outside model block
  DataTree expressions_tree;
54
  //! Dynamic model, as declared in the "model" block
sebastien's avatar
sebastien committed
55
  DynamicModel dynamic_model;
56
57
  //! A copy of Dynamic model, for testing trends declared by user
  DynamicModel trend_dynamic_model;
58
59
  //! A model in which to create the FOC for the ramsey problem
  DynamicModel ramsey_FOC_equations_dynamic_model;
60
61
  //! Static model, as derived from the "model" block when leads and lags have been removed
  StaticModel static_model;
62
63
  //! Static model, as declared in the "steady_state_model" block if present
  SteadyStateModel steady_state_model;
64
65
  //! Option linear
  bool linear;
66
67
68
69

  //! Is the model block decomposed?
  bool block;

sebastien's avatar
sebastien committed
70
  //! Is the model stored in bytecode format (byte_code=true) or in a M-file (byte_code=false)
71
72
  bool byte_code;

sebastien's avatar
sebastien committed
73
  //! Is the model stored in a MEX file ? (option "use_dll" of "model")
74
  bool use_dll;
75

76
77
78
  //! Is the static model have to computed (no_static=false) or not (no_static=true). Option of 'model'
  bool no_static;

79
80
81
  //! Is the 'differentiate_forward_vars' option used?
  bool differentiate_forward_vars;

82
83
84
85
86
87
  /*! If the 'differentiate_forward_vars' option is used, contains the set of
      endogenous with respect to which to do the transformation;
      if empty, means that the transformation must be applied to all endos
      with a lead */
  vector<string> differentiate_forward_vars_subset;

88
89
90
  //! Are nonstationary variables present ?
  bool nonstationary_variables;

91
92
  //! Global evaluation context
  /*! Filled using initval blocks and parameters initializations */
93
  eval_context_t global_eval_context;
94

95
  //! Stores the original number of equations in the model_block
96
  int ramsey_model_orig_eqn_nbr;
97

98
99
100
101
  //! Stores the list of extra files to be transefered during a parallel run
  /*! (i.e. option parallel_local_files of model block) */
  vector<string> parallel_local_files;

102
103
104
105
106
private:
  //! List of statements
  vector<Statement *> statements;
  //! Structure of the mod file
  ModFileStructure mod_file_struct;
107
108
  //! Warnings Encountered
  WarningConsolidation &warnings;
109
110
111
112

public:
  //! Add a statement
  void addStatement(Statement *st);
113
114
  //! Add a statement at the front of the statements vector
  void addStatementAtFront(Statement *st);
115
  //! Evaluate all the statements
116
117
  /*! \param warn_uninit Should a warning be displayed for uninitialized endogenous/exogenous/parameters ? */
  void evalAllExpressions(bool warn_uninit);
118
  //! Do some checking and fills mod_file_struct
sebastien's avatar
sebastien committed
119
  /*! \todo add check for number of equations and endogenous if ramsey_policy is present */
120
  void checkPass();
sebastien's avatar
sebastien committed
121
  //! Perform some transformations on the model (creation of auxiliary vars and equations)
122
  void transformPass(bool nostrict);
123
  //! Execute computations
124
  /*! \param no_tmp_terms if true, no temporary terms will be computed in the static and dynamic files */
125
  void computingPass(bool no_tmp_terms, FileOutputType output);
sebastien's avatar
sebastien committed
126
  //! Writes Matlab/Octave output files
127
128
129
  /*!
    \param basename The base name used for writing output files. Should be the name of the mod file without its extension
    \param clear_all Should a "clear all" instruction be written to output ?
130
    \param console Are we in console mode ?
131
    \param nograph Should we build the figures?
132
    \param nointeractive Should Dynare request user input?
133
    \param cygwin Should the MEX command of use_dll be adapted for Cygwin?
134
    \param msvc Should the MEX command of use_dll be adapted for MSVC?
135
  */
136
  void writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file
137
#if defined(_WIN32) || defined(__CYGWIN32__)
138
                        , bool cygwin, bool msvc
139
#endif
140
                        ) const;
141
142
  //! Writes C output files only => No further Matlab processing
  void writeCOutputFiles(const string &basename) const;
143
  void writeModelCC(const string &basename, bool cuda) const;
144
  void writeExternalFiles(const string &basename, FileOutputType output, bool cuda) const;
145
146
147
};

#endif // ! MOD_FILE_HH