function rm_nan_inAtt(fname) % THREDDS objects to NaN in the minimum and maximum variable attributes. % this program look at all the variables and checks for this, replacing any % NaN's found with 1e35. % emontgomery@usgs.gov 3/26.10 % check the file exists if exist(fname)~=2 [fn,fpath] = uigetfile('*','Choose file to fix'); fname=[fpath '/' fn]; end % Open the file then find and replace the NaN's nc=netcdf(fname,'write'); theVars=var(nc); %autonan cannot be on for this to work!!! if autonan(theVars{1}), % close and open the file to set autonan theFileName = char(ncnames(nc)); close(nc) nctbx_options.theAutoNaN = 0; nc = netcdf(theFileName,'write'); flag=1; else flag=0; end for ik=1:length(theVars) minAtt=att(theVars{ik},'minimum'); if ~isempty(minAtt) tmp=minAtt{1}; nloc=find(isnan(minAtt{1})); % returns indices where NaN if ~isempty(nloc) tmp(nloc)=ones(1,length(nloc))*1e35; theVars{ik}.minimum=tmp; end end clear tmp nloc minAtt maxAtt=att(theVars{ik},'maximum'); if ~isempty(maxAtt) tmp=maxAtt{1}; nloc=find(isnan(maxAtt{1})); % returns indices where NaN if ~isempty(nloc) tmp(nloc)=ones(1,length(nloc))*1e35; theVars{ik}.maximum=tmp; end end clear tmp nloc maxAtt end close(nc) %tidy up before returning. % if the autonan flag was on when the function started, turn it back on if flag==1; nctbx_options.theAutoNaN = 1; end