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.
| Type | Intent | Optional | 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. |
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