[ English | Japanese ] [ Gtool5 Documents | Gtool5 Tutorial ]

種別型パラメタの提供

実数型変数の精度や文字型変数の文字数を指定する際に, Fortran90 では種別型パラメタを用いることができます. gtool5 には標準的な種別型パラメタを提供するモジュール dc_types が用意 されています. これを用いると標準的な種別型パラメタを自分で定義する ことなく利用することが可能となります.

例として, データの入出力: 属性をつける で用いたサンプルプログラムにおいて, 実数型変数の精度を種別型パラメタを用いて指定したプログラムを示します (ソースコードはこちら). 赤字(カラーがでない場合はボールド)が dc_types に関係している箇所です.

!= Sample program for gtool_history/gtool5
!
! * 2007/06/25 M.Odaka
! * 2006/10/25 Y.Morikawa
! * 2003/08/21 M.Odaka
! * 2001/02/27 S.Takehiro
!
! Solving diffusion equation
! \[
!     du/dt = \kappa d^2 u/dx^2
! \]
! for giving values of $u$ at $x=[0,1]$.
!
program diffusion_3

  use gtool_history                                   ! Access module(モジュール指定)
  use dc_types, only : DP                           ! Access module (モジュール指定)

  integer, parameter     :: nx=30                   ! Grid number (グリッド数)
  integer, parameter     :: nt=200                  ! Time step number (時間ステップ数)
  integer, parameter     :: ndisp=10                ! Output interval (出力間隔)
  real(DP), parameter    :: dx=1.0/(nx-1)           ! Grid interval (グリッド間隔)
  real(DP), parameter    :: dt=0.0005               ! Time step (時間間隔)
  real(DP), dimension(nx):: x=(/(dx*(i-1),i=1,nx)/) ! X coordinate (座標変数)
  real(DP), dimension(nx):: temp                    ! Temperature (温度)
  real(DP), parameter    :: kappa=1.0               ! Diffusion coefficient (熱拡散係数)

  tinit = 0.0                                       ! Set initial Time 
                                                    ! (初期時刻設定)
  
  temp = exp(-((x-0.5)/0.1)**2)                     ! Set initial value 
                                                    ! (初期値設定)

  call HistoryCreate( &                             ! Create output file 
    & file='diffusion_3.nc', &                      ! (ヒストリー作成)
    & title='Diffusion equation',                        &
    & source='Sample program of gtool_history/gtool5',   &
    & institution='GFD_Dennou Club davis project',       &
    & dims=(/'x','t'/), dimsizes=(/nx,0/),               &
    & longnames=(/'X-coordinate','time        '/),       &
    & units=(/'m','s'/),                                 &
    & origin=real(tinit), interval=real(ndisp*dt) )

  call HistoryPut('x',x)                            ! Output 'x' (次元変数出力)

  call HistoryAddVariable( &                        ! Set output variable 
    & varname='temp', dims=(/'x','t'/), &           ! (変数定義)
    & longname='temperature', units='K', xtype='double')

  call HistoryAddAttr('temp','gt_graph_tick_all',1)
  call HistoryAddAttr('temp','gt_graph_contour_spacing',(/0.0,1.0,0.01/))
  call HistoryAddAttr('temp','+gt_user_davis_kappa',kappa)

  call HistoryPut('temp',temp)                      ! Output 'temp' (変数出力)

  do it=1,nt
    temp(2:nx-1) = temp(2:nx-1) &                   ! Time integration (時間積分)
      & + kappa*(temp(3:nx)-2*temp(2:nx-1)+temp(1:nx-2))/dx**2*dt

    if ( mod(it,ndisp) == 0 ) then
      call HistoryPut('temp',temp)                  ! Output 'temp' (変数出力)
    endif
  enddo

  call HistoryClose
  stop
end program diffusion_3

ここでは実数型変数の精度を, dc_types モジュールが用意する 倍精度実数種別型パラメタ DP を用いて指定しました. dc_types モジュールにはこの他に整数型や文字型変数のための 種別型パラメタが用意されています. 詳しくは リファレンスマニュアル を参照してください.


$Id: dc_types.rd,v 1.3 2009-02-28 13:36:32 morikawa Exp $
gtool4 Development Group / GFD Dennou Staff dcstaff@gfd-dennou.org