fortran
БесплатноБез исполняемых скриптовНе проверенBest practices for modern Fortran (2003/2008+) scientific and numerical computing, covering modules, explicit interfaces, kind parameters, memory safety, and…
от Mindrally★ 323 звезды на GitHubОб этом скилле
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.
Basic Principles
- Target modern Fortran standards — Fortran 2003, 2008, or newer — and avoid writing in a legacy FORTRAN 77 style just because the compiler still accepts it.
- Put
implicit nonein every program unit (module, program, and — via inheritance from a module or explicit statement — every procedure) so undeclared-variable typos are caught at compile time instead of producing silent wrong answers. - Put procedures in modules rather than external subprograms; module procedures get automatically-generated explicit interfaces, which lets the compiler catch argument mismatches that external procedures cannot.
- Keep modules focused on one concern and place each major module in its own file, named to match the module (e.g.,
module linear_solverinlinear_solver.f90). - Prefer clear, structured code over clever language tricks — Fortran numerical code is read far more often than it's written, usually by someone other than the original author.
- Avoid obsolete features:
COMMONblocks (replace with modules),GOTO-heavy control flow (replace with structuredif/do/select case, plusblockwhere useful), and numeric statement labels used as jump targets.
Kinds and Types
- Define numeric kind parameters in one shared module (e.g.,
kind_modorprecision_mod) so the whole codebase can change precision in one place. - Use
real(kind=dp)(or the project's approved real kind) for floating-point values — never barerealordouble precision, whose actual precision is compiler- and flag-dependent. - Use
integer(kind=i4)(or the project's approved integer kind) for integers where the width matters, especially in interfaces to C or binary I/O. - Define constants such as
piexplicitly and precisely (e.g.,real(dp), parameter :: pi = 4.0_dp * atan(1.0_dp)) rather than truncated literals. - Include the physical units in a comment for any variable representing a physical quantity (
real(dp) :: velocity ! m/s). - Use derived types to group related data (e.g., a
particle_ttype with position, velocity, and mass fields) instead of passing many loose primitive arguments through procedure calls.
Example: Kinds Module and a Numerical Procedure
module kinds_mod
use iso_fortran_env, only: real64, int32
implicit none
private
public :: dp, i4
integer, parameter :: dp = real64
integer, parameter :: i4 = int32
end module kinds_mod
module stats_mod
use kinds_mod, only: dp
implicit none
private
public :: mean, standard_deviation
contains
pure function mean(x) result(m)
real(dp), intent(in) :: x(:)
real(dp) :: m
m = sum(x) / real(size(x), dp)
end function mean
pure function standard_deviation(x) result(s)
real(dp), intent(in) :: x(:)
real(dp) :: s
real(dp) :: m
integer :: n
n = size(x)
if (n < 2) then
s = 0.0_dp
return
end if
m = mean(x)
s = sqrt(sum((x - m)**2) / real(n - 1, dp))
end function standard_deviation
end module stats_mod
program demo
use kinds_mod, only: dp
use stats_mod, only: mean, standard_deviation
implicit none
real(dp) :: samples(5)
samples = [1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp]
print '(A, F0.4)', 'mean = ', mean(samples)
print '(A, F0.4)', 'stddev = ', standard_deviation(samples)
end program demo
Naming and Style
- Use lowercase for language keywords and most identifiers; Fortran is case-insensitive, so consistent lowercase avoids visual noise from mixed-case keywords.
- Use underscores for multi-
Установить fortran в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл fortran?
Best practices for modern Fortran (2003/2008+) scientific and numerical computing, covering modules, explicit interfaces, kind parameters, memory safety, and testing. Use when writing or reviewing Fortran source (.f90/.f95/.f03/.f08), defining modules and derived types, choosing numeric kind parameters, working with allocatable arrays, setting up a Fortran build with CMake or fpm, or writing unit tests for numerical code.
Как установить скилл fortran?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл fortran запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic