function [nugt,sill, L, b, p]=variogramlsqfit(model,data,nugtI,sillI,LI,bI,pI)
% Input: model -> model index
% 	 data(:,1) -> abscisse (distance) (gam(:,1))
% 	 data(:,2) -> ordonnée (variance) (gam(:,2))
%	 nugtI, sillI, LI, pI and bI	-> initial parameter values
%
% Output: 
%   model parameters:
%        nugt:   nugget effect
%	      sill:   sill
%          L :   length scale (range)
%          b :   length scale dut to hole effect (oscillatory pattern)
%          p :   power for general exponential-bessel model


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

model_type=model;

n=length(data(:,1));
data_truncated=data(1:n,:);

% Least-square fitting
para=[nugtI sillI LI bI pI];
[para,option] = leastsq ('funvar',para,[],[],data_truncated);
for i=1:length(para)			% insure nonnegative parameters
   para(i)=max(0,real(para(i)));
end
nugt=para(1);
sill=para(2);
L = para(3);
b = para(4);
p = para(5);

 
  
  