function [find,vaf,outperm,targone,targtwo,lengthsone,coordtwo, ...
    addcontwo] = cent_linearfnd(prox,inperm)


n = size(prox,1);
proxave = zeros(n,n);

[ctfnd,ctvaf,lengths] = centfit(prox);

resprox = prox - ctfnd;

[outperm,rawindex,allperms,index] =  order(resprox,targlin(n),inperm,2);

proxpermut = prox(outperm,outperm);

[ctfnd,ctvaf,lengths] = centfit(proxpermut);

resprox = proxpermut - ctfnd;

[fit, vaf, coord, addcon] = linfitac(resprox,1:n);

for i = 1:n
    for j = 1:n
        if(i ~= j) 
            fit(i,j) = fit(i,j) - addcon;
        end
    end
end

find = ctfnd + fit;

aveprox = sum(sum(prox))/(n*(n-1));

for i = 1:n
    for j = 1:n
        if(i ~= j)
            proxave(i,j) = aveprox;
        else
            proxave(i,j) = 0.0;
        end
    end
end

diff = sum(sum((proxpermut - find).^2));
denom = sum(sum((proxpermut - proxave).^2));
vaf = 1 - (diff/denom);
            
targone = ctfnd;
targtwo = fit;

vafdiff = 1.0;
iteration = 0;

while ((vafdiff >= 1.0e-006) && (iteration < 100 ))
    
    vafprev = vaf;
    iteration = iteration + 1;
    
    resprox = proxpermut - targtwo;
    [targone,vafone,lengthsone] = centfit(resprox);
    
    resprox = proxpermut - targone;
    [targtwo,vaftwo,coordtwo,addcontwo] = linfitac(resprox,1:n);
    
    for i = 1:n
        for j = 1:n
            if(i ~= j)
                targtwo(i,j) = targtwo(i,j) - addcontwo;
            end
        end
    end
    
    
    find = targone + targtwo;
    
    diff = sum(sum((proxpermut - find).^2));
    denom = sum(sum((proxpermut - proxave).^2));
    vaf = 1 - (diff/denom);
    
    vafdiff = abs(vaf - vafprev);
end