function newarray=denanize(array,badval)
%function newarray=denanize(array,badval)
% replaces NaN with badval
%
newarray=array;
[imax,jmax]=size(array);
if imax<jmax
  for i=1:imax
     bad=find( (array(i,:)==nan)|(abs(array(i,:))==inf));
     if length(bad)>0 
         newarray(i,bad)=ones(1,length(bad))*badval;
     end
  end
else
  for i=1:jmax
     bad=find((array(:,i)==nan)|(abs(array(:,i))==inf));
     if length(bad)>0
         newarray(bad,i)=ones(length(bad),1)*badval;
     end
   end
end
