timer_write Subroutine

private impure subroutine timer_write(this, file_name)

Writes the elapsed 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~~timer_write~~CalledByGraph proc~timer_write timer%timer_write program~example2 example2 program~example2->proc~timer_write program~test14 test14 program~test14->proc~timer_write program~test15 test15 program~test15->proc~timer_write program~test2 test2 program~test2->proc~timer_write program~test3 test3 program~test3->proc~timer_write

Source Code

   impure subroutine timer_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 elapsed time to the file
      write(nunit, '(g0)') this%elapsed_time

      ! Close the file
      close(nunit)

   end subroutine timer_write