Commit 4f9e8a6e authored by sebastien's avatar sebastien
Browse files

v4 parser:

* clearly separated the parsing process from the output writing, using an abstract intermediary representation of the mod file
* created the Statement class, and its derivatives, for that purpose
* fixed bug with "corr" statements in "shocks" blocks (variables indexes given to matlab were incorrect)
* fixed bug with "optim" option of "estimation" (this option was not passed to matlab)
* fixed bug with "dynatype" and "dynasave" (variable list was not passed correctly to matlab)
* fixed bug with "calib" and "calib_var" (they were unusable because of flex misspecification)
* fixed segmentation fault with "estimated_params_bound" and "estimation_params_init"


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1117 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 9337cdef
This diff is collapsed.
...@@ -100,7 +100,7 @@ typedef pair<int, Type> ExpObj; ...@@ -100,7 +100,7 @@ typedef pair<int, Type> ExpObj;
| initval | initval
| endval | endval
| histval | histval
| equality_expression | init_param
| shocks | shocks
| mshocks | mshocks
| sigma_e | sigma_e
...@@ -140,8 +140,8 @@ typedef pair<int, Type> ExpObj; ...@@ -140,8 +140,8 @@ typedef pair<int, Type> ExpObj;
; ;
dsample : DSAMPLE INT_NUMBER ';' {driver.option_num("dsample", $2);} dsample : DSAMPLE INT_NUMBER ';' { driver.dsample($2);}
| DSAMPLE INT_NUMBER INT_NUMBER ';' {driver.option_num("dsample", $2, $3);} | DSAMPLE INT_NUMBER INT_NUMBER ';' {driver.dsample($2, $3);}
; ;
rplot : RPLOT tmp_var_list ';' {driver.rplot();} rplot : RPLOT tmp_var_list ';' {driver.rplot();}
...@@ -225,18 +225,16 @@ typedef pair<int, Type> ExpObj; ...@@ -225,18 +225,16 @@ typedef pair<int, Type> ExpObj;
periods periods
: PERIODS INT_NUMBER ';' : PERIODS INT_NUMBER ';'
{ {
driver.option_num("periods", $2); driver.periods($2);
driver.option_num("simul", "1");
} }
| PERIODS EQUAL INT_NUMBER ';' | PERIODS EQUAL INT_NUMBER ';'
{ {
driver.option_num("periods", $3); driver.periods($3);
driver.option_num("simul", "1");
} }
; ;
equality_expression init_param
: NAME EQUAL expression ';' : NAME EQUAL expression ';'
{driver.init_param($1, $3);} {driver.init_param($1, $3);}
; ;
...@@ -297,12 +295,12 @@ typedef pair<int, Type> ExpObj; ...@@ -297,12 +295,12 @@ typedef pair<int, Type> ExpObj;
{$$ = driver.add_expression_token($1, $3, token::COMMA);} {$$ = driver.add_expression_token($1, $3, token::COMMA);}
initval initval
: INITVAL ';' {driver.begin_initval();} initval_list END : INITVAL ';' initval_list END
{driver.end_initval();} {driver.end_initval();}
; ;
endval endval
: ENDVAL ';' {driver.begin_endval();} initval_list END : ENDVAL ';' initval_list END
{driver.end_endval();} {driver.end_endval();}
; ;
...@@ -317,7 +315,9 @@ typedef pair<int, Type> ExpObj; ...@@ -317,7 +315,9 @@ typedef pair<int, Type> ExpObj;
; ;
histval histval
: HISTVAL ';' {driver.begin_histval();} histval_list END : HISTVAL ';' histval_list END
{ driver.end_histval(); }
;
histval_list histval_list
: histval_list histval_elem : histval_list histval_elem
...@@ -331,9 +331,9 @@ typedef pair<int, Type> ExpObj; ...@@ -331,9 +331,9 @@ typedef pair<int, Type> ExpObj;
model model
: MODEL ';' equation_list END : MODEL ';' equation_list END
| MODEL '(' LINEAR ')' ';' {driver.option_num("linear","1");} | MODEL '(' o_linear ')' ';'
equation_list END equation_list END
| MODEL '(' USE_DLL ')' ';' {driver.use_dll();} | MODEL '(' USE_DLL ')' ';' {driver.use_dll();}
equation_list END equation_list END
; ;
...@@ -405,11 +405,11 @@ typedef pair<int, Type> ExpObj; ...@@ -405,11 +405,11 @@ typedef pair<int, Type> ExpObj;
; ;
shocks shocks
: SHOCKS ';' {driver.begin_shocks();} shock_list END {driver.end_shocks();} : SHOCKS ';' shock_list END {driver.end_shocks();}
; ;
mshocks mshocks
: MSHOCKS ';' {driver.begin_mshocks();} shock_list END {driver.end_shocks();} : MSHOCKS ';' shock_list END {driver.end_mshocks();}
; ;
shock_list shock_list
...@@ -612,14 +612,15 @@ typedef pair<int, Type> ExpObj; ...@@ -612,14 +612,15 @@ typedef pair<int, Type> ExpObj;
; ;
estimated_params estimated_params
: ESTIMATED_PARAMS ';' {driver.estimation_init();} estimated_list END : ESTIMATED_PARAMS ';' estimated_list END
{ driver.estimated_params(); }
; ;
estimated_list estimated_list
: estimated_list estimated_elem : estimated_list estimated_elem
{driver.set_estimated_elements();} {driver.add_estimated_params_element();}
| estimated_elem | estimated_elem
{driver.set_estimated_elements();} {driver.add_estimated_params_element();}
; ;
estimated_elem estimated_elem
...@@ -723,12 +724,13 @@ typedef pair<int, Type> ExpObj; ...@@ -723,12 +724,13 @@ typedef pair<int, Type> ExpObj;
; ;
estimated_params_init: ESTIMATED_PARAMS_INIT ';' estimated_init_list END estimated_params_init: ESTIMATED_PARAMS_INIT ';' estimated_init_list END
{ driver.estimated_params_init(); }
; ;
estimated_init_list : estimated_init_list estimated_init_elem estimated_init_list : estimated_init_list estimated_init_elem
{driver.set_estimated_init_elements();} {driver.add_estimated_params_element();}
| estimated_init_elem | estimated_init_elem
{driver.set_estimated_init_elements();} {driver.add_estimated_params_element();}
; ;
estimated_init_elem : STDERR NAME COMMA value ';' estimated_init_elem : STDERR NAME COMMA value ';'
...@@ -757,12 +759,13 @@ typedef pair<int, Type> ExpObj; ...@@ -757,12 +759,13 @@ typedef pair<int, Type> ExpObj;
; ;
estimated_params_bounds: ESTIMATED_PARAMS_BOUNDS ';' estimated_bounds_list END estimated_params_bounds: ESTIMATED_PARAMS_BOUNDS ';' estimated_bounds_list END
{ driver.estimated_params_bounds(); }
; ;
estimated_bounds_list : estimated_bounds_list estimated_bounds_elem estimated_bounds_list : estimated_bounds_list estimated_bounds_elem
{driver.set_estimated_bounds_elements();} {driver.add_estimated_params_element();}
| estimated_bounds_elem | estimated_bounds_elem
{driver.set_estimated_bounds_elements();} {driver.add_estimated_params_element();}
; ;
estimated_bounds_elem : STDERR NAME COMMA value COMMA value ';' estimated_bounds_elem : STDERR NAME COMMA value COMMA value ';'
...@@ -914,8 +917,8 @@ typedef pair<int, Type> ExpObj; ...@@ -914,8 +917,8 @@ typedef pair<int, Type> ExpObj;
; ;
list_optim_option list_optim_option
: '\'' NAME '\'' COMMA '\'' NAME '\'' {driver.optim_options($2, $6, 2);} : '\'' NAME '\'' COMMA '\'' NAME '\'' {driver.optim_options_string($2, $6);}
| '\'' NAME '\'' COMMA value {driver.optim_options($2, $5, 2);} | '\'' NAME '\'' COMMA value {driver.optim_options_num($2, $5);}
; ;
optim_options optim_options
...@@ -929,7 +932,8 @@ typedef pair<int, Type> ExpObj; ...@@ -929,7 +932,8 @@ typedef pair<int, Type> ExpObj;
; ;
observation_trends observation_trends
: OBSERVATION_TRENDS ';' {driver.set_trend_init();} trend_list END : OBSERVATION_TRENDS ';' trend_list END
{ driver.set_trends(); }
; ;
trend_list trend_list
...@@ -944,7 +948,8 @@ typedef pair<int, Type> ExpObj; ...@@ -944,7 +948,8 @@ typedef pair<int, Type> ExpObj;
unit_root_vars : UNIT_ROOT_VARS tmp_var_list ';' {driver.set_unit_root_vars();} unit_root_vars : UNIT_ROOT_VARS tmp_var_list ';' {driver.set_unit_root_vars();}
; ;
optim_weights : OPTIM_WEIGHTS ';' {driver.begin_optim_weights();} optim_weights_list END optim_weights : OPTIM_WEIGHTS ';' optim_weights_list END
{ driver.optim_weights(); }
; ;
optim_weights_list : optim_weights_list NAME expression ';' optim_weights_list : optim_weights_list NAME expression ';'
...@@ -983,7 +988,8 @@ typedef pair<int, Type> ExpObj; ...@@ -983,7 +988,8 @@ typedef pair<int, Type> ExpObj;
olr_inst : OLR_INST tmp_var_list ';' {driver.set_olr_inst();} olr_inst : OLR_INST tmp_var_list ';' {driver.set_olr_inst();}
; ;
calib_var : CALIB_VAR ';' {driver.begin_calib_var();} calib_var_list END calib_var : CALIB_VAR ';' calib_var_list END
{ driver.run_calib_var(); }
; ;
calib_var_list : calib_var_list calib_arg1 calib_var_list : calib_var_list calib_arg1
...@@ -991,7 +997,7 @@ typedef pair<int, Type> ExpObj; ...@@ -991,7 +997,7 @@ typedef pair<int, Type> ExpObj;
; ;
calib_arg1 : NAME calib_arg2 EQUAL expression ';' {driver.set_calib_var($1, $2, $4);} calib_arg1 : NAME calib_arg2 EQUAL expression ';' {driver.set_calib_var($1, $2, $4);}
| NAME COMMA NAME calib_arg2 EQUAL expression ';' {driver.set_calib_var($1, $3, $4, $6);} | NAME COMMA NAME calib_arg2 EQUAL expression ';' {driver.set_calib_covar($1, $3, $4, $6);}
| AUTOCORR NAME '(' INT_NUMBER ')' calib_arg2 EQUAL expression ';' {driver.set_calib_ac($2, $4, $6, $8);} | AUTOCORR NAME '(' INT_NUMBER ')' calib_arg2 EQUAL expression ';' {driver.set_calib_ac($2, $4, $6, $8);}
; ;
...@@ -1018,8 +1024,8 @@ typedef pair<int, Type> ExpObj; ...@@ -1018,8 +1024,8 @@ typedef pair<int, Type> ExpObj;
| DYNASAVE '(' NAME '.' NAME ')' tmp_var_list ';' {driver.run_dynasave($3, $5);} | DYNASAVE '(' NAME '.' NAME ')' tmp_var_list ';' {driver.run_dynasave($3, $5);}
| DYNASAVE NAME '.' NAME ';' {driver.run_dynasave($2, $4);}; | DYNASAVE NAME '.' NAME ';' {driver.run_dynasave($2, $4);};
model_comparison : MODEL_COMPARISON '(' model_comparison_options ')' {driver.begin_model_comparison();} model_comparison : MODEL_COMPARISON '(' model_comparison_options ')' filename_list ';'
filename_list ';' {driver.run_model_comparison();} {driver.run_model_comparison();}
; ;
model_comparison_options: model_comparison_options COMMA model_comparison_option model_comparison_options: model_comparison_options COMMA model_comparison_option
...@@ -1051,7 +1057,7 @@ typedef pair<int, Type> ExpObj; ...@@ -1051,7 +1057,7 @@ typedef pair<int, Type> ExpObj;
o_dr_algo: DR_ALGO EQUAL INT_NUMBER {driver.option_num("dr_algo", $3);}; o_dr_algo: DR_ALGO EQUAL INT_NUMBER {driver.option_num("dr_algo", $3);};
o_solve_algo: SOLVE_ALGO EQUAL INT_NUMBER {driver.option_num("solve_algo", $3);}; o_solve_algo: SOLVE_ALGO EQUAL INT_NUMBER {driver.option_num("solve_algo", $3);};
o_simul_algo: SIMUL_ALGO EQUAL INT_NUMBER {driver.option_num("simul_algo", $3);}; o_simul_algo: SIMUL_ALGO EQUAL INT_NUMBER {driver.option_num("simul_algo", $3);};
o_linear: LINEAR {driver.option_num("linear", "1");}; o_linear: LINEAR {driver.linear();};
o_order: ORDER EQUAL INT_NUMBER {driver.option_num("order", $3);}; o_order: ORDER EQUAL INT_NUMBER {driver.option_num("order", $3);};
o_replic: REPLIC EQUAL INT_NUMBER {driver.option_num("replic", $3);}; o_replic: REPLIC EQUAL INT_NUMBER {driver.option_num("replic", $3);};
o_drop: DROP EQUAL INT_NUMBER {driver.option_num("drop", $3);}; o_drop: DROP EQUAL INT_NUMBER {driver.option_num("drop", $3);};
......
...@@ -67,7 +67,6 @@ int sigma_e = 0; ...@@ -67,7 +67,6 @@ int sigma_e = 0;
<INITIAL>rplot {BEGIN DYNARE_STATEMENT; return token::RPLOT;} <INITIAL>rplot {BEGIN DYNARE_STATEMENT; return token::RPLOT;}
<INITIAL>osr_params {BEGIN DYNARE_STATEMENT; return token::OSR_PARAMS;} <INITIAL>osr_params {BEGIN DYNARE_STATEMENT; return token::OSR_PARAMS;}
<INITIAL>osr {BEGIN DYNARE_STATEMENT; return token::OSR;} <INITIAL>osr {BEGIN DYNARE_STATEMENT; return token::OSR;}
<INITIAL>calib_var {BEGIN DYNARE_STATEMENT; return token::CALIB_VAR;}
<INITIAL>dynatype {BEGIN DYNARE_STATEMENT; return token::DYNATYPE;} <INITIAL>dynatype {BEGIN DYNARE_STATEMENT; return token::DYNATYPE;}
<INITIAL>dynasave {BEGIN DYNARE_STATEMENT; return token::DYNASAVE;} <INITIAL>dynasave {BEGIN DYNARE_STATEMENT; return token::DYNASAVE;}
<INITIAL>olr {BEGIN DYNARE_STATEMENT; return token::OLR;} <INITIAL>olr {BEGIN DYNARE_STATEMENT; return token::OLR;}
...@@ -80,6 +79,7 @@ int sigma_e = 0; ...@@ -80,6 +79,7 @@ int sigma_e = 0;
<INITIAL>stoch_simul {BEGIN DYNARE_STATEMENT; return token::STOCH_SIMUL;} <INITIAL>stoch_simul {BEGIN DYNARE_STATEMENT; return token::STOCH_SIMUL;}
<INITIAL>dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;} <INITIAL>dsample {BEGIN DYNARE_STATEMENT; return token::DSAMPLE;}
<INITIAL>Sigma_e {BEGIN DYNARE_STATEMENT; sigma_e = 1; return token::SIGMA_E;} <INITIAL>Sigma_e {BEGIN DYNARE_STATEMENT; sigma_e = 1; return token::SIGMA_E;}
<INITIAL>calib {BEGIN DYNARE_STATEMENT; return token::CALIB;}
/* End of a Dynare statement */ /* End of a Dynare statement */
<DYNARE_STATEMENT>; { <DYNARE_STATEMENT>; {
...@@ -102,6 +102,7 @@ int sigma_e = 0; ...@@ -102,6 +102,7 @@ int sigma_e = 0;
<INITIAL>estimated_params_bounds {BEGIN DYNARE_BLOCK; return token::ESTIMATED_PARAMS_BOUNDS;} <INITIAL>estimated_params_bounds {BEGIN DYNARE_BLOCK; return token::ESTIMATED_PARAMS_BOUNDS;}
<INITIAL>observation_trends {BEGIN DYNARE_BLOCK; return token::OBSERVATION_TRENDS;} <INITIAL>observation_trends {BEGIN DYNARE_BLOCK; return token::OBSERVATION_TRENDS;}
<INITIAL>optim_weights {BEGIN DYNARE_BLOCK; return token::OPTIM_WEIGHTS;} <INITIAL>optim_weights {BEGIN DYNARE_BLOCK; return token::OPTIM_WEIGHTS;}
<INITIAL>calib_var {BEGIN DYNARE_BLOCK; return token::CALIB_VAR;}
/* End of a Dynare block */ /* End of a Dynare block */
<DYNARE_BLOCK>end[ \t\n]*; {BEGIN INITIAL; return token::END;} <DYNARE_BLOCK>end[ \t\n]*; {BEGIN INITIAL; return token::END;}
...@@ -154,6 +155,7 @@ int sigma_e = 0; ...@@ -154,6 +155,7 @@ int sigma_e = 0;
<DYNARE_STATEMENT>modifiedharmonicmean {return token::MODIFIEDHARMONICMEAN;} <DYNARE_STATEMENT>modifiedharmonicmean {return token::MODIFIEDHARMONICMEAN;}
<DYNARE_STATEMENT>constant {return token::CONSTANT;} <DYNARE_STATEMENT>constant {return token::CONSTANT;}
<DYNARE_STATEMENT>noconstant {return token::NOCONSTANT;} <DYNARE_STATEMENT>noconstant {return token::NOCONSTANT;}
<DYNARE_STATEMENT>covar {return token::COVAR;}
<DYNARE_STATEMENT>[\$][^$]*[\$] { <DYNARE_STATEMENT>[\$][^$]*[\$] {
strtok(yytext+1, "$"); strtok(yytext+1, "$");
...@@ -179,6 +181,7 @@ int sigma_e = 0; ...@@ -179,6 +181,7 @@ int sigma_e = 0;
<DYNARE_BLOCK>; {return yy::parser::token_type (yytext[0]);} <DYNARE_BLOCK>; {return yy::parser::token_type (yytext[0]);}
<DYNARE_BLOCK># {return yy::parser::token_type (yytext[0]);} <DYNARE_BLOCK># {return yy::parser::token_type (yytext[0]);}
<DYNARE_BLOCK>autocorr {return token::AUTOCORR;}
/* Inside Dynare statement */ /* Inside Dynare statement */
<DYNARE_STATEMENT>solve_algo {return token::SOLVE_ALGO;} <DYNARE_STATEMENT>solve_algo {return token::SOLVE_ALGO;}
...@@ -195,7 +198,6 @@ int sigma_e = 0; ...@@ -195,7 +198,6 @@ int sigma_e = 0;
<DYNARE_STATEMENT>simul_seed {return token::SIMUL_SEED;} <DYNARE_STATEMENT>simul_seed {return token::SIMUL_SEED;}
<DYNARE_STATEMENT>qz_criterium {return token::QZ_CRITERIUM;} <DYNARE_STATEMENT>qz_criterium {return token::QZ_CRITERIUM;}
<DYNARE_STATEMENT>simul {return token::SIMUL;} <DYNARE_STATEMENT>simul {return token::SIMUL;}
<DYNARE_STATEMENT>autocorr {return token::AUTOCORR;}
<DYNARE_STATEMENT>olr_beta {return token::OLR_BETA;} <DYNARE_STATEMENT>olr_beta {return token::OLR_BETA;}
<DYNARE_STATEMENT>xtick {return token::XTICK;} <DYNARE_STATEMENT>xtick {return token::XTICK;}
<DYNARE_STATEMENT>xticklabel {return token::XTICKLABEL;} <DYNARE_STATEMENT>xticklabel {return token::XTICKLABEL;}
...@@ -267,15 +269,17 @@ int sigma_e = 0; ...@@ -267,15 +269,17 @@ int sigma_e = 0;
} }
else else
{ {
/* Enter a native block */
BEGIN NATIVE; BEGIN NATIVE;
driver.add_native(yytext); yyless(0);
} }
} }
<INITIAL>. {BEGIN NATIVE; driver.add_native(yytext); } /* Enter a native block */
<INITIAL>. { BEGIN NATIVE; yyless(0); }
/* NATIVE Block */ /* Add the native statement */
<NATIVE>.* {BEGIN INITIAL; driver.add_native(yytext); driver.add_native("\n"); } <NATIVE>.* { driver.add_native(yytext); BEGIN INITIAL; }
<*>. { driver.error("Unrecognized character: '" + string(yytext) + "'"); } <*>. { driver.error("Unrecognized character: '" + string(yytext) + "'"); }
%% %%
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
using namespace std; using namespace std;
#include "ParsingDriver.hh" #include "ParsingDriver.hh"
#include "OutputFile.hh"
#include "ModFile.hh" #include "ModFile.hh"
/*! /*!
...@@ -17,9 +16,6 @@ using namespace std; ...@@ -17,9 +16,6 @@ using namespace std;
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
OutputFile output_file;
ostringstream output;
if (argc < 2) if (argc < 2)
{ {
cerr << "Missing model file" << endl; cerr << "Missing model file" << endl;
...@@ -29,8 +25,7 @@ main(int argc, char** argv) ...@@ -29,8 +25,7 @@ main(int argc, char** argv)
ParsingDriver p; ParsingDriver p;
// Sets string output of parser bool clear_all = true;
p.setoutput(&output);
// Parse options // Parse options
for (int arg = 2; arg < argc; arg++) for (int arg = 2; arg < argc; arg++)
...@@ -42,7 +37,7 @@ main(int argc, char** argv) ...@@ -42,7 +37,7 @@ main(int argc, char** argv)
} }
else else
if (string(argv[arg]) == string("noclearall")) if (string(argv[arg]) == string("noclearall"))
output_file.clear_all = false; clear_all = false;
} }
cout << "Starting Dynare ..." << endl; cout << "Starting Dynare ..." << endl;
...@@ -51,15 +46,11 @@ main(int argc, char** argv) ...@@ -51,15 +46,11 @@ main(int argc, char** argv)
// Launch parsing // Launch parsing
ModFile *mod_file = p.parse(argv[1]); ModFile *mod_file = p.parse(argv[1]);
// Execute final instructions // FIXME
p.finish(); string basename = argv[1];
basename.erase(basename.size() - 4, 4);
string name = argv[1]; mod_file->writeOutputFiles(basename, clear_all);
name.erase(name.size() - 4,4);
// Opening and init main Output file (.m or .sci file)
output_file.Open(name, mod_file);
// Writing remaining string output to output file
output_file.Save(output, mod_file);
delete mod_file; delete mod_file;
......
...@@ -43,7 +43,6 @@ COMMON_OBJ=\ ...@@ -43,7 +43,6 @@ COMMON_OBJ=\
NumericalConstants.o\ NumericalConstants.o\
NumericalInitialization.o\ NumericalInitialization.o\
OperatorTable.o\ OperatorTable.o\
OutputFile.o\
Shocks.o\ Shocks.o\
SigmaeInitialization.o\ SigmaeInitialization.o\
SymbolTable.o\ SymbolTable.o\
...@@ -51,7 +50,8 @@ COMMON_OBJ=\ ...@@ -51,7 +50,8 @@ COMMON_OBJ=\
VariableTable.o\ VariableTable.o\
ParsingDriver.o\ ParsingDriver.o\
DataTree.o \ DataTree.o \
ModFile.o ModFile.o \
Statement.o
MATLAB_OBJ = InterfaceMatlab.o MATLAB_OBJ = InterfaceMatlab.o
......
#include "ModFile.hh" #include "ModFile.hh"
#include "Interface.hh"
ModFile::ModFile() : symbol_table(model_parameters), ModFile::ModFile() : symbol_table(model_parameters),
variable_table(symbol_table, model_parameters), variable_table(symbol_table, model_parameters),
numerical_initialization(symbol_table, model_parameters), model_tree(symbol_table, variable_table, model_parameters, num_constants),
computing_tasks(symbol_table), order(-1), linear(-1)
model_tree(symbol_table, variable_table, model_parameters, num_constants)
{ {
} }
ModFile::~ModFile()
{
for(vector<Statement *>::iterator it = statements.begin();
it != statements.end(); it++)
delete (*it);
}
void
ModFile::addStatement(Statement *st)
{
statements.push_back(st);
}
void
ModFile::writeOutputFiles(const string &basename, bool clear_all)
{
ofstream mOutputFile;
if (basename.size())
{
string fname(basename);
fname += interfaces::function_file_extension();
mOutputFile.open(fname.c_str(), ios::out | ios::binary);
if (!mOutputFile.is_open())
{
cerr << "Error: Can't open file " << fname
<< " for writing" << endl;
exit(-1);
}
}
else
{
cerr << "Error: Missing file name" << endl;
exit(-1);
}
mOutputFile << interfaces::comment() << endl;
mOutputFile << interfaces::comment() << "Status : main Dynare file " << endl;
mOutputFile << interfaces::comment() << endl;
mOutputFile << interfaces::comment() << "Warning : this file is generated automatically by Dynare" << endl;
mOutputFile << interfaces::comment() << " from model file (.mod)" << endl << endl;
if (clear_all)
mOutputFile << "clear all" << endl;
mOutputFile << "tic;" << endl;
mOutputFile << "global M_ oo_ exedet_ exdet_ recur_ recurs_ " << endl;
mOutputFile << "global options_ endval_" << endl;
mOutputFile << "global ys0_ recurs0_ ex0_ ct_" << endl;
mOutputFile << "options_ = [];" << endl;
mOutputFile << "M_.fname = '" << basename << "';" << endl;
mOutputFile << interfaces::comment() << endl;
mOutputFile << interfaces::comment() << "Some global variables initialisation" << endl;
mOutputFile << interfaces::comment() << endl;
mOutputFile << "global_initialization;" << endl;
mOutputFile << "diary off;" << endl << "warning off;" << endl << endl;
mOutputFile << interfaces::delete_file(basename + ".log") << ";" << endl;
mOutputFile << "warning on;" << endl << "warning backtrace;" << endl;
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
mOutputFile << "diary '" << basename << ".log';" << endl;
if (model_tree.offset == 0)
{
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_static.c)") << endl;
mOutputFile << " clear " << basename << "_static" << endl;
mOutputFile << " " << interfaces::compile(basename +"_static.c") << endl;
mOutputFile << "end" << endl;
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_dynamic.c)") << endl;
mOutputFile << " clear " << basename << "_dynamic" << endl;
mOutputFile << " " + interfaces::compile(basename+"_dynamic.c") << endl;
mOutputFile << "end" << endl;
}
else
{
mOutputFile << "erase_compiled_function('" + basename +"_static');" << endl;
mOutputFile << "erase_compiled_function('" + basename +"_dynamic');" << endl;
mOutputFile << interfaces::load_model_function_files(basename);
}
symbol_table.writeOutput(mOutputFile);
if (linear == 1)
mOutputFile << "options_.linear = 1;" << endl;
model_tree.writeOutput(mOutputFile, basename, order, linear);