function OK = oms_makeprodschema(infile, outName)
% OMS_MAKEPRODSCHEMA - Creates an empty ncfile based on an existing ncfile schema
% 
% Use as: OK = oms_makeprodschema(infile, outName)
%
% Inputs: infile = An OMS netcdf file object
%         outName = The name of the empty output file to create
%
% Output: A new netcdf file is created with a schema based on infile. Note
%         that the time values are copied into the new netcdf file.
%         OK = 1 if the specified netcdf file is created., 0 if it failed.

% Brian Schlining
% 13 Dec 1999

% Create a new netcdf file
outfile = netcdf(outName, 'clobber');

if ~isempty(outfile)
   OK = 1;
   fprintf(1, 'Reading %s\n', char(ncnames(infile)));
   fprintf(1, 'Writing %s\n', char(ncnames(outfile)));

   % Copy global attributes
   a = att(infile);
   names = ncnames(a);
   if ~isempty(a)
      for i = 1:length(a)
         if strmatch('depth_', names{i})
         elseif strmatch('instrumentTypeBank', names{i})
         elseif strmatch('dataComment', names{i})
         elseif strmatch('creationDate', names{i})
            outfile.creationDate = datestr(now, 1);
         else
            fprintf(1,'Copying attribute "%s"\n', names{i});
            copy(a{i}, outfile);  
         end
      end
   end
   
   % Add additional global attributes
   [f p e] = fileparts(char(ncnames(infile)));
   outfile.keywords = 'spectroradiometer, attenuation, water-leaving radiance';
   outfile.sourceFile = ncchar([f filesep p e]);
   s = ['This archive contains products derived from data in ' p e];
   outfile.dataComment0 = s;   
   % Copy Dimensions
   d    = dim(infile);
   names = ncnames(d);
   
   for i = 1:length(d)
      if isrecdim(d{i})
         fprintf(1,'Copying unlimited-dimension "%s"\n', names{i});
         outfile(names{i}) = 0;
      else
         if ~strcmp(names{i},'bank_depth')
            fprintf(1,'Copying dimension "%s"\n', names{i});
            copy(d{i}, outfile);
         end
      end
   end
   
   % Copy Dimension Variables (without data)  
   v = var(infile);								% Get the variable objects
   names = ncnames(v);
   if ~isempty(v)
      for i = 1:length(v)
         vDim = dim(v{i});			% Get the dimensions of each variable
         for j = 1:length(vDim)
            isRecordVDim(j) = isrecdim(vDim{j});   
         end
         
         try
            RecordVDim = find(isRecordVDim);
            if isempty(RecordVDim)
               if ~strcmp(names{i}, 'bankDepth')
                  fprintf(1,'Copying Variable %s (non-record)\n', names{i})
                  copy(v{i}, outfile, 1, 1);      % Copy non-record variables with data
               end
            else
               if strcmp(names{i}, 'time')
                  fprintf(1,'Copying Variable %s (unlimited-record)\n', names{i})
                  copy(v{i}, outfile, 1, 1); 		% Copy record variables without data
               else
                  %fprintf(1,'Copying Variable %s (record)\n', names{i})
                  %copy(v{i}, outfile, 0, 1); 		% Copy record variables without data
               end
               
            end
            
         catch
            fprintf(1,'Error\n')
         end
      end
   end
   
   ncquit(outfile);
else
   OK = 0;
end


