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

gyrokinetics / gs2 / 2078172070

03 Oct 2025 09:22AM UTC coverage: 10.835% (+0.03%) from 10.806%
2078172070

push

gitlab-ci

David Dickinson
Merged in experimental/user_controlled_output_base_name (pull request #1184)

5049 of 46599 relevant lines covered (10.83%)

119786.99 hits per line

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

0.0
/src/programs/dump_grids.fpp
1
!> For the given input file initialises the main grids
2
!> and geometry and writes these to file (netcdf or binary).
3
program dump_grids
×
4
  use job_manage, only: job_fork, time_message
×
5
  use mp, only: init_mp, proc0, nproc, broadcast
6
  use file_utils, only: init_file_utils, run_name
7
  use kt_grids, only: init_kt_grids
8
  use theta_grid, only: init_theta_grid
9
  use le_grids, only: init_le_grids
10
  use species, only: init_species
11
  implicit none
12
  logical :: list
13
  logical, parameter :: quiet=.false.
14
  character (len=500) :: filename
15
  real :: time_measure(2)
16

17
  ! Initialize message passing
18
  call init_mp
×
19

20
  ! Report # of processors being used
21
  if (proc0) then
×
22
     if(.not.quiet)then
23
        if (nproc == 1) then
×
24
           write(*,'("Running on ",I0," processor")') nproc
×
25
        else
26
           write(*,'("Running on ",I0," processors")') nproc
×
27
        end if
28
     endif
29

30
     ! Call init_file_utils, ie. initialize the inputs and outputs, checking
31
     !  whether we are doing a run or a list of runs.
32
     call init_file_utils (list, name="gs")
×
33
  end if
34

35
  call broadcast (list)
×
36

37
  ! If given a list of jobs, fork
38
  if (list) call job_fork
×
39
  call broadcast (run_name)
×
40

41
  !Initialise
42
  time_measure=0.
×
43
  !/Theta
44
  if(proc0.and.(.not.quiet)) then
×
45
     write(*,'("Init theta_grids")',advance='no')
×
46
  endif
47
  call time_message(.false.,time_measure,'init-theta')
×
48
  call init_theta_grid
×
49
  call time_message(.false.,time_measure,'init-theta')
×
50
  if(proc0.and.(.not.quiet)) then
×
51
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
52
  endif
53
  time_measure=0.
×
54
  !/KT
55
  if(proc0.and.(.not.quiet)) then
×
56
     write(*,'("Init kt_grids   ")',advance='no')
×
57
  endif
58
  call time_message(.false.,time_measure,'init-kt')
×
59
  call init_kt_grids
×
60
  call time_message(.false.,time_measure,'init-kt')
×
61
  if(proc0.and.(.not.quiet)) then
×
62
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
63
  endif
64
  time_measure=0.
×
65
  !/SPECIES
66
  if(proc0.and.(.not.quiet)) then
×
67
     write(*,'("Init species   ")',advance='no')
×
68
  endif
69
  call time_message(.false.,time_measure,'init-species')
×
70
  call init_species
×
71
  call time_message(.false.,time_measure,'init-species')
×
72
  if(proc0.and.(.not.quiet)) then
×
73
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
74
  endif
75
  time_measure=0.
×
76
  !/LE
77
  if(proc0.and.(.not.quiet)) then
×
78
     write(*,'("Init le_grids   ")',advance='no')
×
79
  endif
80
  call time_message(.false.,time_measure,'init-le')
×
81
  call init_le_grids
×
82
  call time_message(.false.,time_measure,'init-le')
×
83
  if(proc0.and.(.not.quiet)) then
×
84
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
85
  endif
86
  time_measure=0.
×
87

88
  !Now write to file
89
  if(proc0.and.(.not.quiet)) then
×
90
     write(*,'("Write to file   ")',advance='no')
×
91
  endif
92
  call time_message(.false.,time_measure,'write-file')
×
93
  filename=trim(adjustl(run_name))
×
94
  if(proc0) call write_grids_to_file(filename)
×
95
  call time_message(.false.,time_measure,'write-file')
×
96
  if(proc0.and.(.not.quiet)) then
×
97
     write(*,'("  --> Done in : ",F12.6," seconds")') time_measure(1)
×
98
  endif
99
  time_measure=0.
×
100

101
contains
102

103
#ifdef NETCDF
104
!Prefer to write to netcdf file if possible
105

106
  !> FIXME : Add documentation
107
  subroutine write_grids_to_file(fname)
×
108
    use neasyf, only: neasyf_open, neasyf_default_compression, neasyf_dim, neasyf_write, neasyf_close
109
    use kt_grids, only: aky, akx, theta0
110
    use theta_grid, only: theta
111
    use le_grids, only: al, energy, wl, w, negrid
112
    use species, only: nspec
113
    use gs2_metadata, only: create_metadata
114
    use gs2_io, only: nc_geo, nc_species
115
    use gs2_io, only: kx_dim, ky_dim, theta_dim, lambda_dim, species_dim, egrid_dim
116
    implicit none
117
    character(len=*), intent(in) :: fname
118
    integer :: ncid
119
    !> Level of compression if enabled via
120
    !> `GK_NETCDF_DEFAULT_COMPRESSION_ON` macro. Must be a value between
121
    !> 1 (faster, less compression) and 9 (slower, more compression), or
122
    !> 0 (off)
123
#ifdef GK_NETCDF_DEFAULT_COMPRESSION_ON
124
    integer, parameter :: default_compression_level = 1
125
    neasyf_default_compression = default_compression_level
×
126
#else
127
    integer, parameter :: compression_off = 0
128
    neasyf_default_compression = compression_off
129
#endif
130

131
    !First create a file
132
    ncid = neasyf_open(trim(adjustl(fname))//".grids.nc", "w")
×
133
    call create_metadata(ncid, "GS2 grids")
×
134

135
    call neasyf_dim(ncid, trim(kx_dim), values = akx, &
136
         long_name = "Wavenumber perpendicular to flux surface", units = "1/rho_r")
×
137
    call neasyf_dim(ncid, trim(ky_dim), values = aky, &
138
         long_name = "Wavenumber in direction of grad alpha", units = "1/rho_r")
×
139
    call neasyf_dim(ncid, trim(theta_dim), values = theta, long_name = "Poloidal angle", &
140
         units = "rad")
×
141
    call neasyf_dim(ncid, trim(lambda_dim), values = al, &
142
         long_name = "Energy/magnetic moment", units = "1/(2 B_a)")
×
143
    call neasyf_dim(ncid, trim(species_dim), dim_size = nspec)
×
144
    call neasyf_dim(ncid, trim(egrid_dim), dim_size = negrid, &
145
         long_name="See 'energy' for energy grid values")
×
146

147
    call neasyf_write(ncid, 'theta0', theta0, dim_names = [kx_dim,ky_dim], &
148
         long_name = 'theta0')
×
149
    call neasyf_write(ncid, "energy", energy, dim_names = [egrid_dim, species_dim], &
150
         long_name="Energy grid values")
×
151
    call nc_geo(ncid)
×
152
    call nc_species(ncid)
×
153
    call neasyf_write(ncid, 'wl', wl, dim_names = [theta_dim, lambda_dim], &
154
         long_name = "Pitch angle integration weights")
×
155
    call neasyf_write(ncid, 'w', w, dim_names = [egrid_dim, species_dim], &
156
         long_name = "Energy grid integration weights")
×
157
    call neasyf_close(ncid)
×
158
  end subroutine write_grids_to_file
×
159
#else
160
  !Fall back to binary output when netcdf unavailable
161

162
  !> FIXME : Add documentation
163
  subroutine write_grids_to_file(fname)
164
    use kt_grids, only: aky, akx, theta0, kperp2
165
    use theta_grid, only: theta
166
    use theta_grid, only: bmag, bpol, gradpar, grho
167
    use theta_grid, only: cdrift, cvdrift, gbdrift
168
    use theta_grid, only: cdrift0, cvdrift0, gbdrift0
169
    use theta_grid, only: gds2, gds21, gds22, gds23, gds24, gds24_noq
170
    use theta_grid, only: rplot, zplot, aplot
171
    use theta_grid, only: rprime, zprime, aprime
172
    use le_grids, only: al, energy, wl, w
173
    implicit none
174
    character(len=*), intent(in) :: fname
175
    integer :: unit
176

177
    open(newunit=unit,file=trim(adjustl(fname))//".ky",form="unformatted")
178
    write(unit) aky
179
    close(unit)
180

181
    open(newunit=unit,file=trim(adjustl(fname))//".kx",form="unformatted")
182
    write(unit) akx
183
    close(unit)
184

185
    open(newunit=unit,file=trim(adjustl(fname))//".theta0",form="unformatted")
186
    write(unit) theta0
187
    close(unit)
188

189
    open(newunit=unit,file=trim(adjustl(fname))//".theta",form="unformatted")
190
    write(unit) theta
191
    close(unit)
192

193
    open(newunit=unit,file=trim(adjustl(fname))//".lambda",form="unformatted")
194
    write(unit) al
195
    close(unit)
196

197
    open(newunit=unit,file=trim(adjustl(fname))//".energy",form="unformatted")
198
    write(unit) energy
199
    close(unit)
200

201
    open(newunit=unit,file=trim(adjustl(fname))//".bmag",form="unformatted")
202
    write(unit) bmag
203
    close(unit)
204

205
    open(newunit=unit,file=trim(adjustl(fname))//".bpol",form="unformatted")
206
    write(unit) bpol
207
    close(unit)
208

209
    open(newunit=unit,file=trim(adjustl(fname))//".gradpar",form="unformatted")
210
    write(unit) gradpar
211
    close(unit)
212

213
    open(newunit=unit,file=trim(adjustl(fname))//".grho",form="unformatted")
214
    write(unit) grho
215
    close(unit)
216

217
    open(newunit=unit,file=trim(adjustl(fname))//".cdrift",form="unformatted")
218
    write(unit) cdrift
219
    close(unit)
220

221
    open(newunit=unit,file=trim(adjustl(fname))//".cvdrift",form="unformatted")
222
    write(unit) cvdrift
223
    close(unit)
224

225
    open(newunit=unit,file=trim(adjustl(fname))//".gbdrift",form="unformatted")
226
    write(unit) gbdrift
227
    close(unit)
228

229
    open(newunit=unit,file=trim(adjustl(fname))//".cdrift0",form="unformatted")
230
    write(unit) cdrift0
231
    close(unit)
232

233
    open(newunit=unit,file=trim(adjustl(fname))//".cvdrift0",form="unformatted")
234
    write(unit) cvdrift0
235
    close(unit)
236

237
    open(newunit=unit,file=trim(adjustl(fname))//".gbdrift0",form="unformatted")
238
    write(unit) gbdrift0
239
    close(unit)
240

241
    open(newunit=unit,file=trim(adjustl(fname))//".gds2",form="unformatted")
242
    write(unit) gds2
243
    close(unit)
244

245
    open(newunit=unit,file=trim(adjustl(fname))//".gds21",form="unformatted")
246
    write(unit) gds21
247
    close(unit)
248

249
    open(newunit=unit,file=trim(adjustl(fname))//".gds22",form="unformatted")
250
    write(unit) gds22
251
    close(unit)
252

253
    open(newunit=unit,file=trim(adjustl(fname))//".gds23",form="unformatted")
254
    write(unit) gds23
255
    close(unit)
256

257
    open(newunit=unit,file=trim(adjustl(fname))//".gds24",form="unformatted")
258
    write(unit) gds24
259
    close(unit)
260

261
    open(newunit=unit,file=trim(adjustl(fname))//".gds24_noq",form="unformatted")
262
    write(unit) gds24_noq
263
    close(unit)
264

265
    open(newunit=unit,file=trim(adjustl(fname))//".rplot",form="unformatted")
266
    write(unit) rplot
267
    close(unit)
268

269
    open(newunit=unit,file=trim(adjustl(fname))//".zplot",form="unformatted")
270
    write(unit) zplot
271
    close(unit)
272

273
    open(newunit=unit,file=trim(adjustl(fname))//".aplot",form="unformatted")
274
    write(unit) aplot
275
    close(unit)
276

277
    open(newunit=unit,file=trim(adjustl(fname))//".rprime",form="unformatted")
278
    write(unit) rprime
279
    close(unit)
280

281
    open(newunit=unit,file=trim(adjustl(fname))//".zprime",form="unformatted")
282
    write(unit) zprime
283
    close(unit)
284

285
    open(newunit=unit,file=trim(adjustl(fname))//".aprime",form="unformatted")
286
    write(unit) aprime
287
    close(unit)
288

289
    open(newunit=unit,file=trim(adjustl(fname))//".kperp2",form="unformatted")
290
    write(unit) kperp2
291
    close(unit)
292

293
    open(newunit=unit,file=trim(adjustl(fname))//".wl",form="unformatted")
294
    write(unit) wl
295
    close(unit)
296

297
    open(newunit=unit,file=trim(adjustl(fname))//".w",form="unformatted")
298
    write(unit) w
299
    close(unit)
300
  end subroutine write_grids_to_file
301
#endif
302
end program dump_grids
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