% fixhydrarange - use acoustic range information from the ADV and PCADP to % generate a range to boundary time series for the experiment % % function newrange = fixhydrarange(cdfsFile, cdfqFile, cdfsNewFile) % % cdfsFile = netCDF raw statistics data file containing ADV or PCADP data % cdfqFile = the netCDF quality file % cdfsNewFile = new copy of the netCDF raw statistics data file % newrange = the new range time series as a cell array by beam % % First, some of the wild points are filtered out, then the user uses an % interactive plot to drag the remainder back to a realistic value. % % (We have not yet found a reliable filter to automate this entirely, % if you find one that works on this data, please contact the author) % % Written by Marinna Martini % for the USGS Woods Hole Field Center % 8/11/04 % 1/12/06 % -- add information to the quality file a difference between the before and after % 9/16/04 change to always overwrite the output file function newrange = fixhydrarange(cdfsFile, cdfqFile, cdfsNewFile) prog_ver = 0.0; newrange = []; if exist('cdfsFile', 'var') ~=1, [inName, inPath, filterindex] = uigetfile('*s*.cdf', ... 'Pick a netcdf file containing ADV or PCADP statistics data'); if isequal(inName,0) | isequal(inName,0) disp('User pressed cancel') return end cdfsFile = fullfile(inPath, inName); disp(['User selected stats file ', cdfsFile]) end if exist('cdfsNewFile', 'var') ~=1, [inPath, inName, inExt] = fileparts(cdfsFile); cdfsNewFile = fullfile(inPath, [inName,'a',inExt]); cdfsNewFile = inputdlg('Output file name needed','Output file',1,{cdfsNewFile}) cdfsNewFile = char(cdfsNewFile); disp(['User selected output file ', cdfsFile]) end if exist(cdfqFile,'file') ~=2, [inName, inPath, filterindex] = uigetfile('*q.cdf', ... 'Pick a netcdf file containing ADV or PCADP quality information'); if isequal(inName,0) | isequal(inName,0) disp('User pressed cancel') return end cdfqFile = fullfile(inPath, inName); disp(['User selected quality file ', cdfqFile]) end disp(['User selected ', cdfqFile]) cdfq = netcdf(cdfqFile,'write'); if isempty(cdfq), disp(['Unable to open ',cdfqFile]); return; end cdfs = netcdf(cdfsFile,'nowrite'); if isempty(cdfs), disp(sprintf('Could not open netCDF file %s',cdfsFile)) close (cdfs) return end % make sure this is a statistics ADV or PCADP data file % get the variable names if strcmp(cdfs.DESCRIPT(:),'Sontek ADV raw data statistics file'), nBeams = 1; rangevarnames = {'brange','vrange'}; elseif strcmp(cdfs.DESCRIPT(:),'Sontek PCADP raw data statistics file'), nBeams = cdfs.Nbeams(:); for iBeam = 1:nBeams, rangevarnames{iBeam} = sprintf('MeanRange%d',iBeam); end else disp('File is not a Sontek ADV or PCADP raw data netCDF file containing statistics data (*s.cdf)') close (cdfs) return end % get the data, do the primary filtering burstNum = cdfs{'burst'}(:); for iBeam = 1:length(rangevarnames), range{iBeam} = cdfs{rangevarnames{iBeam}}(:); ecrange{iBeam} = ecorr(range{iBeam},0); % suspend plots [x,y] = ydrag(burstNum, ecrange{iBeam}); newrange{iBeam} = y; end close(cdfs); % we're done, write a new file copyfile(cdfsFile, cdfsNewFile); cdfsnew = netcdf(cdfsNewFile,'write'); for iBeam = 1:nBeams, cdfsnew{rangevarnames{iBeam}}(:) = newrange{iBeam}; end data = cdfsnew.history(:); data = sprintf('edited by %s %f; %s', mfilename, prog_ver, data); cdfsnew.history = data; close (cdfsnew) % make the notes in the Quality file cdfq = netcdf(cdfqFile,'write'); for iBeam = 1:length(rangevarnames), varname = sprintf('%s_%s',mfilename,rangevarnames{iBeam}); cdfq{varname} = ncfloat('burst'); cdfq{varname}(:) = range{iBeam}(:)-newrange{iBeam}(:); end close (cdfq)