function I = build_reg(rlist)
%
%  Create an image with registration marks from the
%  cross-correlation matrix
%
%
   nres = 0;
   majtick = [];
   mintick = [];
   lstart = [];
   lend = [];
%
%  Parse the matrix index list to identify the segments
%  commas separate the fields and colons denote the ranges
%
   k = findstr(rlist,',');
   lk = length(k);
   k0 = 2;
   for kk = 1:lk
      [n,tmaj,tmin] = mark_ticks(rlist(k0:k(kk)-1));
      lstart = [lstart nres+1];
      lend = [lend nres+n];
      if (length(tmaj) > 0)
         majtick = [majtick tmaj+nres];
      end
      if (length(tmin) > 0)
         mintick = [mintick tmin+nres];
      end
      nres = nres + n;
      k0 = k(kk)+1;
   end
   [n,tmaj,tmin] = mark_ticks(rlist(k0:length(rlist)-1));
   lstart = [lstart nres+1];
   lend = [lend nres+n];
   if (length(tmaj) > 0)
      majtick = [majtick tmaj+nres];
   end
   if (length(tmin) > 0)
      mintick = [mintick tmin+nres];
   end
   nres = nres + n;
%
%  Create the border image
%
   pcolor = [100 150 200];
   pc = 1;
   jbuf = 5;
   I(1:nres,1:jbuf) = uint8(0);
%
%  Loop over the segments
%
   for j = 1:length(lstart)
      I(lstart(j):lend(j),1) = uint8(pcolor(pc));
      pc = pc + 1;
      if (pc > 3); pc = 1; end
   end
%
%  Loop over the major tick marks
%
   for j = 1:length(majtick)
      I(majtick(j):majtick(j),2:jbuf) = uint8(255);
   end
%
%  Loop over the minor tick marks
%
   for j = 1:length(mintick)
      I(mintick(j):mintick(j),2:3) = uint8(255);
   end
%
return

function [nres,major,minor] = mark_ticks(range)
%
%  This function identifies the locations of major
%  and minor tick marks in the range
%
   major = [];
   minor = [];
   m = findstr(range,':');
   lm = length(m);
   switch lm
%  Only one entry
    case 0
      nres = 1;
      major = [major nres];
%  Two entries
    case 1
      j = sscanf(range,'%d:%d');
      nres = j(2) - j(1) + 1;
      if (nres > 50 )
         majtick = 50;
         mintick = 10;
      else
         majtick = 10;
         mintick = 5;
      end
      for jj = j(1):j(2)
         if (mod(jj,majtick)==0)
            major = [major jj-j(1)+1];
         end
         if (mod(jj,mintick)==0)
            minor = [minor jj-j(1)+1];
         end
      end
%  Three entries
    case 2
      j = sscanf(range,'%d:%d:%d');
      nres = floor((j(3)-j(1))/j(2)) + 1;
      if (nres > 50 )
         majtick = 50;
         mintick = 10;
      else
         majtick = 10;
         mintick = 5;
      end
      for jj = j(1):j(2):j(3)
         if (mod(jj,majtick)==0)
            major = [major jj-j(1)+1];
         end
         if (mod(jj,mintick)==0)
            minor = [minor jj-j(1)+1];
         end
      end 
   end
return
