function A = process(fname);
% PROCESS(fname) read a multi-column data file
% into an MxNxK matrix, where M is the number of columns
% in fname, N is the number of rows per block, and K is
% the number of blocks


f = fopen(fname,'r');
global M N K Dim;
B = fscanf(f, '%f');
fclose(f);

SB = size(B); Dim = SB(1);
e1 = B(1); e2 = B(2);


P = 2;
i0 = 3;

while (B(P+1) ~= B(1)) || (B(2*P+1) ~= B(1))
  for i = i0 : Dim, 
    if  B(i) == B(1)
      P = i - 1;
      break;
    end
  end
  i0 = P + 2;
end

L = 2;
i0 = 3;

while (B(L+2) ~= B(2)) || (B(2*L+2) ~= B(2))
  for i = i0 : Dim, 
      if  B(i) == B(2) 
      L = i - 2;
      break;
    end
  end
  i0 = L + 3;
end

     M = min(L,P);
     N = max(L,P);
     N = N / M;
     K = floor(Dim / M / N); 

AA = B(1:M*N*K);
A = reshape(AA,M,N,K);
