program testoptargs implicit none interface subroutine testopt(one,two,three,four,five) integer, intent(in) :: one,two integer, intent(out) :: three real, intent(in), optional :: four real, intent(out), optional :: five end subroutine testopt end interface integer :: iout real :: rout write(6,"(/)") call testopt(1,2,iout) ! call w/o optional args write(6,"('After main call testopt(1,2,iout): iout=',i4)") iout write(6,"(/)") call testopt(1,2,iout,5.,rout) write(6,"('After main call testopt(1,2,iout,5.,rout): iout=',i4,' rout=',f10.2)") & iout,rout end program testoptargs !----------------------------------------------------------------------- subroutine testopt(one,two,three,four,five) implicit none integer, intent(in) :: one,two integer, intent(out) :: three real, intent(in), optional :: four real, intent(out), optional :: five three = one + two write(6,"('testopt: one=',i4,' two=',i4,' three=',i4,' present(four)=',l1,' present(five)=',l1)") & one,two,three,present(four),present(five) end subroutine testopt