v4: dropped Scilab support

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1878 ac1d8469-bf42-47a9-8791-bf33cf982152
issue#70
sebastien 2008-06-16 16:33:28 +00:00
parent f18f91fe40
commit e0510d4a49
11 changed files with 188 additions and 364 deletions

View File

@ -23,7 +23,6 @@
using namespace std;
#include "ComputingTasks.hh"
#include "Interface.hh"
#include "Statement.hh"
SteadyStatement::SteadyStatement(const OptionsList &options_list_arg) :
@ -570,8 +569,9 @@ void
CalibVarStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << "\n" << interfaces::comment() << "CALIB_VAR \n"
<< interfaces::comment() << "\n";
output << "%" << endl
<< "% CALIB_VAR" << endl
<< "%" << endl;
for(int i = 1; i < 4 ; i++)
{
@ -728,9 +728,11 @@ OptimWeightsStatement::OptimWeightsStatement(const var_weights_type &var_weights
void
OptimWeightsStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << "OPTIM_WEIGHTS\n\n";
output << "optim_weights_ = sparse(M_.endo_nbr,M_.endo_nbr);\n";
output << "obj_var_ = [];\n\n";
output << "%" << endl
<< "% OPTIM_WEIGHTS" << endl
<< "%" << endl
<< "optim_weights_ = sparse(M_.endo_nbr,M_.endo_nbr);" << endl
<< "obj_var_ = [];" << endl << endl;
for(var_weights_type::const_iterator it = var_weights.begin();
it != var_weights.end(); it++)

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2006-2008 Dynare Team
*
* 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/>.
*/
#include <string>
#include "Interface.hh"
namespace interfaces
{
string comment()
{
return "% ";
}
string delete_file(string s)
{
return "delete " + s;
}
string file_exist(string s)
{
return "exist('" + s + "')";
}
string compile(string s)
{
return "mex -O " + s + "\n";
}
string function_close()
{
return "";
}
string function_file_extension()
{
return ".m";
}
string strvcat(string s1, string s2)
{
return "strvcat(" + s1 + "," + s2 + ")";
}
string load_model_function_files(string filename)
{
return "";
}
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2006-2008 Dynare Team
*
* 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/>.
*/
#include <string>
#include "Interface.hh"
namespace interfaces
{
string comment()
{
return "// ";
}
string delete_file(string s)
{
return "mdelete " + s;
}
string file_exist(string s)
{
return "file_exist(" + s + ")";
}
string compile(string s)
{
return "";
}
string function_close()
{
return "endfunction\n";
}
string function_file_extension()
{
return ".sci";
}
string strvcat(string s1, string s2)
{
return "[" + s1 + ";" + s2 + "]";
}
string load_model_function_files(string filename)
{
return "getf('" + filename + "_static.sci');\ngetf('" + filename + "_dynamic.sci');\n";
}
}

View File

@ -2,18 +2,15 @@ include Makefile.include
ifeq ($(shell uname -o), Cygwin)
DYNARE_M = dynare_m.exe
DYNARE_S = dynare_s.exe
else
DYNARE_M = dynare_m
DYNARE_S = dynare_s
endif
ifeq ($(CROSS_WIN32), yes)
DYNARE_M = dynare_m.exe
DYNARE_S = dynare_s.exe
endif
COMMON_OBJ = \
OBJS = \
DynareFlex.o \
DynareBison.o \
ComputingTasks.o \
@ -38,30 +35,22 @@ COMMON_OBJ = \
DynareMain.o \
DynareMain2.o
MATLAB_OBJ = InterfaceMatlab.o
SCILAB_OBJ = InterfaceScilab.o
# Build rules
all: all-recursive $(DYNARE_M) $(DYNARE_S)
all: all-recursive $(DYNARE_M)
all-recursive:
make -C macro
$(DYNARE_M): $(COMMON_OBJ) $(MATLAB_OBJ) macro/libmacro.a
$(CPP) $(CPPFLAGS) -o $(DYNARE_M) $(COMMON_OBJ) $(MATLAB_OBJ) -Lmacro -lmacro
$(DYNARE_M): $(OBJS) macro/libmacro.a
$(CPP) $(CPPFLAGS) -o $(DYNARE_M) $(OBJS) -Lmacro -lmacro
cp $(DYNARE_M) ../matlab/
$(DYNARE_S): $(COMMON_OBJ) $(SCILAB_OBJ) macro/libmacro.a
$(CPP) $(CPPFLAGS) -o $(DYNARE_S) $(COMMON_OBJ) $(SCILAB_OBJ) -Lmacro -lmacro
cp $(DYNARE_S) ../scilab/
# Dependencies
-include $(COMMON_OBJ:.o=.P) $(MATLAB_OBJ:.o=.P) $(SCILAB_OBJ:.o=.P)
-include $(OBJS:.o=.P)
DynareFlex.cc: DynareFlex.ll include/DynareBison.hh include/ParsingDriver.hh
flex -oDynareFlex.cc DynareFlex.ll
@ -83,8 +72,7 @@ clean: clean-recursive
include/stack.hh \
include/location.hh \
include/DynareBison.hh \
$(DYNARE_M) \
$(DYNARE_S)
$(DYNARE_M)
clean-recursive:
make -C macro clean

View File

@ -21,7 +21,6 @@
#include <fstream>
#include "ModFile.hh"
#include "Interface.hh"
ModFile::ModFile() : expressions_tree(symbol_table, num_constants),
model_tree(symbol_table, num_constants),
@ -110,7 +109,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
if (basename.size())
{
string fname(basename);
fname += interfaces::function_file_extension();
fname += ".m";
mOutputFile.open(fname.c_str(), ios::out | ios::binary);
if (!mOutputFile.is_open())
{
@ -125,11 +124,11 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
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;
mOutputFile << "%" << endl
<< "% Status : main Dynare file " << endl
<< "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl;
if (clear_all)
mOutputFile << "clear all" << endl;
@ -139,12 +138,12 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
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 << "%" << endl;
mOutputFile << "% Some global variables initialization" << endl;
mOutputFile << "%" << endl;
mOutputFile << "global_initialization;" << endl;
mOutputFile << "diary off;" << endl << "warning off;" << endl << endl;
mOutputFile << interfaces::delete_file(basename + ".log") << ";" << endl;
mOutputFile << "delete " << basename << ".log;" << endl;
mOutputFile << "warning on;" << endl << "warning backtrace;" << endl;
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
mOutputFile << "diary '" << basename << ".log';" << endl;
@ -154,22 +153,19 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
{
if (model_tree.mode == eDLLMode)
{
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_static.c") << endl;
mOutputFile << "if exist('" << basename << "_static.c')" << endl;
mOutputFile << " clear " << basename << "_static" << endl;
mOutputFile << " " << interfaces::compile(basename +"_static.c") << endl;
mOutputFile << " mex -O " << basename << "_static.c" << endl;
mOutputFile << "end" << endl;
mOutputFile << "if ";
mOutputFile << interfaces::file_exist(basename + "_dynamic.c") << endl;
mOutputFile << "if exist('" << basename << "_dynamic.c')" << endl;
mOutputFile << " clear " << basename << "_dynamic" << endl;
mOutputFile << " " + interfaces::compile(basename+"_dynamic.c") << endl;
mOutputFile << " mex -O " << 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);
}
}

View File

@ -24,7 +24,6 @@
#include <cmath>
#include "ModelTree.hh"
#include "Interface.hh"
#include "Model_Graph.hh"
@ -656,12 +655,12 @@ ModelTree::writeModelEquationsOrdered_M(ostream &output, Model_Block *ModelBlock
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, it_)\n";
else
output << "function [residual, g1, g2, g3, b] = " << dynamic_basename << "_" << j+1 << "(y, x, y_kmin, y_size, periods)\n";
output << " " << interfaces::comment() << "////////////////////////////////////////////////////////////////////////\n" <<
" " << interfaces::comment() << "//" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " " << BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type) <<
" //\n" <<
" " << interfaces::comment() << "// Simulation type ";
output << BlockTriangular::BlockSim(ModelBlock->Block_List[j].Simulation_Type) << " //\n" <<
" " << interfaces::comment() << "////////////////////////////////////////////////////////////////////////\n";
output << " % ////////////////////////////////////////////////////////////////////////" << endl
<< " % //" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " " << BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type)
<< " //" << endl
<< " % // Simulation type "
<< BlockTriangular::BlockSim(ModelBlock->Block_List[j].Simulation_Type) << " //" << endl
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
//The Temporary terms
output << global_output.str();
output << " if M_.param_nbr > 0\n";
@ -687,7 +686,7 @@ ModelTree::writeModelEquationsOrdered_M(ostream &output, Model_Block *ModelBlock
else
sps="";
if (ModelBlock->Block_List[j].Temporary_terms->size())
output << " " << sps << interfaces::comment() << "//Temporary variables\n";
output << " " << sps << "% //Temporary variables" << endl;
i=0;
for(temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
@ -706,8 +705,8 @@ ModelTree::writeModelEquationsOrdered_M(ostream &output, Model_Block *ModelBlock
{
ModelBlock->Block_List[j].Variable_Sorted[i] = variable_table.getID(eEndogenous, ModelBlock->Block_List[j].Variable[i], 0);
string sModel = symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[i]) ;
output << sps << " " << interfaces::comment() << "equation " << ModelBlock->Block_List[j].Equation[i] << " variable : " <<
sModel << " (" << ModelBlock->Block_List[j].Variable[i] << ")\n";
output << sps << " % equation " << ModelBlock->Block_List[j].Equation[i] << " variable : " << sModel
<< " (" << ModelBlock->Block_List[j].Variable[i] << ")" << endl;
if (!lhs_rhs_done)
{
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
@ -764,16 +763,17 @@ ModelTree::writeModelEquationsOrdered_M(ostream &output, Model_Block *ModelBlock
&& ModelBlock->Block_List[j].Simulation_Type!=EVALUATE_BACKWARD_R
&& ModelBlock->Block_List[j].Simulation_Type!=EVALUATE_FOREWARD_R)
{
output << " " << sps << interfaces::comment() << "Jacobian \n";
output << " " << sps << "% Jacobian " << endl;
switch(ModelBlock->Block_List[j].Simulation_Type)
{
case SOLVE_BACKWARD_SIMPLE:
case SOLVE_FOREWARD_SIMPLE:
output << " g1(1)=";
writeDerivative(output, ModelBlock->Block_List[j].Equation[0], ModelBlock->Block_List[j].Variable[0], 0, oMatlabDynamicModelSparse, temporary_terms);
output << "; " << interfaces::comment() << "variable=" << symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[0])
<<"(" << variable_table.getLag(variable_table.getSymbolID(ModelBlock->Block_List[j].Variable[0])) << ") " << ModelBlock->Block_List[j].Variable[0]
<< ", equation=" << ModelBlock->Block_List[j].Equation[0] << "\n";
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[0])
<< "(" << variable_table.getLag(variable_table.getSymbolID(ModelBlock->Block_List[j].Variable[0]))
<< ") " << ModelBlock->Block_List[j].Variable[0]
<< ", equation=" << ModelBlock->Block_List[j].Equation[0] << endl;
break;
case SOLVE_BACKWARD_COMPLETE:
case SOLVE_FOREWARD_COMPLETE:
@ -787,9 +787,9 @@ ModelTree::writeModelEquationsOrdered_M(ostream &output, Model_Block *ModelBlock
Uf[ModelBlock->Block_List[j].Equation[eqr]] << "-u(" << u << ")*y(Per_y_+" << var << ")";
output << " u(" << u+1 << ") = ";
writeDerivative(output, eq, var, 0, oMatlabDynamicModelSparse, temporary_terms);
output << "; " << interfaces::comment() << "variable=" << symbol_table.getNameByID(eEndogenous, var)
<<"(" << variable_table.getLag(variable_table.getSymbolID(var))<< ") " << var
<< ", equation=" << eq << "\n";
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, var)
<< "(" << variable_table.getLag(variable_table.getSymbolID(var)) << ") " << var
<< ", equation=" << eq << endl;
}
for(i = 0;i < ModelBlock->Block_List[j].Size;i++)
output << Uf[ModelBlock->Block_List[j].Equation[i]].str() << ";\n";
@ -820,9 +820,9 @@ ModelTree::writeModelEquationsOrdered_M(ostream &output, Model_Block *ModelBlock
else if(k<0)
output << " g1(" << eqr+1 << "+Per_J_, " << varr+1 << "+y_size*(it_" << k << "-1)) = ";
writeDerivative(output, eq, var, k, oMatlabDynamicModelSparse, temporary_terms);
output << "; " << interfaces::comment() << "variable=" << symbol_table.getNameByID(eEndogenous, var)
<<"(" << k << ") " << var
<< ", equation=" << eq << "\n";
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, var)
<< "(" << k << ") " << var
<< ", equation=" << eq << endl;
#ifdef CONDITION
output << " if (fabs(condition[" << eqr << "])<fabs(u[" << u << "+Per_u_]))\n";
output << " condition(" << eqr << ")=u(" << u << "+Per_u_);\n";
@ -925,12 +925,12 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
else
output << "\n\n";
output << "function [residual, g1, g2, g3, b] = " << static_basename << "_" << j+1 << "(y, x)\n";
output << " " << interfaces::comment() << "////////////////////////////////////////////////////////////////////////\n" <<
" " << interfaces::comment() << "//" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " " << BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type) <<
" //\n" <<
" " << interfaces::comment() << "// Simulation type ";
output << BlockTriangular::BlockSim(ModelBlock->Block_List[j].Simulation_Type) << " //\n" <<
" " << interfaces::comment() << "////////////////////////////////////////////////////////////////////////\n";
output << " % ////////////////////////////////////////////////////////////////////////" << endl
<< " % //" << string(" Block ").substr(int(log10(j + 1))) << j + 1 << " "
<< BlockTriangular::BlockType0(ModelBlock->Block_List[j].Type) << " //" << endl
<< " % // Simulation type ";
output << BlockTriangular::BlockSim(ModelBlock->Block_List[j].Simulation_Type) << " //" << endl
<< " % ////////////////////////////////////////////////////////////////////////" << endl;
//The Temporary terms
output << global_output.str();
output << " if M_.param_nbr > 0\n";
@ -977,7 +977,7 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
output << " g1=spalloc(" << ModelBlock->Block_List[j].Size << ", " << ModelBlock->Block_List[j].Size << ", " << nze << ");\n";
sps="";
if (ModelBlock->Block_List[j].Temporary_terms->size())
output << " " << sps << interfaces::comment() << "//Temporary variables\n";
output << " " << sps << "% //Temporary variables" << endl;
i=0;
for(temporary_terms_type::const_iterator it = ModelBlock->Block_List[j].Temporary_terms->begin();
it != ModelBlock->Block_List[j].Temporary_terms->end(); it++)
@ -996,8 +996,8 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
{
ModelBlock->Block_List[j].Variable_Sorted[i] = variable_table.getID(eEndogenous, ModelBlock->Block_List[j].Variable[i], 0);
string sModel = symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[i]) ;
output << sps << " " << interfaces::comment() << "equation " << ModelBlock->Block_List[j].Equation[i] << " variable : " <<
sModel << " (" << ModelBlock->Block_List[j].Variable[i] << ")\n";
output << sps << " % equation " << ModelBlock->Block_List[j].Equation[i] << " variable : "
<< sModel << " (" << ModelBlock->Block_List[j].Variable[i] << ")" << endl;
if (!lhs_rhs_done)
{
eq_node = equations[ModelBlock->Block_List[j].Equation[i]];
@ -1047,16 +1047,17 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
&& ModelBlock->Block_List[j].Simulation_Type!=EVALUATE_BACKWARD_R
&& ModelBlock->Block_List[j].Simulation_Type!=EVALUATE_FOREWARD_R)
{
output << " " << sps << interfaces::comment() << "Jacobian \n";
output << " " << sps << "% Jacobian " << endl;
switch(ModelBlock->Block_List[j].Simulation_Type)
{
case SOLVE_BACKWARD_SIMPLE:
case SOLVE_FOREWARD_SIMPLE:
output << " g1(1)=";
writeDerivative(output, ModelBlock->Block_List[j].Equation[0], ModelBlock->Block_List[j].Variable[0], 0, oMatlabStaticModelSparse, temporary_terms);
output << "; " << interfaces::comment() << "variable=" << symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[0])
<<"(" << variable_table.getLag(variable_table.getSymbolID(ModelBlock->Block_List[j].Variable[0])) << ") " << ModelBlock->Block_List[j].Variable[0]
<< ", equation=" << ModelBlock->Block_List[j].Equation[0] << "\n";
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, ModelBlock->Block_List[j].Variable[0])
<< "(" << variable_table.getLag(variable_table.getSymbolID(ModelBlock->Block_List[j].Variable[0]))
<< ") " << ModelBlock->Block_List[j].Variable[0]
<< ", equation=" << ModelBlock->Block_List[j].Equation[0] << endl;
break;
case SOLVE_BACKWARD_COMPLETE:
case SOLVE_FOREWARD_COMPLETE:
@ -1070,9 +1071,9 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
Uf[ModelBlock->Block_List[j].Equation[eqr]] << "-u(" << u << ")*y(Per_y_+" << var << ")";
output << " u(" << u+1 << ") = ";
writeDerivative(output, eq, var, 0, oMatlabStaticModelSparse, temporary_terms);
output << "; " << interfaces::comment() << "variable=" << symbol_table.getNameByID(eEndogenous, var)
<<"(" << variable_table.getLag(variable_table.getSymbolID(var))<< ") " << var
<< ", equation=" << eq << "\n";
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, var)
<< "(" << variable_table.getLag(variable_table.getSymbolID(var)) << ") " << var
<< ", equation=" << eq << endl;
}
for(i = 0;i < ModelBlock->Block_List[j].Size;i++)
output << Uf[ModelBlock->Block_List[j].Equation[i]].str() << ";\n";
@ -1099,9 +1100,9 @@ ModelTree::writeModelStaticEquationsOrdered_M(ostream &output, Model_Block *Mode
}
output << " g1(" << eqr+1 << ", " << varr+1 << ") = g1(" << eqr+1 << ", " << varr+1 << ") + ";
writeDerivative(output, eq, var, k, oMatlabStaticModelSparse, temporary_terms);
output << "; " << interfaces::comment() << "variable=" << symbol_table.getNameByID(eEndogenous, var)
<<"(" << k << ") " << var
<< ", equation=" << eq << "\n";
output << "; % variable=" << symbol_table.getNameByID(eEndogenous, var)
<< "(" << k << ") " << var
<< ", equation=" << eq << endl;
#ifdef CONDITION
output << " if (fabs(condition[" << eqr << "])<fabs(u[" << u << "+Per_u_]))\n";
output << " condition(" << eqr << ")=u(" << u << "+Per_u_);\n";
@ -1520,7 +1521,7 @@ ModelTree::writeModelEquationsCodeOrdered(const string file_name, const Model_Bl
void
ModelTree::writeStaticMFile(const string &static_basename) const
{
string filename = static_basename + interfaces::function_file_extension();
string filename = static_basename + ".m";
ofstream mStaticModelFile;
mStaticModelFile.open(filename.c_str(), ios::out | ios::binary);
@ -1530,17 +1531,15 @@ ModelTree::writeStaticMFile(const string &static_basename) const
exit(-1);
}
// Writing comments and function definition command
mStaticModelFile << "function [residual, g1, g2] = " << static_basename << "(y, x, params)" << endl;
mStaticModelFile << interfaces::comment()+"\n"+interfaces::comment();
mStaticModelFile << "Status : Computes static model for Dynare\n" << interfaces::comment() << "\n";
mStaticModelFile << interfaces::comment();
mStaticModelFile << "Warning : this file is generated automatically by Dynare\n";
mStaticModelFile << interfaces::comment();
mStaticModelFile << " from model file (.mod)\n\n";
mStaticModelFile << "function [residual, g1, g2] = " << static_basename << "(y, x, params)" << endl
<< "%" << endl
<< "% Status : Computes static model for Dynare" << endl
<< "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl;
writeStaticModel(mStaticModelFile);
interfaces::function_close();
mStaticModelFile.close();
}
@ -1548,7 +1547,7 @@ ModelTree::writeStaticMFile(const string &static_basename) const
void
ModelTree::writeDynamicMFile(const string &dynamic_basename) const
{
string filename = dynamic_basename + interfaces::function_file_extension();
string filename = dynamic_basename + ".m";
ofstream mDynamicModelFile;
mDynamicModelFile.open(filename.c_str(), ios::out | ios::binary);
@ -1557,17 +1556,15 @@ ModelTree::writeDynamicMFile(const string &dynamic_basename) const
cerr << "Error: Can't open file " << filename << " for writing" << endl;
exit(-1);
}
mDynamicModelFile << "function [residual, g1, g2, g3] = " << dynamic_basename << "(y, x, params, it_)" << endl;
mDynamicModelFile << interfaces::comment()+"\n"+interfaces::comment();
mDynamicModelFile << "Status : Computes dynamic model for Dynare\n" << interfaces::comment() << "\n";
mDynamicModelFile << interfaces::comment();
mDynamicModelFile << "Warning : this file is generated automatically by Dynare\n";
mDynamicModelFile << interfaces::comment();
mDynamicModelFile << " from model file (.mod)\n\n";
mDynamicModelFile << "function [residual, g1, g2, g3] = " << dynamic_basename << "(y, x, params, it_)" << endl
<< "%" << endl
<< "% Status : Computes dynamic model for Dynare" << endl
<< "%" << endl
<< "% Warning : this file is generated automatically by Dynare" << endl
<< "% from model file (.mod)" << endl << endl;
writeDynamicModel(mDynamicModelFile);
interfaces::function_close();
mDynamicModelFile.close();
}
@ -1799,39 +1796,41 @@ ModelTree::writeStaticModel(ostream &StaticOutput) const
// Writing ouputs
if (mode != eDLLMode)
{
StaticOutput << " residual = zeros( " << equations.size() << ", 1);\n";
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
StaticOutput << "Model equations\n\t";
StaticOutput << interfaces::comment() + "\n\n";
StaticOutput << model_output.str();
StaticOutput << "if ~isreal(residual)\n";
StaticOutput << " residual = real(residual)+imag(residual).^2;\n";
StaticOutput << "end\n";
StaticOutput << "if nargout >= 2,\n";
StaticOutput << " g1 = " <<
"zeros(" << equations.size() << ", " <<
symbol_table.endo_nbr << ");\n" ;
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
StaticOutput << "Jacobian matrix\n\t";
StaticOutput << interfaces::comment() + "\n\n";
StaticOutput << jacobian_output.str();
StaticOutput << " if ~isreal(g1)\n";
StaticOutput << " g1 = real(g1)+2*imag(g1);\n";
StaticOutput << " end\n";
StaticOutput << "end\n";
StaticOutput << "residual = zeros( " << equations.size() << ", 1);" << endl << endl
<< "%" << endl
<< "% Model equations" << endl
<< "%" << endl
<< endl
<< model_output.str()
<< "if ~isreal(residual)" << endl
<< " residual = real(residual)+imag(residual).^2;" << endl
<< "end" << endl
<< "if nargout >= 2," << endl
<< " g1 = zeros(" << equations.size() << ", " << symbol_table.endo_nbr << ");" << endl
<< endl
<< "%" << endl
<< "% Jacobian matrix" << endl
<< "%" << endl
<< endl
<< jacobian_output.str()
<< " if ~isreal(g1)" << endl
<< " g1 = real(g1)+2*imag(g1);" << endl
<< " end" << endl
<< "end" << endl;
if (computeStaticHessian)
{
StaticOutput << "if nargout >= 3,\n";
// Writing initialization instruction for matrix g2
int ncols = symbol_table.endo_nbr * symbol_table.endo_nbr;
StaticOutput << " g2 = " <<
"sparse([],[],[]," << equations.size() << ", " << ncols << ", " <<
5*ncols << ");\n";
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
StaticOutput << "Hessian matrix\n\t";
StaticOutput << interfaces::comment() + "\n\n";
StaticOutput << hessian_output.str() << lsymetric.str();
StaticOutput << "end;\n";
StaticOutput << " g2 = sparse([],[],[], " << equations.size() << ", " << ncols << ", " << 5*ncols << ");" << endl
<< endl
<< "%" << endl
<< "% Hessian matrix" << endl
<< "%" << endl
<< endl
<< hessian_output.str()
<< lsymetric.str()
<< "end;" << endl;
}
}
else
@ -3401,47 +3400,53 @@ ModelTree::writeDynamicModel(ostream &DynamicOutput) const
if (mode == eStandardMode)
{
DynamicOutput << interfaces::comment() << endl << interfaces::comment();
DynamicOutput << "Model equations" << endl;
DynamicOutput << interfaces::comment() + "\n\n";
DynamicOutput << "residual = zeros(" << nrows << ", 1);\n";
DynamicOutput << model_output.str();
DynamicOutput << "%" << endl
<< "% Model equations" << endl
<< "%" << endl
<< endl
<< "residual = zeros(" << nrows << ", 1);" << endl
<< model_output.str();
if (computeJacobian || computeJacobianExo)
{
DynamicOutput << "if nargout >= 2,\n";
// Writing initialization instruction for matrix g1
DynamicOutput << " g1 = " <<
"zeros(" << nrows << ", " << nvars << ");\n" ;
DynamicOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
DynamicOutput << "Jacobian matrix\n\t";
DynamicOutput << interfaces::comment()+"\n\n";
DynamicOutput << jacobian_output.str();
DynamicOutput << "end\n";
DynamicOutput << "if nargout >= 2," << endl
<< " g1 = zeros(" << nrows << ", " << nvars << ");" << endl
<< endl
<< "%" << endl
<< "% Jacobian matrix" << endl
<< "%" << endl
<< endl
<< jacobian_output.str()
<< "end" << endl;
}
if (computeHessian)
{
DynamicOutput << "if nargout >= 3,\n";
// Writing initialization instruction for matrix g2
int ncols = nvars_sq;
DynamicOutput << " g2 = sparse([],[],[]," << nrows << ", " << ncols << ", "
<< 5*ncols << ");\n";
DynamicOutput << "\n\t"+interfaces::comment() << "\n\t" << interfaces::comment();
DynamicOutput << "Hessian matrix\n\t" << interfaces::comment() << "\n\n";
DynamicOutput << hessian_output.str() << lsymetric.str();
DynamicOutput << "end;\n";
DynamicOutput << "if nargout >= 3," << endl
<< " g2 = sparse([],[],[], " << nrows << ", " << ncols << ", " << 5*ncols << ");" << endl
<< endl
<< "%" << endl
<< "% Hessian matrix" << endl
<< "%" << endl
<< endl
<< hessian_output.str()
<< lsymetric.str()
<< "end;" << endl;
}
if (computeThirdDerivatives)
{
DynamicOutput << "if nargout >= 4,\n";
int ncols = nvars_sq * nvars;
DynamicOutput << " g3 = sparse([],[],[]," << nrows << ", " << ncols << ", "
<< 5*ncols << ");\n";
DynamicOutput << "\n\t" + interfaces::comment() + "\n\t" + interfaces::comment();
DynamicOutput << "Third order derivatives\n\t" << interfaces::comment() << "\n\n";
DynamicOutput << third_derivatives_output.str();
DynamicOutput << "end;\n";
DynamicOutput << "if nargout >= 4," << endl
<< " g3 = sparse([],[],[], " << nrows << ", " << ncols << ", " << 5*ncols << ");" << endl
<< endl
<< "%" << endl
<< "% Third order derivatives" << endl
<< "%" << endl
<< endl
<< third_derivatives_output.str()
<< "end;" << endl;
}
}
else

View File

@ -18,7 +18,6 @@
*/
#include "NumericalInitialization.hh"
#include "Interface.hh"
InitParamStatement::InitParamStatement(const string &param_name_arg,
const NodeID param_value_arg,
@ -80,10 +79,12 @@ InitValStatement::InitValStatement(const init_values_type &init_values_arg,
void
InitValStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << "\n" << interfaces::comment() << "INITVAL instructions \n"
<< interfaces::comment() << "\n";
output << "%" << endl
<< "% INITVAL instructions" << endl
<< "%" << endl;
// Writing initval block to set initial values for variables
output << "options_.initval_file = 0;\nendval_=0;\n";
output << "options_.initval_file = 0;" << endl
<< "endval_=0;" << endl;
if (symbol_table.recur_nbr > 0)
output << "recurs_ = zeros(" << symbol_table.recur_nbr << ", 1);\n";
@ -110,10 +111,14 @@ EndValStatement::EndValStatement(const init_values_type &init_values_arg,
void
EndValStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << "\n" << interfaces::comment() << "ENDVAL instructions\n"
<< interfaces::comment() << "\n";
output << "%" << endl
<< "% ENDVAL instructions" << endl
<< "%" << endl;
// Writing endval block to set terminal values for variables
output << "ys0_= oo_.steady_state;\nex0_ = oo_.exo_steady_state;\nrecurs0_ = recurs_;\nendval_ = 1;\n";
output << "ys0_= oo_.steady_state;" << endl
<< "ex0_ = oo_.exo_steady_state;" << endl
<< "recurs0_ = recurs_;" << endl
<< "endval_ = 1;" << endl;
writeInitValues(output);
}
@ -128,8 +133,9 @@ HistValStatement::HistValStatement(const hist_values_type &hist_values_arg,
void
HistValStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << "\n" << interfaces::comment() << "HISTVAL instructions\n"
<< interfaces::comment() << "\n";
output << "%" << endl
<< "% HISTVAL instructions" << endl
<< "%" << endl;
for(hist_values_type::const_iterator it = hist_values.begin();
it != hist_values.end(); it++)
@ -161,12 +167,11 @@ InitvalFileStatement::InitvalFileStatement(const string &filename_arg) :
void
InitvalFileStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << endl
<< interfaces::comment() << "INITVAL_FILE statement" << endl
<< interfaces::comment() << endl
<< "options_.initval_file = 1;" << endl;
output << "initvalf('" << filename << "');" << endl;
output << "%" << endl
<< "% INITVAL_FILE statement" << endl
<< "%" << endl
<< "options_.initval_file = 1;" << endl
<< "initvalf('" << filename << "');" << endl;
}
HomotopyStatement::HomotopyStatement(const homotopy_values_type &homotopy_values_arg,
@ -179,9 +184,9 @@ HomotopyStatement::HomotopyStatement(const homotopy_values_type &homotopy_values
void
HomotopyStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << endl
<< interfaces::comment() << "HOMOTOPY_SETUP instructions" << endl
<< interfaces::comment() << endl
output << "%" << endl
<< "% HOMOTOPY_SETUP instructions" << endl
<< "%" << endl
<< "options_.homotopy_values = [];" << endl;
for(homotopy_values_type::const_iterator it = homotopy_values.begin();

View File

@ -22,7 +22,6 @@ using namespace std;
#include <iostream>
#include "Shocks.hh"
#include "Interface.hh"
AbstractShocksStatement::AbstractShocksStatement(bool mshocks_arg,
const det_shocks_type &det_shocks_arg,
@ -149,12 +148,12 @@ ShocksStatement::ShocksStatement(const det_shocks_type &det_shocks_arg,
void
ShocksStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << endl << interfaces::comment();
output << "SHOCKS instructions \n";
output << interfaces::comment() << "\n";
output << "%" << endl
<< "% SHOCKS instructions" << endl
<< "%" << endl;
// Write instruction that initializes a shock
output << "make_ex_;\n";
output << "make_ex_;" << endl;
writeDetShocks(output);
writeVarAndStdShocks(output);
@ -175,12 +174,12 @@ MShocksStatement::MShocksStatement(const det_shocks_type &det_shocks_arg,
void
MShocksStatement::writeOutput(ostream &output, const string &basename) const
{
output << interfaces::comment() << endl << interfaces::comment();
output << "SHOCKS instructions \n";
output << interfaces::comment() << "\n";
output << "%" << endl
<< "% SHOCKS instructions" << endl
<< "%" << endl;
// Write instruction that initializes a shock
output << "make_ex_;\n";
output << "make_ex_;" << endl;
writeDetShocks(output);
writeVarAndStdShocks(output);

View File

@ -18,7 +18,6 @@
*/
#include "SymbolList.hh"
#include "Interface.hh"
void
SymbolList::addSymbol(const string &symbol)
@ -32,10 +31,7 @@ SymbolList::writeOutput(const string &varname, ostream &output) const
output << varname << "=[];" << endl;
for (vector<string>::const_iterator it = symbols.begin();
it != symbols.end(); it++)
{
output << varname << " = "
<< interfaces::strvcat(varname, "'" + *it + "'") << ";" << endl;
}
output << varname << " = strvcat(" << varname << ", '" << *it << "');" << endl;
}
void

View File

@ -21,7 +21,6 @@
#include <sstream>
#include "SymbolTable.hh"
#include "Interface.hh"
SymbolTable::SymbolTable() : endo_nbr(0), exo_nbr(0), exo_det_nbr(0), recur_nbr(0),
parameter_nbr(0), model_local_variable_nbr(0),
@ -83,8 +82,8 @@ SymbolTable::writeOutput(ostream &output) const
output << "M_.exo_names_tex = '" << getTeXNameByID(eExogenous, 0) << "';" << endl;
for (int id = 1; id < exo_nbr; id++)
{
output << "M_.exo_names = " << interfaces::strvcat("M_.exo_names","'"+getNameByID(eExogenous, id)+"'") << ";" << endl;
output << "M_.exo_names_tex = " << interfaces::strvcat("M_.exo_names_tex","'"+getTeXNameByID(eExogenous, id)+"'") << ";" << endl;
output << "M_.exo_names = strvcat(M_.exo_names, '" << getNameByID(eExogenous, id) << "');" << endl
<< "M_.exo_names_tex = strvcat(M_.exo_names_tex, '" << getTeXNameByID(eExogenous, id) << "');" << endl;
}
}
if (exo_det_nbr > 0)
@ -93,8 +92,8 @@ SymbolTable::writeOutput(ostream &output) const
output << "lgxdet_tex_ = '" << getTeXNameByID(eExogenousDet, 0) << "';" << endl;
for (int id = 1; id < exo_det_nbr; id++)
{
output << "lgxdet_ = " << interfaces::strvcat("lgxdet_","'"+getNameByID(eExogenousDet, id)+"'") << ";" << endl;
output << "lgxdet_tex_ = " << interfaces::strvcat("lgxdet_tex_","'"+getTeXNameByID(eExogenousDet, id)+"'") << ";" << endl;
output << "lgxdet_ = srtvcat(lgxdet_, '" << getNameByID(eExogenousDet, id) << "');" << endl
<< "lgxdet_tex_ = strvcat(lgxdet_tex_, '" << getTeXNameByID(eExogenousDet, id) << "');" << endl;
}
}
if (endo_nbr > 0)
@ -103,8 +102,8 @@ SymbolTable::writeOutput(ostream &output) const
output << "M_.endo_names_tex = '" << getTeXNameByID(eEndogenous, 0) << "';" << endl;
for (int id = 1; id < endo_nbr; id++)
{
output << "M_.endo_names = " << interfaces::strvcat("M_.endo_names","'"+getNameByID(eEndogenous, id)+"'") << ";" << endl;
output << "M_.endo_names_tex = " << interfaces::strvcat("M_.endo_names_tex","'"+getTeXNameByID(eEndogenous, id)+"'") << ";" << endl;
output << "M_.endo_names = strvcat(M_.endo_names, '" << getNameByID(eEndogenous, id) << "');" << endl
<< "M_.endo_names_tex = strvcat(M_.endo_names_tex, '" << getTeXNameByID(eEndogenous, id) << "');" << endl;
}
}
if (recur_nbr > 0)
@ -113,8 +112,8 @@ SymbolTable::writeOutput(ostream &output) const
output << "M_.recur_names_tex = '" << getTeXNameByID(eRecursiveVariable, 0) << "';" << endl;
for (int id = 1; id < recur_nbr; id++)
{
output << "M_.recur_names = " << interfaces::strvcat("M_.recur_names","'"+getNameByID(eRecursiveVariable, id)+"'") << ";" << endl;
output << "M_.recur_names_tex = " << interfaces::strvcat("M_.recur_names_tex","'"+getTeXNameByID(eRecursiveVariable, id)+"'") << ";" << endl;
output << "M_.recur_names = strvcat(M_.recur_names, '" << getNameByID(eRecursiveVariable, id) << "');" << endl
<< "M_.recur_names_tex = strvcat(M_.recur_names_tex, '" << getTeXNameByID(eRecursiveVariable, id) << "');" << endl;
}
}
if (parameter_nbr > 0)
@ -123,8 +122,8 @@ SymbolTable::writeOutput(ostream &output) const
output << "M_.param_names_tex = '" << getTeXNameByID(eParameter, 0) << "';" << endl;
for (int id = 1; id < parameter_nbr; id++)
{
output << "M_.param_names = " << interfaces::strvcat("M_.param_names","'"+getNameByID(eParameter, id)+"'") << ";" << endl;
output << "M_.param_names_tex = " << interfaces::strvcat("M_.param_names_tex","'"+getTeXNameByID(eParameter, id)+"'") << ";" << endl;
output << "M_.param_names = strvcat(M_.param_names, '" << getNameByID(eParameter, id) << "');" << endl
<< "M_.param_names_tex = strvcat(M_.param_names_tex, '" << getTeXNameByID(eParameter, id) << "');" << endl;
}
}

View File

@ -1,36 +0,0 @@
/*
* Copyright (C) 2006-2008 Dynare Team
*
* 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 _INTERFACE_HH
#define _INTERFACE_HH
using namespace std;
namespace interfaces
{
string comment();
string delete_file(string s);
string file_exist(string s);
string compile(string s);
string function_close();
string function_file_extension();
string strvcat(string s1, string s2);
string load_model_function_files(string filename);
}
#endif