# Cursor rules for Fortran

**URL:** <https://fortran-lang.discourse.group/t/cursor-rules-for-fortran/9596>\
**Category:** Help\
**Created:** [April 19, 2025, 8:01pm UTC](https://fortran-lang.discourse.group/t/cursor-rules-for-fortran/9596 "2025-04-19T20:01:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 19, 2025, 8:15pm UTC](https://fortran-lang.discourse.group/t/cursor-rules-for-fortran/9596/2 "2025-04-19T20:15:35Z")

</div>

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](https://github.com/Beliavsky/Gemini-Fortran-agent) I tell them to iterate until the code compiles with the gfortran options

```auto
-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

1. Assume pi is a built-in constant
2. Declare variables after executable code, without using `block`
3. `print` or `write` in pure procedures or use `random_number`
4. Think that `random_number` is a function rather than a subroutine
5. Declare superfluous variables such as `i` and `j`.
6. Declare variables more than once
7. Not to explicitly declare as `public` module entities that need to be `public`. This is allowed by the standard, but I want code that compiles with `gfortran -fmodule-private`.
8. 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.

---

_[View the full topic](https://fortran-lang.discourse.group/t/cursor-rules-for-fortran/9596)._
