2012-06-08 14:46:44 +02:00
|
|
|
function read_data_()
|
2009-12-16 18:17:34 +01:00
|
|
|
% 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
|
|
|
|
|
2012-06-08 18:22:34 +02:00
|
|
|
% Copyright (C) 2007-2012 Dynare Team
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% 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;
|
2010-02-12 10:58:10 +01:00
|
|
|
|
|
|
|
if size(oo_.endo_simul,2) < M_.maximum_lag+M_.maximum_lead+options_.periods
|
|
|
|
fid = fopen([dname '_endo.dat'],'r');
|
|
|
|
names_line = fgetl(fid);
|
|
|
|
allVariables = '';
|
|
|
|
positions = ones(0);
|
|
|
|
while (any(names_line))
|
|
|
|
[chopped,names_line] = strtok(names_line);
|
2010-09-26 13:42:41 +02:00
|
|
|
if isempty(allVariables)
|
|
|
|
allVariables = chopped;
|
|
|
|
else
|
|
|
|
allVariables = char(allVariables, chopped);
|
|
|
|
end
|
2010-02-12 10:58:10 +01:00
|
|
|
positions = [positions ; strmatch(chopped,M_.endo_names,'exact')];
|
|
|
|
end
|
|
|
|
Values=fscanf(fid,'%f',inf);
|
2010-07-23 11:20:24 +02:00
|
|
|
Values=reshape(Values,M_.orig_endo_nbr,size(Values,1)/M_.orig_endo_nbr);
|
2010-09-17 09:57:38 +02:00
|
|
|
oo_.endo_simul=[Values(positions,:); kron(oo_.steady_state((M_.orig_endo_nbr+1) : M_.endo_nbr , 1) , ones(1 , size(Values, 2)))];
|
2010-02-12 10:58:10 +01:00
|
|
|
fclose(fid);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2010-02-12 10:58:10 +01:00
|
|
|
if size(oo_.exo_simul,1) < M_.maximum_lag+M_.maximum_lead+options_.periods
|
|
|
|
fid = fopen([dname '_exo.dat'],'r');
|
|
|
|
names_line = fgetl(fid);
|
|
|
|
allVariables = '';
|
|
|
|
positions = ones(0);
|
|
|
|
while (any(names_line))
|
|
|
|
[chopped,names_line] = strtok(names_line);
|
2010-09-26 13:42:41 +02:00
|
|
|
if isempty(allVariables)
|
|
|
|
allVariables = chopped;
|
|
|
|
else
|
|
|
|
allVariables = char(allVariables, chopped);
|
|
|
|
end
|
2010-02-12 10:58:10 +01:00
|
|
|
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);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
%disp([allVariables M_.endo_names]);
|
|
|
|
%disp(positions);
|
|
|
|
|
2007-06-01 13:43:49 +02:00
|
|
|
end
|