%  Units conversion utility 
function [val2 units2] = ConvertUnits(A2B,val1,units1)
  if units1(1)=='1'
    units1=units1(2:end);
    units2='1'
  else units2='';
  end
  val2=val1;
  while ~isempty(units1)
    if units1(1)=='/'
      units2=strcat(units2,'/');
      units1=units1(2:end);
      pow=-1;
    else pow=1;
    end
    jj=0;
    for len=3:-1:1
      for j=1:size(A2B,1)
        if length(A2B{j,1})~=len continue;
        elseif strncmp(A2B{j,1},units1,length(A2B{j,1}))
          jj=j;
          break;
        end
      end
      if jj break;
      end
    end
    if ~jj 
      units=units1
      error('cannot convert');
    end
    units2=strcat(units2,A2B{jj,3});
    n=length(A2B{jj,1});
    if n+1<length(units1) && units1(n+1:n+1)=='^';
      pow=pow*str2num(units1(n+2:n+2));
      units2=strcat(units2,units1(n+1:n+2));
      n=n+2;
    end
    val2=val2*A2B{jj,2}^pow;
    units1=units1(n+1:end);
  end
end
