fortran
Installation
SKILL.md
Modern Fortran Development
This skill covers writing modern, maintainable Fortran (2003/2008 and later) for scientific and numerical computing, including module organization, kind parameters, procedure design, memory safety, and testing.
Workflow for Writing a Modern Fortran Module
- Define shared kinds first — Create a
kinds_mod(or similarly named) module withiso_fortran_envorselected_real_kind/selected_int_kindparameters used across the whole project. - Design the module — Group related derived types and procedures into one focused module per file; declare
implicit noneat the top. - Write procedure interfaces — Give every dummy argument an explicit
intent(in),intent(out), orintent(inout); useuse, only:to import exactly what's needed. - Implement with early validation — Check preconditions (array bounds, allocation state, valid ranges) at the top of each procedure and return/stop early rather than nesting deeply.
- Manage arrays explicitly — Use allocatable arrays, check
allocated()before use, and deallocate when the lifetime isn't naturally scoped. - Build with warnings on — Compile with
-Wall -Wextra -std=f2008(gfortran) or the equivalent, and fail CI on new warnings. - Test — Write unit tests for individual procedures and integration tests for full numerical workflows, checking tolerances rather than exact floating-point equality.