• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gyrokinetics / gs2 / 2021218321

04 Sep 2025 07:44AM UTC coverage: 10.606% (+0.03%) from 10.577%
2021218321

push

gitlab-ci

David Dickinson
Merged in feature/move_more_initialisation_to_init_levels (pull request #1161)

4710 of 44407 relevant lines covered (10.61%)

125698.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.62
/src/standard_header.f90
1
!> Contains functions for creating a standard header for files and output
2
module standard_header
3
  use uuid_mod, only : uuid_len
4
  implicit none
5

6
  private :: default_header
7

8
  !> A header for files and output.
9
  !>
10
  !> This is a type rather than a function so that we can use a
11
  !> consistent date/time and UUID across different files by reusing
12
  !> the same object.
13
  !>
14
  !> Call `standard_header_type::to_string` to get the header as text.
15
  type :: standard_header_type
16
    character(:), allocatable :: date_time
17
    character(len=uuid_len) :: run_uuid
18
  contains
19
    procedure :: to_string => standard_header_to_string
20
  end type standard_header_type
21

22
  interface standard_header_type
23
    module procedure make_standard_header
24
  end interface standard_header_type
25

26
  type(standard_header_type), allocatable :: default_header
27

28
contains
29

30
  !> Returns the default_header instance, allocating and populating
31
  !> this if not yet set
32
  function get_default_header() result(this)
×
33
    type(standard_header_type) :: this
34
    if (.not. allocated(default_header)) then
×
35
       allocate(standard_header_type::default_header)
×
36
       default_header = make_standard_header()
×
37
    end if
38
    this = default_header
×
39
  end function get_default_header
×
40

41
  !> Sets the module level default header instance
42
  subroutine set_default_header(header)
×
43
    type(standard_header_type), intent(in) :: header
44
    default_header = header
×
45
  end subroutine set_default_header
×
46

47
  !> Return the UUID for this run
48
  !>
49
  !> Generated when first called, guaranteed not to change during the
50
  !> simulation. Communicates when first called to broadcast the UUID
51
  !> to all processors
52
  function simulation_run_uuid()
4✔
53
    use mp, only : proc0, broadcast
54
    use uuid_mod, only : generate_uuid, uuid_len
55
    character(len=uuid_len) :: simulation_run_uuid
56
    character(len=uuid_len), save :: run_uuid
57
    logical, save :: first_run = .true.
58

59
    if (first_run) then
4✔
60
      if (proc0) then
2✔
61
        run_uuid = generate_uuid()
2✔
62
      end if
63
      call broadcast(run_uuid)
2✔
64
      first_run = .false.
2✔
65
    end if
66

67
    simulation_run_uuid = run_uuid
4✔
68
  end function simulation_run_uuid
4✔
69

70
  !> Return the current date and time in ISO8601 format:
71
  !>     YYYY-MM-DDThh:mm:ss.ssssZhh:mm
72
  function date_iso8601()
×
73
    character(:), allocatable :: date_iso8601
74
    character(8) :: date
75
    character(10) :: time
76
    character(5) :: zone
77
    call date_and_time(date, time, zone)
×
78

79
    date_iso8601 = date(1:4) // "-" // date(5:6) // "-" // date (7:8) &
80
         // "T" // time(1:2) // ":" // time(3:4) // ":" // time(5:10) &
81
         // "Z" // zone(1:3) // ":" // zone(4:5)
×
82
  end function date_iso8601
×
83

84
  !> Constructor for `standard_header_type`.
85
  !>
86
  !> Stores the date using `date_is08601` and the UUID using
87
  !> `simulation_run_uuid`. Note that this may involve collective
88
  !> communication, so all processors should be involved in
89
  !> construction.
90
  function make_standard_header() result(this)
×
91
    type(standard_header_type) :: this
92

93
    this%date_time = date_iso8601()
×
94
    this%run_uuid = simulation_run_uuid()
×
95
  end function make_standard_header
×
96

97
  !> Return a multiline string with a standard header of the form:
98
  !>
99
  !>     Created by GS2 at 2021-02-02T15:01:26.370Z+00:00
100
  !>     Run UUID: 36310A48-6A73-4941-9366-410C5731027A
101
  !>     GK_SYSTEM: ubuntu
102
  !>     Compiler: gfortran
103
  !>     <optional file description>
104
  !>
105
  !> If \p comment_character is passed, it is prepended to the start
106
  !> of each line. Note that it is used as-is, including any whitespace.
107
  function standard_header_to_string(this, comment_character, file_description) result(header)
×
108
    use runtime_tests, only: runtime_info
109
    use git_version_mod, only: get_git_version
110
    use build_config, only: gs2_build_tag
111
    use optionals, only: get_option_with_default
112
    character(:), allocatable :: header
113

114
    class(standard_header_type), intent(in) :: this
115
    !> Optional character(s) to start each line. Whitespace is not
116
    !> stripped or added. Default is empty string
117
    character(*), optional, intent(in) :: comment_character
118
    !> Optional file description. Treated as a single line, that is,
119
    !> new lines in this string will not begin with
120
    !> [[comment_character]]
121
    character(*), optional, intent(in) :: file_description
122

123
    ! Actual comment character to use, may be empty
124
    character(:), allocatable :: comment_char
×
125
    ! Note that description_line will contain the comment character if
126
    ! present
127
    character(:), allocatable :: description_line
×
128
    ! A literal new line `\n`, because Fortran
129
    character(*), parameter :: newline = new_line('a')
130

131
    comment_char = get_option_with_default(comment_character, "")
×
132
    description_line = get_option_with_default(file_description, "")
×
133
    if (len_trim(description_line) > 0) then
×
134
      ! If we add more lines to the header, we should add a newline here
135
      description_line = comment_char // description_line
×
136
    end if
137

138
    header = comment_char // "Created by GS2 at " // this%date_time // newline &
139
         // comment_char // "GS2 version: " // get_git_version() // newline &
140
         // comment_char // "Run UUID: " // this%run_uuid // newline &
141
         // comment_char // "GK_SYSTEM: " // trim(runtime_info%get_gk_system()) // newline &
142
         // comment_char // "Compiler: " // trim(runtime_info%get_compiler_name()) // newline &
143
         // comment_char // "Build tag: " // gs2_build_tag // newline &
144
         // description_line
×
145

146
  end function standard_header_to_string
×
147

148
end module standard_header
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc