LoginSignup
1
1

More than 5 years have passed since last update.

Fortranプログラムでterminalのコマンドを使う方法

Last updated at Posted at 2018-02-20

今回はFortranからterminalのコマンドを使う方法を紹介したいと思います。
Fortranを使っているとフォルダ(ディレクトリ)の作成やlsコマンド、rmコマンドなどを使いたい場合があります。この他にもpythonやC言語などのスクリプトやプログラムがあれば、それを動かすこともできます。例では「lsコマンド」を用いたものにします。

test.f90
program test
 implicit none
 call system("ls")
end program test

上記のプログラムファイルを作成し、terminalで

gfortran test.f90
./a.out

とします。
これで、自分の作業ディレクトリ内のファイルが表示されています。
とても簡単です。
characterを組み合わせることで、rmを行うsubroutineも自分で作成できます。

1
1
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
1