  program main

    use vtype_module
    use ni3_module

    implicit none

    character(len=extstr)            :: InFN
    integer(i4b)                     :: FU


    integer(i4b)                     :: NHeader
    integer(i4b)                     :: NData

    real(dp)  :: WaveNumber
    real(dp)  :: Wavelength
    real(dp)  :: RefIndexReal
    real(dp)  :: RefIndexImag


    character(len=extstr)            :: NcFN
    integer(i4b)                     :: NcID
    character(len=extstr)            :: Mode, title, com, ref, &
         name, stdname, longname, units
    integer(i4b)         , parameter :: ndims = 1
    character(len=extstr)            :: dimname( ndims )
!!$    real(dp)                         :: fillvalue

    integer(i4b)          :: l


    title   = 'Refractive index for H2SO4 75%'
    InFN    = "data/data_files/Acids/Sulphuric/70%_to_79%/" &
      & // "75%,_300_K_(Palmer_and_Williams_1975)/interpolated/H2SO4_75_Palmer_1975.ri"
    NcFN    = '../ncfiles/RefIndex_H2SO4-75%_PW1975.nc'
    com     = 'Electric data was downloaded from http://eodg.atm.ox.ac.uk/ARIA/.'
    ref     = 'Warren, S. G., and R. E. Brandt (2008), '
    ref     = 'Palmer, K. F., and D. Williams (1975), '
    ref     = trim( ref ) // 'Optical Constants of Sulfuric Acid; Application to the Clouds of Venus?, '
    ref     = trim( ref ) // 'Appl. Opt. 14, 208-219.'
    NHeader = 8
    NData   = 235 - NHeader


    !
    ! Preparation for input file
    !
    FU = 50
    open( FU, file = InFN, status='unknown' )
    do l = 1, NHeader
      read( FU, * )
    end do


    !
    ! Preparation for output file
    !
    Mode = "new"
    call ni3_open( NcFN, Mode, NcID )
    call ni3_set_ga( ncid, title = title, com = com, ref = ref )

    name     = "wl"
    stdname  = name
    longname = 'wavelength'
    units    = "m"
    call ni3_def_dim( NcID, name, NI3_REAL, 0, &
      stdname = stdname, longname = longname, units  = units )

    dimname( 1 ) = "wl"

    name         = "refindexreal"
    stdname      = name
    longname     = "real part of refractive index"
    units        = "1"
    call ni3_def_var( NcID, name, NI3_REAL, ndims, dimname, &
         stdname = stdname, longname = longname, units = units )

    name         = "refindeximag"
    stdname      = name
    longname     = "imaginary part of refractive index"
    units        = "1"
    call ni3_def_var( NcID, name, NI3_REAL, ndims, dimname, &
         stdname = stdname, longname = longname, units = units )

!!$    do l = 1, NData
    do l = NData, 1, -1
      read( fu, * ) WaveNumber, RefIndexReal, RefIndexImag
      WaveNumber = WaveNumber * 1.0d2
      Wavelength = 1.0d0 / WaveNumber
      name = "wl"
      call ni3_put_varss( NcID, name, l, Wavelength )
      name = "refindexreal"
      call ni3_put_varss( NcID, name, l, RefIndexReal )
      name = "refindeximag"
      call ni3_put_varss( NcID, name, l, RefIndexImag )
    end do


    close( FU )
    call ni3_close( NcID )


  end program main
