  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
    integer(i4b)                     :: NData1
    integer(i4b)                     :: NData2

    integer, parameter :: NPtcl = 1
    integer            :: a_PtclNum ( NPtcl )
    character(stdstr)  :: a_PtclName( NPtcl )

    integer              , parameter   :: NChar = stdstr
    integer                            :: a_CharNum( NChar )

    real(dp), allocatable :: w_Wavelength(:)
    real(dp), allocatable :: wa_QExt(:,:)
    real(dp), allocatable :: wa_SSA (:,:)
    real(dp), allocatable :: wa_AF  (:,:)


    character(len=extstr)            :: NcFN
    integer(i4b)                     :: NcID
    character(len=extstr*3)          :: ref
    character(len=extstr)            :: Mode, title, com, &
         name, stdname, longname, units
    integer(i4b)                       :: ndims
    character(len=extstr), allocatable :: a_dimnames(:)
!!$    real(dp)                         :: fillvalue

    integer(i4b)          :: l
    integer(i4b)          :: n


    title   = 'Optical properties of dust'
    NcFN    = '../ncfiles/dust_opt_prop_Ockert-Bell1997_Forget1998.nc'
    com     = 'For visible and infrared, optical properties by Ockert-Bell et al. (1997) and Forget (1998) are used, respectively.'
    ref   = "  Forget (1998) Improved optical properties of the Martian " &
      // "atmospheric dust for radiative transfer calculations in the " &
      // "infrared, GRL, 25, 1105.; " &
      // "Ockert-Bell et al. (1997) Absorption and scattering properties " &
      // "of the Martian dust in the solar wavelengths, JGR, 102, 9039."

    NHeader = 1
    NData1   = 23 - NHeader
    NData2   = 1950
    NData    = NData1 + NData2

    allocate( w_Wavelength( NData ) )
    allocate( wa_QExt( NData, NPtcl ) )
    allocate( wa_SSA ( NData, NPtcl ) )
    allocate( wa_AF  ( NData, NPtcl ) )


    do n = 1, NPtcl
      a_PtclNum(n) = n
    end do
    a_PtclName( 1 ) = "mdust"

    do l = 1, NChar
      a_CharNum(l) = l
    end do

    !
    ! Preparation for input file
    !
    FU = 50
    !
    InFN    = '../dust_prop_0/visparam.data'
    open( FU, file = InFN, status='unknown' )
    do l = 1, NHeader
      read( FU, * )
    end do
    do l = 1, NData1
      read( FU, * ) w_Wavelength(l), &
        & wa_SSA(l,1), wa_AF(l,1), wa_QExt(l,1)
      w_Wavelength(l) = w_Wavelength(l) * 1.0d-6
    end do
    close( FU )


    InFN    = '../dust_prop_0/omegamod.data'
    open( FU, file = InFN, status='unknown' )
!!$    do l = 1, NHeader
!!$      read( FU, * )
!!$    end do
    do l = NData1+1, NData1+NData2
      read( FU, * ) w_Wavelength(l), &
        & wa_SSA(l,1)
    end do
    close( FU )
    !
    InFN    = '../dust_prop_0/gmod.data'
    open( FU, file = InFN, status='unknown' )
!!$    do l = 1, NHeader
!!$      read( FU, * )
!!$    end do
    do l = NData1+1, NData1+NData2
      read( FU, * ) w_Wavelength(l), &
        & wa_AF(l,1)
    end do
    close( FU )
    !
    InFN    = '../dust_prop_0/qextmod.data'
    open( FU, file = InFN, status='unknown' )
!!$    do l = 1, NHeader
!!$      read( FU, * )
!!$    end do
    do l = NData1+1, NData1+NData2
      read( FU, * ) w_Wavelength(l), &
        & wa_QExt(l,1)
    end do
    close( FU )


    !
    ! 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_set_dim( NcID, name, NI3_REAL, w_Wavelength, &
      stdname = stdname, longname = longname, units  = units )

    name     = "PtclNum"
    stdname  = name
    longname = 'particle number'
    units    = "1"
    call ni3_set_dim( NcID, name, NI3_INT, a_PtclNum, &
      stdname = stdname, longname = longname, units  = units )

    Name     = "CharNum"
    StdName  = Name
    LongName = "character number"
    Units    = "1"
    call ni3_set_dim( NcID, Name, NI3_INT, a_CharNum, &
      & StdName, LongName, Units )

    NDims = 2
    allocate( a_dimnames( NDims ) )

    Name     = "PtclName"
    StdName  = Name
    LongName = "particle name"
    Units    = "m"
    a_DimNames( 1 ) = "CharNum"
    a_DimNames( 2 ) = "PtclNum"
    call ni3_def_var( NcID, Name, NI3_CHAR, NDims, a_DimNames, &
      & StdName, LongName, Units )
    call ni3_put_var( NcID, Name, a_PtclName )

    a_dimnames( 1 ) = "wl"
    a_dimnames( 2 ) = "PtclNum"

    name         = "QExt"
    stdname      = name
    longname     = "extinction efficiency factor"
    units        = "1"
    call ni3_def_var( NcID, name, NI3_REAL, ndims, a_dimnames, &
         stdname = stdname, longname = longname, units = units )
    call ni3_put_var( NcID, name, wa_QExt )

    name         = "SSA"
    stdname      = name
    longname     = "single scattering albedo"
    units        = "1"
    call ni3_def_var( NcID, name, NI3_REAL, ndims, a_dimnames, &
         stdname = stdname, longname = longname, units = units )
    call ni3_put_var( NcID, name, wa_SSA  )

    name         = "AF"
    stdname      = name
    longname     = "asymmetry factor"
    units        = "1"
    call ni3_def_var( NcID, name, NI3_REAL, ndims, a_dimnames, &
         stdname = stdname, longname = longname, units = units )
    call ni3_put_var( NcID, name, wa_AF   )

    deallocate( a_dimnames )

    close( FU )
    call ni3_close( NcID )


  end program main
