function trunc_cdf(infile, outfile, indxs) % trunc_cdf- truncates a netcdf file to contain only the specified records % function to truncate a .cdf file by cutting off initial % and final records or otherwise outside a designated "good" range of values. % usage : trunc_cdf('8173sc-cal.cdf','8173sc-trm.nc',[1129 22764]) % nb- record record numbers! if a file contains bursts 1600-2929, to % keep bursts 1600-2900, use [1 1300] % NOTE! this doesn't work with sonar images or pcadp bursts- use trunc_img % Fran Hotchkiss April 8, 1998, & emontgomery 7/08 % %%% START USGS BOILERPLATE ------------- % There is no published documentation for these programs- use the % internal comments and help function. % Programs written in Matlab- as early as 7.2.0.232 (R2006a) and % most recent modifications in v7.8.0 (R2009a) % Programs ran on PC with Windows XP Professional OS, and RHEL4 linux. % % "Although this program has been used by the USGS, no warranty, % expressed or implied, is made by the USGS or the United States % Government as to the accuracy and functioning of the program % and related program material nor shall the fact of distribution % constitute any such warranty, and no responsibility is assumed % by the USGS in connection therewith." %%% END USGS BOILERPLATE -------------- mvers='SVN $Revision$'; % open input file rawc = netcdf(infile); % and the output file to take trimmed data outc = netcdf(outfile,'noclobber'); % set the bounds to keep start=indxs(1); stop=indxs(end); % Call nctrim, using a work-aroud that's OK in Matlab > 2009b newc = nctrim(rawc,outc, start:stop, 'time'); clear outc outc=newc % Update global attributes. history =['Trimmed using ', mfilename, ', ',mvers, ' to select records in the range ']; history =[history num2str(start) ' to ' num2str(stop) '. :' outc.history(:)]; outc.history = history; % time = outc{'time'}(:); % time2 = outc{'time2'}(:); % stime = ep_datenum([time(1) time2(1)]); % n = length(time); % ltime = ep_datenum([time(n) time2(n)]); % outc.start_time(:) = datestr(stime,0); % outc.stop_time(:) = datestr(ltime,0); outc.start_time=datestr(ep_datenum([outc{'time'}(1) outc{'time2'}(1)]),0); outc.stop_time=datestr(ep_datenum([outc{'time'}(end) outc{'time2'}(end)]),0); outc.CREATION_DATE = ncchar(datestr(now,0)); % Update minima and maxima of truncated variables. theVars = var(outc); theRecdim = recdim(outc); for i = 1:length(theVars) theDims = dim(theVars{i}); if length(theDims) > 1 if isequal(name(theDims{1}),name(theRecdim)) data = outc{name(theVars{i})}(:); outc{name(theVars{i})}.minimum = ncfloat(min(data)); outc{name(theVars{i})}.maximum = ncfloat(max(data)); end end end close(outc) ncclose