function out=divy2(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=90; %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(N,m))-2*A(1,m))/((DO(2)+(P-DO(NN)))^2);
        out(m,N)= (A(m,1)+A(m,N-1)-2*A(m,N))/((DO(1)+P-DO(NN-1))^2);
    end
    
    for m=2:1:NN-1
        for n=1:1:N
            out(m,n)=((A(m,n+1)+A(m,n-1)-2*A(m,n))/((DO(m+1)-DO(m-1))^2));
        end
    end

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