# Fortran Support in Maguyva: Code Graphs for Scientific Codebases

Canonical source: https://maguyva.ai/languages/fortran

License: text under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/); code samples under [MIT-0](https://opensource.org/license/mit-0); the Maguyva name, logos, brand assets and other code are not covered. Details: [maguyva.ai/license](https://maguyva.ai/license).

Maguyva parses Fortran with AST, symbol, and graph support, so AI agents can trace subroutines, modules, and derived types before changing numerical code.

## Support snapshot

- Tier: AST and symbol support
- Programming
- Extensions: .f, .f03, .f08, .f90, .f95, .for, +1 more
- Real AST parsing for syntax-aware search and structural context.
- Named symbols feed semantic lookup and cross-reference. Graph navigation is available when relationship extraction is enabled.
- This language contributes symbols and relationships to graph-aware search; supported edge types vary with its native constructs.
- AST parsing and symbol extraction are both available.

## Best fit

- Research, engineering, and HPC teams maintaining Fortran solvers, simulations, or numerical libraries that predate the current team.
- Repositories that mix fixed-form `.f` files with free-form `.f90` and later modules, often beside C or Python wrappers.
- Agent-assisted reviews where the first job is mapping which subroutines touch a shared module before a numerical change.

## Agent workflows

- Trace which subroutines and functions call a solver routine before changing its arguments or units.
- List the modules a program unit pulls in with `use` and follow them to their definitions.
- Find where a derived type is declared and which procedures work with it.

## Why Fortran needs structure, not string matching

Fortran codebases tend to be old, large, and written by domain experts rather than software teams. Routines named `SOLVE`, `Solve`, and `solve` are the same routine. Modules are shared across hundreds of files, and the intrinsic library is big enough that a naive call list is mostly `SQRT`, `SUM`, and `WRITE`.

An agent that only greps will drown in that noise. Maguyva gives it the structure first: which program units exist, which modules they use, and which user routines call each other.

## What Maguyva extracts in Fortran

Maguyva covers fixed-form and free-form source (`.f`, `.for`, `.ftn`, `.f90`, `.f95`, `.f03`, `.f08`). Functions and subroutines are extracted as callable symbols, and derived types are selectable as type definitions in structural search.

Symbol matching is case-insensitive, matching Fortran's own rules. Import relationships come from `use` and `include`, with the keyword stripped so the module name is what the graph stores. Calls, reads, assignments, type references, and inheritance from extended derived types are all part of the graph.

The relationship filter removes around 165 intrinsics (I/O statements, math, array, string, type-conversion, and bit-manipulation routines), so the edges that remain point at your own code.

## Example agent prompts

- "Which subroutines call `compute_flux`, and which modules do they use?" (`find_symbol`, then `dependency_search` incoming)
- "Trace how boundary conditions are applied in the solver loop." (`get_task_context`)
- "Find every program unit that uses the `constants` module." (`text_pattern_search` for `use constants`, then `find_symbol`)

## Known limits

- Fortran has no decorators or exception handling, so those relationship types are marked not applicable.
- Type-bound procedures share the same nodes as ordinary functions and subroutines. Use the `functions` preset in `structural_search`; the `methods` preset selects no Fortran nodes.
- Calls to filtered intrinsics do not appear as graph edges. Use `text_pattern_search` when you need every `WRITE` or `OPEN`.

## Next steps

Connect a repository with the [quickstart](/docs/quickstart), then check the full support matrix on the [compatibility page](/docs/compatibility). If Fortran sits beside C glue code, read the [C guide](/languages/c) too.

## Engine details

- Fortran support covers fixed-form and free-form source: `.f`, `.for`, `.ftn`, `.f90`, `.f95`, `.f03`, and `.f08`.
- Functions and subroutines are callable symbols, symbol matching is case-insensitive, and `use` and `include` become import relationships.
- About 165 intrinsics (I/O, math, array, string, type-conversion, and bit routines) are filtered from relationships. Decorator and exception relationships are marked not applicable.

## Useful MCP entry points

- `find_symbol`: Start with the subroutine, function, or module name; matching ignores case, as Fortran does.
- `dependency_search`: Use incoming traversal on a solver or shared module routine to see every caller before a numerical change.
- `get_task_context`: Use it for prompts like “trace how boundary conditions are applied in the solver loop.”
