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

Debug support

Dc_trace module of gt4f90io provides subroutines useful for debugging user's programs. By using dc_trace module, it is easy to trace user's program in debugging.

For example, a sample program using the dc_clock module (diffusion_6.f90) is shown here, which are modified from diffusion_4.f90 in Fortran 90/95 general-purpose modules: (2) Message dump. Statements with colored font (or bold font) are associated with the dc_clock module.

!= Sample program for gt4_history/gt4f90io
!
! * 2007/06/27 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_6

  use gt4_history                                   ! Access module (モジュール指定)
  use dc_types, only : DP                           ! Access module (モジュール指定)
  use dc_message, only : MessageNotify              ! Access module (モジュール指定)
  use dc_trace, only : SetDebug, DbgMessage         ! 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 (熱拡散係数)
  real(DP)               :: sigma                   ! Parameter (計算安定条件パラメタ)

  call SetDebug                                     ! Debug mode on 
                                                    ! (デバッグモードオン)

  call DbgMessage(fmt="*** Debug Message [diffusion_6] *** Debug Message On")
                                                    ! Debug message dump 
                                                    ! (デバッグ出力)  

  tinit = 0.0                                       ! Set initial time 
                                                    ! (初期時刻設定)

  sigma = kappa*dt/dx**2.0d0

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

  call HistoryCreate( &                             ! Create output file 
    & file='diffusion_6.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)                            ! 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' (変数出力)

  
    call DbgMessage(fmt="*** Debug Message [diffusion_6] *** Begin time integration")
                                                    ! Debug message dump
                                                    ! (デバッグ出力) 
  
    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
  
      call DbgMessage(fmt="*** Debug Message [diffusion_6] *** it=%d, &
        &             i= (/it/) )               
                                                    ! Debug message dump
                                                    ! (デバッグ出力) 
  
    end do
  
    call DbgMessage(fmt="*** Debug Message [diffusion_6] *** End time integration")                           
                                                    ! Debug message dump
                                                    ! (デバッグ出力) 
  
  call HistoryClose
  
  stop
  end program diffusion_6
  

In this program, debug messages are dumped before and after the loop of time integration. The messages are displayed on standard error out as follows. Debug messages included subroutines of gt4f90io library are also dumped.

#SetDebug: dbg = 0
#*** Debug Message [diffusion_5] *** Debug Message On
 *** WARNING [diffusion_6] ***  dt is moderately large: k*dt/(dx)^2 = 0.4205000231056476
#call HistoryCreate1 version=<$Name: gt4f90io-20080211 $$Id: dc_trace.rd,v 1.4 2007/08/31 05:13:19 odakker2 Exp $> : file=diffusion_6.nc ndims=2
#|-dims(:)=x, t, dimsizes(:)=30, 0, longnames(:)=X-coordinate, time, units(:)=m, s
#| call DCDateTimeCreate1 : current_time_used=<yes>
#| end DCDateTimeCreate1 : time (caltype=4, day=733253, sec=5976., zone=+09:00, day_seconds=86400.)
#| call DCDateTimeEval1
#| end DCDateTimeEval1
#| call GTVarCreateD version=<$Name: gt4f90io-20080211 $$Id: dc_trace.rd,v 1.4 2007/08/31 05:13:19 odakker2 Exp $> : url=<diffusion_6.nc@x> length=30
#| | call ANVarCreateD : url=<diffusion_6.nc@x>, xtype=<>, length=<30>
#| | | call ANFileOpen : writable=yes overwrite=yes file=diffusion_6.nc
 *** MESSAGE [ANFileOpen] ***  diffusion_6.nc is overwritten.
#| | | end ANFileOpen : id=4 stat=0
#| | |-anfiledefinemode 4
#| | |-an_vartable.add: added 1
#| | end ANVarCreateD : stat=0
#| |-[gt_variable 1: ndims=1, map.size=1]
#| |-[dim1 dimno=1 ofs=0 step=1 all=30 start=1 count=30 stride=1 url=]
#| |-[vartable 1: class=netcdf cid=1 ref=1]
#| |-[AN_VARIABLE(file=4, var=1, dim=1)]
#| end GTVarCreateD : class=netcdf mapid=1

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

use dc_trace
Access dc_trace module. This statement is located at the beginning of main program. In this case, ONLY option is used.
SetDebug
Turn on debug mode. By calling this subroutine, DbgMessage, BeginSub, and EndSub subroutines of dc_trace module can be used.
DbgMessage(fmt, [i], [r], [d], [L], [n], [c1], [c2], [c3], [ca])

Dump string given as argument fmt on standard error out when SetDebug subroutine is called. The argument fmt can include variables which are specified by corresponding type optional arguments.

Descriptions of each argument are as follows.


$Id: dc_trace.rd,v 1.4 2007/08/31 05:13:19 odakker2 Exp $
Gtool4 Development Group / GFD Dennou Staff dcstaff@gfd-dennou.org