Skip to content
Preview.f90@modelscript/fortran 15 diagnostic rules
Parser WASM GLR
Diagnostics 15 rules
DAE Arena Lowering
Simulation Co-sim / Export
Projections DAE
Live ExampleTwoBodyRk4Integrator.f90

Fortran 90 Orbital Mechanics & Thermal DAE Subroutine

Legacy scientific Fortran subroutine lowered directly into ModelScript's linear-memory DAE arena for coupled co-simulation.

Playground
Source (11 lines)
1subroutine thermal_node_step(t_wall, t_fluid, q_solar, c_th, h_conv, dt)
2  implicit none
3  real(8), intent(inout) :: t_wall
4  real(8), intent(in)    :: t_fluid, q_solar, c_th, h_conv, dt
5  real(8) :: q_conv, dt_wall_dt
6 
7  ! Convective heat transfer and radiative dissipation
8  q_conv = h_conv * (t_wall - t_fluid)
9  dt_wall_dt = (q_solar - q_conv) / c_th
10  t_wall = t_wall + dt_wall_dt * dt
11end subroutine thermal_node_step
Fortran Subroutine & State Lowering Flow
t_wall(k+1) «fortran_in» intent(in) Parameters «real(8)» t_fluid, q_solar c_th, h_conv, dt «subroutine» thermal_node_step «energy balance» q_conv = h_conv*(t_wall - t_fluid) dt_wall = (q_solar - q_conv)/c_th t_wall = t_wall + dt_wall*dt «dae_state» intent(inout) State «updated state» real(8) :: t_wall [K] DAE Arena State Slot
Drag to pan · Click % to reset

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 ​

ExtensionStandard / FormatDescription
.f, .for, .f77Fortran 77 (Fixed Form)Column-based legacy engineering subroutines and mathematical libraries
.f90, .f95Fortran 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, COMMON blocks, EQUIVALENCE, PARAMETER, DATA statements, 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 Fortran SUBROUTINE and FUNCTION definitions 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's DAEBuilder SoA 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

CodeRuleSeverityMessage
M4070undeclared-variableerrorVariable '<varName>' referenced without declaration under strict typing.
M4071uninitialized-variablewarningVariable '<varName>' may be used before being assigned a value.
M4072constant-division-by-zeroerrorDivision by constant zero detected in arithmetic expression.
M4073storage-bounds-overflowerrorStorage array index <arrayName>(<index>) exceeds allocated capacity of <maxCapacity>.
M4074dead-code-after-returnwarningUnreachable statements detected following unconditional RETURN.
M4075do-loop-index-mutationerrorDO-loop index variable '<indexVar>' is modified within its loop body.
M4076procedural-algebraic-loopwarningAlgebraic cycle detected among procedural assignments without time-step lag: <cycleStr>.
M4077common-block-mismatcherrorCOMMON block '/<blockName>/' definition conflict: <reason>.
M4078array-dimension-underflowerrorArray '<arrName>' declared with non-positive dimension size (<dim> <= 0).
M4079obsolete-arithmetic-ifinfoThree-way arithmetic IF is obsolescent; prefer structured IF/THEN/ELSE.
M4080identifier-mismatcherrorEnd <unitKind> identifier '<endName>' does not match '<startName>'.
M4081intent-in-mutationerrorDummy argument '<varName>' declared with 'INTENT(IN)' cannot be modified.
M4082invalid-statement-syntaxerrorSyntax error in Fortran statement: <detail>.
M4083unclosed-blockerrorUnclosed or mismatched '<blockName>' block structure.
M4084math-domain-violationerrorIntrinsic 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).

bash
# 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.f90

DAE lowering is available from the package API (there is no dedicated msx fortran command yet):

ts
import { lintFortranSource, lowerFortranToDae } from "@modelscript/fortran";

const diagnostics = lintFortranSource(source);
const result = lowerFortranToDae(builder, source.split("\n"));

Open-Core under the GNU AGPL v3 License; Enterprise Edition (ee/) under the ModelScript Enterprise License. • Trademark Policy