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

%  Version SWD970823
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global DATA

%
%  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, return, end
   
   fprintf(1,'Loading File #%d of %d\n',ib,nboot)
   
   loaddata2(pathname,filename,1)
   
   if isfield(DATA{1},'G'),
         
      if ib == 1,
         Gnew = zeros(size(DATA{1}.G,1),size(DATA{1}.G,2),size(DATA{1}.G,3),nboot);
      end
      
      Gnew(:,:,:,ib) = DATA{1}.G;
      
   end

   if isfield(DATA{1},'Coh'),
         
      if ib == 1,
         Cohnew = zeros(size(DATA{1}.Coh,1),size(DATA{1}.Coh,2),size(DATA{1}.Coh,3),nboot);
      end
   
      Cohnew(:,:,:,ib) = DATA{1}.Coh;
         
   end
      
   if isfield(DATA{1},'Gxy'),
         
      if ib == 1,
         Gxynew = zeros(size(DATA{1}.Gxy,1),size(DATA{1}.Gxy,2),size(DATA{1}.Gxy,3),nboot);
      end

      Gxynew(:,:,:,ib) = DATA{1}.Gxy;
         
   end

   if isfield(DATA{1},'Gxx'),
      
      if ib == 1,
         Gxxnew = zeros(size(DATA{1}.Gxx,1),size(DATA{1}.Gxx,2),nboot);
      end
         
      Gxxnew(:,:,ib) = DATA{1}.Gxx;
         
   end

   if isfield(DATA{1},'Gyy'),
         
      if ib == 1,
         Gyynew = zeros(size(DATA{1}.Gyy,1),size(DATA{1}.Gyy,2),nboot);
      end
      
      Gyynew(:,:,ib) = DATA{1}.Gyy;
      
   end
end

if exist('Gnew')==1,
   DATA{1}.G = Gnew;
end

if exist('Cohnew')==1,
   DATA{1}.Coh = Cohnew;
end

if exist('Gxynew')==1,
   DATA{1}.Gxy = Gxynew;
end

if exist('Gxxnew')==1,
   DATA{1}.Gxx = Gxxnew;
end

if exist('Gyynew')==1,
   DATA{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(pathname,filename,1)
   
else
   
   disp('ERROR Saving Bootstrap Datafile!')
   
end

disp('Done Creating Bootstrap-compatible file')

return