[ English | Japanese ] [ Gt4f90io Reference Manual | Gt4f90io Tutorial ]

Message dump

In many cases, it is necessary to dump message on standard output during program execution. However, well sophisticated WRITE and FORMAT statements are required for readable message. Moreover, when the message includes variables of not character literal constants, the conversion of type and concatenation are required, which are troublesome for programers.

Dc_message module of gt4f90io provide subroutine for message dump. By using the dc_message module, readable message dump is realized in user's programs with ease.

For example, a sample program using the dc_message module (diffusion_4.f90) is shown here, which are modified from diffusion_3.f90 in Fortran 90/95 general-purpose modules: (1) Type parameter specification. Statements with colored font (or bold font) are associataed with the dc_message module.

!= Sample program for gt4_history/gt4f90io
!
! * 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_4

  use gt4_history                                   ! モジュール指定
  use dc_types, only : DP                           ! モジュール指定
  use dc_message, only : MessageNotify              ! モジュール指定

  integer, parameter     :: nx=30                   ! グリッド数
  integer, parameter     :: nt=200                  ! 時間ステップ数
  integer, parameter     :: ndisp=10                ! 出力間隔
  real(DP), parameter    :: dx=1.0/(nx-1)           ! グリッド間隔
  real(DP), parameter    :: dt=0.0005               ! 時間間隔
  real(DP), dimension(nx):: x=(/(dx*(i-1),i=1,nx)/) ! 座標変数
  real(DP), dimension(nx):: temp                    ! 温度
  real(DP), parameter    :: kappa=1.0               ! 熱拡散係数
  real(DP)               :: sigma                   ! 計算安定条件パラメタ

  tinit = 0.0                                       ! 初期時刻設定

  sigma = kappa*dt/dx**2.0d0

  if ( sigma >= 0.5d0 ) then
    call MessageNotify( "E", &                      ! エラーメッセージ出力 
      &                 "diffusion_4", &
      &                 "dt is too large: k*dt/(dx)^2 = %f", &
      &                  d=(/sigma/) )
  else if ( sigma >= 0.4d0 ) then
    call MessageNotify( "W", &                      ! 警告メッセージ出力 
      &                 "diffusion_4", &
      &                 "dt is moderately large: k*dt/(dx)^2 = %f", &
      &                 d=(/sigma/) )
  else
    call MessageNotify( "M", &                      ! メッセージ出力 
      &                 "diffusion_4", &
      &                 "dt is sufficiently small: k*dt/(dx)^2 = %f", &
      &                  d=(/sigma/) )
  end if
    
  temp = exp(-((x-0.5)/0.1)**2)                     ! 初期値設定

  call HistoryCreate( &                             ! ヒストリー作成
    & file='diffusion_4.nc', title='Diffusion equation', &
    & source='Sample program of gt4_history/gt4f90io',   &
    & 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)                            ! 次元変数出力

  call HistoryAddVariable( &                        ! 変数定義
    & 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)                      ! 変数出力

  do it=1,nt
    temp(2:nx-1) = temp(2:nx-1) &                   ! 時間積分
      & + 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)                  ! 変数出力
    endif
  enddo

  call HistoryClose
  stop
end program diffusion_4

Summary of dc_message module and its subroutines used in the sample program are as follows. In detail, please see gt4f90io reference manual.

use dc_message
Access dc_message module. This statement is located at the begining of main program. In this case, only MessageNotify subroutine is accessed by ONLY option.
call MessageNotify(level, where, message, [i], [r], [d], [L], [n], [c1], [c2], [c3])
Dump message. Notation of each arguments are follows.

$Id: dc_message.rd,v 1.3 2007/08/28 09:22:29 odakker2 Exp $
Gtool4 Development Group / GFD Dennou Staff dcstaff@gfd-dennou.org