function statrtn=cvt_nep2sed_brst(infile,outfile, extmeta) % cvt_nep2sed_brst: computes sediment concentration from nep (raw volts) % uses equation from dohydraoptic to correct or compute sed. conc. from OBS. % works on burst files. % % ** this is very slow, and doesn't put optic into sed_981 properly. It % can be used to remove the bad sed from the data, but not putting new % in % % usage : % extm.height = 0.99; % m % extm.cals.gain = .33; % for OBS gain setting, g/l per volt % extm.cals.coef = [2.4687 133.1316]; % extm.remove_minVolt=0; % remove minimum voltage (1 for yes) % status ==cvt_nep2sed_brst('8446advb-cal.nc','8446advb-new.nc',extm) % emontgomery 9/3/09 if exist(infile,'file') nc = netcdf(infile); else [infile,inpath] = uigetfile('*.cdf','Choose input file'); nc = netcdf(infile); if isempty(nc) disp (['Cannot open input file ' infile]); statrtn=0; disp (['Execution ends.']); return; end end [nvarin,chosen] = em_dollyvar(nc,'y'); nvarout=nvarin; % Get the global attributes keepatts = att(nc); ngatts=length(keepatts); % get the variablenames for ivar = 1:nvarin; invar = nc{chosen{ivar}}; invar = autonan(invar,1); inname{ivar} = name(invar); end % get the length of the data- this won't change ntimes=length(nc{'time'}(:)); %get existing neph data % so far we only have one OBS/logger, so we don't need to handle more than % one thing in loc (yet) loc=strmatch('NEP',chosen); loc2=strmatch('Sed',chosen); extvolts=nc{chosen{loc}}(:,:); sz=size(nc{'time'}); p=sz(1); q=sz(2); % p = #bursts, q = pts in burst % find the number of the ext connector extno=chosen{loc}(4); % this is the part from dohydraoptic if ~isempty(findstr('OBS',extmeta.serial)), if ~(isfield(extmeta,'remove_minVolt')) extmeta.remove_minVolt=0; end if extmeta.remove_minVolt adj_evolt =extvolts-min(extvolts); else adj_evolt=extvolts; end if isfield(extmeta.cals,'coef') && ~isempty(extmeta.cals.coef), % user has supplied coefficients optic = min(min(extvolts)).*ones(size(extvolts)); for n = 2:length(extmeta.cals.coef), optic = optic + extmeta.cals.coef(n).*(extvolts.^(n-1)); end else % No coefficients, no conversion %disp('dohydraoptic: No coefficients supplied for the OBS') optic = []; end else optic = extvolts; end % end part from dohydraoptic % Open output cdf outc = netcdf(outfile,'noclobber'); if isempty(outc) [outfile,outpath] = uiputfile('*.nc','Choose output file'); outc = netcdf(fullfile(outpath,outfile),'noclobber'); % MM 11/18/04 add path if isempty(outc) disp (['Cannot open output file ' outfile]); disp (['Data will be parked in temporary.nc']); outc = netcdf('temporary.nc','clobber'); end end %Update global attributes and variables in output file. history =['Sed_981 created or modified by cvt_nep2sed_brst :' nc.history(:)] vardesc=nc.VAR_DESC(:); if isempty(strfind(vardesc,'sed')) % add sed to the list, if missing vardesc = [vardesc ':sed' extno]; nvarout=nvarout+1; loc2=nvarout; % new cases of sed will be added to the end end % Dimensions: outc('time') = p; outc('depth') = 1; outc('lon') = 1; outc('lat') = 1; outc('sample') = q; % Variables and attributes: % ncvar/copy with 1,1,1 == copy data, copy attributes, copy dimensions copy(nc{'time'},outc,1,1,1); copy(nc{'time2'},outc,1,1,1); copy(nc{'depth'},outc,1,1,1); copy(nc{'lon'},outc,1,1,1); copy(nc{'lat'},outc,1,1,1); copy(nc{'burst'},outc,1,1,1); % Copy global attributes from input file to output file. for i = 1 : length(keepatts); copy(keepatts{i},outc); end % now add the ones that needed updating outc.history = history; outc.VAR_DESC = ncchar(vardesc); outc.CREATION_DATE = ncchar(datestr(now,0)); for i = 2: nvarout; disp (['creating output variable ' inname{i}]); ivar = nc{inname{i}}; if ~isempty(strmatch('Sed',chosen{i})) copy(ivar,outc,1,1,1); else sedname=['Sed' extno '_981']; nc{sedname} = ncfloat('time', 'depth', 'lat', 'lon', 'sample') nc{sedname}.name = ncchar('Sed'); nc{sedname}.long_name = ncchar('Sediment concentration '); nc{sedname}.generic_name = ncchar('sed'); nc{sedname}.FORTRAN_format = ncchar('f10.2'); nc{sedname}.units = ncchar('g/l'); nc{sedname}.epic_code = nclong(981); nc{sedname}.code = ncchar('R'); nc{sedname}.sensor_depth = ncfloat(0); nc{sedname}.serial_number = ncchar('OBS2181'); nc{sedname}.minimum = ncfloat(0); nc{sedname}.maximum = ncfloat(0); nc{sedname}.valid_range = ncfloat([0 1500]); nc{sedname}.FillValue_ = 1.0e35; end end %disable define mode endef(outc) % put new optic data in the file outc{chosen{loc2}}(1:p,1:q) = optic; outc{chosen{loc2}}.minimum = ncfloat(min(min(optic))); outc{chosen{loc2}}.maximum = ncfloat(max(max(optic))); % now close the ncfiles close (outc); close (nc); statrtn=1;