By default some LLMs will produce Fortran code with default reals. To avoid this, I often instruct them to
Declare real variables as
real(kind=dp) with
dp a kind constant imported from module kind_mod, which I will provide
I tell them to put procedures in modules, and in my Fortran agents I tell them to iterate until the code compiles with the gfortran options
-O0 -fmax-errors=1 -Wall -Werror=unused-parameter -Werror=unused-variable -Werror=unused-function -Wno-maybe-uninitialized -Wno-surprising -fbounds-check -static -g
Common mistakes that LLM make are to
- Assume pi is a built-in constant
- Declare variables after executable code, without using
block printorwritein pure procedures or userandom_number- Think that
random_numberis a function rather than a subroutine - Declare superfluous variables such as
iandj. - Declare variables more than once
- Not to explicitly declare as
publicmodule entities that need to bepublic. This is allowed by the standard, but I want code that compiles withgfortran -fmodule-private. - Have two variables that differ only by case in the same scope. In other languages those variables are distinct.
You can instruct them not to do this.