%
%  This script reads cross-correlation matrix files
%  and produces an image plot
%
%  Get the input file
   filename = input('Enter cross-correlation matrix file name: ','s');
%
%  Read the data
   [seg,resid,C] = read_ccmat(filename);
%
%  Identify the segment names and ranges
   [seglist,rmin,rmax,ixmin,ixmax] = parse_head(seg,resid);
%
%  What to plot?
   avail = '';
   for j = 1:length(seglist)
      astr = sprintf('%s  %d:%d   ',char(seglist(j)),rmin(j),rmax(j));
      avail = [avail astr];
   end
   pquery = sprintf('Available segments and residues are:\n %s \nEnter selection: ',avail);
   plist = input(pquery,'s');
   [mlist,rlist] = build_index(plist,seglist,rmin,rmax,ixmin,ixmax);
%
%  Create the basic image
   I0 = uint8(round(255*abs(C(eval(mlist),eval(mlist)))));
   isize = size(I0);
   ni = isize(1);
%
%  Create the border image
   Ibord = build_reg(rlist);
   bsize = size(Ibord);
   nb = bsize(2);
   Iflip(1:ni,1:nb) = Ibord(1:ni,nb:-1:1);
%
%  Create the final image
   ntot = ni + 2*nb;
   I(1:ntot,1:ntot) = uint8(0);
   I(1+nb:ni+nb,1+nb:ni+nb) = I0;
%
%  Add the registration marks to the final image
   I(1+nb:ni+nb,1:nb) = Ibord;
   I(1+nb:ni+nb,1+ni+nb:ntot) = Iflip;
   I(1:nb,1+nb:ni+nb) = Ibord';
   I(1+ni+nb:ntot,1+nb:ni+nb) = Iflip';
%
%  Write the output file
   outfile = input('Enter output file name: ','s');
   imwrite(I,hot(256),outfile,'bmp');

