  subroutine rdtoon_psc(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 :: ndat=500,ncomp=8
  integer :: id1,istat,noprf,mset
  integer :: start(1),count(1),stride(1)
  integer :: nbetanat,nnad,nalphanat,nnam,nanat,nanad,nanam
  integer :: ntext,n70
  real :: wcmdat(ndat),wavedat(ndat),rnval(ndat),rival(ndat)
  character(len=30) :: fil
  character (len=16) :: files(ncomp),llset

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

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

! Obtain the full pathname of the input netCDF file
   noprf=0
  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,"rdtoon_psc: id1,filnm ",i8,2x,a100)
  end if

! ***
! Get dimension ids (work with variables part of ncdump)
  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,'nbetanat',idnbetanat)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nnad',idnnad)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nalphanat',idnalphanat)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nnam',idnnam)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nice163',idnice163)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nanat',idnanat)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nanad',idnanad)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'nanam',idnanam)
   call handle(iout,istat)

! *****
! Get the dimensions
  istat=nf90_get_var(id1,idnbetanat,nbetanat)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnnad,nnad)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnalphanat,nalphanat)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnnam,nnam)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnice163,nice163)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnanat,nanat)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnanad,nanad)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idnanam,nanam)
   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)
  
  if (nopr .eq. 1) then
   write(iout,fmt=110) nbetanat,nnad,nalphanat,nnam
   110 format(/,2x,"rdtoon_psc: nbetanat,nnad,nalphanat,nnam ",/,&
   2x,4(1x,i4))
   write(iout,fmt=112) nice163,nanat,nanad,nanam
   112 format(/,2x,"rdtoon_psc:  nice163,nanat,nanad,nanam ",/,&
   2x,4(1x,i4))
   write(iout,fmt=120) ntext,n70
   120 format(/,2x,"rdtoon_psc:  ntext,n70",/,&
   2x,2(1x,i4))
  end if

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

! The different compositions
!          '1234567890123456'
  files(1)='Beta NAT        '
  files(2)='NAD             '
  files(3)='Alpha NAT       ' 
  files(4)='NAM             '
  files(5)='Ice 163 K       '
  files(6)='A NAT           '
  files(7)='A NAD           '
  files(8)='A NAM           '

! *
! Write out the compounds included in the netCDF file
  write(0,fmt=140)
  140 format(2x," Will select mset value for a specific compound")
  write(0,fmt=145)
  145 format(2x," i, compound")

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

  write(0,fmt=160)
  160 format(2x,"Specify mset (1-8) e.g. mset=1 for Beta NAT ")

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

! The compound string
  llset=files(mset)

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

! ***
! Obtain the specific indices

   if (mset .eq. 1) then 
     nlines=nbetanat
    istat=nf90_inq_varid(id1,'wcmbetanat',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicbetanat',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnbetanat',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'ribetanat',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 2) then
     nlines=nnad
    istat=nf90_inq_varid(id1,'wcmnad',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicnad',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnnad',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rinad',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 3) then
     nlines=nalphanat
    istat=nf90_inq_varid(id1,'wcmalphanat',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicalphanat',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnalphanat',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rialphanat',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 4) then 
     nlines=nnam
    istat=nf90_inq_varid(id1,'wcmnam',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicnam',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnnam',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rinam',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 5) then 
     nlines=nice163
    istat=nf90_inq_varid(id1,'wcmice163',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicice163',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnice163',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'riice163',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 6) then 
     nlines=nanat
    istat=nf90_inq_varid(id1,'wcmanat',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicanat',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnanat',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rianat',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 7) then 
     nlines=nanad
    istat=nf90_inq_varid(id1,'wcmanad',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicanad',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnanad',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rianad',idri)
     call handle(iout,istat)
   end if

   if (mset .eq. 8) then
     nlines=nanam
    istat=nf90_inq_varid(id1,'wcmanam',idwcm)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'wmicanam',idwave)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rnanam',idrn)
     call handle(iout,istat)
    istat=nf90_inq_varid(id1,'rianam',idri)
     call handle(iout,istat)
   end if

  if (nopr .eq. 1) then
   write(0,fmt=190) nlines,idwcm,idwave,idrn,idri
   write(iout,fmt=190) nlines,idwcm,idwave,idrn,idri
   190 format(/,2x,"nlines, idwcm,idwave,idrn,idri ",/,&
   2x,1(1x,i4),2x,4(1x,i4))
  end if 

! ****
!  Read in the real and imaginary indices
   start(1)=1
   count(1)=nlines
   stride(1)=1
  istat=nf90_get_var(id1,idwcm,wcmdat,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idwave,wavedat,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idrn,rnval,start,count,stride)
   call handle(iout,istat)
  istat=nf90_get_var(id1,idri,rival,start,count,stride)
   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=800) mset,files(mset)
    800 format(/,2x,"rdtoon_psc: work with mset, files(mset)",/,&
    2x,i3,2x,a16)
    write(iout,fmt=840)
    840 format(2x,"rdtoon_psc: 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


