  program main

    use vtype_module
    use ni3_module
    use netcdf

    implicit none

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


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

    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 carbon dioxide ice'
    InFN    = 'data4/Warren1986.txt'
    NcFN    = '../ncfiles/RefIndex_CO2Sol_Warren1986.nc'
    com     = ''
    ref     = 'Warren, S. G., 1986: "Optical constants of carbon dioxide ice", Applied Optics, 25, 2650.'
    NHeader = 0
    NData   = 945 - 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
      read( fu, * ) Wavelength, RefIndexReal, RefIndexImag
      Wavelength = Wavelength * 1.0d-6
      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
