dynare/matlab/read_data_.m

64 lines
2.0 KiB
Matlab

function read_data_
% function read_data_
% reads endogenous and exogenous variables from a text file
% Used by datafile option in simulate
%
% INPUT
% none
%
% OUTPUT
% none
%
% SPECIAL REQUIREMENT
% none
% Copyright (C) 2007-2008 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 <http://www.gnu.org/licenses/>.
global options_ M_ oo_;
dname= options_.datafile;
fid = fopen([dname '_endo.dat'],'r');
names_line = fgetl(fid);
allVariables = '';
positions = ones(0);
while (any(names_line))
[chopped,names_line] = strtok(names_line);
allVariables = strvcat(allVariables, chopped);
positions = [positions ; strmatch(chopped,M_.endo_names,'exact')];
end
Values=fscanf(fid,'%f',inf);
Values=reshape(Values,M_.endo_nbr,size(Values,1)/M_.endo_nbr);
oo_.endo_simul=Values(positions,:);
fclose(fid);
fid = fopen([dname '_exo.dat'],'r');
names_line = fgetl(fid);
allVariables = '';
positions = ones(0);
while (any(names_line))
[chopped,names_line] = strtok(names_line);
allVariables = strvcat(allVariables, chopped);
positions = [positions ; strmatch(chopped,M_.exo_names,'exact')];
end
Values=fscanf(fid,'%f',inf);
Values=reshape(Values,M_.exo_nbr,size(Values,1)/M_.exo_nbr);
oo_.exo_simul=(Values(positions,:))';
fclose(fid);
%disp([allVariables M_.endo_names]);
%disp(positions);
end