Class logfile_class
In: LatticeClass/logfile_class.F90
lattice_class file_tools_class error_class logfile_class dot/f_247.png

Logfile class

Defines log files

Logging is done only by master node (nodeid=0)

Version

$Id: logfile_class.F90,v 1.10 2011/06/14 11:10:12 ishikawa Exp $

Methods

delete   get_file_unit   is_open   logfile   new   print   print  

Included Modules

lattice_class file_tools_class error_class

Public Instance methods

Subroutine :
this :type(logfile), intent(inout)

delete logger object and close log file

  • this : logfile
  • fname : logging output file name

[Source]

subroutine delete_log(this)
!
! delete logger object and close log file
!
! -  this : logfile
! - fname : logging output file name 
!
  implicit none
  type(logfile), intent(inout) :: this
  logical :: is_opened
  character(len=CHARLEN) :: cdate,ctime,czone,str
  character(len=CHARLEN) :: fname

  if (0 == nodeid) then
    if (this%is_opened) then

      cdate = REPEAT(' ',LEN(cdate))
      ctime = REPEAT(' ',LEN(ctime))
      czone = REPEAT(' ',LEN(czone))

      INQUIRE(this%iout,opened=is_opened)
      if (is_opened) then
        call DATE_AND_TIME(DATE=cdate,TIME=ctime,ZONE=czone)
        write(this%iout,'("# ",A,1X,A,1X,A," : log_close : iout=",I3," fname= ",A)') TRIM(ADJUSTL(cdate)), TRIM(ADJUSTL(ctime)), TRIM(ADJUSTL(czone)), this%iout,TRIM(ADJUSTL(this%fname))
        close(this%iout)
      endif
    endif
  endif

  this%fname = REPEAT(' ',LEN(this%fname))
  this%is_opened = .false.
  this%iout = DEFAULT_IO_UNIT
  this%id = 0

  return
end subroutine
Function :
unit :integer
this :type(logfile), intent(in)

[Source]

function get_file_unit_log(this) result(unit)
  implicit none
  type(logfile), intent(in) :: this
  integer :: unit
  unit = this%iout
  return
end function
Function :
is_open :logical
this :type(logfile), intent(in)

[Source]

function is_open_log(this) result(is_open)
  implicit none
  type(logfile), intent(in) :: this
  logical :: is_open
  is_open = this%is_opened
  return
end function
logfile
Derived Type :

logger object

Subroutine :
this :type(logfile), intent(inout)
fname :character(len=*), intent(in)

Initialize logger object and open log file

  • this : logfile
  • fname : logging output file name

[Source]

subroutine new_log(this,fname)
!
! Initialize logger object and open log file
!
! -  this : logfile
! - fname : logging output file name 
!
  implicit none
  type(logfile), intent(inout) :: this
  character(len=*), intent(in)     :: fname

  this%fname = TRIM(ADJUSTL(fname))

  return
end subroutine
Subroutine :
this :type(logfile), intent(inout)
str :character(len=*), intent(in)

print log in log file

  • this : logfile
  • str : logging strings

[Source]

subroutine print_log(this,str)
!
! print log in log file
!
! - this : logfile
! - str  : logging strings
!
  implicit none
  type(logfile), intent(inout) :: this
  character(len=*), intent(in) :: str
  character(len=CHARLEN) :: id_str
  character(len=CHARLEN) :: cdate,ctime,czone,fname
  logical :: is_opened
  integer :: i

  fname = this%fname

  if (0 == nodeid) then
  if (.not.this%is_opened) then

    cdate = REPEAT(' ',LEN(cdate))
    ctime = REPEAT(' ',LEN(ctime))
    czone = REPEAT(' ',LEN(czone))

    !
    ! assign free file io unit
    !
    this%iout = search_free_file_unit()

    !-------------------------
    ! inquire by file name
    !-------------------------
    INQUIRE(file=TRIM(fname),opened=is_opened)
    if (is_opened) then
      !
      ! fname is already opened. 
      !
      ! new file name is assigned with requested fname + id number
      !
      this%id = this%id + 1
      write(id_str,'(".",I2.2)')this%id
      this%fname = TRIM(ADJUSTL(fname))//TRIM(id_str)
    else
      !
      ! fname is not opeend.
      !
      ! file name is assigned by requested fname
      !
      this%fname = TRIM(ADJUSTL(fname))
    endif

    call DATE_AND_TIME(DATE=cdate,TIME=ctime,ZONE=czone)
    open(this%iout,file=this%fname,status='unknown',form='formatted')
    write(this%iout,'("# ",A,1X,A,1X,A," : log_open : iout=",I3," fname= ",A)') TRIM(ADJUSTL(cdate)), TRIM(ADJUSTL(ctime)), TRIM(ADJUSTL(czone)), this%iout,TRIM(ADJUSTL(this%fname))
    this%is_opened = .true.
  endif
  endif

  if (0 == nodeid) then
    if (this%is_opened) then
      write(this%iout,'(A)')TRIM(str)
    else
      write(*,'(A)')"# Logging file is closed."
      write(*,'(A)')"# fname : "//TRIM(this%fname)
      write(*,'(A)')"# state : "//TRIM(str)
      call error_stop("")
    endif
  endif

  return
end subroutine
Subroutine :
this :type(logfile), intent(inout)
str(:) :character(len=*), intent(in)

print log in log file

  • this : logfile
  • str : logging strings

[Source]

subroutine print_log_array(this,str)
!
! print log in log file
!
! - this : logfile
! - str  : logging strings
!
  implicit none
  type(logfile), intent(inout) :: this
  character(len=*), intent(in) :: str(:)
  integer :: is,ns

  ns = SIZE(str)
  do is=1,ns
    call print_log(this,str(is))
  enddo

  return
end subroutine