diff --git a/DynareMain.cc b/DynareMain.cc index 0535663c3a6b5893118b744ea614ba9a6fd12461..76d5e9ce8d3d446cdc933e98c1b12334b26a1d20 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -49,7 +49,7 @@ usage() { cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]" - << " [-D<variable>[=<value>]] [nostrict] [fast] [minimal_workspace] [output=dynamic|first|second|third] [language=C|C++]" + << " [-D<variable>[=<value>]] [nostrict] [fast] [minimal_workspace] [output=dynamic|first|second|third] [language=C|C++|julia]" #if defined(_WIN32) || defined(__CYGWIN32__) << " [cygwin] [msvc]" #endif diff --git a/ExtendedPreprocessorTypes.hh b/ExtendedPreprocessorTypes.hh index d9a210e7706492cfc6bae18c6880b90bfd0453b4..e0a955f2c8222b611512d31a296902b9e4e65fbd 100644 --- a/ExtendedPreprocessorTypes.hh +++ b/ExtendedPreprocessorTypes.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Dynare Team + * Copyright (C) 2014-2015 Dynare Team * * This file is part of Dynare. * @@ -35,7 +35,7 @@ enum LanguageOutputType c, // outputs files for C cpp, // outputs files for C++ cuda, // outputs files for CUDA (not yet implemented) - julia, // outputs files for Julia (not yet implemented) + julia, // outputs files for Julia python, // outputs files for Python (not yet implemented) (not yet implemented) }; #endif diff --git a/Makefile.am b/Makefile.am index 77f87922fdc142cfc2030ef8d5457d9a6c97e61c..502e46172d20111b0792a06f64ec64934e475b63 100644 --- a/Makefile.am +++ b/Makefile.am @@ -75,7 +75,9 @@ all-local: $(PROGRAMS) ARCH="64"; \ fi; \ mkdir -p ../matlab/preprocessor$$ARCH ; \ - cd ../matlab/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS) + cd ../matlab/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS) ; \ + mkdir -p ../../julia/preprocessor$$ARCH ; \ + cd ../../julia/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS) if HAVE_DOXYGEN html-local: diff --git a/ModFile.cc b/ModFile.cc index a4693cfc7160011bdf48bf88830e57d5892f7a57..3d9a95f4b88b45d1a181a4f54a27e830cbafcfcc 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -821,7 +821,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo // Create steady state file steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present); } - + cout << "done" << endl; } @@ -836,6 +836,9 @@ ModFile::writeExternalFiles(const string &basename, FileOutputType output, Langu case cpp: writeExternalFilesCC(basename, output); break; + case julia: + writeExternalFilesJulia(basename, output); + break; default: cerr << "This case shouldn't happen. Contact the authors of Dynare" << endl; exit(EXIT_FAILURE); @@ -1051,3 +1054,42 @@ ModFile::writeModelCC(const string &basename) const mOutputFile.close(); } +void +ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) const +{ + ofstream jlOutputFile; + if (basename.size()) + { + string fname(basename); + fname += ".jl"; + jlOutputFile.open(fname.c_str(), ios::out | ios::binary); + if (!jlOutputFile.is_open()) + { + cerr << "ERROR: Can't open file " << fname + << " for writing" << endl; + exit(EXIT_FAILURE); + } + } + else + { + cerr << "ERROR: Missing file name" << endl; + exit(EXIT_FAILURE); + } + + jlOutputFile << "module " << basename << endl + << "#" << endl + << "# Note : this file was automatically generated by Dynare" << endl + << "# from " << basename << ".mod" << endl + << "#" << endl + << "using model" << endl + << "using utils" << endl + << "export dynamicmodel!, staticmodel!, steadystate!" << endl + << "export model__" << endl + << "model__ = modeldescription()" << endl + << "model__.fname = \"" << basename << "\"" << endl; + + symbol_table.writeJuliaOutput(jlOutputFile); + + jlOutputFile << "end" << endl; + jlOutputFile.close(); +} diff --git a/ModFile.hh b/ModFile.hh index 11e3e4246166102f6c28ff5ac9eed950117ec93c..1437115fc4dcdd3a90c7617635c1b0dca84a69a7 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -155,6 +155,7 @@ public: void writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language) const; void writeExternalFilesC(const string &basename, FileOutputType output) const; void writeExternalFilesCC(const string &basename, FileOutputType output) const; + void writeExternalFilesJulia(const string &basename, FileOutputType output) const; //! Writes C output files only => No further Matlab processing void writeCOutputFiles(const string &basename) const; void writeModelC(const string &basename) const; diff --git a/SymbolTable.cc b/SymbolTable.cc index 2c1a699c593433fb06dd58e6cb1245d328e363c9..dfa7fa7d449f48f2e32971e4bf29e13963814533 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -718,3 +718,75 @@ SymbolTable::getOrigEndogenous() const origendogs.insert(it->second); return origendogs; } + +void +SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenException) +{ + if (!frozen) + throw NotYetFrozenException(); + + if (exo_nbr() > 0) + { + output << "model__.exonames = [\"" << getName(exo_ids[0]) << "\""; + for (int id = 1; id < exo_nbr(); id++) + output << ", \"" << getName(exo_ids[id]) << "\""; + output << "]" << endl + << "model__.tex_exonames = [\"" << getTeXName(exo_ids[0]) << "\""; + for (int id = 1; id < exo_nbr(); id++) + output << ", \"" << getTeXName(exo_ids[id]) << "\""; + output << "]" << endl + << "model__.long_exonames = [\"" << getLongName(exo_ids[0]) << "\""; + for (int id = 1; id < exo_nbr(); id++) + output << ", \"" << getLongName(exo_ids[id]) << "\""; + output << "]" << endl; + } + + if (exo_det_nbr() > 0) + { + output << "model__.exodetnames = [\"" << getName(exo_det_ids[0]) << "\""; + for (int id = 1; id < exo_det_nbr(); id++) + output << ", \"" << getName(exo_det_ids[id]) << "\""; + output << "]" << endl + << "model__.tex_exodetnames = [\"" << getTeXName(exo_det_ids[0]) << "\""; + for (int id = 1; id < exo_det_nbr(); id++) + output << ", \"" << getTeXName(exo_det_ids[id]) << "\""; + output << "]" << endl + << "model__.long_exodetnames = [\"" << getLongName(exo_det_ids[0]) << "\""; + for (int id = 1; id < exo_det_nbr(); id++) + output << ", \"" << getLongName(exo_det_ids[id]) << "\""; + output << "]" << endl; + } + + if (endo_nbr() > 0) + { + output << "model__.endonames = [\"" << getName(endo_ids[0]) << "\""; + for (int id = 1; id < endo_nbr(); id++) + output << ", \"" << getName(endo_ids[id]) << "\""; + output << "]" << endl + << "model__.tex_endonames = [\"" << getTeXName(endo_ids[0]) << "\""; + for (int id = 1; id < endo_nbr(); id++) + output << ", \"" << getTeXName(endo_ids[id]) << "\""; + output << "]" << endl + << "model__.long_endonames = [\"" << getLongName(endo_ids[0]) << "\""; + for (int id = 1; id < endo_nbr(); id++) + output << ", \"" << getLongName(endo_ids[id]) << "\""; + output << "]" << endl; + } + + if (param_nbr() > 0) + { + output << "model__.paramnames = [\"" << getName(param_ids[0]) << "\""; + for (int id = 1; id < param_nbr(); id++) + output << ", \"" << getName(param_ids[id]) << "\""; + output << "]" << endl + << "model__.tex_paramnames = [\"" << getTeXName(param_ids[0]) << "\""; + for (int id = 1; id < param_nbr(); id++) + output << ", \"" << getTeXName(param_ids[id]) << "\""; + output << "]" << endl + << "model__.long_paramnames = [\"" << getLongName(param_ids[0]) << "\""; + for (int id = 1; id < param_nbr(); id++) + output << ", \"" << getLongName(param_ids[id]) << "\""; + output << "]" << endl; + } + +} diff --git a/SymbolTable.hh b/SymbolTable.hh index 4be960a1c87bb6265a977ee2af25b0ff166801a3..b93e1b3fe312fab52cf337c4aabcfea69c31d16e 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -283,6 +283,8 @@ public: inline int orig_endo_nbr() const throw (NotYetFrozenException); //! Write output of this class void writeOutput(ostream &output) const throw (NotYetFrozenException); + //! Write Julia output of this class + void writeJuliaOutput(ostream &output) const throw (NotYetFrozenException); //! Write C output of this class void writeCOutput(ostream &output) const throw (NotYetFrozenException); //! Write CC output of this class