function redo_minmax(nc) % redo_minmax: recomputes the mins and maxs of non-coordinate variables % % usage: redo_minmax(nc); % where nc is a netcdf object that was already opened by % nc=netcdf('file_name.cdf','write') % autonan MUST be ON before the .nc file is loaded for gmin and gmax to % work correctly on 1e35, since gmin and gmax actually look for NaN % from MM code in sg2nc.m % emontgomery@usgs.gov if ~(nargin ==1); help (mfilename); return end if ~exist('nctbx_options','var'), global nctbx_options; nctbx = 0; else nctbx = 1; end theVars = var(nc); if ~autonan(theVars{1}), % close and open the file to set autonan theFileName = char(ncnames(nc)); close(nc) nctbx_options.theAutoNaN = 1; nc = netcdf(theFileName,'write'); end theVars = var(nc); for i = 1:length(theVars), if (~strcmp(ncnames(theVars{i}),'time') && ~strcmp(ncnames(theVars{i}),'time2')... && ~strcmp(ncnames(theVars{i}),'lon') && ~strcmp(ncnames(theVars{i}),'lat')... && ~strcmp(ncnames(theVars{i}),'depth') && ~strcmp(ncnames(theVars{i}),'burst' )) data = theVars{i}(:); [row, col] = size(data); mins = zeros(1,col); maxs = zeros(1,col); if col == 1, theVars{i}.minimum = ncfloat(gmin(data)); theVars{i}.maximum = ncfloat(gmax(data)); % elseif col == 2, elseif col == 2, theVars{i}.minimum = ncfloat(gmin(gmin(data))); theVars{i}.maximum = ncfloat(gmax(gmax(data))); elseif col > 2, % then these are amp and cor or some other 3d var % this is clunky but gets a single min and max over all the bursts mins = gmin(gmin(data)); maxs = gmax(gmax(data)); theVars{i}.minimum = ncfloat(gmin(mins'))'; theVars{i}.maximum = ncfloat(gmax(maxs')); end clear mins maxs end end % update the creation date nc.CREATION_DATE(:)=datestr(now); history=nc.history(:); ncatt('history',['corrected variable min and max:' sprintf('\n') history],nc);