Fortran Legacy Engineering Integration (.f, .f90)
@modelscript/fortran (languages/fortran) provides native GLR parsing, AST analysis, Triple Graph Grammar (TGG) synchronization, and DAE wrapping for legacy Fortran 77 and Fortran 90 computational engines.
Supported Extensions & Standards
| Extension | Standard / Format | Description |
|---|---|---|
.f, .for, .f77 | Fortran 77 (Fixed Form) | Column-based legacy engineering subroutines and mathematical libraries |
.f90, .f95 | Fortran 90 / 95 (Free Form) | Free-form modular subroutines, derived types, and array syntax |
Key Capabilities
1. WebAssembly GLR Fortran Parser
- Built on
@modelscript/dsl's ahead-of-time compiled WASM GLR parser table. - Accurately parses both fixed-form (columns 1-5 label, 6 continuation, 7-72 statements) and modern free-form source files.
- Supports subroutines, functions,
COMMONblocks,EQUIVALENCE,PARAMETER,DATAstatements, multidimensional array indexing, and intrinsic mathematical functions (SIN,COS,SQRT,EXP, etc.).
2. Bidirectional Triple Graph Grammar (TGG) Rules
- Features formal bidirectional graph rewriting rules (
languages/fortran/src/language.ts):FortranSubroutineToModelicaFunction: Maps FortranSUBROUTINEandFUNCTIONdefinitions to strongly typed Modelica functions.FortranAssignToModelicaEquation: Transforms Fortran numerical assignment statements into declarative Modelica equality equations.
3. Direct DAE Subroutine Lowering
- Compiles Fortran continuous state derivative subroutines directly into
@modelscript/runtime'sDAEBuilderSoA linear memory arena. - Enables legacy aero-propulsion, ballistics, and nuclear thermal routines to execute within modern hybrid continuous-discrete simulation solvers without manual recoding.
Static Analysis & Modernization Linter Rules
The Fortran analyzer surfaces modernization issues and common numeric defects:
15 rules11 error3 warning1 info Run with msx lint
| Code | Rule | Severity | Message |
|---|---|---|---|
M4070 | undeclared-variable | error | Variable '<varName>' referenced without declaration under strict typing. |
M4071 | uninitialized-variable | warning | Variable '<varName>' may be used before being assigned a value. |
M4072 | constant-division-by-zero | error | Division by constant zero detected in arithmetic expression. |
M4073 | storage-bounds-overflow | error | Storage array index <arrayName>(<index>) exceeds allocated capacity of <maxCapacity>. |
M4074 | dead-code-after-return | warning | Unreachable statements detected following unconditional RETURN. |
M4075 | do-loop-index-mutation | error | DO-loop index variable '<indexVar>' is modified within its loop body. |
M4076 | procedural-algebraic-loop | warning | Algebraic cycle detected among procedural assignments without time-step lag: <cycleStr>. |
M4077 | common-block-mismatch | error | COMMON block '/<blockName>/' definition conflict: <reason>. |
M4078 | array-dimension-underflow | error | Array '<arrName>' declared with non-positive dimension size (<dim> <= 0). |
M4079 | obsolete-arithmetic-if | info | Three-way arithmetic IF is obsolescent; prefer structured IF/THEN/ELSE. |
M4080 | identifier-mismatch | error | End <unitKind> identifier '<endName>' does not match '<startName>'. |
M4081 | intent-in-mutation | error | Dummy argument '<varName>' declared with 'INTENT(IN)' cannot be modified. |
M4082 | invalid-statement-syntax | error | Syntax error in Fortran statement: <detail>. |
M4083 | unclosed-block | error | Unclosed or mismatched '<blockName>' block structure. |
M4084 | math-domain-violation | error | Intrinsic math function '<fnName>' evaluated outside its real domain with argument '<argVal>'. |
Generated from languages/fortran/src/lints/index.ts. All languages →
CLI Usage
Fortran sources are handled by the generic workspace commands. The language is detected from the file extension (.f, .for, .f90, .f95, .f03, .f08).
# Lint legacy Fortran engineering subroutines
msx lint TurbomachineryModel.f
# Lint only the Fortran files in a mixed-language workspace
msx lint ./src --language fortran
# Print the parse tree of a Fortran source file
msx parse PropulsionAero.f90DAE lowering is available from the package API (there is no dedicated msx fortran command yet):
import { lintFortranSource, lowerFortranToDae } from "@modelscript/fortran";
const diagnostics = lintFortranSource(source);
const result = lowerFortranToDae(builder, source.split("\n"));
