function out=divy(opt,A,do)
N=length(mean(A));
NN=length(mean(A'));
if nargin<1; error('Error - Not enough input parameters specified'), end;
if nargin>3; error('Error - too many input parameters specified'), end;

if nargin>=3; DO=do;, end;
if nargin<=2;
    for m=1:1:NN
        DO(1,m)=m;
    end
    ,end


if length(DO)>NN;error('Error - vector of domain values has too large of dimensions'),end;
if length(DO)<NN;error('Error - vector of domain values has too small of dimensions'),end;


out=zeros(NN,N);
DOMAIN=DO;

P=180; %wavelenght of domain
a=6.37*10^6;
if opt=='p'  %periodic domain
    for m=1:1:N
        out(1,m)= (A(2,m)-A(NN,m))/(DO(2)+(P-DO(NN)));
        out(NN,m)= (A(1,m)-A(NN-1,m))/(DO(1)+P-DO(NN-1));
    end
    
    for m=2:1:NN-1
        for n=1:1:N
            out(m,n)=(A(m+1,n)-A(m-1,n))/(DO(m+1)-DO(m-1));
        end
    end

elseif opt=='pl'
      for m=1:1:N
        out(1,m)= (A(2,m)-A(NN,m))/(DO(2)+(P-DO(NN)));
        out(m,N)= (A(1,m)-A(NN-1,m))/(DO(1)+P-DO(NN-1));
    end
    
    for m=2:1:NN-1
        for n=1:1:N
            out(m,n)=(A(m+1,n)-A(m-1,n))/(DO(m+1)-DO(m-1));
        end
    end
    
    out=out/(a*pi/180);
elseif opt=='l'
    for m=1:1:N
        out(1,m)= (A(2,m)-A(1,m))/(DO(2)-DO(1));
        out(NN,m)= (A(NN,m)-A(NN-1,m))/(DO(NN)-DO(NN-1));
    end
    
    for m=2:1:NN-1
        for n=1:1:N
            out(m,n)=(A(m+1,n)-A(m-1,n))/(DO(m+1)-DO(m-1));
        end
    end
    
    out=out/(a*pi/180);
    
else
    for m=1:1:N
        out(1,m)= (A(2,m)-A(1,m))/(DO(2)-DO(1));
        out(NN,m)= (A(NN,m)-A(NN-1,m))/(DO(NN)-DO(NN-1));
    end
    
    for m=2:1:NN-1
        for n=1:1:N
            out(m,n)=(A(m+1,n)-A(m-1,n))/(DO(m+1)-DO(m-1));
        end
    end
end


    
    