!+CALDBINFO
subroutine caldbo()
    implicit none

    ! Description:
    !  Checks out and reports upon the status of the CALDB available to
    ! a user, with the level of checking & information controlled by the
    ! mode & chatter parameters.
    !
    ! Passed parameters:
    !  None
    !
    ! Origin:
    !  Written for the Calibration Database, based largely upon pre-existing
    ! CALLIB subroutines
    !
    ! Authors/Modification History:
    !  Ian M George (1.0.0: 95 Dec 13), original version
    !  Ian M George (1.0.1: 96 Feb 03), deleted unused variable
    !  MFC (1.0.2, 20180430) removed non-conforming tab characters
    ! MFC (1.1.0 20250122) uses caldb_info v. 1.4.0, which provides improved user output
    character(7) version
    parameter (version = '1.1.0')
    !-
    ! Internals
    character(40) taskname
    character(10)  missn, instr, mode
    integer ierr, chatter
    character(20)  cnfgvar, caldbvar
    ! Initialize
    taskname = 'caldbinfo'
    ierr = 0
    cnfgvar = 'CALDBCONFIG'
    caldbvar = 'CALDB'

    ! Get Parameters from the par file
    call gpcaldbinfo(mode, chatter, missn, instr, ierr)
    if(ierr.NE.0) goto 148

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

    ! Do the job
    call infocaldb(mode, chatter, missn, instr, ierr)
    if(ierr.NE.0) goto 148

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

    return
end

!-----------------------------------------------------------------------
!+GPCALDBINFO
subroutine gpcaldbinfo(mode, chatter, missn, instr, ierr)

    implicit none
    character*(*) missn, instr
    character*(*) mode
    integer chatter, ierr

    ! Description:
    !     Gets the parameters required by the CALTOOLS task CALDBINFO
    !
    !     Passed parameters:
    !     mode              r : The mode os invetigation
    !     chatter           r : Chattiness flag
    !     missn             r : Mission string
    !     instr             r : Instrument string
    !     ierr             r : Error flag (zero if all OK)
    !
    ! Origin:
    !     Written for the Calibration Database, based largely upon pre-existing
    !     CALLIB subroutines
    !
    ! Authors/Modification History:
    !     Ian M George (1.0.0: 95 Dec 13), original version
    character(7) version
    parameter (version = '1.0.0')
    !-
    ! Internals
    character(11) subname
    parameter (subname = 'gpcaldbinfo')
    character(50) contxt
    ! Initialize
    ierr = 0

    ! Get mode parameter
    call uclgst('infomode', mode, ierr)
    if(ierr.ne.0) then
        call wterrm(subname, version, &
                'Problem getting MODE parameter')
        ierr = 0
        call wtinfo(1, 1, 1, 'setting MODE = BASIC')
        mode = 'BASIC'
    else
        call ftupch(mode)
    endif


    ! Get mission and instrument parameters if requested
    if (mode(1:4).eq.'INST') then
        call uclgst('mission', missn, ierr)
        if(ierr.ne.0) then
            call wterrm(subname, version, &
                    'Problem getting MISSION parameter')
            goto 999
        endif
        call uclgst('instrument', instr, ierr)
        if(ierr.ne.0) then
            call wterrm(subname, version, &
                    'Problem getting INSTRUMENT parameter')
            goto 999
        endif
    endif

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

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

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

    return
end

!---------------------------------------------------------------------
!+INFOCALDB
subroutine infocaldb(mode, chatter, missn, instr, ierr)

    implicit none
    character*(*) missn, instr
    character*(*) mode
    integer chatter, ierr


    ! Description:
    ! Reports the status of the CALDB available to
    ! a user, with the level of checking & information controlled by the
    ! mode & chatter parameters.
    !
    ! Passed parameters:
    !  mode              r : The mode of investigation (BASIC or INSTR)
    !  chatter           r : Chattiness flag
    !  missn             r : Mission string
    !  instr             r : Instrument string
    !  ierr              r : Error flag (zero if all OK)
    !
    ! Origin:
    !  Written for the Calibration Database, based largely upon pre-existing
    ! CALLIB subroutines
    !
    ! Authors/Modification History:
    !  Ian M George (1.0.0: 95 Dec 13), original version
    !  M. F. Corcoran (1.0.1: 04 Dec 14) convert missn, instr to upper case
    !                 before passing to caldb_info to solve swift xrt problem
    !
    character(7) version
    parameter (version = '1.0.1')
    !-
    ! Internals
    character(11) subname
    character(160) message
    parameter (subname = 'infocaldb')

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

    ! Convert missn, instr into uppercase
    call ftupch(missn)
    call ftupch(instr)


    ! Check that the CALDB is defined & available to the user
    call caldb_info(chatter, mode, missn, instr, ierr)
    if(ierr.NE.0) then
        message = 'PROBLEM with your local CALDB setup'
        call wterrm(subname, version, message)
        ! message = 'Task requires CALDB to be both defined ' // &
        !         '& available in order to run'
        ! call wtinfo(chatter, 1, 1, message)
        goto 148
    endif

    148   if(ierr.eq.0) then
        message = 'CALDB appears to be set-up & accessible'
        call wtinfo(chatter, 1, 1, message)
    endif

    return
end


