simplify parsing of MATLAB command line arguments

closes #1696

includes preprocessor changes
- Removed prefixing of doubles between -1 and 1 with 0.
- Fixed bug introduced in 985d742.
- macro processor: simplify handling of `@#define`
time-shift
Houtan Bastani 2020-01-28 15:09:15 +01:00
parent 7f02fe5a78
commit d527096e61
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
3 changed files with 27 additions and 5 deletions

View File

@ -338,9 +338,20 @@ by the ``dynare`` command.
.. option:: -DMACRO_VARIABLE=MACRO_EXPRESSION
Defines a macro-variable from the command line (the same
effect as using the Macro directive ``@#define`` in a model
file, see :ref:`macro-proc-lang`).
Defines a macro-variable from the command line (the same effect as
using the Macro directive ``@#define`` in a model file, see
:ref:`macro-proc-lang`). Note that when passing a MACRO_EXPRESSION that
contains a space, you must surround the entire ``-D`` flag with single
quotes, as in the following example. Also note that an expression
passed on the command line can reference variables defined before it.
*Example*
Call dynare with command line defines
.. code-block:: matlab
>> dynare <<modfile.mod>> -DA=true '-DB="A string with space"' -DC=[1,2,3] '-DD=[ i in C when i > 1 ]'
.. option:: -I<<path>>

View File

@ -213,7 +213,18 @@ end
command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ;
command = [ command ' mexext=' mexext ' "matlabroot=' matlabroot '"'];
if ~isempty(varargin)
dynare_varargin = strjoin(varargin);
if ispc
varargincopy = varargin;
for i = 1:length(varargincopy)
if varargincopy{i}(end) == '\'
varargincopy{i} = [varargincopy{i} '\'];
end
end
varargincopy = strrep(varargincopy, '"', '\"');
dynare_varargin = ['"' strjoin(varargincopy, '" "') '"'];
else
dynare_varargin = ['''' strjoin(varargin, ''' ''') ''''];
end
command = [command ' ' dynare_varargin];
end

@ -1 +1 @@
Subproject commit bef537d40accd597c19f112471974b726c9c9890
Subproject commit 148aa9d9249577e72213e8856d7d5e97fcf75db3