function t = nctime(infile) % NCTIME - Return the time from an MBARI convention netcdf file % % Time is stored as seconds since Jan 1, 1970 00:00:00 in MBARI % convention netCDF files. NCTIME converts this the time from a netcdf % file in matlabs data format. % % Use as: t = nctime(infile) % % Inputs: infile = a netcdf object % % Output: Entire record of time in matlab's date format % % Requires: NETCDF toolbox, STRINGTOKENIZER % Brian Schlining % 10 Mar 2000 % conventions = infile.conventions(:); % flag = 1; % % if isempty(conventions) % warning(sprintf(' %s is not an MBARI convention netCDF file.\n Any time variables found will not be converted to matlabs data format', char(ncnames(infile)))); % flag = 0; % end % % a = stringtokenizer(conventions, 1, '/'); % b = stringtokenizer(conventions, 2, '/'); % % if strcmp(upper(a), 'MBARI') % if ~strcmp(lower(b), 'timeseries') % warning([' ' char(ncnames(infile)) ' does not contain a timeSeries of data.']) % end % else % warning(sprintf(' %s is not an MBARI convention netCDF file.\n Any time variables found will not be converted to matlabs data format', char(ncnames(infile)))); % flag = 0; % end t = infile{'time'}(:); flag = 0; if isempty(t) warning(['The variable "time" was not found in ' char(ncnames(infile))]); return end units = infile{'time'}.units(:); if (isempty(units)) warning([char(ncnames(infile)) ' does not follow CF or COARDS conventions']) return end if (findstr(lower(units),'seconds')) flag = 1; % utc seconds end switch flag case 1 t = t/60/60/24 + datenum('01 Jan 1970 00:00:00'); end