Updated load data routine (for new ops class member).

parent 1bb7762b
......@@ -27,12 +27,13 @@ function [init, data, varlist, tex] = load_data(filename)
if ~nargin || ~ischar(filename) || isempty(filename)
error('dseries:load_data: WrongInputArguments', 'Input argument cannot be an empty string!')
elseif check_file_extension(filename,'m')
[freq, init, data, varlist, tex] = load_m_file_data(filename);
[freq, init, data, varlist, tex, ops] = load_m_file_data(filename);
elseif check_file_extension(filename,'mat')
[freq, init, data, varlist, tex] = load_mat_file_data(filename);
[freq, init, data, varlist, tex, ops] = load_mat_file_data(filename);
elseif check_file_extension(filename,'csv')
[freq, init, data, varlist] = load_csv_file_data(filename);
tex = [];
ops = [];
elseif check_file_extension(filename,'xls') || check_file_extension(filename,'xlsx')
if isglobalinbase('options_')
% Check that the object is instantiated within a dynare session so that options_ global structure exists.
......@@ -46,6 +47,7 @@ elseif check_file_extension(filename,'xls') || check_file_extension(filename,'xl
end
[freq, init, data, varlist] = load_xls_file_data(filename, sheet, range);
tex = [];
ops = [];
else
error('dseries:WrongInputArguments', 'I''m not able to load data from %s!', filename);
end
......
function [freq,init,data,varlist,tex] = load_m_file_data(file)
function [freq, init, data, varlist, tex, ops] = load_m_file_data(file) % --*-- Unitary tests --*--
% Loads data in a matlab/octave script.
%
......@@ -77,6 +77,12 @@ else
tex = [];
end
if exist('OPS__','var')
ops = OPS__;
clear('OPS__');
else
ops = [];
end
if isempty(varlist0)
list_of_variables = whos();
......@@ -94,6 +100,7 @@ if isempty(varlist0)
|| isequal(list_of_variables(current_variable_index).name,'varlist0') ...
|| isequal(list_of_variables(current_variable_index).name,'list_of_variables') ...
|| isequal(list_of_variables(current_variable_index).name,'tex') ...
|| isequal(list_of_variables(current_variable_index).name,'ops') ...
continue
end
if list_of_variables(current_variable_index).global || list_of_variables(current_variable_index).persistent
......@@ -122,6 +129,10 @@ else
varlist = varlist0;
end
if isempty(ops)
ops = cell(length(varlist), 1);
end
%@test:1
%$ % Create a data m-file
%$ fid = fopen('data_m_file.m','w');
......@@ -129,14 +140,16 @@ end
%$ fprintf(fid,'INIT__ = ''1938Q4'';');
%$ fprintf(fid,'NAMES__ = {''azert'';''yuiop''};');
%$ fprintf(fid,'TEX__ = {''azert'';''yuiop''};');
%$ fprintf(fid,'OPS__ = {''method1(azert)'';''method2(yuiop)''};');
%$ fprintf(fid,'azert = [1; 2; 3; 4; 5];');
%$ fprintf(fid,'yuiop = [2; 3; 4; 5; 6];');
%$ fclose(fid);
%$
%$ % Try to read the data m-file
%$ try
%$ datafile = 'data_m_file';
%$ [freq,init,data,varlist,tex] = load_m_file_data(datafile);
%$ datafile = 'data_m_file.m';
%$ [freq, init, data, varlist, tex, ops] = load_m_file_data(datafile);
%$ delete('data_m_file.m');
%$ t(1) = 1;
%$ catch exception
%$ t(1) = 0;
......@@ -147,12 +160,13 @@ end
%$
%$ % Check the results.
%$ t(2) = dassert(freq,4);
%$ t(3) = dassert(isa(init,'dates'),1);
%$ t(3) = isdates(init);
%$ t(4) = dassert(init.freq,4);
%$ t(5) = dassert(init.time,[1938 4]);
%$ t(6) = dassert(varlist,{'azert';'yuiop'});
%$ t(7) = dassert(tex,{'azert';'yuiop'});
%$ t(8) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(9) = dassert(data(:,2),[2;3;4;5;6]);
%$ t(8) = dassert(ops,{'method1(azert)';'method2(yuiop)'});
%$ t(9) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(10) = dassert(data(:,2),[2;3;4;5;6]);
%$ T = all(t);
%@eof:1
function [freq,init,data,varlist,tex] = load_mat_file_data(file) % --*-- Unitary tests --*--
function [freq, init, data, varlist, tex, ops] = load_mat_file_data(file) % --*-- Unitary tests --*--
% Loads data in a matlab/octave mat-file.
%
......@@ -71,6 +71,13 @@ else
tex = [];
end
if isfield(datafile,'OPS__')
ops = datafile.OPS__;
datafile = rmfield(datafile, 'OPS__');
else
ops = [];
end
data = [];
if isempty(varlist)
varlist = fieldnames(datafile);
......@@ -85,20 +92,25 @@ for i=1:length(varlist)
end
end
if isempty(ops)
ops = cell(length(varlist), 1);
end
%@test:1
%$ % Create a data mat-file
%$ FREQ__ = 12;
%$ INIT__ = '1938M11';
%$ NAMES__ = {'hagop'; 'bedros'};
%$ TEX__ = NAMES__;
%$ OPS__ = {'grandad(hagop)'; 'dad(bedros)'};
%$ hagop = [1; 2; 3; 4; 5];
%$ bedros = [2; 3; 4; 5; 6];
%$ save('datafile_for_test.mat');
%$
%$ % Try to read the data mat-file
%$ t = zeros(8,1);
%$ t = zeros(10,1);
%$ try
%$ [freq,init,data,varlist,tex] = load_mat_file_data('datafile_for_test');
%$ [freq, init, data, varlist, tex, ops] = load_mat_file_data('datafile_for_test');
%$ t(1) = 1;
%$ catch exception
%$ t = t(1);
......@@ -115,9 +127,10 @@ end
%$ t(4) = dassert(init.freq,12);
%$ t(5) = dassert(init.time,[1938 11]);
%$ t(6) = dassert(varlist,{'hagop';'bedros'});
%$ t(7) = dassert(varlist,{'hagop';'bedros'});
%$ t(8) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(9) = dassert(data(:,2),[2;3;4;5;6]);
%$ t(7) = dassert(tex,{'hagop';'bedros'});
%$ t(8) = dassert(ops,{'grandad(hagop)';'dad(bedros)'});
%$ t(9) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(10) = dassert(data(:,2),[2;3;4;5;6]);
%$ T = all(t);
%@eof:1
......@@ -127,14 +140,15 @@ end
%$ INIT__ = '1938M11';
%$ NAMES__ = {'hagop'; 'bedros'};
%$ TEX__ = NAMES__;
%$ OPS__ = {'grandad(hagop)'; 'dad(bedros)'};
%$ hagop = [1, 2, 3, 4, 5];
%$ bedros = [2, 3, 4, 5, 6];
%$ save('datafile_for_test.mat');
%$
%$ % Try to read the data mat-file
%$ t = zeros(8,1);
%$ t = zeros(10,1);
%$ try
%$ [freq,init,data,varlist,tex] = load_mat_file_data('datafile_for_test');
%$ [freq, init, data, varlist, tex, ops] = load_mat_file_data('datafile_for_test');
%$ t(1) = 1;
%$ catch exception
%$ t = t(1);
......@@ -151,8 +165,9 @@ end
%$ t(4) = dassert(init.freq,12);
%$ t(5) = dassert(init.time,[1938 11]);
%$ t(6) = dassert(varlist,{'hagop';'bedros'});
%$ t(7) = dassert(varlist,{'hagop';'bedros'});
%$ t(8) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(9) = dassert(data(:,2),[2;3;4;5;6]);
%$ t(7) = dassert(tex,{'hagop';'bedros'});
%$ t(8) = dassert(ops,{'grandad(hagop)';'dad(bedros)'});
%$ t(9) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(10) = dassert(data(:,2),[2;3;4;5;6]);
%$ T = all(t);
%@eof:2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment