!------------------------------------------------------------------------------
!
!  Program name:
!
!    errors_sol
!
!  Purpose:
!
!    This program shows a better way to rewrite err_main.f90 and 
!    err_sub.f90 by using an internal procedure.
!
!------------------------------------------------------------------------------


PROGRAM errors_sol

  IMPLICIT NONE

  INTEGER, PARAMETER :: iki = SELECTED_INT_KIND(4)
  INTEGER, PARAMETER :: ikr = SELECTED_REAL_KIND(10,200)

  REAL(ikr) :: ia, ib, ic, id
  INTEGER(iki) :: a, b, c, d

  a = 3_iki
  b = 2_iki    

  ia = 3_ikr
  ib = 2_ikr

  ! Find ratios:

  CALL ratio(a, b, c, ia, ib, ic)
  CALL ratio(b, a, d, ib, ia, id)

  ! Multiply ratios to get unity:

  WRITE(*,*)  c*d, ic*id

CONTAINS

  SUBROUTINE ratio(a, b, c, ia, ib, ic)

    REAL(ikr) :: ia, ib, ic
    INTEGER(iki) :: a, b, c
    
    c = a/b
    ic = ia/ib

  END SUBROUTINE ratio

END PROGRAM errors_sol

  
