Home > matlab > dynare.m

dynare

PURPOSE ^

This command runs dynare with specified model file in argument

SYNOPSIS ^

function dynare(fname, varargin)

DESCRIPTION ^

       This command runs dynare with specified model file in argument
       Filename.
       The name of model file begins with an alphabetic character, 
       and has a filename extension of .mod or .dyn.
       When extension is omitted, a model file with .mod extension
       is processed.

 INPUTS
   fname:      file name
   varargin:   list of arguments following fname
             
 OUTPUTS
   none
        
 SPECIAL REQUIREMENTS
   none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dynare(fname, varargin)
0002 %       This command runs dynare with specified model file in argument
0003 %       Filename.
0004 %       The name of model file begins with an alphabetic character,
0005 %       and has a filename extension of .mod or .dyn.
0006 %       When extension is omitted, a model file with .mod extension
0007 %       is processed.
0008 %
0009 % INPUTS
0010 %   fname:      file name
0011 %   varargin:   list of arguments following fname
0012 %
0013 % OUTPUTS
0014 %   none
0015 %
0016 % SPECIAL REQUIREMENTS
0017 %   none
0018 
0019 % Copyright (C) 2001-2012 Dynare Team
0020 %
0021 % This file is part of Dynare.
0022 %
0023 % Dynare is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % Dynare is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 if strcmpi(fname,'help')
0037     disp(' ')
0038     disp(['This is dynare version ' dynare_version() '.'])
0039     disp(' ')
0040     disp('USAGE: dynare FILENAME[.mod,.dyn] [OPTIONS]')
0041     disp(' ')
0042     disp('dynare executes instruction included in FILENAME.mod.')
0043     disp('See the reference manual for the available options.')
0044     return
0045 end
0046 
0047 warning_config()
0048 
0049 if exist('OCTAVE_VERSION')
0050     if octave_ver_less_than('3.2.2')
0051         warning('This version of Dynare has only been tested on Octave 3.2.2 and above. Since your Octave version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your Octave installation.');
0052     end
0053 else
0054     if matlab_ver_less_than('7.0')
0055         warning('This version of Dynare has only been tested on MATLAB 7.0 (R14) and above. Since your MATLAB version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your MATLAB installation, or switch to Octave.');
0056     end
0057 end
0058 
0059 % disable output paging (it is on by default on Octave)
0060 more off
0061 
0062 % sets default format for save() command
0063 if exist('OCTAVE_VERSION')
0064     default_save_options('-mat')
0065 end
0066 
0067 % detect if MEX files are present; if not, use alternative M-files
0068 dynareroot = dynare_config;
0069 
0070 if nargin < 1
0071     error('DYNARE: you must provide the name of the MOD file in argument')
0072 end
0073 
0074 if ~ischar(fname)
0075     error('DYNARE: argument of dynare must be a text string')
0076 end
0077 
0078 % Testing if file have extension
0079 % If no extension default .mod is added
0080 if isempty(strfind(fname,'.'))
0081     fname1 = [fname '.dyn'];
0082     d = dir(fname1);
0083     if length(d) == 0
0084         fname1 = [fname '.mod'];
0085     end
0086     fname = fname1;
0087     % Checking file extension
0088 else
0089     if ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ...
0090             && ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN')
0091         error('DYNARE: argument must be a filename with .mod or .dyn extension')
0092     end;
0093 end;
0094 d = dir(fname);
0095 if length(d) == 0
0096     error(['DYNARE: can''t open ' fname])
0097 end
0098 
0099 command = ['"' dynareroot 'dynare_m" ' fname] ;
0100 for i=2:nargin
0101     command = [command ' ' varargin{i-1}];
0102 end
0103 
0104 % Workaround for bug in Octave 3.2
0105 % See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=550823
0106 if exist('OCTAVE_VERSION') && octave_ver_less_than('3.4.0')
0107     sleep(2)
0108 end
0109 
0110 [status, result] = system(command);
0111 disp(result)
0112 if status
0113     % Should not use "error(result)" since message will be truncated if too long
0114     error('DYNARE: preprocessing failed')
0115 end
0116 
0117 if ~ isempty(find(abs(fname) == 46))
0118     fname = fname(:,1:find(abs(fname) == 46)-1) ;
0119 end
0120 evalin('base',fname) ;

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005