I am having some issues calling subroutines. First of all, am I allowed to call a subroutine within an IF statement?
IF (...) THEN
...
ELSE
CALL sub1(...)
END IF
Second question. Sub1 calls sub2 within it self. Then sub2 has an input from the main program, lets say x.
MODULE mod1
...
CONTAINS
SUBROUTINE sub1(w)
IMPLICIT NONE
INTENT(OUT) :: w
REAL :: x, z
CALL sub2(x, z)
w = z + 1
END SUBROUTINE sub1
SUBROUTINE sub2(x, z)
IMPLICIT NONE
INTENT(IN) :: x
INTENT(OUT) :: z
z = x + 1
END SUBROUTINE sub2
END MODULE mod1
PROGRAM prog
USE mod1
IMPLICIT NONE
IF (...) THEN
...
ELSE
x = y
CALL sub1(w)
x = w + y
END IF
END PROGRAM prog
NOTE: The addition between variable isn't the exact mathematical operation taking place
Basically every variable depends on each other, but the x = y is the initial condition which I think is the only way this could work. It seems that the sub2 isn't picking up on the initial x = y, which then gives its value to sub1, when called from sub1. So maybe I don't understand how the variables are being passed around. The errors I am getting is not with compiling but a run time error which leads me to the line where I call sub2 within sub1. Any help is much appreciated.