Search by

vlauciani / fortran-formatter

vlauciani

PHP Fortran Formatter

Package info

github.com/vlauciani/fortran-formatter

pkg:composer/vlauciani/fortran-formatter

Statistics

Installs: 4 009

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-11-23 11:23 UTC

This package is auto-updated.

Last update: 2026-11-23 11:58:37 UTC


README

Tests Packagist License Total Downloads

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