function [mvals]=get_meta_ncml(url); % GET_META_NCML Get lon,lat,start,stop from an WHSC time series file % assess whether timebase is uniformly spaced % return a structure of useful stuff for future use % RPS & ETM 5/2008 nc=netcdf(url); mvals.lon=nc{'lon'}(1); mvals.lonmeta=nc.longitude(:); mvals.lat=nc{'lat'}(1); mvals.latmeta=nc.latitude(:); % get the instrument type if available if isempty(nc.INST_TYPE(:)) mvals.sensr='unavailable'; else mvals.sensr=nc.INST_TYPE(:); end % Assume that if BBV, data has a uniform time base % the values in time2 are often close but exactly the specified % Delta_T. The instrument's precision most likely isn't to the msec, so it % may be a red hearing to try to use it to determine dt. ntimes=length(nc('time')); d1=nc{'time'}(1); % round time2 values to nearest second to cover for previous sins % in processing which have led to 1 millisecond errors t1=round(nc{'time2'}(1)/1000)*1000; tend=(nc{'time'}(end)-d1)*3600*24*1000+round(nc{'time2'}(end)/1000)*1000; % use the attribute for delta_T if available if (strmatch('DELTA_T',ncnames(att(nc)))) if isnumeric(nc.DELTA_T(:)) dt=nc.DELTA_T(:)*1000; %as msec else % earliest files had 60.0 minutes in DELTA_T if (~isempty(strfind(nc.DELTA_T(:),'min'))) lx=findstr('.', nc.DELTA_T(:)); dt=str2num(nc.DELTA_T(1:lx))*60*1000; else % should be a number with seconds assumed dt=str2num(nc.DELTA_T(:))*1000; %as msec end end else %use the mean diff of values within a day dd=find(abs(diff(nc{'time2'}(:))) > 8630000); dt=mean(diff(nc{'time2'}(dd(5)+1:dd(6)))) end % Express start/stop times in Matlab datenum mvals.jd_start=(d1 - 1721059)+t1/3600/24/1000; mvals.jd_start=(d1 - 1721059)+tend/3600/24/1000; % Calculate start/stop times in Matlab datenum with units=milliseconds mvals.mjd_start=(d1 - 1721059)*3600*24*1000 + t1; %mvals.mjd_stop =(d1 - 1791059)*3600*24*1000 + tend; % typo mvals.mjd_stop =(d1 - 1721059)*3600*24*1000 + tend; tot1=dt*(ntimes-1); tot2=tend-t1; % accept as uniform, even if a sceond off if (tot1==tot2) | (abs(tot2-tot1) <= 1000) mvals.timebase_uniform=1; mvals.dt=dt/1000; % dt in seconds mvals.dtms=dt; % dt in milliseconds elseif abs(tot2-tot1) <= 10000 % within 10 seconds disp('within 10 seconds- do something here') else mvals.timebase_uniform=0; end % use WATER_DEPTH or water_depth attribute if isempty(nc.WATER_DEPTH(:)) if isnumeric(nc.water_depth(:)) mvals.wdep=nc.WATER_DEPTH(:); else mvals.wdep='missing'; end else mvals.wdep=nc.WATER_DEPTH(:); end mvals.meas_dep=nc{'depth'}(:); mvals.varnames=ncnames(var(nc)); for ik=1:length(mvals.varnames) eval(['mvals.long_names{ik} = nc{''' mvals.varnames{ik} '''}.long_name(:);']) end close(nc);