ctimer_write Subroutine

private impure subroutine ctimer_write(this, file_name)

Writes the CPU time to a file.

Type Bound

timer

Arguments

Type IntentOptional Attributes Name
class(timer), intent(in) :: this
character(len=*), intent(in) :: file_name

Called by

proc~~ctimer_write~~CalledByGraph proc~ctimer_write timer%ctimer_write program~example4 example4 program~example4->proc~ctimer_write program~test17 test17 program~test17->proc~ctimer_write program~test18 test18 program~test18->proc~ctimer_write program~test5 test5 program~test5->proc~ctimer_write program~test6 test6 program~test6->proc~ctimer_write

Source Code

   impure subroutine ctimer_write(this, file_name)
      class(timer), intent(in) :: this
      character(*), intent(in) :: file_name
      logical                  :: file_exists
      integer                  :: nunit

      ! Check if the file exists
      inquire(file=file_name, exist=file_exists)

      ! Open the file in appropriate mode
      if (file_exists) then
         open(newunit=nunit, file=file_name, status='old', action='write', position='append')
      else
         open(newunit=nunit, file=file_name, status='new', action='write')
      end if

      ! Write the CPU time to the file
      write(nunit, '(g0)') this%cpu_time

      ! Close the file
      close(nunit)

   end subroutine ctimer_write