From ee506c4ebe461e1dc759ea779b2e65173bb5d339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 29 Nov 2013 17:47:53 +0100 Subject: [PATCH] Added new routine to test if a global variable exist in the base workspace. --- matlab/@dseries/dseries.m | 2 +- matlab/isglobalinbase.m | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 matlab/isglobalinbase.m diff --git a/matlab/@dseries/dseries.m b/matlab/@dseries/dseries.m index 7d5060270..67ea90c0c 100644 --- a/matlab/@dseries/dseries.m +++ b/matlab/@dseries/dseries.m @@ -118,7 +118,7 @@ switch nargin [freq,init,data,varlist] = load_csv_file_data(varargin{1}); tex = []; elseif check_file_extension(varargin{1},'xls') || check_file_extension(varargin{1},'xlsx') - if ~isempty(who('global','options_')); + if isglobalinbase('options_') % Check that the object is instantiated within a dynare session so that options_ global structure exists. % Should provide latter a mechanism to pass range and sheet to dseries constructor... range = evalin('base','options_.xls_range'); diff --git a/matlab/isglobalinbase.m b/matlab/isglobalinbase.m new file mode 100644 index 000000000..6c93d3dd2 --- /dev/null +++ b/matlab/isglobalinbase.m @@ -0,0 +1,25 @@ +function a = isglobalinbase(var) + +% Copyright (C) 2013 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +tmp = whos('global'); +if isempty(strmatch(var,{tmp.name})) + a = 0; +else + a = 1; +end \ No newline at end of file