2006-11-27 14:53:53 +01:00
|
|
|
function ReshapeMatFiles(type, type2)
|
2006-03-17 10:31:03 +01:00
|
|
|
% Reshape and sort (along the mcmc simulations) the mat files generated
|
2006-03-16 18:07:58 +01:00
|
|
|
% by DYNARE.
|
2006-03-17 10:31:03 +01:00
|
|
|
%
|
|
|
|
% 4D-arrays are splitted along the first dimension.
|
|
|
|
% 3D-arrays are splitted along the second dimension.
|
|
|
|
%
|
|
|
|
%
|
2006-03-16 18:07:58 +01:00
|
|
|
global M_ options_
|
|
|
|
|
2006-11-27 14:53:53 +01:00
|
|
|
if nargin==1,
|
2006-03-16 18:07:58 +01:00
|
|
|
MhDirectoryName = [ CheckPath('metropolis') '/' ];
|
2006-11-27 14:53:53 +01:00
|
|
|
else
|
|
|
|
if strcmpi(type2,'posterior')
|
|
|
|
MhDirectoryName = [CheckPath('metropolis') '/' ];
|
|
|
|
elseif strcmpi(type2,'gsa')
|
|
|
|
if options_.opt_gsa.morris==1,
|
|
|
|
MhDirectoryName = [CheckPath('GSA\SCREEN') '/' ];
|
|
|
|
elseif options_.opt_gsa.morris==2,
|
|
|
|
MhDirectoryName = [CheckPath('GSA\IDENTIF') '/' ];
|
|
|
|
else
|
|
|
|
MhDirectoryName = [CheckPath('GSA') '/' ];
|
|
|
|
end
|
|
|
|
else
|
|
|
|
MhDirectoryName = [CheckPath('prior') '/' ];
|
|
|
|
end
|
|
|
|
end
|
2006-03-16 18:07:58 +01:00
|
|
|
switch type
|
2006-12-15 12:37:24 +01:00
|
|
|
case 'irf_dsge'
|
|
|
|
CAPtype = 'IRF_DSGE';
|
2007-06-04 16:26:49 +02:00
|
|
|
TYPEsize = [ options_.irf , size(options_.varlist,1) , M_.exo_nbr ];
|
2006-12-15 12:37:24 +01:00
|
|
|
TYPEarray = 4;
|
|
|
|
case 'irf_bvardsge'
|
|
|
|
CAPtype = 'IRF_BVARDSGE';
|
|
|
|
TYPEsize = [ options_.irf , size(options_.varobs,1) , M_.exo_nbr ];
|
|
|
|
TYPEarray = 4;
|
2006-03-17 10:31:03 +01:00
|
|
|
case 'smooth'
|
|
|
|
CAPtype = 'SMOOTH';
|
|
|
|
TYPEsize = [ M_.endo_nbr , options_.nobs ];
|
|
|
|
TYPEarray = 3;
|
|
|
|
case 'filter'
|
|
|
|
CAPtype = 'FILTER';
|
|
|
|
TYPEsize = [ M_.endo_nbr , options_.nobs + 1 ];% TO BE CHECKED!
|
|
|
|
TYPEarray = 3;
|
|
|
|
case 'error'
|
|
|
|
CAPtype = 'ERROR';
|
|
|
|
TYPEsize = [ size(options_.varobs,1) , options_.nobs ];
|
|
|
|
TYPEarray = 3;
|
|
|
|
case 'innov'
|
|
|
|
CAPtype = 'INNOV';
|
|
|
|
TYPEsize = [ M_.exo_nbr , options_.nobs ];
|
|
|
|
TYPEarray = 3;
|
|
|
|
case 'forcst'
|
|
|
|
CAPtype = 'FORCST';
|
2006-11-14 21:26:38 +01:00
|
|
|
TYPEsize = [ M_.endo_nbr , options_.forecast ];
|
2006-03-17 10:31:03 +01:00
|
|
|
TYPEarray = 3;
|
|
|
|
case 'forcst1'
|
|
|
|
CAPtype = 'FORCST1';
|
2006-11-14 21:26:38 +01:00
|
|
|
TYPEsize = [ M_.endo_nbr , options_.forecast ];
|
2006-03-17 10:31:03 +01:00
|
|
|
TYPEarray = 3;
|
|
|
|
otherwise
|
2006-03-17 12:20:25 +01:00
|
|
|
disp('ReshapeMatFiles :: Unknown argument!')
|
2006-03-17 10:31:03 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2006-12-15 12:37:24 +01:00
|
|
|
TYPEfiles = dir([MhDirectoryName M_.fname '_' type '*.mat']);
|
2006-03-17 10:31:03 +01:00
|
|
|
NumberOfTYPEfiles = length(TYPEfiles);
|
2006-03-17 12:20:25 +01:00
|
|
|
B = options_.B;
|
2006-03-17 10:31:03 +01:00
|
|
|
|
|
|
|
switch TYPEarray
|
|
|
|
case 4
|
2006-03-17 12:20:25 +01:00
|
|
|
if NumberOfTYPEfiles > 1
|
2006-03-17 10:31:03 +01:00
|
|
|
NumberOfPeriodsPerTYPEfiles = ceil(TYPEsize(1)/NumberOfTYPEfiles);
|
2006-11-27 14:53:53 +01:00
|
|
|
foffset = NumberOfTYPEfiles-floor(TYPEsize(1)/NumberOfPeriodsPerTYPEfiles);
|
|
|
|
reste = TYPEsize(1)-NumberOfPeriodsPerTYPEfiles*(NumberOfTYPEfiles-foffset);
|
2006-03-16 18:07:58 +01:00
|
|
|
idx = 0;
|
|
|
|
jdx = 0;
|
2006-11-27 14:53:53 +01:00
|
|
|
for f1=1:NumberOfTYPEfiles-foffset
|
2006-03-17 10:31:03 +01:00
|
|
|
eval(['STOCK_' CAPtype ' = zeros(NumberOfPeriodsPerTYPEfiles,TYPEsize(2),TYPEsize(3),B);'])
|
2006-03-17 12:20:25 +01:00
|
|
|
for f2 = 1:NumberOfTYPEfiles
|
2006-03-17 10:31:03 +01:00
|
|
|
load([MhDirectoryName M_.fname '_' type int2str(f2)]);
|
2007-06-11 21:56:31 +02:00
|
|
|
eval(['STOCK_' CAPtype '(:,:,:,idx+1:idx+size(stock_' type ',4))=stock_' ...
|
|
|
|
type '(jdx+1:jdx+NumberOfPeriodsPerTYPEfiles,:,:,:);'])
|
|
|
|
eval(['idx = idx + size(stock_' type ',4);'])
|
2006-03-16 18:07:58 +01:00
|
|
|
end
|
2006-11-27 14:53:53 +01:00
|
|
|
%eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',4);'])
|
2006-03-17 10:31:03 +01:00
|
|
|
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(f1)],['STOCK_' CAPtype]);
|
|
|
|
jdx = jdx + NumberOfPeriodsPerTYPEfiles;
|
2006-03-16 18:07:58 +01:00
|
|
|
idx = 0;
|
|
|
|
end
|
2006-11-27 14:53:53 +01:00
|
|
|
if reste
|
2006-03-17 10:31:03 +01:00
|
|
|
eval(['STOCK_' CAPtype ' = zeros(reste,TYPEsize(2),TYPEsize(3),B);'])
|
|
|
|
for f2 = 1:NumberOfTYPEfiles
|
|
|
|
load([MhDirectoryName M_.fname '_' type int2str(f2)]);
|
2006-03-17 12:20:25 +01:00
|
|
|
eval(['STOCK_' CAPtype '(:,:,:,idx+1:idx+size(stock_' type ',4))=stock_' type '(jdx+1:jdx+reste,:,:,:);'])
|
2006-03-17 10:31:03 +01:00
|
|
|
eval(['idx = idx + size(stock_' type ',4);'])
|
2006-03-16 18:07:58 +01:00
|
|
|
end
|
2006-11-27 14:53:53 +01:00
|
|
|
%eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',4);'])
|
|
|
|
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(NumberOfTYPEfiles-foffset+1)],['STOCK_' CAPtype]);
|
|
|
|
end
|
2006-03-16 18:07:58 +01:00
|
|
|
else
|
2006-03-17 10:31:03 +01:00
|
|
|
load([MhDirectoryName M_.fname '_' type '1']);
|
2006-11-27 14:53:53 +01:00
|
|
|
%eval(['STOCK_' CAPtype ' = sort(stock_' type ',4);'])
|
2007-05-14 10:56:39 +02:00
|
|
|
eval(['STOCK_' CAPtype ' = stock_' type ';'])
|
2006-03-17 10:31:03 +01:00
|
|
|
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(1)],['STOCK_' CAPtype ]);
|
|
|
|
end
|
2006-12-15 12:37:24 +01:00
|
|
|
% Original file format may be useful in some cases...
|
|
|
|
% for file = 1:NumberOfTYPEfiles
|
|
|
|
% delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
|
|
|
|
% end
|
2006-03-17 10:31:03 +01:00
|
|
|
case 3
|
2006-03-16 18:07:58 +01:00
|
|
|
if NumberOfTYPEfiles>1
|
|
|
|
NumberOfPeriodsPerTYPEfiles = ceil( TYPEsize(2)/NumberOfTYPEfiles );
|
|
|
|
reste = TYPEsize(2)-NumberOfPeriodsPerTYPEfiles*(NumberOfTYPEfiles-1);
|
|
|
|
idx = 0;
|
|
|
|
jdx = 0;
|
2006-03-17 12:20:25 +01:00
|
|
|
for f1=1:NumberOfTYPEfiles-1
|
2006-03-16 18:07:58 +01:00
|
|
|
eval(['STOCK_' CAPtype ' = zeros(TYPEsize(1),NumberOfPeriodsPerTYPEfiles,B);'])
|
2006-03-17 12:20:25 +01:00
|
|
|
for f2 = 1:NumberOfTYPEfiles
|
2006-03-16 18:07:58 +01:00
|
|
|
load([MhDirectoryName M_.fname '_' type int2str(f2)]);
|
|
|
|
eval(['STOCK_' CAPtype '(:,:,idx+1:idx+size(stock_ ' type ',3))=stock_' type '(:,jdx+1:jdx+NumberOfPeriodsPerTYPEfiles,:);'])
|
|
|
|
eval(['idx = idx + size(stock_' type ',3);'])
|
|
|
|
end
|
2006-11-27 14:53:53 +01:00
|
|
|
%eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',3);'])
|
2006-03-16 18:07:58 +01:00
|
|
|
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(f1)],['STOCK_' CAPtype]);
|
2006-03-17 10:31:03 +01:00
|
|
|
jdx = jdx + NumberOfPeriodsPerTYPEfiles;
|
2006-03-16 18:07:58 +01:00
|
|
|
idx = 0;
|
|
|
|
end
|
|
|
|
eval(['STOCK_' CAPtype ' = zeros(TYPEsize(1),reste,B);'])
|
2006-03-17 10:31:03 +01:00
|
|
|
for f2 = 1:NumberOfTYPEfiles
|
2006-03-16 18:07:58 +01:00
|
|
|
load([MhDirectoryName M_.fname '_' type int2str(f2)]);
|
2006-03-17 12:20:25 +01:00
|
|
|
eval(['STOCK_' CAPtype '(:,:,idx+1:idx+size(stock_' type ',3))=stock_' type '(:,jdx+1:jdx+reste,:);'])
|
2006-03-16 18:07:58 +01:00
|
|
|
eval(['idx = idx + size(stock_' type ',3);'])
|
|
|
|
end
|
2006-11-27 14:53:53 +01:00
|
|
|
%eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',3);'])
|
2006-03-17 10:31:03 +01:00
|
|
|
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(NumberOfTYPEfiles)],['STOCK_' CAPtype]);
|
2006-03-16 18:07:58 +01:00
|
|
|
else
|
|
|
|
load([MhDirectoryName M_.fname '_' type '1']);
|
2006-11-27 14:53:53 +01:00
|
|
|
%eval(['STOCK_' CAPtype ' = sort(stock_' type ',3);'])
|
2007-05-14 10:56:39 +02:00
|
|
|
eval(['STOCK_' CAPtype ' = stock_' type ';'])
|
2006-03-16 18:07:58 +01:00
|
|
|
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(1)],['STOCK_' CAPtype ]);
|
|
|
|
end
|
2006-12-15 12:37:24 +01:00
|
|
|
% Original file format may be useful in some cases...
|
|
|
|
% for file = 1:NumberOfTYPEfiles
|
|
|
|
% delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
|
|
|
|
% end
|
2006-03-16 18:07:58 +01:00
|
|
|
end
|