function Amap=maptoint(A,ci);
% function Amap=maptoint(A,ci);
% b klinger, 2/4/15
% If A is an array w/ >2 rows, 
% map array A so that if A=ci(1), Amap=1; if A=ci(2), Amap=2, etc.
% If A is contour output, transform values n --> ci(n).
% Useful if N colors chosen for contourf plot.  
% Map original values to 1,2...N and then map values of contours
% in plot back to original values for use w/ contour labels.

nci=length(ci);
[ny,nx]=size(A);
Amap=A;

if ny==2

%  n1=A(1,1)=# points in contour, A(2,1)=contour value, 
%  A(2+n1,:)=same parameters for next point etc.

   inext=1;
   iall=[];
   while inext<=nx
      iall=[iall inext];
      inext=inext+A(2,inext)+1;
   end
   Amap(1,iall)=interp1(1:nci,ci,A(1,iall));   
else
%   for j=1:ny
%      Amap(j,:)=interp1(ci,1:nci,A(j,:));
%   end
   for i=1:nx
      Amap(:,i)=interp1(ci,[1:nci],A(:,i));
   end
end
