vlauciani / fortran-formatter
PHP Fortran Formatter
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^10.5|^11.5|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Installation
composer require vlauciani/fortran-formatter
Usage
<?php use VLauciani\FortranFormatter\Traits\FortranFormatTrait; class PhaseCard { use FortranFormatTrait; public function build(): string { $pad = '*'; return self::fromFortranFormatToString('A5', 'ACER', $pad, STR_PAD_RIGHT) // 'ACER*' .self::fromFortranFormatToString('A2', 'IV', $pad) // 'IV' .self::fromFortranFormatToString('F3.0', '12', $pad) // '12.' .self::fromFortranFormatToString('6X', null, $pad) // '******' .self::fromFortranFormatToString('I6', '123', $pad); // '***123' } }
Float formats: new and old
The fifth argument chooses how an Fw.d field is written.
new (the default) writes the digits only, with the decimal point implied by
d, as in the fixed-column formats where the reader puts the point back
(Hypoinverse archive files):
self::fromFortranFormatToString('F5.2', 12.34, ' '); // ' 1234' self::fromFortranFormatToString('F5.2', 2.5, ' '); // ' 250'
old writes the decimal point. When the value does not fit in w characters
it drops decimals, one at a time, and writes * only when not even the whole
part fits. A Fortran Fw.d read honours an explicit point, so the value is read
back with less precision, not wrong (hypo71 phase cards):
self::fromFortranFormatToString('F5.2', 12.34, ' ', STR_PAD_LEFT, 'old'); // '12.34' self::fromFortranFormatToString('F5.2', 107.72, ' ', STR_PAD_LEFT, 'old'); // '107.7' self::fromFortranFormatToString('F5.2', 1234.5, ' ', STR_PAD_LEFT, 'old'); // '1235.' self::fromFortranFormatToString('F5.2', 99999, ' ', STR_PAD_LEFT, 'old'); // '*****'
Tests
composer install
vendor/bin/phpunit
Contribute
Thanks to your contributions!
Here is a list of users who already contributed to this repository:
Author
(c) 2026 Valentino Lauciani vlauciani[at]gmail.com