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

! ****
! 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

! See rdindices.f90
  character(len=16) :: llset

! Used here
  integer :: icheck,id1,istat,noprf,ilook
  integer,parameter :: nmaxids=10
  integer :: cdfid(nmaxids)
  integer :: start(1)
  integer :: count(1)
  integer :: stride(1)
  integer,parameter :: ndat=5000
  real :: wcmdat(ndat),wavedat(ndat),rnval(ndat),rival(ndat)
  character(len=30) :: fil
  character(len=1) :: textval(6,70)
  character (len=70) :: c70

! ***
! Read in the data from the netCDF file
   lset=lstrn
!       '1234567890123456'
   llset='downing_water   '

! ***
! The input netCDF file
!     '123456789012345678901234567890'
  fil='downing_williams_water.nc     '
!       '1234567890123456'
   noprf=1
  call getfilnm(noprf,iout,fil,indir,filnm)
  if (noprf .eq. 1) then  
!  stop
  end if

! *****
! Open the netCDF file
   ifile=1
  istat=nf90_open(filnm,nf90_nowrite,id1)
  call handle(iout,istat)
  cdfid(ifile)=id1
 
! *****
  if (nopr .eq. 1) then 
   write(iout,fmt=30) ifile,fil,cdfid(ifile)
   30 format(/,2x,"ifile ",i4,/, &
   2x,"fil",/, &
   2x,a50,/, &
   2x,"cdfid",/, &
   2x,i12)
  end if

! ***
! Get dimension ids
   noprg=0
  istat=nf90_inq_varid(id1,'nlines',idnlines)
   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)

! ***
! Get the dimensions
  istat=nf90_get_var(id1,idnlines,nlines)
   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=500) nlines,ntext,n70
   500 format(/,2x,"nlines ",i4,/,2x,"ntext ",i4,/,2x,"n70 ",i4)
  end if

! ***
! Get variable ids 
  istat=nf90_inq_varid(id1,'wcm',idwcm)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'wavelength',idwave)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'rn',idrn)
   call handle(iout,istat)
  istat=nf90_inq_varid(id1,'ri',idri)
   call handle(iout,istat)

  istat=nf90_inq_varid(id1,'text',idtext)
   call handle(iout,istat)

! idtext=ncdf_varid(nc_id,'text')
! idn70=ncdf_varid(nc_id,'n70')

  if (nopr .eq. 1) then
   write(iout,fmt=510) idwcm,idwave,idrn,idri,idtext
   510 format(/,2x," idwcm,idwave,idrn,idri,idtext ",/,2x,5(1x,i4))
  end if

! ***
! Get data
   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)

  istat=nf90_get_var(id1,idtext,textval)
   call handle(iout,istat)

! Look at the values read in
   ilook=0
  if (ilook .eq. 1) then 
    write(iout,fmt=400) 
    400 format(/,2x,"i,wcmdat(i),wavedat(i),rnval(i),rival(i)")
   do i=1,nlines
    write(iout,fmt=410) i,wcmdat(i),wavedat(i),rnval(i),rival(i)
    410 format(2x,i4,1p,4(1x,e10.3))
   end do
    write(iout,fmt=420) 
    420 format(/,2x,"i,textval(i)")
   do i=1,ntext
    do j=1,70
     c70(j:j)=textval(j,i)
    end do
    write(iout,fmt=430) i,c70
    430 format(2x,i4,2x,a70)
   end do
   stop
  end if

! text=strarr(n70,ntext)
! ncdf_varget,nc_id,idtext,text
! text=string(text)

! ****
! 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=200)
   200 format(/)
   write(iout,fmt=210)
   210 format(2x,"rddowning: text(i)")
   do i=1,ntext
!   write(iout,fmt=*) text(i)
   end do

   write(iout,fmt=200)
   write(iout,fmt=230)
   230 format(2x,"rddowning: i,wcm,wavelength,rndat and ridat")
   do i=1,nlines
    write(iout,fmt=240) i,wcm(i),wavelength(i),rndat(i),ridat(i)
    240 format(2x,i4,1p,2(1x,e10.3),2x,2(1x,e10.3))
   end do

  end if

! ******
  return
  end


