I'm currently learning FORTRAN (I am familiar with MatLab) and I am very confused about the point of subroutines. Why would anyone use them as opposed to functions. Also, how is it that they can return values when called in the main programs? For example:
PROGRAM SUBDEM
REAL A,B,C,SUM,SUMSQ
CALL INPUT( + A,B,C)
CALL CALC(A,B,C,SUM,SUMSQ)
CALL OUTPUT(SUM,SUMSQ)
END
SUBROUTINE INPUT(X, Y, Z)
REAL X,Y,Z
PRINT *,'ENTER THREE NUMBERS => '
READ *,X,Y,Z
RETURN
END
SUBROUTINE CALC(A,B,C, SUM,SUMSQ)
REAL A,B,C,SUM,SUMSQ
SUM = A + B + C
SUMSQ = SUM **2
RETURN
END
SUBROUTINE OUTPUT(SUM,SUMSQ)
REAL SUM, SUMSQ
PRINT *,'The sum of the numbers you entered are: ',SUM
PRINT *,'And the square of the sum is:',SUMSQ
RETURN
END
My question is essentially, how do I know what each subroutine is returning? Thank you.
numpy
andscipy
, it's partially old pal Fortran. OTOH it's reasonable to learn Fortran 90/95, not Fortran IV. I believe Fortran 90 allows you to pass / return parameters in more sophisticated ways.