function out=divx(A,lon,lat)
c=size(A);
N=c(1,2);
NN=c(1,1);
if nargin<3; error('Error - Not enough input parameters specified'), end;
if nargin>3; error('Error - too many input parameters specified'), end;
if length(lon)>N;error('Error - vector of longitude values has too large of dimensions'),end;
if length(lon)<N;error('Error - vector of longitude values has too small of dimensions'),end;
if length(lat)>NN;error('Error - vector of LATITUDE values has too larg of dimensions'),end;
if length(lat)<NN;error('Error - vector of LATITUDE values has too small of dimensions'),end;
if max(lat)>pi; error('Error- latitude input should be in radians'), end;
if max(lon)>2*pi; error('Error- longitude input should be in radians'), end; 

out=zeros(NN,N);
a=6.37*10^6;

for m=1:1:NN
    out(m,1)= (A(m,2)-A(m,N))/(((lon(2)-lon(N))+2*pi)*a*cos(lat(m)));
    out(m,N)= (A(m,1)-A(m,N-1))/((lon(1)-lon(N-1)+2*pi)*a*cos(lat(m)));
end
    
for m=2:1:N-1
    for n=1:1:NN
        out(n,m)=(A(n,m+1)-A(n,m-1))/((lon(m+1)-lon(m-1))*a*cos(lat(n)));
    end
end
    
