計算データファイルを開く処理、閉じる処理の記述¶
計算データファイルを開く処理、閉じる処理を記述します。
ソルバーは、処理開始時に計算データファイルを開き、終了時に計算データファイルを 閉じる必要があります。
iRIC は引数として計算データファイルのファイル名を渡すため、 そのファイルを開きます。
引数の数と引数を取得するための方法は、コンパイラによって異なります。 Intel Fortran Compiler, gfortran での引数の取得方法を Fortran プログラムでの引数の読み込み処理 で説明していますので、参考にしてください。 ここでは、Intel Fortran Compiler でコンパイルする場合の方法で記述します。
計算データファイルを開く処理と閉じる処理を追記したソースコードを リスト 7 に示します。強調して示したのが追記した部分です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | program SampleProgram implicit none include 'cgnslib_f.h' include 'iriclib_f.h' integer:: fin, ier integer:: icount, istatus character(200)::condFile write(*,*) "Sample Program" icount = nargs() if ( icount.eq.2 ) then call getarg(1, condFile, istatus) else write(*,*) "Input File not specified." stop endif ! 計算データファイルを開く call cg_open_f(condFile, CG_MODE_MODIFY, fin, ier) if (ier /=0) stop "*** Open error of CGNS file ***" ! 内部変数の初期化 call cg_iric_init_f(fin, ier) if (ier /=0) STOP "*** Initialize error of CGNS file ***" ! オプションの設定 call iric_initoption_f(IRIC_OPTION_CANCEL, ier) if (ier /=0) STOP "*** Initialize option error***" ! 計算データファイルを閉じる call cg_close_f(fin, ier) stop end program SampleProgram |
骨組みの作成 と同様に、ファイルのコンパイルと、 実行プログラムの配置を行います。
骨組みの作成 と同様の手順で、iRIC からソルバーが正しく起動できるか 確認します。エラーメッセージが表示されずに終了すれば成功です。
この節で追加した関数の詳細については、 CGNS ファイルを開く, 内部変数の初期化, CGNSファイルを閉じる を参照してください。