   subroutine rdmyhre_ternary(nopr,iout,indir,outdir,lstrn,iset,&
   lset,llset,nlines,wcm,wavelength,rndat,ridat,iwave)

! ***
! Read in the data from the netCDF file
! Will use netCDF f90 routines
  use netcdf

! param1.inc gives the maximum size of indices and extinction vectors
  include 'param1.inc'

! ****
! See rdinoutdir.f90
  character(len=60) :: indir,outdir
  integer :: nopr,iout,iset

! See main.f90
  integer :: nlines,iwave
  real :: wcm(nwavemax),wavelength(nwavemax)
  real :: rndat(nwavemax),ridat(nwavemax)
  character(len=100) :: lstrn,lset,filnm

! Used here
  integer,parameter :: ncomp=3,ndat=6050,mtempmax=8
  integer :: i
  integer :: ntext,n70,ntempmx
  integer :: start(1),count(1),stride(1)
  integer :: start2(2),count2(2),stride2(2)
  integer :: start3(3),count3(3),stride3(3)
  integer :: ivec1(mtempmax)
  integer :: nlinesr,nlinesi
  real :: a1
  real :: wcmdat(ndat),wavedat(ndat),rnval(ndat),rival(ndat)
  real :: temps(ncomp,mtempmax) 
  real :: vec1(mtempmax)
  real :: whno3(ncomp),wh2so4(ncomp),wh2o(ncomp)
  real :: numlinesr(ncomp),numlinesi(ncomp)
  real :: ntemps(mtempmax)
  character(len=30) :: fil
  character (len=16) :: llset,file2(ncomp)
  character (len=32) :: files(ncomp)

! ***
! Obtain the listing of the compounds
! Will ask the user to choose which compound to work with

! Specify by hand (have code read in values)
!          '12345678901234567890123456789012'
  files(1)=' 21% H2SO4, 56% H2O, 23% HNO3   ' 
  files(2)=' 25% H2SO4, 58% H2O, 17% HNO3   ' 
  files(3)='  4% H2SO4, 50% H2O, 46% HNO3   ' 
!          '1234567890123456'
  file2(1)='21%s,56%w,23%nit' 
  file2(2)='25%s,58%w,17%nit' 
  file2(3)=' 4%s,50%w,46%nit ' 

  write(0,fmt=140)
  140 format(2x," Will select  mset  value for a specific compound")
  write(0,fmt=145)
  145 format(2x," mset, compound")

  do i=1,ncomp
   write(0,fmt=150) i,files(i)
   150 format(2x,i3,2x,a32)
  end do

  write(0,fmt=160)
  160 format(2x,"Specify mset (1-3) ")

  read(5,*) mset
  mset=int(mset)

! The compound string
  llset=file2(mset)

  write(0,fmt=170) mset,llset
  170 format(2x," mset,llset ",i4,2x,a16)

! ***
! Read in the data from the netCDF file
   lset=lstrn

! ***
! The input netCDF file
!     '123456789012345678901234567890'
  fil='myhre_ternary.nc              '

! Obtain the full pathname of the input netCDF file
   noprf=1
  call getfilnm(noprf,iout,fil,indir,filnm)
  if (noprf .eq. 1) then
!  stop
  end if

! ***
! Open the netCDF file
  istat=nf90_open(filnm,nf90_nowrite,id1)
   call handle(iout,istat)

  if (nopr .eq. 1) then
   write(iout,fmt=100) id1,filnm
   100 format(/,2x,"rdmyhre_ternary: id1,filnm ",i8,2x,a100)
  end if

! ***
! Get dimension ids (work with variables part of ncdump)
  istat=nf90_inq_varid(id1,'ncases',idncases)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nlinesr',idnlinesr)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nlinesi',idnlinesi)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'ntext',idntext)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'n70',idn70)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'ntempmax',idntempmax)
   call handle(iout,istat)

! *****
! Get the dimensions
  istat=nf90_get_var(id1,idncases,ncases)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnlinesr,nlinesr)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnlinesi,nlinesi)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idntext,ntext)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idn70,n70)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idntempmax,ntempmax)
   call handle(iout,istat)

   if (nopr .eq. 1) then
    write(iout,fmt=110) mset,ntext,n70,ncases,nlinesr,nlinesi,ntempmax
    110 format(2x,"mset,ntext,n70,ncases,nlinesr,nlinesi,ntempmax",/,&
    2x,7(1x,i4))
   end if

! ****
! Specify the variables
     nlines=ndat

    istat=nf90_inq_varid(id1,'whno3',idwhno3)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wh2so4',idwh2so4)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wh2o',idwh2o)
     call handle(iout,istat)

    istat=nf90_inq_varid(id1,'numlinesr',idnumlinesr)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'numlinesi',idnumlinesi)
     call handle(iout,istat)

    istat=nf90_inq_varid(id1,'temps',idtemps)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'ntemps',idntemps)
     call handle(iout,istat)

    istat=nf90_inq_varid(id1,'wcmr',idwcmr)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wavelengthr',idwaver)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rn',idrn)
     call handle(iout,istat)

    istat=nf90_inq_varid(id1,'wcmi',idwcmi)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wavelengthi',idwavei)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'ri',idri)
     call handle(iout,istat)

   if (nopr .eq. 1) then
    write(iout,fmt=115) idwhno3,idwh2so4,idwh2o,idnumlinesr,idnumlinesi
    115 format(2x,"idwhno3,idwh2so4,idwh2o,idnumlinesr,idnumlinesi",/,&
    2x,5(1x,i4))
    write(iout,fmt=120) idtemps,idntemps
    120 format(2x,"idtemps,idntemps",/,&
    2x,2(1x,i4))
    write(iout,fmt=130) idwcmr,idwaver,idrn,idwcmi,idwavei,idri
    130 format(2x,"idwcmr,idwaver,idrn,idwcmi,idwavei,idri",/,&
    2x,6(1x,i4))
   end if

! ****
! Get the whno3 values
   start(1)=1
   count(1)=ncomp
   stride(1)=1
  istat=nf90_get_var(id1,idwhno3,whno3,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idwh2so4,wh2so4,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idwh2o,wh2o,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnumlinesr,numlinesr,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnumlinesi,numlinesi,start,count,stride)
   call handle(iout,istat)

! Get the temps values
   start2(1)=1
   start2(2)=1
   count2(1)=ncomp
   count2(2)=mtempmax
   stride2(1)=1
   stride2(2)=1
  istat=nf90_get_var(id1,idtemps,temps,start2,count2,stride2)
   call handle(iout,istat)

! Get the ntemps values
   start(1)=1
   count(1)=ncomp
   stride(1)=1
  istat=nf90_get_var(id1,idntemps,ntemps,start,count,stride)
   call handle(iout,istat)

! **
! Write out to the screen
   nc=ntemps(mset)

   write(0,fmt=360)
   360 format(/,2x,"rdmyhre_ternary: temps(mset,i)")
   do i=1,mtempmax
    ivec1(i)=int(temps(mset,i))
   end do
   write(0,fmt=365) (ivec1(j),j=1,8)
   365 format(2x,8(1x,i4))

! Specify the temp and wghth2so4 values
  write(0,fmt=165)
  165 format(2x,"Specify temp value (e.g. 253) ")
  read(5,*) temp

    diffmin=1.0e3
    ival=-99
   do i=1,nc
   if (temps(mset,i) .gt. 10.0) then
    diff1=temps(mset,i)-temp
    a1=sqrt((diff1*diff1))
    if (a1 .lt. diffmin) then
     ival=i
     diffmin=a1
    end if
   end if
   end do

  if (ival .lt. 0) then
   write(iout,fmt=350) ival
   350 format(/,2x,"rdmyhre_ternary: ival ",1(1x,i4)," will stop")
   stop
  end if

  if (nopr .eq. 1) then
   write(iout,fmt=410) mset,ival,temps(mset,ival)
   410 format(/,2x,"rdmyhre_ternary: mset,ival,temps(mset,ival) ",/,&
   2x,2(1x,i4),1(1x,f10.4))
  end if

! ****
! Read in the wcm and wavelength data
! Notice that you specify start2(2)=mset, and count2(2)=1  to work with 1 index
   start2(1)=1
   start2(2)=mset
   count2(1)=ndat
   count2(2)=1
   stride2(1)=1
   stride2(2)=1
  istat=nf90_get_var(id1,idwcmr,wcmdat,start2,count2,stride2)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idwaver,wavedat,start2,count2,stride2)
   call handle(iout,istat)

! ****
!  Read in the real and imaginary indices
   start3(1)=1
   start3(2)=mset
   start3(3)=ival
   count3(1)=ndat
   count3(2)=1
   count3(3)=1
   stride3(1)=1
   stride3(2)=1
   stride3(3)=1
  istat=nf90_get_var(id1,idrn,rnval,start3,count3,stride3)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idri,rival,start3,count3,stride3)
   call handle(iout,istat)

! ****
! Exit define mode
  istat=nf90_enddef(id1)

! Close the data set
  istat=nf90_close(id1)

! *****
! Put values into the output arrays
  do i=1,nlines
   wcm(i)=wcmdat(i)
   wavelength(i)=wavedat(i)
   rndat(i)=rnval(i)
   ridat(i)=rival(i)
  end do

! *****
  if (nopr .eq. 1) then
    write(iout,fmt=840)
    840 format(/,2x,"rdmyhre_ternary: i,wcm,wavelength,rndat,ridat")
   do i=1,nlines
    write(iout,fmt=850) i,wcm(i),wavelength(i),rndat(i),ridat(i)
    850 format(2x,i4,2(1x,f10.4),1p,2(1x,e10.3))
   end do
  end if

! ******
  return
  end
