gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dc_trace Module Reference

デバッグ時の追跡用モジュール More...

Data Types

interface  debug
interface  datadump

Functions/Subroutines

integer function, public sublevel ()
subroutine, public dbg_scratch (on)
subroutine, public setdebug (debug)
subroutine, public beginsub (name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
subroutine, public endsub (name, fmt, i, r, d, l, n, c1, c2, c3, ca)
subroutine, public dbgmessage (fmt, i, r, d, l, n, c1, c2, c3, ca)

Variables

integer, save, public dbg = -1

Detailed Description

デバッグ時の追跡用モジュール

Author
Yasuhiro MORIKAWA, Eizi TOYODA

dc_trace はデバッグ時の原因の追跡を補助するためのサブルーチン群 を持つモジュールです。このモジュールを利用する事で、 以下のようにサブルーチンの階層構造がそのまま分かるような デバッグメッセージを出力する事が可能です。

:
#call HistoryPut0
#| call HistoryPutEx : time
#| | call TimeGoAhead : varname=time head=1.
#| | | call lookup_dimension
#| | | | call gtvarinquire : var.mapid=1
#| | | | | call gdncvarinqurie : var.id=1
#| | | | | end gdncvarinqurie : ok
#| | | | |-name=time
#| | | | end gtvarinquire
#| | | end lookup_dimension : ord=1
#| | end TimeGoAhead
#| end HistoryPutEx
#end HistoryPut0
:

手続一覧

手続名 説明
SetDebug デバッグモードをオンオフ
BeginSub 副プログラム開始のメッセージ出力
EndSub 副プログラム終了のメッセージ出力
DbgMessage デバッグ用メッセージ出力
DataDump 多次元データ出力

使用方法

副プログラムの実行文の先頭と最後で BeginSub と EndSub を使用します。

subroutine testroutine(file, var, times, url)
use dc_types, only: string
use dc_trace, only: beginsub, endsub
character(*), intent(in) :: file, var
integer, intent(in) :: times
character(*), intent(out):: url
character(STRING), parameter:: subname =
continue
call beginsub(subname, 'file=%c, var=%c, times=%d', &
& c1=trim(file), c2=trim(var), i=(/times/) )
url = trim(file) // trim(var)
call endsub(subname, 'url=%c', c1=trim(url) )
end subroutine TestRoutine
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:457
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:580
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137

主プログラムの実行文の先頭で SetDebug を使用します。

program main
use dc_trace, only: setdebug
continue
call setdebug
call testroutine(...)
end program main
subroutine, public setdebug(debug)
Definition dc_trace.f90:336
Note
BeginSub よりも前に SetDebug が呼ばれている必要があります。
BeginSub と同じ回数だけ EndSub が呼ばれていなければなりません。

Function/Subroutine Documentation

◆ beginsub()

subroutine, public dc_trace::beginsub ( character(*), intent(in) name,
character(*), intent(in), optional fmt,
integer, dimension(:), intent(in), optional i,
real, dimension(:), intent(in), optional r,
real(dp), dimension(:), intent(in), optional d,
logical, dimension(:), intent(in), optional l,
integer, dimension(:), intent(in), optional n,
character(*), intent(in), optional c1,
character(*), intent(in), optional c2,
character(*), intent(in), optional c3,
character(*), dimension(:), intent(in), optional ca,
character(*), intent(in), optional version )

副プログラム開始のメッセージ出力

文字型変数 name に与えた副プログラム名を以下のように出力します。

# call name

複数回呼ぶ事で階層構造が分かるメッセージが出力されます (dc_trace の Overview 参照)。 必ず BeginSub と同様な数だけ EndSub を呼ぶようにしてください。

fmt およびそれ以降の引数を与える事で、付加メッセージも出力可能です:

# call name : fmt

書式は dc_string::CPrintf を参照して下さい。

version には副プログラムのバージョンナンバーを与えます。 version に与えられた文字列は、初回に呼び出された時のみ表示されます。

Note
このサブルーチンにより内部変数 level の値が 1 増えます。
Parameters
[in]name副プログラム名
[in]fmt付加メッセージ用フォーマット文字列 (省略可)
[in]iフォーマット用整数配列
[in]rフォーマット用実数配列
[in]dフォーマット用倍精度実数配列
[in]Lフォーマット用論理配列
[in]nフォーマット用整数配列
[in]c1フォーマット用文字列1
[in]c2フォーマット用文字列2
[in]c3フォーマット用文字列3
[in]caフォーマット用文字列配列
[in]version副プログラムのバージョンナンバー (省略可)

Definition at line 455 of file dc_trace.f90.

457 use dc_types, only: string, dp
458 use dc_string, only: cprintf, strinclude
459 character(*), intent(in) :: name
460 character(*), intent(in), optional:: fmt
461 integer, intent(in), optional:: i(:), n(:)
462 real, intent(in), optional:: r(:)
463 real(DP), intent(in), optional:: d(:)
464 logical, intent(in), optional:: L(:)
465 character(*), intent(in), optional:: c1, c2, c3
466 character(*), intent(in), optional:: ca(:)
467 character(*), intent(in), optional:: version
468 character(STRING) :: cbuf
469 character(STRING) :: name_ver
470 logical :: dbg_mode, print_version
471 integer :: alloc_size
472 continue
473 if ( dbg < 0 ) return
474 if (lfirst) call initialize
475 call debug( dbg_mode )
476 if ( dbg_mode ) then
477 name_ver = name
478 print_version = .false.
479 !---------------------------------
480 ! Print Version check
481 if (present(version)) then
482 if (.not. allocated(called_subname)) then
483 allocate(called_subname(1))
484 called_subname(1) = name
485 print_version = .true.
486 else
487 if (.not. strinclude(called_subname, trim(name))) then
488 alloc_size = size(called_subname)
489 allocate(called_subname_tmp(alloc_size))
490 called_subname_tmp = called_subname
491 deallocate(called_subname)
492 allocate(called_subname(alloc_size + 1))
493 called_subname(1:alloc_size) = called_subname_tmp
494 deallocate(called_subname_tmp)
495 called_subname(alloc_size + 1) = name
496 print_version = .true.
497 end if
498 end if
499 if (print_version) then
500 name_ver = cprintf('%c version=<%c>', &
501 & c1=trim(name), c2=trim(version))
502 end if
503 end if
504 !---------------------------------
505 ! Print Debug message
506 if (present(fmt)) then
507 cbuf = cprintf(fmt, i, r, d, l, n, c1, c2, c3, ca)
508 write(dbg, "(A, A, 'call ', A, ' : ', A)") trim(head), &
509 & repeat(indent, level), trim(name_ver), trim(cbuf)
510 else
511 write(dbg, "(A, A, 'call ',A)") trim(head), &
512 & repeat(indent, level), trim(name_ver)
513 endif
514 endif
515 ! call errtra ! --- for Fujitsu debug
516 if (level > size(table)) return
517 level = level + 1
518 table(level) = name
文字型変数の操作
Definition dc_string.f90:83
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92

References dbg, dc_types::dp, and dc_types::string.

◆ dbg_scratch()

subroutine, public dc_trace::dbg_scratch ( logical, intent(in) on)

デバッグメッセージの抹消

動作未確認ですので利用の際にはご注意下さい。

論理型変数 on に .true. を与える事で、 以降のデバッグメッセージを抹消する事が出来ます。

なお、論理型変数 on に .false. を与える事で、 直前に呼んだ Dbg_Scratch 以降のメッセージを デバッグメッセージとして再び出力し、 以降のデバッグメッセージも出力されるようにします。

Parameters
[in]on.true. の場合、以降のデバッグメッセージを抹消する。 .false. の場合、抹消されたメッセージを出力し、通常出力を再開する。

Definition at line 233 of file dc_trace.f90.

234 logical, intent(in):: on
235 integer, save:: saved_dbg = -1
236 logical:: x, p
237 character(80):: line
238 integer:: ios
239 continue
240 if (on) then
241 if (dbg < 0) return
242 saved_dbg = dbg
243 ! 有効な 1 〜 99 の装置番号の内の大きめの値を設定 (?)
244 dbg = 98
245 do
246 inquire(unit=dbg, exist=x, opened=p)
247 ! 装置番号 dbg が接続可能で、かつ未接続の場合
248 if (x .and. .not. p) then
249 ! 装置番号 deg をスクラッチファイルとして開く。
250 ! ※ スクラッチファイルとは、特殊な外部ファイルである。
251 ! これは名前なしの一時ファイルであり、開いている
252 ! 間だけ存在する。つまり、プログラムが終了すると
253 ! 存在しなくなる。
254 open(unit=dbg, status='SCRATCH')
255 ! 開く事が出来ればそれで終了。
256 return
257 endif
258 ! 装置番号 dbg が利用不可、または利用済の場合は 0 以下に
259 ! なるまで dbg - 1 して繰り返す。
260 dbg = dbg - 1
261 if (dbg < 0) exit
262 enddo
263 ! 装置番号 dbg が開けない場合、dbg と saved_dbg を初期化
264 dbg = saved_dbg
265 saved_dbg = -1
266 else
267 ! 以前に装置番号 dbg = 98〜0 でスクラッチファイルを開けてい
268 ! なければそれで終了
269 if (saved_dbg < 0) return
270 ! 装置番号 dbg に接続されたスクラッチファイルをその開始位置
271 ! に位置付ける。エラーが生じたら「100 continue」へ
272 rewind(dbg, err=100)
273 do
274 ! 装置番号 dbg に接続されたスクラッチファイルの一行を
275 ! line へ
276 read(dbg, '(A)', iostat=ios) line
277 if (ios /= 0) exit
278 ! line を装置番号 saved_dbg へ書き出す。
279 write(saved_dbg, '(A)', iostat=ios) trim(line)
280 if (ios /= 0) exit
281 enddo
282 100 continue
283 close(dbg, iostat=ios)
284 ! 最後に dbg と saved_dbg を初期化
285 dbg = saved_dbg
286 saved_dbg = -1
287 endif

References dbg.

◆ dbgmessage()

subroutine, public dc_trace::dbgmessage ( character(*), intent(in) fmt,
integer, dimension(:), intent(in), optional i,
real, dimension(:), intent(in), optional r,
real(dp), dimension(:), intent(in), optional d,
logical, dimension(:), intent(in), optional l,
integer, dimension(:), intent(in), optional n,
character(*), intent(in), optional c1,
character(*), intent(in), optional c2,
character(*), intent(in), optional c3,
character(*), dimension(:), intent(in), optional ca )

デバッグ用メッセージ出力

フォーマット文字列 fmt に従ってデバッグメッセージを出力します。 書式は dc_string::CPrintf を参照して下さい。

利用例に関しては dc_trace の Example を参照して下さい。

Note
このサブルーチンを用いても内部変数 level の値は変化しません。
Parameters
[in]fmtフォーマット文字列
[in]iフォーマット用整数配列
[in]rフォーマット用実数配列
[in]dフォーマット用倍精度実数配列
[in]Lフォーマット用論理配列
[in]nフォーマット用整数配列
[in]c1フォーマット用文字列1
[in]c2フォーマット用文字列2
[in]c3フォーマット用文字列3
[in]caフォーマット用文字列配列

Definition at line 660 of file dc_trace.f90.

661 use dc_types, only: string, dp
662 use dc_string, only: cprintf, tochar
663 character(*), intent(in) :: fmt
664 integer, intent(in), optional:: i(:), n(:)
665 real, intent(in), optional:: r(:)
666 real(DP), intent(in), optional:: d(:)
667 logical, intent(in), optional:: L(:)
668 character(*), intent(in), optional:: c1, c2, c3
669 character(*), intent(in), optional:: ca(:)
670 character(STRING):: cbuf
671 character(STRING):: meshead_tmp
672 integer :: meshead_len
673 continue
674 if ( dbg < 0 ) return
675 cbuf = cprintf(fmt, i, r, d, l, n, c1, c2, c3, ca)
676 if (level < 1) then
677 meshead_tmp = ''
678 meshead_len = 0
679 else
680 meshead_tmp = meshead
681 meshead_len = len(meshead)
682 endif
683 write(dbg, "(A, A, A, A)") &
684 & trim(head), repeat( indent, max(level-1, 0) ), &
685 & meshead_tmp(1:meshead_len), trim(cbuf)

References dbg, dc_types::dp, and dc_types::string.

◆ endsub()

subroutine, public dc_trace::endsub ( character(*), intent(in) name,
character(*), intent(in), optional fmt,
integer, dimension(:), intent(in), optional i,
real, dimension(:), intent(in), optional r,
real(dp), dimension(:), intent(in), optional d,
logical, dimension(:), intent(in), optional l,
integer, dimension(:), intent(in), optional n,
character(*), intent(in), optional c1,
character(*), intent(in), optional c2,
character(*), intent(in), optional c3,
character(*), dimension(:), intent(in), optional ca )

副プログラム終了のメッセージ出力

文字型変数 name に与えた副プログラム名を以下のように出力します。

# end name

BeginSub に対して一対一対応していますので、name には対応する BeginSub の引数 name と同じものを与えて下さい。

fmt およびそれ以降の引数を与える事で、付加メッセージも出力可能です:

# end name fmt

書式は dc_string::CPrintf を参照して下さい。

Note
このサブルーチンにより内部変数 level の値が 1 減ります。
Parameters
[in]name副プログラム名
[in]fmt付加メッセージ用フォーマット文字列 (省略可)
[in]iフォーマット用整数配列
[in]rフォーマット用実数配列
[in]dフォーマット用倍精度実数配列
[in]Lフォーマット用論理配列
[in]nフォーマット用整数配列
[in]c1フォーマット用文字列1
[in]c2フォーマット用文字列2
[in]c3フォーマット用文字列3
[in]caフォーマット用文字列配列

Definition at line 579 of file dc_trace.f90.

580 use dc_types, only: dp
581 use dc_string, only: cprintf
582 character(*), intent(in) :: name
583 character(*), intent(in), optional:: fmt
584 integer, intent(in), optional:: i(:), n(:)
585 real, intent(in), optional:: r(:)
586 real(DP), intent(in), optional:: d(:)
587 logical, intent(in), optional:: L(:)
588 character(*), intent(in), optional:: c1, c2, c3
589 character(*), intent(in), optional:: ca(:)
590 character(STRING):: cbuf
591 logical:: debug_mode
592 continue
593 if ( dbg < 0 ) return
594 if (lfirst) call initialize
595 ! call errtra ! --- for Fujitsu debug
596 if (level <= 0) then
597 write(*, "(A, 'Warning EndSub[',A,'] without BeginSub')") &
598 & trim(head), trim(name)
599 else if (name /= table(level)) then
600 write(*, "(A, 'Warning EndSub[',A,'] but tos[',A,']')") &
601 & trim(head), trim(name), trim(table(level))
602 else
603 level = level - 1
604 endif
605 call debug( debug_mode )
606 if ( debug_mode ) then
607 if (present(fmt)) then
608 cbuf = cprintf(fmt, i, r, d, l, n, c1, c2, c3, ca)
609 write(dbg, "(A, A, 'end ', A, ' : ', A)") trim(head), &
610 & repeat(indent, level), trim(name), trim(cbuf)
611 else
612 write(dbg, "(A, A, 'end ', A)") trim(head), &
613 & repeat(indent, level), trim(name)
614 endif
615 endif

References dbg, and dc_types::dp.

◆ setdebug()

subroutine, public dc_trace::setdebug ( integer, intent(in), optional debug)

デバッグモードをオンオフ

デバッグメッセージを出力したい時にこのサブルーチンを呼びます。

整数型変数 debug が与えられる場合は、その装置番号 debug に、 以降のサブルーチンによるデバッグメッセージを出力するようにします。 debug が与えられない場合、装置番号 0 (標準エラー出力) にデバッグメッセージが出力されるようになります。 装置番号 0 への出力が成功しない場合は代わりに 装置番号 6 (標準出力) にデバッグメッセージが出力されるようになります。

debug に負の整数を与える場合、デバッグモードが解除され、 以降デバッグメッセージは出力されません。

なお、この SetDebug を呼んだ際にも、装置番号 debug に以下のメッセージが表示されます。

#SetDebug: dbg = debug
Parameters
[in]debugデバッグメッセージ出力用の装置番号 (省略可)。 省略時は標準エラー出力を使用。負の値を与えるとデバッグモード解除。

Definition at line 335 of file dc_trace.f90.

336 use dc_types, only: stdout, stderr
337 implicit none
338 integer, intent(in), optional:: debug
339 integer:: ios
340 continue
341 if (present(debug)) then
342 ! debug が与えられる時は装置番号として deg を用いる。
343 dbg = debug
344 write(dbg, "(A, 'SetDebug: dbg =', i4)", iostat=ios) &
345 & trim(head), dbg
346 if (ios == 0) return
347 else
348 ! debug が与えられ無い時は装置番号 0 (標準エラー出力)
349 dbg = stderr
350 write(dbg, "(A, 'SetDebug: dbg = ', I0)", iostat=ios) trim(head), dbg
351 if (ios == 0) return
352 ! 装置番号 0 への出力が失敗したら装置番号 6 (標準出力)
353 dbg = stdout
354 write(dbg, "(A, 'SetDebug: dbg = ', I0)", iostat=ios) trim(head), dbg
355 if (ios == 0) return
356 endif
357 ! 例外処理として dbg の初期化
358 dbg = -1
integer, parameter, public stdout
標準出力の装置番号
Definition dc_types.f90:117
integer, parameter, public stderr
標準エラー出力の装置番号
Definition dc_types.f90:122

References dbg, dc_types::stderr, and dc_types::stdout.

◆ sublevel()

integer function, public dc_trace::sublevel

副プログラムの階層レベルを返す

副プログラムの階層レベルを返します。レベルのデフォルトは 0 で、 BeginSub によりレベルは 1 増え、EndSub によりレベルは 1 減ります。

Returns
副プログラムの階層レベル

Definition at line 198 of file dc_trace.f90.

199 result = level

Variable Documentation

◆ dbg

integer, save, public dc_trace::dbg = -1

Definition at line 156 of file dc_trace.f90.

156 integer, save, public :: dbg = -1 ! SetDebug で設定された