function [mvals]=get_whfc_varmeta(url,mvals); % GET_WHFC_VARMETA Get variable names, long_name and units from an WHFC time series file % return a structure of useful stuff for use in supplying TDS metadata % % must be called after get_whfc_time so mvals is established % RPS & ETM 9/07 % % etm 3/2010 modified to use mDataset from njtools % if(strncmp(url(end),'<',1)) url=url(1:end-1); end % can't do burst files of any sort since no lat and lon coords % this condition shouldn't be necessary here since do_sta2ncml_tdsmeta (the % calling program) tries to deal with skipping the bursts... 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.varname=getVarNames(nc); kk=1; % don't process things likely to be coordinate variables- 1st find them for ik=1:length(mvals.varname) c1=strcmp(mvals.varname{ik},'time') | strcmp (mvals.varname{ik},'time2'); c2=strcmp(mvals.varname{ik},'depth') | strcmp(mvals.varname{ik},'burst'); c3=strcmp(mvals.varname{ik},'lon') | strcmp(mvals.varname{ik},'lat'); if (c1 | c2 |c3) idx_coordvar(kk)=ik; kk=kk+1; end end allindx=[1:1:length(mvals.varname)]; ncidx=setdiff(allindx, idx_coordvar); % only the indexes of non-coord vars clear ij kk jj for ik=1:length(ncidx) eval(['mvals.varnames{ik} = ''' mvals.varname{ncidx(ik)} ''';']) %this worked OK for most % eval(['mvals.long_name{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.long_name(:);']) % eval(['mvals.cf_name{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.long_name(:);']) % this works OK for PVSHELF07/8521wh-a.nc eval(['mvals.long_name{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.long_name;']) eval(['mvals.cf_name{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.long_name;']) newname=lookup_cf(mvals.long_name{ik}); if isempty(newname) if (1) % some condition may be needed here to get to the else eval(['mvals.cf_name{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.long_name;']) else eval(['mvals.cf_name{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.long_name(:);']) end mvals.cf_sub{ik}=0; else mvals.cf_name{ik} = newname; mvals.cf_sub{ik}=1; end eval(['mvals.units{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.units;']) if isfield(mvals,'sensor_type') eval(['mvals.sensor_type{ik} = nc{''' mvals.varname{ncidx(ik)} '''}.sensor_type;']) end end mvals=rmfield(mvals,'varname'); % now add the generic stuff we thought would be inherited % getInfo returns a string, getAttributes returns a structure- plan % accordingly! EXPERIMENT is always present, but is sometimes empty, % if it's empty and it's referred to as nc.EXPERIMENT it bombs % the commented condition works for most but some are actually missing the % EXPERIMENT attribute, so hopefully the new one will work. %if ~isempty(getfield(getAttributes(nc),'EXPERIMENT')) if isfield(getAttributes(nc),'EXPERIMENT') if ~isempty(getfield(getAttributes(nc),'EXPERIMENT')) mvals.title=nc.EXPERIMENT; else mvals.title='unavailable'; end else mvals.title='unavailable'; end % the SciPi attribute is only in newer datasets- needs to be hand edited for older ones if ~isempty(strfind(getInfo(nc),'SciPi')) mvals.scipi=nc.SciPi; else mvals.scipi='unavailable'; end close(nc); end