What does “real*8” mean?

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. A quick search found this guide to Fortran data types, which includes: The “real*4” statement specifies the variable names to be single precision 4-byte real numbers which has 7 digits of accuracy … 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

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

What are the ways to pass a set of variable values through the subroutine to a function without common block?

What you care about here is association: you want to be able to associate entities in the function f with those in the subroutine condat. Storage association is one way to do this, which is what the common block is doing. There are other forms of association which can be useful. These are use association … 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