%
%  Name: makeboot.m
% 
%  Usage: makeboot
% 
%  Description:
%    Creates a DIAMOND data file with bootstrap data matrices
%     from multiple DIAMOND data files with single data ensembles
%

%  Version SWD970725
%
%  Author(s): Scott W. Doebling, doebling@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%		ESA-EA
%
%  Copyright (c) 1997, The Regents of the University
%     	of California. (See top level of code for
%        full copyright statement)
%

%
%  Determine how many files are available
%

nboot = input('How many files form the Bootstrap set?');

disp(['Preparing to load ',num2str(nboot),' files'])

%  Prompt for each one of the bootstrap files

pathname = 'C:\';

for ib = 1:nboot,
   
   fprintf(1,'Preparing to Load File #%d of %d\n',ib,nboot)
   
   [filename,pathname,error] = loadfile(0,pathname);

   if error == 0,
      
      fprintf(1,'Loading File #%d of %d\n',ib,nboot)

      eval(['load ',[pathname,filename]]);

      if exist('G')==1,
         
         if ib == 1,
            Gnew = zeros(size(G,1),size(G,2),nboot);
         end

         Gnew(:,:,ib) = G;
         
      end

      if exist('Coh') == 1,
         
         if ib == 1,
            Cohnew = zeros(size(Coh,1),size(Coh,2),nboot);
         end
   
         Cohnew(:,:,ib) = Coh;
         
      end
      
      if exist('Gxy'),
         
         if ib == 1,
            Gxynew = zeros(size(Gxy,1),size(Gxy,2),nboot);
         end

         Gxynew(:,:,ib) = Gxy;
         
      end

      if exist('Gxx') == 1,
         
         if ib == 1,
            Gxxnew = zeros(size(Gxx,1),size(Gxx,2),nboot);
         end

         Gxxnew(:,:,ib) = Gxx;
         
      end

      if exist('Gyy') == 1,
         
         if ib == 1,
            Gyynew = zeros(size(Gyy,1),size(Gyy,2),nboot);
         end

         Gyynew(:,:,ib) = Gyy;
         
      end
   end
end

if exist('Gnew')==1,
   G = Gnew;
end

if exist('Cohnew')==1,
   Coh = Cohnew;
end

if exist('Gxynew')==1,
  Gxy = Gxynew;
end

if exist('Gxxnew')==1,
  Gxx = Gxxnew;
end

if exist('Gyynew')==1,
   Gyy = Gyynew;
end

%
%   Save the new DIAMOND data file with the Bootstrap-compatible variables
%

fprintf(1,'Saving Bootstrap Datafile...')

[filename,pathname,error] = savefile(0,pathname);

if error == 0,
   
   savedata
   
else
   
   disp('ERROR Saving Bootstrap Datafile!')
   
end

disp('Done Creating Bootstrap-compatible file')