From 08c97bbef70f3324dc53c476f541961f7bcddf70 Mon Sep 17 00:00:00 2001 From: ferhat Date: Fri, 10 Jul 2009 15:40:31 +0000 Subject: [PATCH] - Files needed to debug simulate.dll git-svn-id: https://www.dynare.org/svn/dynare/trunk@2837 ac1d8469-bf42-47a9-8791-bf33cf982152 --- mex/sources/simulate/mex_interface.cc | 83 +++++++++++++++++++ mex/sources/simulate/testing/simulate_debug.m | 28 +++++++ 2 files changed, 111 insertions(+) create mode 100644 mex/sources/simulate/mex_interface.cc create mode 100644 mex/sources/simulate/testing/simulate_debug.m diff --git a/mex/sources/simulate/mex_interface.cc b/mex/sources/simulate/mex_interface.cc new file mode 100644 index 000000000..09c64f1a7 --- /dev/null +++ b/mex/sources/simulate/mex_interface.cc @@ -0,0 +1,83 @@ +#include "mex_interface.hh" +#include +#include + +using namespace std; + +int +mexPrintf(string str, ...) +{ + va_list vl; + size_t found, found_p=0; + found=str.find_first_of("%"); + va_start(vl,str); + while (found!=string::npos) + { + ostringstream tmp_out(""); + //tmp_out.clear(); + tmp_out << "%"; + char c = str[found+1]; + while((c>='0' and c<='9') or c=='.') + { + tmp_out << c; + found++; + c = str[found+1]; + } + tmp_out << c; + switch(c) + { + case 'd': + printf(str.substr(found_p, found-found_p).c_str()); + printf(tmp_out.str().c_str(),va_arg(vl,int)); + break; + case 'e': + case 'f': + case 'g': + printf(str.substr(found_p, found-found_p).c_str()); + printf(tmp_out.str().c_str(),va_arg(vl,double)); + break; + case 's': + printf(str.substr(found_p, found-found_p).c_str()); + printf(tmp_out.str().c_str(),va_arg(vl,char*)); + break; + case 'x': + printf(str.substr(found_p, found-found_p).c_str()); + printf(tmp_out.str().c_str(),va_arg(vl,int)); + break; + } + found_p = found+2; + found=str.find_first_of("%",found_p); + } + printf(str.substr(found_p, str.size()-found_p+1).c_str()); + return 0; +} + +void +mexErrMsgTxt(const string str) +{ + perror(str.c_str()); +} + +void +mxFree(void* to_release) +{ + free(to_release); +} + +void* +mxMalloc(int amount) +{ + return malloc(amount); +} + +void* +mxRealloc(void* to_extend, int amount) +{ + return realloc(to_extend, amount); +} + + +void +mexEvalString(const string str) +{ +} diff --git a/mex/sources/simulate/testing/simulate_debug.m b/mex/sources/simulate/testing/simulate_debug.m new file mode 100644 index 000000000..ce21bfa34 --- /dev/null +++ b/mex/sources/simulate/testing/simulate_debug.m @@ -0,0 +1,28 @@ +function simulate_debug() +global M_ oo_ options_; + fid = fopen([M_.fname '_options.txt'],'wt'); + fprintf(fid,'%d\n',options_.periods); + fprintf(fid,'%d\n',options_.maxit_); + fprintf(fid,'%f\n',options_.slowc); + fprintf(fid,'%f\n',options_.markowitz); + fprintf(fid,'%f\n',options_.dynatol); + fclose(fid); + + fid = fopen([M_.fname '_M.txt'],'wt'); + fprintf(fid,'%d\n',M_.maximum_lag); + fprintf(fid,'%d\n',M_.maximum_lead); + fprintf(fid,'%d\n',M_.maximum_endo_lag); + fprintf(fid,'%d\n',M_.param_nbr); + fprintf(fid,'%d\n',size(oo_.exo_simul, 1)); + fprintf(fid,'%d\n',size(oo_.exo_simul, 2)); + fprintf(fid,'%d\n',M_.endo_nbr); + fprintf(fid,'%d\n',size(oo_.endo_simul, 2)); + fprintf(fid,'%d\n',M_.exo_det_nbr); + fprintf(fid,'%f\n',M_.params); + + fclose(fid); + fid = fopen([M_.fname '_oo.txt'],'wt'); + fprintf(fid,'%f\n',oo_.endo_simul); + fprintf(fid,'%f\n',oo_.exo_simul); + fclose(fid); + \ No newline at end of file