function tplot1(m,com,n0,n1,n2,fx,fy)
% function tplot1(m,com,n0,n1,n2,fx,fy) plots two columns of matrix with labels
% Turns the plot hold OFF.
% Plots column n2 vs column n1 in m with lines of constant
%    column n0 connected by solid lines and marked with 
%    different symbols.
% Adds title and axis labels.
%      Argument List
% Arg   Specifies
%  m   matrix of data from thermo properties FORTRAN program.
% con  name of the compound in single quotes.
%  n0  column with data to sort on: 1 is p, 2 is t
%  n1  column of data for x axis
%  n2  column of data for y axis
%  fx  fraction to shift text in x direction.
%  fy  fraction to shift text in y direction.
%      If these are not given, 0.1 is used for each.
%       Values of nk
%  k    Specifies
%  1   Pressure kPa
%  11  log(Pressure)
%  2   Temperature C
%  3   Volume m3/kg
%  13  log(Volume)
%  4   Entropy kJ/kg-K
%  5   Enthalpy kJ/kg
%  6   Int. Eng. kJ/kg
%  7   Gibbs Eng. kJ/kg
% Example: Create steam1.dat file in your matlab directory
%          with the tprop2 program, then
%   >> load steam1.dat
%   >> tplot1(steam1,'Water',1,2,5)
%  will plot enthalpy as a function of temp. for various Ps.
con=[];
if nargin<6
   fx=0.1;
   fy=0.1;
end
maxp=50;
m1=m;
hold off
logf=0;
if n2>10
   n2=n2-10;
   logf=1;
end
logx=0;
if n1>10
   n1=n1-10;
   logx=1;
end
xx=max(m(:,n1));
xn=min(m(:,n1));
if (n2>6)|(n1>6)
   gf=m(:,5)-(m(:,2)+273.15).*m(:,4);
   yx=max(gf);
   yn=min(gf);
   m1=[m';gf']';
else
   yx=max(m(:,n2));
   yn=min(m(:,n2));
end
labs=['Pressure kPa    '
      'Temperature C   '
      'Volume m3/kg    '
      'Entropy kJ/kg-K '
      'Enthalpy kJ/kg  '
      'Int. Eng. kJ/kg '
      'Gibbs Eng. kJ/kg']; 
sy='+*ox+*ox+*ox+*ox+*ox+*ox+*ox+*ox+*ox+*ox+*ox+*ox';
for k=1:maxp
  i1=find(m1(1,n0)==m1(:,n0));
  i2=find(m1(1,n0)~=m1(:,n0));
  m2=m1(i1,:);
  m1=m1(i2,:);
  [nra,nca]=size(m2);
  if nra>2
    nr=floor(k/5);
    if k-nr*5==0 
      if nr>1
         con1=cgrp(con1,con);
      else
         con1=con;
      end
      con=[];
    end
    con=[con,' ',sy(k),' ',num2str(m2(1,n0))];
    if logf & logx
        loglog(m2(:,n1)',m2(:,n2)')
    elseif logf & ~logx
        semilogy(m2(:,n1)',m2(:,n2)')
    elseif ~logf & logx
        semilogx(m2(:,n1)',m2(:,n2)')
    else
        plot(m2(:,n1),m2(:,n2))
    end
    if logf & logx
       axis([log10(xn),log10(xx),log10(yn),log10(yx)])
    elseif logf & ~logx
       axis([xn,xx,log10(yn),log10(yx)])
    elseif ~logf & logx
       axis([log10(xn),log10(xx),yn,yx])
    else
       axis([xn,xx,yn,yx])
    end
    if k==1
        hold on
    end
    if logf & logx
        loglog(m2(:,n1),m2(:,n2),sy(k))
    elseif logf & ~logx
        semilogy(m2(:,n1),m2(:,n2),sy(k))
    elseif ~logf & logx
        semilogx(m2(:,n1),m2(:,n2),sy(k))
    else
        plot(m2(:,n1),m2(:,n2),sy(k))
    end
  end
  if length(m1)==0
     break
  end
end
if length(con)>0
   con1=cgrp(con1,con);
end
[nr,nc]=size(con1);
xlabel(labs(n1,:))
ylabel(labs(n2,:))
title([com,' Solid lines of constant ',labs(n0,:)])
for k=1:nr
   f=.04*k;
   if logf
     yp=exp((1-fy+f)*log(yn)+(fy-f)*log(yx));
   else
     yp=(1-fy+f)*yn+(fy-f)*yx;
   end
   if logx
     xp=exp((1-fx+f)*log(xn)+(fx-f)*log(xx));
   else
     xp=(1-fx)*xn+fx*xx;
   end
   if k==1
      text(xp,yp,[labs(n0,:),con1(k,:)])
   else
      text(xp,yp,con1(k,:))
   end
end
