Fortran SAVE statement

In principal when a module goes out-of-scope, the variables of that module become undefined — unless they are declared with the SAVE attribute, or a SAVE statement is used. “Undefined” means that you are not allowed to rely on the variable having the previous value if you again use the module — it might have … Read more

How to increase array size on-the-fly in Fortran?

Here is a Stack Overflow question with some code examples showing several ways of using Fortran allocatable arrays: How to get priorly-unkown array as the output of a function in Fortran: declaring, allocating, testing for being already being allocated, using the new move_alloc and allocation on assignment. Not shown there is explicit deallocation, since the … Read more

Fortran intent(inout) versus omitting intent

According to The Fortran 2003 Handbook by Adams, et al., there is one difference between an intent(inout) argument and argument without specified intent. The actual argument (i.e., in the caller) in the intent(inout) case must always be definable. If the intent is not specified, the argument must be definable if execution of the subroutine attempts … Read more

Function in fortran, passing array in, receiving array out

With RESULT(FluxArray), fluxArray is the name of the result variable. As such, your attempt to declare the characteristics in the result clause are mis-placed. Instead, the result variable should be specified within the function body: function Flux(W1,W2) result(fluxArray) double precision, dimension(3), intent(in)::W1, W2 double precision, dimension(3) :: fluxArray ! Note, no intent for result. end … Read more