function [mvals]=get_whfc_meta(url); % GET_WHFC_META Get lon,lat,start,stop from an WHFC time series file % return a structure of useful stuff for future use % RPS & ETM 9/07 % % etm 3/2010 modified to use mDataset from njtools instead of using a % DAP-enabled netcdf (requiring avery old mexnc_dap_r14) % mDataset doesn't get all the global attributes- important to this program % are .longitude, .latitude, and .WATER_DEPTH % % Could use mdataset for web resources, use netcdf for local, but am trying % to do it all with mDataset if(strncmp(url(end),'<',1)) url=url(1:end-1); end % can't do burst files since no lat and lon coords if ~isempty(strfind(url,'b-cal')) mvals=[]; disp(['skipping ' url]) else disp(url) nc=mDataset(url) % uses njTools- doesn't work fully Apr. 2010 %nc=netcdf(url); % old way uses mexnc_linux_r14_dap/mexnc.mexglx if isempty(nc) respns=input('there is nothing in nc- want to continue? ','s') if strncmp(lower(respns),'n',1) disp('exiting program') return end end 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 % Determine if uniform time base by checking if % dt*(nt-1) = t(end)-t(1) % Why use dt=(t(3)-t(1))/2 instead of dt=t(2)-t(1)? % Good question. Because in the first dataset I tried % (MYRTLEBEACH/7201adc-a.nc), t(2) was off by 1 millisecond. % Do exact math in integers (milliseconds) ntimes=length(nc{'time'}(:)); d1=double(nc{'time'}(1)); % having these as double is necessary d3=double(nc{'time'}(3)); % when netcdf-java is used. d99=double(nc{'time'}(end)); e1=double(nc{'time2'}(1)); e3=double(nc{'time2'}(3)); e99=double(nc{'time2'}(end)); if isnan(e99) d99=double(nc{'time'}(ntimes)); e99=double(nc{'time2'}(ntimes)); end % in this program, d?=the day part of the EPIC time, e? is the parts of the % day or "time" component (based on EPIC time2). % round time2 values to nearest second to cover for previous sins % in processing which have led to 1 millisecond errors t1=round(e1/1000)*1000; t3=(d3-d1)*3600*24*1000+round(e3/1000)*1000; tend=(d99-d1)*3600*24*1000+round(e99/1000)*1000; dt=(t3-t1)/2; % Express start/stop times in Matlab datenum % so datestr(mvals.jd_start) returns an answer that matches % gregorian(nc{'time'}(1)+(nc{'time2'}(1)/86400000)) % 1721059 is a factor that allows our julian day 2440000 that begin at % 0000 hours, May 23, 1968. to be used with datenum mvals.jd_start=(d1 - 1721059)+t1/3600/24/1000; mvals.jd_stop=(d1 - 1721059)+tend/3600/24/1000; mvals.mjd_start=(d1 - 1721059)*3600*24*1000 + t1; mvals.mjd_stop =(d1 - 1721059)*3600*24*1000 + tend; % fixed typo here tot1=dt*(ntimes-1); tot2=tend-t1; if tot1==tot2, mvals.timebase_uniform=1; mvals.dt=dt/1000; % dt in milliseconds mvals.dtms=dt; % dt in milliseconds else mvals.timebase_uniform=0; end % use WATER_DEPTH (1st) or water_depth (if WATER_DEPTH missing) 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'}(:); % ncnames doesn't work with mDatset %mvals.varnames=ncnames(var(nc)); mvals.varnames=getVarNames(nc); for ik=1:length(mvals.varnames) eval(['mvals.long_names{ik} = nc{''' mvals.varnames{ik} '''}.long_name(:);']) end close(nc); end