Home > . > ReshapeMatFiles.m

ReshapeMatFiles

PURPOSE ^

Reshape and sort (along the mcmc simulations) the mat files generated

SYNOPSIS ^

function ReshapeMatFiles(type)

DESCRIPTION ^

 Reshape and sort (along the mcmc simulations) the mat files generated
 by DYNARE.

 4D-arrays are splitted along the first dimension.
 3D-arrays are splitted along the second dimension.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ReshapeMatFiles(type)
0002   % Reshape and sort (along the mcmc simulations) the mat files generated
0003   % by DYNARE.
0004   %
0005   % 4D-arrays are splitted along the first dimension.
0006   % 3D-arrays are splitted along the second dimension.
0007   %
0008   %
0009   global M_ options_
0010 
0011   MhDirectoryName = [ CheckPath('metropolis') '/' ];
0012   
0013   switch type
0014    case 'irf'
0015     CAPtype  = 'IRF';
0016     TYPEsize = [ options_.irf , M_.endo_nbr , M_.exo_nbr ];
0017     TYPEarray = 4; 
0018    case 'smooth'
0019     CAPtype  = 'SMOOTH';
0020     TYPEsize = [ M_.endo_nbr , options_.nobs ];
0021     TYPEarray = 3;
0022    case 'filter'
0023     CAPtype = 'FILTER';
0024     TYPEsize = [ M_.endo_nbr , options_.nobs + 1 ];% TO BE CHECKED!
0025     TYPEarray = 3;
0026    case 'error'
0027     CAPtype = 'ERROR';
0028     TYPEsize = [ size(options_.varobs,1) , options_.nobs ];
0029     TYPEarray = 3;
0030    case 'innov'
0031     CAPtype = 'INNOV';
0032     TYPEsize = [ M_.exo_nbr , options_.nobs ];
0033     TYPEarray = 3;
0034    case 'forcst'
0035     CAPtype = 'FORCST';
0036     TYPEsize = [ M_.endo_nbr , options_.forecast ];
0037     TYPEarray = 3;
0038    case 'forcst1'
0039     CAPtype = 'FORCST1';
0040     TYPEsize = [ M_.endo_nbr , options_.forecast ];
0041     TYPEarray = 3;
0042    otherwise
0043     disp('ReshapeMatFiles :: Unknown argument!')
0044     return
0045   end
0046   
0047   TYPEfiles = dir([MhDirectoryName M_.fname '_' type '*']);
0048   NumberOfTYPEfiles = length(TYPEfiles);
0049   B = options_.B;
0050   
0051   switch TYPEarray
0052    case 4
0053     if NumberOfTYPEfiles > 1
0054       NumberOfPeriodsPerTYPEfiles = ceil(TYPEsize(1)/NumberOfTYPEfiles);
0055       reste = TYPEsize(1)-NumberOfPeriodsPerTYPEfiles*(NumberOfTYPEfiles-1);
0056       idx = 0;
0057       jdx = 0;
0058       for f1=1:NumberOfTYPEfiles-1
0059         eval(['STOCK_' CAPtype ' = zeros(NumberOfPeriodsPerTYPEfiles,TYPEsize(2),TYPEsize(3),B);'])
0060         for f2 = 1:NumberOfTYPEfiles
0061           load([MhDirectoryName M_.fname '_' type int2str(f2)]);
0062           eval(['STOCK_' CAPtype '(:,:,:,idx+1:idx+size(stock_' type ',4))=stock_' type '(jdx+1:jdx+NumberOfPeriodsPerTYPEfiles,:,:,:);'])
0063           eval(['idx = idx + size(stock_' type ',4);'])          
0064         end
0065         eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',4);'])
0066         save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(f1)],['STOCK_' CAPtype]);
0067         jdx = jdx + NumberOfPeriodsPerTYPEfiles;
0068         idx = 0;
0069       end
0070       eval(['STOCK_' CAPtype ' = zeros(reste,TYPEsize(2),TYPEsize(3),B);'])
0071       for f2 = 1:NumberOfTYPEfiles
0072         load([MhDirectoryName M_.fname '_' type int2str(f2)]);
0073         eval(['STOCK_' CAPtype '(:,:,:,idx+1:idx+size(stock_' type ',4))=stock_' type '(jdx+1:jdx+reste,:,:,:);'])
0074         eval(['idx = idx + size(stock_' type ',4);'])
0075       end
0076       eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',4);'])
0077       save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(NumberOfTYPEfiles)],['STOCK_' CAPtype]);      
0078     else
0079       load([MhDirectoryName M_.fname '_' type '1']);
0080       eval(['STOCK_' CAPtype ' = sort(stock_' type ',4);'])
0081       save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(1)],['STOCK_' CAPtype ]);
0082     end
0083     for file = 1:NumberOfTYPEfiles
0084       delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
0085     end
0086    case 3
0087     if NumberOfTYPEfiles>1
0088       NumberOfPeriodsPerTYPEfiles = ceil( TYPEsize(2)/NumberOfTYPEfiles );
0089       reste = TYPEsize(2)-NumberOfPeriodsPerTYPEfiles*(NumberOfTYPEfiles-1);
0090       idx = 0;
0091       jdx = 0;
0092       for f1=1:NumberOfTYPEfiles-1
0093         eval(['STOCK_' CAPtype ' = zeros(TYPEsize(1),NumberOfPeriodsPerTYPEfiles,B);'])
0094         for f2 = 1:NumberOfTYPEfiles
0095           load([MhDirectoryName M_.fname '_' type int2str(f2)]);
0096           eval(['STOCK_' CAPtype '(:,:,idx+1:idx+size(stock_ ' type ',3))=stock_' type '(:,jdx+1:jdx+NumberOfPeriodsPerTYPEfiles,:);'])
0097           eval(['idx = idx + size(stock_' type ',3);'])
0098         end
0099         eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',3);'])
0100         save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(f1)],['STOCK_' CAPtype]);
0101         jdx = jdx + NumberOfPeriodsPerTYPEfiles;
0102         idx = 0;
0103       end
0104       eval(['STOCK_' CAPtype ' = zeros(TYPEsize(1),reste,B);'])
0105       for f2 = 1:NumberOfTYPEfiles
0106         load([MhDirectoryName M_.fname '_' type int2str(f2)]);
0107         eval(['STOCK_' CAPtype '(:,:,idx+1:idx+size(stock_' type ',3))=stock_' type '(:,jdx+1:jdx+reste,:);'])
0108         eval(['idx = idx + size(stock_' type ',3);'])
0109       end
0110       eval(['STOCK_' CAPtype ' = sort(STOCK_' CAPtype ',3);'])
0111       save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(NumberOfTYPEfiles)],['STOCK_' CAPtype]);
0112     else
0113       load([MhDirectoryName M_.fname '_' type '1']);
0114       eval(['STOCK_' CAPtype ' = sort(stock_' type ',3);'])
0115       save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(1)],['STOCK_' CAPtype ]);      
0116     end
0117     for file = 1:NumberOfTYPEfiles
0118       delete([MhDirectoryName M_.fname '_' type  int2str(file) '.mat'])
0119     end
0120   end

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003