write_to_file Subroutine

private subroutine write_to_file(time, file_name)

This internal helper opens an existing file in append mode or creates a new file, writes one timing value using g0 formatting, and reports file I/O errors through error_unit.

Arguments

Type IntentOptional Attributes Name
real(kind=rk), intent(in) :: time

Timing value in seconds to write.

character(len=*), intent(in) :: file_name

Path to the output text file.


Called by

proc~~write_to_file~~CalledByGraph proc~write_to_file write_to_file proc~ctimer_write timer%ctimer_write proc~ctimer_write->proc~write_to_file proc~dtimer_write timer%dtimer_write proc~dtimer_write->proc~write_to_file proc~timer_write timer%timer_write proc~timer_write->proc~write_to_file proc~run_test14 run_test14 proc~run_test14->proc~timer_write proc~run_test15 run_test15 proc~run_test15->proc~timer_write proc~run_test17 run_test17 proc~run_test17->proc~ctimer_write proc~run_test18 run_test18 proc~run_test18->proc~ctimer_write proc~run_test2 run_test2 proc~run_test2->proc~timer_write proc~run_test26 run_test26 proc~run_test26->proc~dtimer_write proc~run_test27 run_test27 proc~run_test27->proc~dtimer_write proc~run_test29 run_test29 proc~run_test29->proc~dtimer_write proc~run_test3 run_test3 proc~run_test3->proc~timer_write proc~run_test30 run_test30 proc~run_test30->proc~dtimer_write proc~run_test5 run_test5 proc~run_test5->proc~ctimer_write proc~run_test6 run_test6 proc~run_test6->proc~ctimer_write program~example2 example2 program~example2->proc~timer_write program~example4 example4 program~example4->proc~ctimer_write program~example6 example6 program~example6->proc~dtimer_write program~check check program~check->proc~run_test14 program~check->proc~run_test15 program~check->proc~run_test17 program~check->proc~run_test18 program~check->proc~run_test2 program~check->proc~run_test26 program~check->proc~run_test27 program~check->proc~run_test29 program~check->proc~run_test3 program~check->proc~run_test30 program~check->proc~run_test5 program~check->proc~run_test6

Source Code

   subroutine write_to_file(time, file_name)
      real(rk), intent(in) :: time
         !! Timing value in seconds to write.
      character(*), intent(in) :: file_name
         !! Path to the output text file.

      character(len=:), allocatable :: fname
         !! Trimmed output file path.
      logical :: file_exists
         !! True when `fname` already exists.
      integer :: nunit
         !! Scratch unit number assigned by `open(newunit=...)`.
      integer :: ios
         !! I/O status code returned by file operations.
      character(len=256) :: iomsg
         !! Diagnostic message returned by file I/O operations.

      fname = trim(file_name)
      inquire(file=fname, exist=file_exists)

      if (file_exists) then
         open(newunit=nunit, file=fname, status='old', action='write', position='append', iostat=ios, iomsg=iomsg)
      else
         open(newunit=nunit, file=fname, status='new', action='write', iostat=ios, iomsg=iomsg)
      end if

      if (ios /= 0) then
         write(error_unit, '(A)') 'Error opening file: ' // fname // ' : ' // trim(iomsg)
         return
      end if

      write(nunit, '(g0)', iostat=ios, iomsg=iomsg) time
      if (ios /= 0) then
         write(error_unit, '(A)') 'Error writing file: ' // fname // ' : ' // trim(iomsg)
      end if

      close(nunit)
   end subroutine write_to_file