diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index d327cf5238cc9ba89b503fe2feb577d8eda2786d..d38ee7c4698a402e8e572b071d71649cd0f3fc57 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -450,6 +450,22 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool console, if (!use_dll) mOutputFile << "erase_compiled_function('" + basename + "_dynamic');" << endl; + // Erase generated steady state file (see ticket #224) + string steadystatefile = basename + "_steadystate.m"; + ifstream in(steadystatefile.c_str(), ios::binary); + if (!in.fail()) + { + string line; + getline(in, line); + if (!line.compare(STEADY_STATE_GENERATED_HEADER)) + { + in.close(); + unlink(steadystatefile.c_str()); + } + else + in.close(); + } + #if defined(_WIN32) || defined(__CYGWIN32__) // If using USE_DLL with MSVC, check that the user didn't use a function not supported by MSVC (because MSVC doesn't comply with C99 standard) if (use_dll && msvc) diff --git a/preprocessor/SteadyStateModel.cc b/preprocessor/SteadyStateModel.cc index d665428bb99830ae195258c0022ed4590762e595..77ddbe2d7934bcc0e9240c88a3c6d6733d87b548 100644 --- a/preprocessor/SteadyStateModel.cc +++ b/preprocessor/SteadyStateModel.cc @@ -113,7 +113,11 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_polic exit(EXIT_FAILURE); } - output << "function [ys_, check_] = " << basename << "_steadystate("; + /* The following header is used when the preprocessor deletes the old + generated steady state file: it distinguishes this file from a hand + written one (see ticket #224) */ + output << STEADY_STATE_GENERATED_HEADER << endl + << "function [ys_, check_] = " << basename << "_steadystate("; if (ramsey_policy) output << "ys_"; else diff --git a/preprocessor/SteadyStateModel.hh b/preprocessor/SteadyStateModel.hh index cbb206afa32d91f375e5457536f9a5d1c5fb07d9..6b532fc27d9cc26dd9702c119dea43faa3c41b6e 100644 --- a/preprocessor/SteadyStateModel.hh +++ b/preprocessor/SteadyStateModel.hh @@ -23,6 +23,8 @@ #include "DataTree.hh" #include "StaticModel.hh" +#define STEADY_STATE_GENERATED_HEADER "% Generated file, will be deleted at next run of Dynare" + class SteadyStateModel : public DataTree { private: