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

How to alias a function name in Fortran

Yes, Fortran has procedure pointers, so you can in effect alias a function name. Here is a code example which assigns to the function pointer “f_ptr” one function or the other. Thereafter the program can use “f_ptr” and the selected function will be invoked. module ExampleFuncs implicit none contains function f1 (x) real :: f1 … Read more

What flags to set for GFORTRAN 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

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

SciPy build/install Mac Osx

Your problem is that you need to install a Fortran compiler to build scipy. Also, if you already have a numpy that’s built with Fortran support disabled, you may have to replace it. Some of Apple’s pre-installed Python versions have such a numpy build pre-installed. The easiest way to get Fortran is with Homebrew. As … Read more

Fortran intrinsic timing routines, which is better? cpu_time or system_clock

These two intrinsics report different types of time. system_clock reports “wall time” or elapsed time. cpu_time reports time used by the CPU. On a multi-tasking machine these could be very different, e.g., if your process shared the CPU equally with three other processes and therefore received 25% of the CPU and used 10 cpu seconds, … Read more