% cement a range of images from entrance77 sequence
%
% Examples: c3133=cement77(31,33);
%
% saves memory by loading images, cementing to make mosaic, then clearing images

function mosaic=cementrange(l1,l2);

disp('loading from entrance77_parameters_pairwise.mat')
load entrance77_parameters_pairwise
% now in vector ``p''

increment=1;
if l1>l2
  disp('cement77: l1 is greater than l2; calculating reverse parameters')
  disp('cement77: this feature still not working')
  p_inverse=NaN*p;  % initialize to empty
  for l=l2:l1
    p_inverse(l,:)=pinverse(p(l,:));
  end%for
  p=p_inverse;
  %l=l1;
  %l1=l2;
  %l2=l;
  increment=-1;
end%if

for l=l1:increment:l2
  eval(sprintf('v%02d=load77(%02d);',l,l))
end%for

s=sprintf('mosaic=cement_pairwise([1 0 0 0 1 0 0 0],v%02d, ',l1);
for l=l1+increment:increment:l2-increment
  s=[s sprintf('p(%02d,:),v%02d, ',l,l)];
end%for
s=[s sprintf('p(%02d,:),v%02d);',l2,l2)];

disp('cement77.m: about to call cement')
%keyboard
eval(s);

%example of what the above is doing:
%mosaic34to39=cement(v34,  p(35,:),v35, p(36,:),v36, p(37,:),v37, p(38,:),v38...
%                    , p(39,:),v39 ...
%                   );

