program test
  implicit none

  real one, two, three

  ! uncomment to make call to s2 work, when debugging symbols added
  ! interface 
  !    subroutine s1(one, two, three, four)
  !      implicit none
  !      real, intent(in) :: one, two
  !      real, intent(in), optional :: three, four
  !    end subroutine s1
  ! end interface

  one = 1.
  two = 2.
  three = 3.

  write(*,*) 'test passing of optional arguments'
  write(*,*) 'calling s1 directly'
  call s1(one, two, three)
  write(*,*) 'calling s2, then s1 indirectly'
  call s2(one, two, three)
  write(*,*) 'calling s3 (program contains), then s1 indirectly'
  call s3(one, two, three)

contains
  subroutine s3(one, two, three, four)
    implicit none
    real, intent(in) :: one, two
    real, intent(in), optional :: three, four
    write(*,*) '  hi, subroutine s3 calling s1'
    call s1(one, two, three, four)
  end subroutine s3

end program test
