PTF is a Python-to-Fortran translator for scientific and numerical computing.
It is not a general Python compiler. It is a focused CLI and library for turning numerical Python and NumPy source into inspectable Fortran, compiling it locally, and optionally running the generated program.
The full positioning note lives in PROJECT_POSITIONING.md.
Short version:
Python is fast to write. Fortran is fast to run. PTF connects the two for numerical and scientific code.
- translates scientific Python into Fortran using the local
Array Compilercheckout as the source of truth - applies explicit Fortran dialect profiles for
Fortran 95,2003,2008, and2018 - emits diagnostics when code still relies on features newer than the selected dialect
- compiles translated Fortran with a local compiler such as
gfortran - optionally runs the resulting executable and keeps the runtime output visible
- saves generated
.f90artifacts for downstream use
- translate arbitrary Python application code
- promise support for all Python syntax or all third-party packages
- replace normal Python development
- hide unsupported constructs behind vague or unsafe output
- ptf: Python package and CLI
- examples: runnable example inputs
- tests: package tests
- docs/fortran-dialect-profiles.md: repository-local Fortran dialect reference used by PTF
- vendor/array-compiler: bundled translation engine used by PTF
python -m venv .venv
source .venv/bin/activate
pip install -e .On Windows PowerShell:
.venv\Scripts\Activate.ps1Translate an example file:
ptf translate examples\formatted_array_output.py --show-fortranBuild and run:
ptf build examples\formatted_array_output.py --runRead from standard input:
type examples\formatted_array_output.py | ptf translate --stdin --name formatted_array_output.pyList bundled examples:
ptf examplesTranslate to Fortran:
ptf translate examples\polynomial_roots.py --dialect fortran-2008Compile and run:
ptf build examples\weighted_rng_choice.py --dialect fortran-2018 --runStructured JSON output:
ptf build examples\formatted_array_output.py --run --jsonBy default, PTF uses the bundled translator in vendor/array-compiler.
PTF reads these optional environment variables:
PTF_ARRAY_COMPILER_ROOT="./vendor/array-compiler"
PTF_PYTHON=python
PTF_FORTRAN_COMPILER="D:/msys64/ucrt64/bin/gfortran.exe"For compatibility with the earlier web prototype, ARRAY_COMPILER_ROOT,
ARRAY_COMPILER_PYTHON, and ARRAY_COMPILER_COMPILER are also accepted.
See docs/environment-and-software.md.
PTF should be treated as a scientific-subset translator.
numpyis the primary first-class package target- supported package features should be mapped explicitly to runtime/helper behavior
- unsupported imports should fail clearly and early
python -m unittest discover -s tests -vThis repository is structured to be pushed directly as a GitHub project:
- the Python package and examples live at the repository root
- unrelated PDFs, research references, benchmarks, and the earlier web prototype are excluded by .gitignore
- a basic GitHub Actions workflow is included in .github/workflows/ci.yml
- project-level files such as LICENSE, CONTRIBUTING.md, and ROADMAP.md are present