LoginSignup
1
0

FORTRAN77対応(Ubuntu 22.04)

Last updated at Posted at 2024-03-12

そろそろ半世紀、流石にレガシーのはずなのですが移行できない人達はいる様で…

本題

Ubuntu 22.04ではFORTRANコンパイラ(GCCの一部)は以下のコマンドでインストールできます。

$ sudo apt update
$ sudo apt install gfortran

gfortranは77仕様も後方互換性のために残してあるそうですが、77仕様でのコンパイルを要求する-std=f77は廃止されています。/usr/bin/f77(gfortranへのシンボリックリンク)は存在するのですが後述の通り77仕様を反映する様な実装にはなっていない様です。

古すぎてほとんどWebに情報が残っていないですが、95仕様をサポートするFORTRANコンパイラの開発時にGNUがG95(別のオープンソース実装)をフォークする等ひと悶着あった様で、恐らくその時に廃止されたと思われます。
https://ja.wikipedia.org/wiki/GFortran
https://developers.srad.jp/story/04/08/02/0927228/

77仕様相当はgfortran 11.4.0では-std=legacyであり、後に廃止された機能も警告なくコンパイルできます。オプションなしでは警告付きでコンパイルできるものの、95仕様に準拠する-std=f95ではコンパイルがエラー終了します。なお/usr/bin/f77で実行しても警告付きでコンパイルされます。

このことは95仕様で廃止されたPAUSEを使用した以下テストコードで確認しました。

      PROGRAM HELLO
      PAUSE
      PRINT *, "hello, world"
      END PROGRAM HELLO
$ lsb_release -sd
Ubuntu 22.04.4 LTS
$ uname -r
6.5.0-25-generic
$ gfortran --version
GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.04.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran hello.f -o hello
hello.f:3:72:

       PAUSE
                                                                        1
Warning: Deleted feature: PAUSE statement at (1)
$ ./hello
PAUSE 
To resume execution, type go.  Other input will terminate the job.
go
RESUMED
 hello, world
$ gfortran -std=f95 hello.f -o hello
hello.f:3:72:

       PAUSE
                                                                        1
Error: Deleted feature: PAUSE statement at (1)
$ gfortran -std=legacy hello.f -o hello
$ ./hello
PAUSE 
To resume execution, type go.  Other input will terminate the job.
go
RESUMED
 hello, world
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0