% Script to truncate a file by cutting off initial % and final records % (a) outside a designated range of records, or % (b) for which a designated variable falls % outside a designated "good" range of values. % Fran Hotchkiss April 8, 1998 % Use dialog box to choose input file. Instructions = '* Select raw data file.' pause rawc = netcdf; % Use dialog box to name output file. Instructions = 'Select output data file.' pause outc = netcdf('noclobber'); % Use dialog box to designate variable that is % basis of truncation, and its range of % "good values." criterion.infile = justname(name(rawc)); criterion.input_record_num = 'YES'; criterion.variable = 'P_4023'; criterion.good_minimum = 1241; criterion.good_maximum = 21600; uigetparm(criterion); load criterion cmin = criterion.good_minimum; cmax = criterion.good_maximum; if strncmp(upper(criterion.input_record_num),'NO',1) % Find first and last record for which designated % variable is good. dvar = rawc{criterion.variable}(:); i = find(dvar>=cmin & dvar<=cmax); start = i(1); stop = i(length(i)); elseif strncmp(upper(criterion.input_record_num),'YES',1) start = cmin; stop = cmax; else update = 'Quitting: truncation criterion makes no sense.' ncclose return end % Call nctrim. outc = nctrim(rawc,outc,start:stop); % Update global attributes. if strncmp(upper(criterion.input_record_num),'NO',1) history =['Trimmed using truncate.m to select ' criterion.variable ]; history =[history ' in the range ' num2str(cmin) ' to ' num2str(cmax) '. :' outc.history(:)]; else strncmp(upper(criterion.input_record_num),'YES',1) history =['Trimmed using truncate.m to select records in the range ']; history =[history num2str(cmin) ' to ' num2str(cmax) '. :' outc.history(:)]; end 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.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 ncclose