%% compute variogram or covariance function from the observation 

%%  Kriging Software Package  version 1.0 beta,   October 29, 1998
%%  Copyright (c) 1998, property of Dezhang Chu and Woods Hole Oceanographic
%%  Institution.  All Rights Reserved.


global lag gammah

  ht1=text(0.02,0.5,'Computing Variogram/Covariance Function','sc');
  ht2=text(0.25,0.4,'  Please be patient, ...','sc');
  htxt=[ht1 ht2];   
  set(htxt,'color','b','fontweight','bold');
  drawnow
  hvrg=findobj(gcf,'Tag','range');
  hvres=findobj(gcf,'Tag','delx');
  range=str2num(get(hvrg,'String'));
  res=str2num(get(hvres,'String'));
  [lag,gammah,S2,cnt]=variogram(x,y,var,res,range,anisotropy_para);
  set(htxt,'visible','off');
  hvVar=findobj(gcf,'Tag','radioVAR');
  if ~isempty(hvVar) 
    if (get(hvVar,'value')) == 1
      hv0=plot(lag,gammah,'o');
      hy=ylabel('Variogram');
    else
      hv0=plot(lag,1-gammah,'o');
      hy=ylabel('Correlogram');   
    end
  else
    hv0=plot(lag,1-gammah,'o');
    hy=ylabel('Correlogram');   
  end  
  set(get(hv0(1),'parent'),'Tag','variogramAxes1')
  if Lat_long == 0
     hx=xlabel('Lag (km)');
  else
     hx=xlabel('Lag (km)');
  end
  set([hx hy],'fontsize',12,'fontweight','bold')
  hvlscl=findobj(gcf,'Tag','txtlscl');
  [tmp indx1]=max(gammah);
  [tmp indxl]=min(abs(gammah(1:indx1)-0.3));			% 6dB 
  lscl=lag(indxl);
  if lscl <= 0.01*max(lag)
     lscl=0.1*max(lag);
  end
  set(hvlscl,'String',num2str(lscl));
