4

I am doing a program in which the main contains many subroutines and functions. For constructing one of these subroutines of the main (let's say subroutine A) I need to make use of another subroutine (let's say B). My question is, how can I make subroutine A call and use subroutine B? I am a beginner and I have searched a lot but found nothing that I understand clearly...

Any help would be appreciated, thanks in advance!

user3134479
  • 41
  • 1
  • 1
  • 2

2 Answers2

2

Example of layout, in one file:

module MySubs

contains

subroutine A (..)

end subroutine A

subroutine B (..)

   call subroutine A (..)

end subroutine B

function C (..)

end function C

end module MySubs

program MyProg

  use MySubs

  call A (..)

  X = C (..)

end program MyProg

You can also place the module and and main program in different files. In that case compile the file with the module first.

M. S. B.
  • 28,968
  • 2
  • 46
  • 73
1

Normally you put all procedures in a module and then use the module.

If, as your question suggest make all procedures as internal to your main program, there is no problem in calling them. Just invoke them normally using the call statement, or by using the function name with the argument list.