function [coord,permut,cumobfun,diff] = uniscaldpf(prox)
tic;
n = size(prox,1);
bigneg = -1.0e+20;
nsum = (2^n) - 1;
sub = zeros(n,1);
subcomp = zeros(n,1);
coord = zeros(n,1);
permut = zeros(n,1);
cumobfun = zeros(n,1);

[valstore vidxstore] = uscalfor(prox);


permut(n) = vidxstore(nsum);
cumobfun(n) = valstore(nsum);
index = nsum;
lastint = permut(n);
for i = 1:(n-1)
   index = index - (2^(lastint-1));
   lastint = vidxstore(index);
   permut(n-i) = lastint;
   cumobfun(n-i) = valstore(index);
end

for i = 1:n
   for j = 1:n
      if(i > j)
         coord(i) = coord(i) + prox(permut(i),permut(j));
      end
      if(i < j) 
         coord(i) = coord(i) - prox(permut(i),permut(j));
      end
   end
   coord(i) = coord(i)/n;
end

diff = 0;
for i = 1:(n-1)
   for j = (i+1):n
      diff = diff + (prox(permut(i),permut(j)) - ...
         abs(coord(i) - coord(j)))^2;
   end
end
toc
        
      
      
      
      
      
      
      
  


          


