module rad_utils

  use dc_types

  implicit none

  private

  public :: InqDimLength
  public :: MkRangeString
  public :: InqPFIntGQNum

contains

  !----------------------------------------------------------------------------

  function InqDimLength( InFileName, DimName ) result( DimLength )

    use gtool5

    character(*), intent(in) :: InFileName
    character(*), intent(in) :: DimName

    integer :: DimLength

    real(8), pointer :: a_dAxis(:)

    call HistoryGetPointer( InFileName, DimName, a_dAxis, quiet = .true. )
    DimLength = size( a_dAxis )
    Nullify( a_dAxis )

  end function InqDimLength

  !----------------------------------------------------------------------------

  function MkRangeString( VarName, Index ) result( String )


    character(*)  , intent(in ) :: VarName
    integer       , intent(in ) :: Index

    character(128) :: String


    ! local variables
    !
    character(128) :: StringNum
    character(128) :: StringFMT


    write( StringNum, '(i10)' ) int( log10(real(Index))+1 )
    write( StringFMT, '(a,a,a)' ) '(a,a,i', trim( StringNum ), ')'
    write( String   , StringFMT ) trim( VarName ), '=^', Index


  end function MkRangeString

  !----------------------------------------------------------------------------

  function InqPFIntGQNum( DelWaveNum ) result( GQNum )


    real(DP), intent(in) :: DelWaveNum

    integer :: GQNum

    real(DP), parameter :: DelWaveNumPerPoint = 10.0d0


    GQNum = int( DelWaveNum / DelWaveNumPerPoint ) + 1


  end function InqPFIntGQNum

  !----------------------------------------------------------------------------

end module rad_utils
