program sort3_external

!-- read in three real numbers and print them in ascending order

  implicit none
  real :: n1, n2, n3

  call read_the_numbers(n1,n2,n3)
  call sort_the_numbers(n1,n2,n3)
  call print_the_numbers(n1,n2,n3)
  
end program sort3_external
  
subroutine read_the_numbers(n1,n2,n3)

  implicit none
  real, intent(out) :: n1, n2, n3
  
!-- read the numbers
  read*, n1, n2, n3
  print*, "Input data n1:",n1
  print*, "           n2:",n2
  print*, "           n3:",n3
  
end subroutine read_the_numbers
  
subroutine sort_the_numbers(n1,n2,n3)

  implicit none
  real, intent(inout) :: n1, n2, n3
  real :: temp
  
!-- sort the numbers
  if (n1 > n2) then
    temp = n1; n1 = n2; n2 = temp
  endif
  if (n1 > n3) then
    temp = n1; n1 = n3; n3 = temp
  endif
  if (n2 > n3) then
    temp = n2; n2 = n3; n3 = temp
  endif
  
end subroutine sort_the_numbers

subroutine print_the_numbers(n1,n2,n3)

  implicit none
  real, intent(in) :: n1, n2, n3

!-- print the numbers
  print *, "The numbers in ascending order are:"
  print *, n1, n2, n3

end subroutine print_the_numbers
  
