Open an output file to write (appending if existing) whose name is
<run_name>.<ext>
, and set unit
to the unit number of that
output file. If the optional run_name_in
variable is present, this
replaces run_name as the root of the output file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | unit |
Unit number of opened file, in append mode |
||
character(len=*), | intent(in) | :: | ext |
File extension to open, appended to run_name |
||
character(len=*), | intent(in), | optional | :: | run_name_in |
Optional root name for the output file. If not specified, run_name is used as the root. |
subroutine append_output_file (unit, ext, run_name_in)
use optionals, only: get_option_with_default
implicit none
!> Unit number of opened file, in append mode
integer, intent (out) :: unit
!> File extension to open, appended to [[file_utils:run_name]]
character (*), intent (in) :: ext
!> Optional root name for the output file. If not specified,
!> [[file_utils:run_name]] is used as the root.
character (*), intent (in), optional :: run_name_in
character(run_name_size) :: file_name
logical :: exists
call get_unused_unit (unit)
file_name = trim(get_option_with_default(run_name_in, run_name)) // ext
inquire(file=file_name, exist=exists)
if (exists) then
open (unit=unit, file=trim(file_name), status="old", position="append", action="write")
else
open (unit=unit, file=trim(file_name), status="new", action="write")
end if
end subroutine append_output_file