% cements 2 or more frames together, given the CUMULATIVE cross chirp between
%
% cements over previous...
%
% parameters are vectors, cumulatively expressed already
%
% Examples: mosaic=cement2(v0,p1,v1); % where p takes v2 to v1
%           mosaic=cement2(v0,p1,v1,p2,v2,v3,p3);
%
% Bugs: now only up to 10 frames (quick hack)
%
% See also: cement_pairwise (uses pairwise parameters)

function empty=limitednumberofinputs(p00,v00,p01,v01,p02,v02,p03,v03,p04,v04,p05,v05,p06,v06,p07,v07,p08,v08,p09,v09,p10,v10,p11,v11,p12,v12,p13,v13,p14,v14,p15,v15)

if (nargin/2) ~= round (nargin/2)
  error('cement.m: need even number of input args; 1 parameter for each image')
end%if

LENGTH_P=(nargin/2);  % p00 included in this list now (change from before)
P=NaN*ones(LENGTH_P,8);
for length_P=0:LENGTH_P-1
  if max(size(eval(sprintf('p%02d',length_P))))~=8
    disp(sprintf('cement2: input parameter %d must be of length 8',length_P))
  end%if
  if min(size(eval(sprintf('p%02d',length_P))))~=1
    disp(sprintf('cement2: input parameter %d must be a vector',length_P))
  end%if
  P(length_P+1,:)=eval(sprintf('p%02d',length_P));
end%for

%keyboard

% now all are in vector P

[Ml,Nl,Mh,Nh]=boundingboxextrema([P]); % now P includes reference parameter
                                       % which may or may not be the identity

[M00,N00]=size(v00);
Ml00=0; Nl00=0; Mh00=(M00-1)/M00; Nh00=(N00-1)/N00;  % frame 0 on [0,1)
M=M00; N=N00; % reference image size

canvassize=[M*(Mh-Ml),  N*(Nh-Nl)];
canvassize=2*ceil(canvassize/2);  % getting even with mpeg
empty=NaN*ones(ceil(canvassize));

%Mpixell00=round(M*Ml00+1   - M*Ml);
%Mpixelh00=round(M*Ml00+M00 - M*Ml);
%Npixell00=round(N*Nl00+1   - N*Nl);
%Npixelh00=round(N*Nl00+N00 - N*Nl);
%empty(Mpixell00:Mpixelh00, Npixell00:Npixelh00)=v00;
%clear v00

% insert v00
if LENGTH_P >=00+1;
  [v00d,Ml00,Nl00]=pchirp2nocrop(P(00+1,:),v00);
  clear v00
  [M00,N00]=size(v00d);
  Mh00=Ml00+(M00-1)/M00; Nh00=Nl00+(N00-1)/N00;
  Mpixell00=round(M*Ml00+1   - M*Ml);
  Mpixelh00=round(M*Ml00+M00 - M*Ml);
  Npixell00=round(N*Nl00+1   - N*Nl);
  Npixelh00=round(N*Nl00+N00 - N*Nl);
  empty(Mpixell00:Mpixelh00, Npixell00:Npixelh00)=maxnan(...
  empty(Mpixell00:Mpixelh00, Npixell00:Npixelh00),v00d);
  clear v00d
end%if

% insert v01
if LENGTH_P >=01+1
  [v01d,Ml01,Nl01]=pchirp2nocrop(P(01+1,:),v01); % with P00, counts 0..N-1
  clear v01
  [M01,N01]=size(v01d);
  Mh01=Ml01+(M01-1)/M01; Nh01=Nl01+(N01-1)/N01;
  Mpixell01=round(M*Ml01+1   - M*Ml);
  Mpixelh01=round(M*Ml01+M01 - M*Ml);
  Npixell01=round(N*Nl01+1   - N*Nl);
  Npixelh01=round(N*Nl01+N01 - N*Nl);
  empty(Mpixell01:Mpixelh01, Npixell01:Npixelh01)=v01d;
  clear v01d
end%if

% insert v02
if LENGTH_P >=02+1
  [v02d,Ml02,Nl02]=pchirp2nocrop(P(02+1,:),v02);
  clear v02
  [M02,N02]=size(v02d);
  Mh02=Ml02+(M02-1)/M02; Nh02=Nl02+(N02-1)/N02;
  Mpixell02=round(M*Ml02+1   - M*Ml);
  Mpixelh02=round(M*Ml02+M02 - M*Ml);
  Npixell02=round(N*Nl02+1   - N*Nl);
  Npixelh02=round(N*Nl02+N02 - N*Nl);
  empty(Mpixell02:Mpixelh02, Npixell02:Npixelh02)=v02d;
  clear v02d
end%of

% insert v03
if LENGTH_P >=03+1
  [v03d,Ml03,Nl03]=pchirp2nocrop(P(03+1,:),v03);
  clear v03
  [M03,N03]=size(v03d);
  Mh03=Ml03+(M03-1)/M03; Nh03=Nl03+(N03-1)/N03;
  Mpixell03=round(M*Ml03+1   - M*Ml);
  Mpixelh03=round(M*Ml03+M03 - M*Ml);
  Npixell03=round(N*Nl03+1   - N*Nl);
  Npixelh03=round(N*Nl03+N03 - N*Nl);
  empty(Mpixell03:Mpixelh03, Npixell03:Npixelh03)=v03d;
  clear v03d
end%if

% insert v04
if LENGTH_P >=04+1
  [v04d,Ml04,Nl04]=pchirp2nocrop(P(04+1,:),v04);
  clear v04
  [M04,N04]=size(v04d);
  Mh04=Ml04+(M04-1)/M04; Nh04=Nl04+(N04-1)/N04;
  Mpixell04=round(M*Ml04+1   - M*Ml);
  Mpixelh04=round(M*Ml04+M04 - M*Ml);
  Npixell04=round(N*Nl04+1   - N*Nl);
  Npixelh04=round(N*Nl04+N04 - N*Nl);
  empty(Mpixell04:Mpixelh04, Npixell04:Npixelh04)=v04d;
  clear v04d
end%if

% insert v05
if LENGTH_P >=05+1
  [v05d,Ml05,Nl05]=pchirp2nocrop(P(05+1,:),v05);
  clear v05
  [M05,N05]=size(v05d);
  Mh05=Ml05+(M05-1)/M05; Nh05=Nl05+(N05-1)/N05;
  Mpixell05=round(M*Ml05+1   - M*Ml);
  Mpixelh05=round(M*Ml05+M05 - M*Ml);
  Npixell05=round(N*Nl05+1   - N*Nl);
  Npixelh05=round(N*Nl05+N05 - N*Nl);
  empty(Mpixell05:Mpixelh05, Npixell05:Npixelh05)=v05d;
  clear v05d
end%if

% insert v06
if LENGTH_P >=06+1
  [v06d,Ml06,Nl06]=pchirp2nocrop(P(06+1,:),v06);
  clear v06
  [M06,N06]=size(v06d);
  Mh06=Ml06+(M06-1)/M06; Nh06=Nl06+(N06-1)/N06;
  Mpixell06=round(M*Ml06+1   - M*Ml);
  Mpixelh06=round(M*Ml06+M06 - M*Ml);
  Npixell06=round(N*Nl06+1   - N*Nl);
  Npixelh06=round(N*Nl06+N06 - N*Nl);
  empty(Mpixell06:Mpixelh06, Npixell06:Npixelh06)=v06d;
  clear v06d
end%if

% insert v07
if LENGTH_P >=07+1
  [v07d,Ml07,Nl07]=pchirp2nocrop(P(07+1,:),v07);
  clear v07
  [M07,N07]=size(v07d);
  Mh07=Ml07+(M07-1)/M07; Nh07=Nl07+(N07-1)/N07;
  Mpixell07=round(M*Ml07+1   - M*Ml);
  Mpixelh07=round(M*Ml07+M07 - M*Ml);
  Npixell07=round(N*Nl07+1   - N*Nl);
  Npixelh07=round(N*Nl07+N07 - N*Nl);
  empty(Mpixell07:Mpixelh07, Npixell07:Npixelh07)=v07d;
  clear v07d
end%if

% insert v08
if LENGTH_P >=08+1
  [v08d,Ml08,Nl08]=pchirp2nocrop(P(08+1,:),v08);
  clear v08
  [M08,N08]=size(v08d);
  Mh08=Ml08+(M08-1)/M08; Nh08=Nl08+(N08-1)/N08;
  Mpixell08=round(M*Ml08+1   - M*Ml);
  Mpixelh08=round(M*Ml08+M08 - M*Ml);
  Npixell08=round(N*Nl08+1   - N*Nl);
  Npixelh08=round(N*Nl08+N08 - N*Nl);
  empty(Mpixell08:Mpixelh08, Npixell08:Npixelh08)=v08d;
  clear v08d
end%if

% insert v09
if LENGTH_P >=09+1
  [v09d,Ml09,Nl09]=pchirp2nocrop(P(09+1,:),v09);
  clear v09
  [M09,N09]=size(v09d);
  Mh09=Ml09+(M09-1)/M09; Nh09=Nl09+(N09-1)/N09;
  Mpixell09=round(M*Ml09+1   - M*Ml);
  Mpixelh09=round(M*Ml09+M09 - M*Ml);
  Npixell09=round(N*Nl09+1   - N*Nl);
  Npixelh09=round(N*Nl09+N09 - N*Nl);
  empty(Mpixell09:Mpixelh09, Npixell09:Npixelh09)=v09d;
  clear v09d
end%if

% insert v10
if LENGTH_P >=10+1
  [v10d,Ml10,Nl10]=pchirp2nocrop(P(10+1,:),v10);
  clear v10
  [M10,N10]=size(v10d);
  Mh10=Ml10+(M10-1)/M10; Nh10=Nl10+(N10-1)/N10;
  Mpixell10=round(M*Ml10+1   - M*Ml);
  Mpixelh10=round(M*Ml10+M10 - M*Ml);
  Npixell10=round(N*Nl10+1   - N*Nl);
  Npixelh10=round(N*Nl10+N10 - N*Nl);
  empty(Mpixell10:Mpixelh10, Npixell10:Npixelh10)=v10d;
  clear v10d
end%if

% insert v11
if LENGTH_P >=11+1
  [v11d,Ml11,Nl11]=pchirp2nocrop(P(11+1,:),v11);
  clear v11
  [M11,N11]=size(v11d);
  Mh11=Ml11+(M11-1)/M11; Nh11=Nl11+(N11-1)/N11;
  Mpixell11=round(M*Ml11+1   - M*Ml);
  Mpixelh11=round(M*Ml11+M11 - M*Ml);
  Npixell11=round(N*Nl11+1   - N*Nl);
  Npixelh11=round(N*Nl11+N11 - N*Nl);
  empty(Mpixell11:Mpixelh11, Npixell11:Npixelh11)=v11d;
  clear v11d
end%if

% insert v12
if LENGTH_P >=12+1
  [v12d,Ml12,Nl12]=pchirp2nocrop(P(12+1,:),v12);
  clear v12
  [M12,N12]=size(v12d);
  Mh12=Ml12+(M12-1)/M12; Nh12=Nl12+(N12-1)/N12;
  Mpixell12=round(M*Ml12+1   - M*Ml);
  Mpixelh12=round(M*Ml12+M12 - M*Ml);
  Npixell12=round(N*Nl12+1   - N*Nl);
  Npixelh12=round(N*Nl12+N12 - N*Nl);
  empty(Mpixell12:Mpixelh12, Npixell12:Npixelh12)=v12d;
  clear v12d
end%if

% insert v13
if LENGTH_P >=13+1
  [v13d,Ml13,Nl13]=pchirp2nocrop(P(13+1,:),v13);
  clear v13
  [M13,N13]=size(v13d);
  Mh13=Ml13+(M13-1)/M13; Nh13=Nl13+(N13-1)/N13;
  Mpixell13=round(M*Ml13+1   - M*Ml);
  Mpixelh13=round(M*Ml13+M13 - M*Ml);
  Npixell13=round(N*Nl13+1   - N*Nl);
  Npixelh13=round(N*Nl13+N13 - N*Nl);
  empty(Mpixell13:Mpixelh13, Npixell13:Npixelh13)=v13d;
  clear v13d
end%if

% insert v14
if LENGTH_P >=14+1
  [v14d,Ml14,Nl14]=pchirp2nocrop(P(14+1,:),v14);
  clear v14
  [M14,N14]=size(v14d);
  Mh14=Ml14+(M14-1)/M14; Nh14=Nl14+(N14-1)/N14;
  Mpixell14=round(M*Ml14+1   - M*Ml);
  Mpixelh14=round(M*Ml14+M14 - M*Ml);
  Npixell14=round(N*Nl14+1   - N*Nl);
  Npixelh14=round(N*Nl14+N14 - N*Nl);
  empty(Mpixell14:Mpixelh14, Npixell14:Npixelh14)=v14d;
  clear v14d
end%if

% insert v15
if LENGTH_P >=15+1
  [v15d,Ml15,Nl15]=pchirp2nocrop(P(15+1,:),v15);
  clear v15
  [M15,N15]=size(v15d);
  Mh15=Ml15+(M15-1)/M15; Nh15=Nl15+(N15-1)/N15;
  Mpixell15=round(M*Ml15+1   - M*Ml);
  Mpixelh15=round(M*Ml15+M15 - M*Ml);
  Npixell15=round(N*Nl15+1   - N*Nl);
  Npixelh15=round(N*Nl15+N15 - N*Nl);
  empty(Mpixell15:Mpixelh15, Npixell15:Npixelh15)=v15d;
  clear v15d
end%if






