function f = funvar(para,data)
%% construct a cost function
% 	f = fun(para,data)
%
% Input: para  -> [nugt sill L b p]
%	 data -> [distance variance weighting function]
%
% Output: f -> cost function
%

%%  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 model_type

  x = data(:,1);							% lag
  y = data(:,2);							% variogram computed form observed data
  
% compute selected model with parameter 'para'
 yr = variogrammodel(model_type,x,para);
 w = data(:,3);   % weigthing function or proportionality coef. in least-square sense
 f = (yr(:) - y).*w;	% cost function

