function [p,T,QV,Tnlte,bandcenter] = read_vt_profiles(fname);

%% [p,T,QV,Tnlte] = read_vt_profiles(fname);
%% reads in the NLTE profiles produced/given by Manul Lopez Puertas
%% these files can be ingested by kCARTA or GENLN2

%% input
%%   fname eg '/home/sergio/KCARTA/SRCv1.16/NONLTE/sergio/...
%%             VT_48PROFILES_120_400ppmv/sergio_mergeMAIN/vt5_s0.prf';
%%         eg '/home/sergio/HITRAN2UMBCLBL/MAKEIR_4umNLTE/NLTEProfs/IPFILES/
%%             nlte_1_1_1_3.genln2';
%%
%% output
%%     p = n x 1 array of pressures
%%     T = n x 1 array of kinetic temps (LTE)
%%    QV = n x 6 matrix of vib partition functions (for 6 isotopes)
%% Tnlte = n x 30 matrix of nlte vibrational temps
%%   bc  = 1 x 30 matrix of band centers

p = [];
T = [];
QV  = [];
Tnlte = [];

fid = fopen(fname,'r');
GoOn = 1;
iCnt = 0;
while GoOn > 0
  strAll = fgetl(fid);
  str1   = strAll(1);
  if strcmp(str1,'!')
    GoOn = 1;
    iCnt = iCnt + 1;
  else
    GoOn = -1;
  end
end

fprintf(1,'have read in  %3i lines of comments starting with ! \n',iCnt+1)
fprintf(1,'First useful string = %s \n',strAll);

[junk,junkI1,numBands,junk2,numLevs] = strread(strAll,'%s%d%d%d%d', 'delimiter',' ');

strAll = fgetl(fid);
[iGasID,numIso] = strread(strAll,'%d%d', 'delimiter',' ');

fprintf(1,'there are %3i bands, %3i levels, %3i isos \n',numBands,numLevs,numIso);

%%%%%%%%%%%%%%%%%%%%%%%%%
%% so now we know how many blocks of 5 to read, and lines containing less 
%% than 5 elements 
iNumFullBlocks = floor(numLevs/5);
iLeftover = numLevs - 5*iNumFullBlocks;
%%%%%%%%%%%%%%%%%%%%%%%%%

%% get p and T
p = get_vt_blocks(iNumFullBlocks,iLeftover,fid);
strAll = fgetl(fid);
T = get_vt_blocks(iNumFullBlocks,iLeftover,fid);
semilogy(T,p); set(gca,'ydir','reverse');

%%%%%%%%%%%%%%%%%%%%%%%%%
%% get the QV

strAll = fgetl(fid);
for ii = 1 : numIso
  strAll = fgetl(fid);
  QV(:,ii) = get_vt_blocks(iNumFullBlocks,iLeftover,fid);
end

%%%%%%%%%%%%%%%%%%%%%%%%%
%% get the vibtemps
strAll = fgetl(fid);
for ii = 1 : numBands
  strAll = fgetl(fid);
  xarr = strread(strAll);
  %xarr = xarr(1:end-1);
  bandcenter(ii) = xarr(5);
  fprintf(1,'reading Tnlte for %2i bandcenter = %8.4f \n',ii,bandcenter(ii))
  Tnlte(:,ii) = get_vt_blocks(iNumFullBlocks,iLeftover,fid);
  if (abs(bandcenter(ii)-2350) < 1)
    fprintf(1,'%3i %3i %3i \n',xarr(2:4))
    semilogy(T,p,'b',Tnlte(:,ii),p,'r'); set(gca,'ydir','reverse');
  end
end

fclose(fid);
