Standard input and output units in Fortran 90?

If you have a Fortran 2003 compiler, the intrinsic module iso_fortran_env defines the variables input_unit, output_unit and error_unit which point to standard in, standard out and standard error respectively. I tend to use something like #ifdef f2003 use, intrinsic :: iso_fortran_env, only : stdin=>input_unit, & stdout=>output_unit, & stderr=>error_unit #else #define stdin 5 #define stdout 6 … Read more

Assumed size arrays: Colon vs. asterisk – DIMENSION(:) arr vs. arr(*)

The form real, dimension(:) :: arr declares an assumed-shape array, while the form real :: arr(*) declares an assumed-size array. And, yes, there are differences between their use. The differences arise because, approximately, the compiler ‘knows’ the shape of the assumed-shape array but not of the assumed-size array. The extra information available to the compiler … Read more

Where to put `implicit none` in Fortran

The implicit statement (including implicit none) applies to a scoping unit. Such a thing is defined as BLOCK construct, derived-type definition, interface body, program unit, or subprogram, excluding all nested scoping units in it This “excluding all nested scoping units in it” suggests that it may be necessary/desirable to have implicit none in each function … Read more

What does “real*8” mean?

As indicated in comments, real*8 isn’t standard Fortran. This FAQ entry has more details. That said, once we’re into the non-standard realm… The 8 refers to the number of bytes that the data type uses. So a 32-bit integer is integer*4 along the same lines. (But is also non-standard.) A quick search found this guide … Read more

Arrays of pointers

Yeah, pointer arrays are funny in Fortran. The problem is that this: TYPE(domain),DIMENSION(:),POINTER :: dom does not define an array of pointers, as you might think, but a pointer to an array. There’s a number of cool things you can do with these things in Fortran – pointing to slices of large arrays, even with … 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

What flags do you set for your GFORTRAN debugger/compiler to catch faulty code?

Bare minimum -Og/-O0 -O0 basically tells the compiler to make no optimisations. Optimiser can remove some local variables, merge some code blocks, etc. and as an outcome it can make debugging unpredictable. The price for -O0 option is very slow code execution, but starting from version 4.8 GCC compilers (including the Fortran one) accept a … Read more