Home > matlab > read_data_.m

read_data_

PURPOSE ^

function read_data_

SYNOPSIS ^

function read_data_

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function read_data_
0002 % function read_data_
0003 % reads endogenous and exogenous variables from a text file
0004 % Used by datafile option in simulate
0005 %
0006 % INPUT
0007 %   none
0008 %
0009 % OUTPUT
0010 %   none
0011 %
0012 % SPECIAL REQUIREMENT
0013 %   none
0014 
0015 % Copyright (C) 2007-2010 Dynare Team
0016 %
0017 % This file is part of Dynare.
0018 %
0019 % Dynare is free software: you can redistribute it and/or modify
0020 % it under the terms of the GNU General Public License as published by
0021 % the Free Software Foundation, either version 3 of the License, or
0022 % (at your option) any later version.
0023 %
0024 % Dynare is distributed in the hope that it will be useful,
0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 % GNU General Public License for more details.
0028 %
0029 % You should have received a copy of the GNU General Public License
0030 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0031 
0032 global options_ M_ oo_;
0033 dname= options_.datafile;
0034 
0035 if size(oo_.endo_simul,2) < M_.maximum_lag+M_.maximum_lead+options_.periods
0036     fid = fopen([dname '_endo.dat'],'r');
0037     names_line = fgetl(fid);
0038     allVariables = '';
0039     positions = ones(0);
0040     while (any(names_line))
0041         [chopped,names_line] = strtok(names_line);
0042         if isempty(allVariables)
0043             allVariables = chopped;
0044         else
0045             allVariables = char(allVariables, chopped);
0046         end
0047         positions = [positions ; strmatch(chopped,M_.endo_names,'exact')];
0048     end
0049     Values=fscanf(fid,'%f',inf);
0050     Values=reshape(Values,M_.orig_endo_nbr,size(Values,1)/M_.orig_endo_nbr);
0051     oo_.endo_simul=[Values(positions,:); kron(oo_.steady_state((M_.orig_endo_nbr+1) : M_.endo_nbr , 1) , ones(1 , size(Values, 2)))];
0052     fclose(fid);
0053 end
0054 
0055 if size(oo_.exo_simul,1) < M_.maximum_lag+M_.maximum_lead+options_.periods
0056     fid = fopen([dname '_exo.dat'],'r');
0057     names_line = fgetl(fid);
0058     allVariables = '';
0059     positions = ones(0);
0060     while (any(names_line))
0061         [chopped,names_line] = strtok(names_line);
0062         if isempty(allVariables)
0063             allVariables = chopped;
0064         else
0065             allVariables = char(allVariables, chopped);
0066         end
0067         positions = [positions ; strmatch(chopped,M_.exo_names,'exact')];
0068     end
0069     Values=fscanf(fid,'%f',inf);
0070     Values=reshape(Values,M_.exo_nbr,size(Values,1)/M_.exo_nbr);
0071     oo_.exo_simul=(Values(positions,:))';
0072     fclose(fid);
0073 end
0074 %disp([allVariables M_.endo_names]);
0075 %disp(positions);
0076 
0077 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005