以前のリビジョンの文書です


Fortranのtips

コンパイラオプション

compiler gfortran ifort frt
エラーの検出FIXME-Wall-check all-Eg?
配列外参照-fbounds-check-CB
暗黙の型宣言-fimplicit-none-warn declarations
浮動小数点演算例外の検出-ffpe-trap=zero-fpe0
標準外機能の警告?-std

連番のファイル名をつける。

ファイル名をcharacter変数に代入して使う。ファイル名の変更にはwrite文を使う。 逐次計算に使える。

character(len=12) filename
...
do i=1,100
  ...
  write(filename,'(a,i4.4,a)') 'hoge',i,'.dat'
  open(10,file=filename)
  ...
    write(10,*) ...
  ...
  close(10)
end do

このファイルをperlに食わせて処理すると便利かも. 以下,サンプル.

#!/usr/bin/perl
$gpfile .= sprintf("%s\n","set terminal gif");
$gpfile .= sprintf("%s\n","set pm3d map");
for($i=1;$i < 30;$i++){
    $file = sprintf("hoge%04d",$i*10);
    $gpfile .= sprintf("%s\n","set output \"$file.gif\"");
    $gpfile .= sprintf("%s\n","splot \"$file.dat\" using 1:2:5");
};
open (GP, "| gnuplot" ) or die "no gnuplot";
print GP "$gpfile";
close GP;
system("gifsicle --delay 50 hoge*gif > anime.gif");

gifsicle はgifアニメを作成するツール.アニメを見るにはgifview.

gifview -a anim.gif

ifortで改行を抑制する

ifortでは出力時に勝手に改行する仕様になっている。改行を抑制するためには、Format文を使用すればよい。

integer n
real(8),allocatable::a(:)
n=9
allocate(a(9))
do i=1,n
   a(i)=i
end do
write(*,'(<n>f)') a
end program
fortran.1245832060.txt.gz · 最終更新: 2009/06/24 17:27 by saito
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0