!+MKCLDR
subroutine mkcalr

    implicit none

    !-----------------------------------------------------------------------
    ! Description: Reads the file given by the value of the CALDBCONFIG
    !              environment variable or logical, and creates the
    !              directories found there.
    !
    ! Arguments:   NONE
    !
    ! Origin:      Written for the Calibration Database
    !
    ! Authors/Modification History:
    !  Ron Zellar   (1.0.0:94 Sep 13) Original Version
    !  Ron Zellar   (2.0.0:94 Sep 28) Added the mkcifs parameter
    !  Ian M George (3.0.0:95 Dec 29) verbose -> chatter & Cleaned up
    !  MFC (3.1.0 20 Apr 16) f90 version
    character(7) version
    parameter (version = '3.1.0')
    !-----------------------------------------------------------------------
    !-
    ! Internals
    character(10) taskname
    logical mkcifs
    integer errstat, chatter
    ! Initialize

    taskname = 'mkcaldir'
    errstat = 0

    ! Get the parameters
    call gpmkcd(chatter, mkcifs, errstat)
    if (errstat.ne.0) goto 148

    ! Start-up Main
    call wtbegm(taskname, version, chatter)

    ! Make the Caldb directories
    call mkcdir(chatter, mkcifs, errstat)
    if (errstat .ne. 0) goto 148

    ! Finish-Off
    148     continue
    call wtendm(taskname, version, errstat, chatter)

    return
end
! -------------------------------------------------------------------------
!+GPMKCD
subroutine gpmkcd(chatter, mkcifs, status)

    implicit none
    logical mkcifs
    integer status, chatter

    !-----------------------------------------------------------------------
    ! Description: Gets the parameters for the mkcaldir task
    !
    ! Arguments:   chatter (i): Chattiness flag (zero = silent)
    !              mkcifs  (i): whether or not the mkcaldir task should
    !                           create Index files.
    !              status  (r): the success status of this routine
    !
    ! Origin:      Written for the Calibration Database
    !
    ! Authors/Modification History:
    !  Ron Zellar   (1.0.0:94 Sep 13) Original Version
    !  Ron Zellar   (2.0.0:94 Sep 28) Added the mkcifs parameter
    !  Ian M George (3.0.0:95 Dec 29) verbose -> chatter & Cleaned up
    character(7) version
    parameter (version = '3.0.0')
    !-----------------------------------------------------------------------
    !-
    ! Internals
    character(6) subname
    parameter (subname = 'gpmkcd')
    integer errstat
    character(160) contxt
    ! Initialize internal and external status flags
    status = 0
    errstat = 0

    ! Get the chattiness flag
    call uclgsi('chatter', chatter, errstat)
    if(errstat.NE.0) then
        call wtwarm(subname, version, 1, 1, &
                'Problem getting CHATTER parameter')
        errstat = 0
        call wtinfo(1, 1, 1, 'setting CHATTER = 10')
        chatter = 10
    endif

    ! Get the mkcifs parameter
    call uclgsb('mkcifs', mkcifs, errstat)
    if (errstat.ne.0) then
        call wtwarm(subname, version, 1, 1, &
                'Problem getting MKCIFS parameter')
        errstat = 0
        call wtinfo(1, 1, 1, 'setting MKCIFS = FALSE')
        mkcifs = .false.
    endif

    ! Give user info if requested
    contxt = ' using ' // subname // ' ' // version
    call wtinfo(chatter, 20, 1, contxt)

    999     if(status.ne.0) then
        call wterrm(subname, version, ' unable to continue')
    endif

    return
end
!-----------------------------------------------------------------------
