Fortran

Fortran

Sets modern Fortran rules for scientific code: implicit none, modules, kind parameters, intent, naming, memory safety and testing, plus common mistakes to avoid.


description: Modern Fortran rules for scientific computing, modules, explicit interfaces, kind parameters, memory safety, and testing
globs: ["/*.f", "/.f90", "**/.f95", "/*.f03", "/.f08", "**/.for", "**/.ftn", "CMakeLists.txt", ".cmake", "Makefile"]
alwaysApply: false


Fortran Programming Guidelines

Basic Principles

  • Use modern Fortran standards such as Fortran 2003, 2008, or newer.
  • Use implicit none in every program unit.
  • Put procedures in modules to provide explicit interfaces.
  • Keep modules focused and place each major module in its own file.
  • Prefer clear, structured code over clever language tricks.
  • Avoid obsolete features such as COMMON blocks, GOTO-heavy control flow, and numeric labels.

Kinds and Types

  • Define numeric kind parameters in one shared module, such as kind_mod.
  • Use real(kind=dp) or the project-approved real kind for floating point values.
  • Use integer(kind=i4) or the project-approved integer kind for integer values.
  • Define constants such as pi explicitly.
  • Include units in comments for physical quantities.
  • Use derived types to group related data instead of passing many primitive arguments.

Naming and Style

  • Use lowercase for language keywords and most identifiers.
  • Use underscores for multi-word names.
  • Avoid names that differ only by case.
  • Use descriptive names for procedures and state.
  • Repeat the procedure or module name after end statements.
  • Keep indentation consistent in do, if, select case, and module blocks.

Procedures

  • Keep subroutines and functions short and single-purpose.
  • Use intent(in), intent(out), or intent(inout) for every dummy argument.
  • Keep functions free of side effects whenever possible.
  • Prefer early validation and clear returns over deep nesting.
  • Use use, only: when importing from modules.

Memory and Arrays

  • Prefer allocatable arrays over pointers unless pointer semantics are required.
  • Check allocation state and array sizes before use.
  • Deallocate allocatable arrays when their lifetime is not naturally scoped.
  • Specify array bounds clearly when they matter.
  • Avoid unnecessary dynamic allocation in hot loops.

Testing and Build

  • Use CMake, fpm, Make, or the project-standard build system consistently.
  • Compile with warnings enabled and treat important warnings as failures in CI.
  • Add unit tests for public procedures and integration tests for numerical workflows.
  • Test boundary conditions, invalid inputs, and representative scientific cases.
  • Verify numerical tolerances explicitly rather than relying on exact floating point equality.

Common Mistakes

  • Do not declare variables after executable code unless using a block construct.
  • Do not assume random_number is a function; it is a subroutine.
  • Do not write to stdout from pure procedures.
  • Do not declare the same variable twice in the same scope.
  • Do not assume pi, dp, or project kinds already exist without importing or defining them.

Public domain (CC0 1.0) · by awesome-cursorrules contributors · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…