    module ferror
    use io,only:IERR  ! standard error unit number
    contains
!------------------------------------------------------------------------
    subroutine fexit(msg,errcode,unit)
!  FEXIT - print the indicated message and halt with an exit code (default 1).
!  ERRCODE : if present, the exit error code to return to the shell (default 1).
!  UNIT    : if present, the logical unit number on which to diplay msg
!            (default 0, std error).
!
    use command_line_support,only:program_exit
    character(*),intent(in)::msg
    integer,intent(in),optional::errcode,unit
!
    character(80)::progname
    integer::iunit
!
    call getarg(0,progname)
    if(present(unit)) then
       iunit=unit
    else
       iunit=IERR
    endif
    if(len_trim(progname).gt.0) &
       write(iunit,100,advance='no') trim(progname)//': '
100 format(a)
    write(iunit,100) msg
    if(present(errcode)) then
       call program_exit(errcode)
    else
       call program_exit(1)
    endif
    end subroutine fexit
!------------------------------------------------------------------------
    subroutine fabort(msg,unit)
!  FABORT - print the indicated message and abort.
!  UNIT    : if present, the logical unit number on which to diplay msg
!            (default 0, std error).
!
    character(*),intent(in)::msg
    integer,intent(in),optional::unit
!
    character(80)::progname
    integer::iunit
!
    call getarg(0,progname)
    if(present(unit)) then
       iunit=unit
    else
       iunit=IERR
    endif
    if(len_trim(progname).gt.0) &
       write(iunit,100,advance='no') trim(progname)//': '
100 format(a)
    write(iunit,100) msg
    call abort
    end subroutine fabort
!------------------------------------------------------------------------
    subroutine finfo(msg,unit)
!  FINFO - print the indicated message and return.
!  UNIT    : if present, the logical unit number on which to diplay msg
!            (default 0, std error).
!
    character(*),intent(in)::msg
    integer,intent(in),optional::unit
!
    character(80)::progname
    integer::iunit
!
    call getarg(0,progname)
    if(present(unit)) then
       iunit=unit
    else
       iunit=IERR
    endif
!
    if(len_trim(progname).gt.0) &
       write(iunit,100,advance='no') trim(progname)//': '
100 format(a)
    write(iunit,100) trim(msg)
    return
    end subroutine finfo
!------------------------------------------------------------------------
    end module ferror
