Return a multiline string with a standard header of the form:
Created by GS2 at 2021-02-02T15:01:26.370Z+00:00
Run UUID: 36310A48-6A73-4941-9366-410C5731027A
"fedora": ubuntu
Compiler: gfortran
<optional file description>
If \p comment_character is passed, it is prepended to the start of each line. Note that it is used as-is, including any whitespace.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(standard_header_type), | intent(in) | :: | this | |||
character(len=*), | intent(in), | optional | :: | comment_character |
Optional character(s) to start each line. Whitespace is not stripped or added. Default is empty string |
|
character(len=*), | intent(in), | optional | :: | file_description |
Optional file description. Treated as a single line, that is, new lines in this string will not begin with comment_character |
function standard_header_to_string(this, comment_character, file_description) result(header)
use runtime_tests, only: runtime_info
use git_version_mod, only: get_git_version
use build_config, only: gs2_build_tag
use optionals, only: get_option_with_default
character(:), allocatable :: header
class(standard_header_type), intent(in) :: this
!> Optional character(s) to start each line. Whitespace is not
!> stripped or added. Default is empty string
character(*), optional, intent(in) :: comment_character
!> Optional file description. Treated as a single line, that is,
!> new lines in this string will not begin with
!> [[comment_character]]
character(*), optional, intent(in) :: file_description
! Actual comment character to use, may be empty
character(:), allocatable :: comment_char
! Note that description_line will contain the comment character if
! present
character(:), allocatable :: description_line
! A literal new line `\n`, because Fortran
character(*), parameter :: newline = new_line('a')
comment_char = get_option_with_default(comment_character, "")
description_line = get_option_with_default(file_description, "")
if (len_trim(description_line) > 0) then
! If we add more lines to the header, we should add a newline here
description_line = comment_char // description_line
end if
header = comment_char // "Created by GS2 at " // this%date_time // newline &
// comment_char // "GS2 version: " // get_git_version() // newline &
// comment_char // "Run UUID: " // this%run_uuid // newline &
// comment_char // "GK_SYSTEM: " // trim(runtime_info%get_gk_system()) // newline &
// comment_char // "Compiler: " // trim(runtime_info%get_compiler_name()) // newline &
// comment_char // "Build tag: " // gs2_build_tag // newline &
// description_line
end function standard_header_to_string