function [seg,resid,C] = read_ccmat(filename)
%
%  Read the cross-correlation matrix
%
%  open the input file
   fid = fopen(filename,'r');
   if (fid < 0 )
      sprintf('File not found: %s',filename)
      return
   end
%
%  get the number of residues
   line = fgets(fid);
   nres = sscanf(line(6:length(line)),'%d');
%
   fclose(fid);
%
%  get the segment/residue lists
   [seg,resid] = textread(filename,'%s %d',nres,'commentstyle','matlab');
%
%  read the cross-correlation matrix
   fid = fopen(filename,'r');
   line = fgets(fid);
   while (1),
      if (line(1:2) == '%M') ; break ; end
      line = fgets(fid);
   end
   C = fscanf(fid,'%f',[nres,nres]);
%
%  clean up and return
   fclose(fid);
return
