if exist('xi_xo.mat')
  disp('loading mat file')
  load xi_xo.mat
else
  disp('reading rtp files')
  addpath /asl/matlib/h4tools
  addpath /asl/matlib/rtptools
  [hi,hai,xi,xai] = rtpread('eric_maddy2.ip.rtp');
  [ho,hao,xo,xao] = rtpread('eric_maddy2.op.rtp');

  save xi_xo.mat hi ho xi xo
end

%addpath /home/sergio/MATLABCODE/CONVERT_GAS_UNITS

iaGas = [1  2  3  4  6];
mass  = [18 44 48 44 16];
for ii = 1 : length(iaGas)
  gid = iaGas(ii);
  [ppmvLAY,ppmvAVG,ppmvMAX,pavgLAY,tavgLAY,ppmv500,ppmv75] = layers2ppmv(ho,xo,1,gid);

  oo = find(hi.glist == gid);
  str = ['q = xi.gas_' num2str(gid) ';'];
  eval(str)
  if hi.gunit(oo) ~= 10
    y = toppmv(xi.plevs,xi.ptemp,q,mass(ii),hi.gunit(oo));
  else
    y = q;
  end
  
  loglog(ppmvLAY,pavgLAY,'ro-',y,xi.plevs,'b','linewidth',2); title(['gas ' num2str(gid) 'ppmv :  (b) IP (r) OP'])
  set(gca,'ydir','reverse');
  disp('ret'); pause
end

semilogy(xo.ptemp(1:97),pavgLAY,'ro-',xi.ptemp,xi.plevs,'b','linewidth',2); title(['T(K) (b) IP (r) OP'])
set(gca,'ydir','reverse');