function OK = oms_checkfile(infile)
% OMS_CHECKFILE - Checks to make sure specified file is a valid OMS netcdf file
%
% Use as: outfile = oms_checkfile(infile)
%
% Inputs: infile = A netcdf object
%
% Output: OK = 1 if a valid oms netcdf file, 0 otherwise

% Brian Schlining
% 10 Dec 1999

OK = 1;

try
   if ~strcmp(class(infile),'netcdf')
      warning([char(ncnames(infile)) ' is not a netcdf file']);
      OK = 0;
      return;
   else
      
      conventions = infile.conventions(:);
      
      if isempty(conventions)
         warning(sprintf('  %s is not an MBARI convention netCDF file.', ncnames(infile)));
         OK = 0;
         return;
      end
      
      a = stringtokenizer(conventions, 1, '/');
      b = stringtokenizer(conventions, 2, '/');
      c = stringtokenizer(conventions, 3, '/');
      d = stringtokenizer(conventions, 4, '/');
      if ~isempty(a)
         if strcmp(upper(a), 'MBARI')
            if strcmp(lower(b), 'timeseries')
               if strcmp(lower(c), 'mooring')
                  if strcmp(lower(d), 'spectroradiometer')
                  else
                     warning(sprintf('  %s is not an MBARI/timeSeries/mooring convention netCDF file.', ncnames(infile)));
                     OK = 0;
                  end
               else
                  warning(sprintf('  %s is not an MBARI/timeSeries/mooring convention netCDF file.', ncnames(infile)));
                  OK = 0;
               end
            else
               warning(sprintf('  %s is not an MBARI/timeSeries convention netCDF file.', ncnames(infile)));
               OK = 0;
            end
         else
            warning(sprintf('  %s is not an MBARI convention netCDF file.', ncnames(infile)));
            OK = 0;
         end
      else
         warning(sprintf('  %s is not an MBARI convention netCDF file.', ncnames(infile)));
         OK = 0;
         
      end
   end
   
   
   
catch
   OK = 0;
end



