gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Data Types | Functions/Subroutines | Variables
dc_trace Module Reference

Debug tracing module. More...

Data Types

interface  datadump
 
interface  debug
 

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

Debug tracing module.

Author
Yasuhiro MORIKAWA, Eizi TOYODA

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 
)

Output subprogram start message

Outputs the subprogram name given to name as follows:

# call name

By calling multiple times, messages are output showing the hierarchical structure (see dc_trace Overview). Make sure to call EndSub the same number of times as BeginSub.

Additional messages can be output by providing fmt and subsequent arguments:

# call name : fmt

See dc_string::CPrintf for format specification.

The version argument specifies the version number of the subprogram. The version string is displayed only on the first call of a subprogram.

Parameters
[in]nameSubprogram name
[in]fmtFormat string for additional message (optional)
[in]iInteger array for formatting
[in]rReal array for formatting
[in]dDouble precision array for formatting
[in]LLogical array for formatting
[in]nInteger array for formatting
[in]c1Character string 1 for formatting
[in]c2Character string 2 for formatting
[in]c3Character string 3 for formatting
[in]caCharacter array for formatting
[in]versionVersion number of the subprogram (optional)

Definition at line 474 of file dc_trace.f90.

476 use dc_types, only: string, dp
477 use dc_string, only: cprintf, strinclude
478 character(*), intent(in) :: name
479 character(*), intent(in), optional:: fmt
480 integer, intent(in), optional:: i(:), n(:)
481 real, intent(in), optional:: r(:)
482 real(DP), intent(in), optional:: d(:)
483 logical, intent(in), optional:: L(:)
484 character(*), intent(in), optional:: c1, c2, c3
485 character(*), intent(in), optional:: ca(:)
486 character(*), intent(in), optional:: version
487 character(STRING) :: cbuf
488 character(STRING) :: name_ver
489 logical :: dbg_mode, print_version
490 integer :: alloc_size
491 continue
492 if ( dbg < 0 ) return
493 if (lfirst) call initialize
494 call debug( dbg_mode )
495 if ( dbg_mode ) then
496 name_ver = name
497 print_version = .false.
498 !---------------------------------
499 ! Print Version check
500 if (present(version)) then
501 if (.not. allocated(called_subname)) then
502 allocate(called_subname(1))
503 called_subname(1) = name
504 print_version = .true.
505 else
506 if (.not. strinclude(called_subname, trim(name))) then
507 alloc_size = size(called_subname)
508 allocate(called_subname_tmp(alloc_size))
509 called_subname_tmp = called_subname
510 deallocate(called_subname)
511 allocate(called_subname(alloc_size + 1))
512 called_subname(1:alloc_size) = called_subname_tmp
513 deallocate(called_subname_tmp)
514 called_subname(alloc_size + 1) = name
515 print_version = .true.
516 end if
517 end if
518 if (print_version) then
519 name_ver = cprintf('%c version=<%c>', &
520 & c1=trim(name), c2=trim(version))
521 end if
522 end if
523 !---------------------------------
524 ! Print Debug message
525 if (present(fmt)) then
526 cbuf = cprintf(fmt, i, r, d, l, n, c1, c2, c3, ca)
527 write(dbg, "(A, A, 'call ', A, ' : ', A)") trim(head), &
528 & repeat(indent, level), trim(name_ver), trim(cbuf)
529 else
530 write(dbg, "(A, A, 'call ',A)") trim(head), &
531 & repeat(indent, level), trim(name_ver)
532 endif
533 endif
534 ! call errtra ! --- for Fujitsu debug
535 if (level > size(table)) return
536 level = level + 1
537 table(level) = name
Handling character types.
Definition dc_string.f90:83
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92
integer, parameter, public string
Character length for string
Definition dc_types.f90:137

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

◆ dbg_scratch()

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

Erase debug messages

Operation has not been confirmed. Please use with caution.

By giving .true. to the logical variable on, subsequent debug messages can be erased.

By giving .false. to the logical variable on, messages since the previous Dbg_Scratch call will be output as debug messages again, and subsequent debug messages will also be output.

Parameters
[in]onIf .true., erase subsequent debug messages. If .false., output erased messages and resume normal output.

Definition at line 237 of file dc_trace.f90.

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

Output debug message

Outputs debug messages according to the format string fmt. See dc_string::CPrintf for format specification.

See dc_trace Example for usage examples.

Note
This subroutine does not change the internal variable level.
Parameters
[in]fmtFormat string
[in]iInteger array for formatting
[in]rReal array for formatting
[in]dDouble precision array for formatting
[in]LLogical array for formatting
[in]nInteger array for formatting
[in]c1Character string 1 for formatting
[in]c2Character string 2 for formatting
[in]c3Character string 3 for formatting
[in]caCharacter array for formatting

Definition at line 679 of file dc_trace.f90.

680 use dc_types, only: string, dp
681 use dc_string, only: cprintf, tochar
682 character(*), intent(in) :: fmt
683 integer, intent(in), optional:: i(:), n(:)
684 real, intent(in), optional:: r(:)
685 real(DP), intent(in), optional:: d(:)
686 logical, intent(in), optional:: L(:)
687 character(*), intent(in), optional:: c1, c2, c3
688 character(*), intent(in), optional:: ca(:)
689 character(STRING):: cbuf
690 character(STRING):: meshead_tmp
691 integer :: meshead_len
692 continue
693 if ( dbg < 0 ) return
694 cbuf = cprintf(fmt, i, r, d, l, n, c1, c2, c3, ca)
695 if (level < 1) then
696 meshead_tmp = ''
697 meshead_len = 0
698 else
699 meshead_tmp = meshead
700 meshead_len = len(meshead)
701 endif
702 write(dbg, "(A, A, A, A)") &
703 & trim(head), repeat( indent, max(level-1, 0) ), &
704 & 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 
)

Output subprogram end message

Outputs the subprogram name given to name as follows:

# end name

This corresponds one-to-one with BeginSub, so give the same name as the corresponding BeginSub argument.

Additional messages can be output by providing fmt and subsequent arguments:

# end name fmt

See dc_string::CPrintf for format specification.

Parameters
[in]nameSubprogram name
[in]fmtFormat string for additional message (optional)
[in]iInteger array for formatting
[in]rReal array for formatting
[in]dDouble precision array for formatting
[in]LLogical array for formatting
[in]nInteger array for formatting
[in]c1Character string 1 for formatting
[in]c2Character string 2 for formatting
[in]c3Character string 3 for formatting
[in]caCharacter array for formatting

Definition at line 598 of file dc_trace.f90.

599 use dc_types, only: dp
600 use dc_string, only: cprintf
601 character(*), intent(in) :: name
602 character(*), intent(in), optional:: fmt
603 integer, intent(in), optional:: i(:), n(:)
604 real, intent(in), optional:: r(:)
605 real(DP), intent(in), optional:: d(:)
606 logical, intent(in), optional:: L(:)
607 character(*), intent(in), optional:: c1, c2, c3
608 character(*), intent(in), optional:: ca(:)
609 character(STRING):: cbuf
610 logical:: debug_mode
611 continue
612 if ( dbg < 0 ) return
613 if (lfirst) call initialize
614 ! call errtra ! --- for Fujitsu debug
615 if (level <= 0) then
616 write(*, "(A, 'Warning EndSub[',A,'] without BeginSub')") &
617 & trim(head), trim(name)
618 else if (name /= table(level)) then
619 write(*, "(A, 'Warning EndSub[',A,'] but tos[',A,']')") &
620 & trim(head), trim(name), trim(table(level))
621 else
622 level = level - 1
623 endif
624 call debug( debug_mode )
625 if ( debug_mode ) then
626 if (present(fmt)) then
627 cbuf = cprintf(fmt, i, r, d, l, n, c1, c2, c3, ca)
628 write(dbg, "(A, A, 'end ', A, ' : ', A)") trim(head), &
629 & repeat(indent, level), trim(name), trim(cbuf)
630 else
631 write(dbg, "(A, A, 'end ', A)") trim(head), &
632 & repeat(indent, level), trim(name)
633 endif
634 endif

References dbg, and dc_types::dp.

◆ setdebug()

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

Turn debug mode on/off

Call this subroutine when you want to output debug messages.

If the integer variable debug is given, debug messages from subsequent subroutines will be output to that unit number. If debug is not given, debug messages will be output to unit number 0 (standard error output). If output to unit number 0 fails, debug messages will be output to unit number 6 (standard output) instead.

If a negative integer is given to debug, debug mode is disabled and no debug messages will be output.

When SetDebug is called, the following message is displayed:

#SetDebug: dbg = debug
Parameters
[in]debugUnit number for debug message output (optional). If not given, standard error output is used. If negative, debug mode is disabled.

Definition at line 339 of file dc_trace.f90.

340 use dc_types, only: stdout, stderr
341 implicit none
342 integer, intent(in), optional:: debug
343 integer:: ios
344 logical:: initflag_mpi
345 character(4):: myrank_str_mpi
346 integer:: myrank_mpi, err_mpi
347 continue
348 call mpi_initialized(initflag_mpi, err_mpi)
349 if ( initflag_mpi ) then
350 call mpi_comm_rank(mpi_comm_world, myrank_mpi, err_mpi)
351 if ( myrank_mpi > 9999 ) then
352 head = '#rOVER#'
353 else
354 write(unit=myrank_str_mpi, fmt="(i4.4)") myrank_mpi
355 head = '#r' // myrank_str_mpi // '#'
356 end if
357 else
358 head = '#'
359 end if
360 if (present(debug)) then
361 ! debug が与えられる時は装置番号として deg を用いる。
362 dbg = debug
363 write(dbg, "(A, 'SetDebug: dbg =', i4)", iostat=ios) &
364 & trim(head), dbg
365 if (ios == 0) return
366 else
367 ! debug が与えられ無い時は装置番号 0 (標準エラー出力)
368 dbg = stderr
369 write(dbg, "(A, 'SetDebug: dbg = ', I0)", iostat=ios) trim(head), dbg
370 if (ios == 0) return
371 ! 装置番号 0 への出力が失敗したら装置番号 6 (標準出力)
372 dbg = stdout
373 write(dbg, "(A, 'SetDebug: dbg = ', I0)", iostat=ios) trim(head), dbg
374 if (ios == 0) return
375 endif
376 ! 例外処理として dbg の初期化
377 dbg = -1
integer, parameter, public stdout
Unit number for Standard OUTPUT
Definition dc_types.f90:117
integer, parameter, public stderr
Unit number for Standard ERROR
Definition dc_types.f90:122

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

◆ sublevel()

integer function, public dc_trace::sublevel

Return the hierarchical level of subprograms

Returns the hierarchical level of subprograms. The default level is 0. The level increases by 1 with BeginSub and decreases by 1 with EndSub.

Returns
Hierarchical level of subprograms

Definition at line 202 of file dc_trace.f90.

203 result = level

Variable Documentation

◆ dbg

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

Definition at line 160 of file dc_trace.f90.

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