@@ -128,7 +128,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
128128 ! Dimensions
129129 use grids_kxky, only: nakx, naky
130130 use grids_velocity, only: nvpa, nmu
131- use grids_z, only: nztot, ntubes
131+ use grids_z, only: nztot, ntubes, nzgrid
132132 use grids_species, only: nspec
133133
134134 ! Write to netcdf file
@@ -176,7 +176,6 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
176176
177177 use parameters_diagnostics, only: write_g_vs_zvpas_zonal
178178 use parameters_diagnostics, only: write_free_energy
179- use parameters_diagnostics, only: number_zonals_kxs, zonal_iks
180179
181180 ! Calculations
182181 use calculations_tofrom_ghf, only: g_to_f, g_to_h
@@ -193,7 +192,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
193192 real , dimension (:, :, :, :), allocatable :: g2_vs_zvpas, g2_vs_zmus, g2nozonal_vs_zvpas, g2nozonal_vs_zmus
194193
195194 ! Zonals
196- real , dimension (:, :, :, :, :, :), allocatable :: g_vs_zvpas_zonal
195+ complex , dimension (:, :, :, :, :), allocatable :: g_vs_zvpas_zonal
197196 real , dimension (:), allocatable :: free_energy_vs_kx
198197
199198 real , dimension (:, :, :, :, :), allocatable :: g2_vs_zkykxs, g2_vs_zvpamus, g2nozonal_vs_zvpamus
@@ -222,7 +221,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
222221 if (write_g2_vs_kxkyzs) allocate (g2_vs_zkykxs(ntubes, nztot, naky, nakx, nspec))
223222
224223 ! Zonal diagnostics
225- if (write_g_vs_zvpas_zonal) allocate (g_vs_zvpas_zonal(2 , number_zonals_kxs , ntubes, nztot , nvpa, nspec))
224+ if (write_g_vs_zvpas_zonal) allocate (g_vs_zvpas_zonal(nakx, - nzgrid:nzgrid , ntubes, nvpa, nspec))
226225 if (write_free_energy) allocate (free_energy_vs_kx(nakx))
227226
228227 ! Redistribute the data from <gnew>(ky,kx,z,tube,i[vpa,mu,s]) to <gvmu>(vpa,mu,i[kx,ky,z,s]) for |g|^2(z,kx,ky,s)
@@ -248,9 +247,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
248247 if (write_g2_vs_zvpamus .and. proc0) call write_g2nozonal_vs_zvpamus_nc(nout, g2nozonal_vs_zvpamus)
249248
250249 ! Zonals
251- if (write_g_vs_zvpas_zonal .and. proc0) then
252- call write_g_vs_zvpas_zonal_nc(nout, g_vs_zvpas_zonal)
253- end if
250+ if (write_g_vs_zvpas_zonal .and. proc0) call write_g_vs_zvpas_zonal_nc(nout, g_vs_zvpas_zonal)
254251
255252 if (write_free_energy) then
256253 call g_to_h(gnew, phi, bpar, fphi)
@@ -380,7 +377,6 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
380377 use parameters_diagnostics, only: write_g2_vs_zvpamus
381378
382379 use parameters_diagnostics, only: write_g_vs_zvpas_zonal
383- use parameters_diagnostics, only: number_zonals_kxs, zonal_iks
384380
385381 implicit none
386382
@@ -392,14 +388,14 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
392388 real , dimension (:, :, :), intent (out ) :: g2_vs_vpamus, g2nozonal_vs_vpamus
393389
394390 ! Zonals
395- real , dimension (:, :, :, :, :, :), intent (out ) :: g_vs_zvpas_zonal
391+ complex , dimension (:, - nzgrid :, :, :, :), intent (out ) :: g_vs_zvpas_zonal
396392
397393 ! Arrays needed to perform calculations
398394 real , dimension (:, :, :), allocatable :: g2_vs_ztubeivmus, g2nozonal_vs_ztubeivmus
399395 real , dimension (:, :), allocatable :: g2_vs_ztube, g2_vs_vpamu
400396
401397 ! Zonals
402- real , dimension (:, :, :, :, :), allocatable :: g_vs_zivmus_zonal
398+ complex , dimension (:, :, :, :), allocatable :: g_vs_zivmus_zonal
403399
404400 integer :: ivmus, ia, iz, it, ikx, iky, izp, is, iv, imu, ikxkyzs
405401 integer :: j, ikx_plot
@@ -414,8 +410,8 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
414410 if (write_g2_vs_kxkyzs) then ; allocate (g2_vs_vpamu(nvpa, nmu)); g2_vs_vpamu = 0 .; end if
415411 allocate (g2_vs_ztube(- nzgrid:nzgrid, ntubes)); g2_vs_ztube = 0 .
416412
417- if (write_g_vs_zvpas_zonal .and. number_zonals_kxs > 0 ) then
418- allocate (g_vs_zivmus_zonal(2 , number_zonals_kxs , - nzgrid:nzgrid, ntubes, vmu_lo% llim_proc:vmu_lo% ulim_alloc))
413+ if (write_g_vs_zvpas_zonal) then
414+ allocate (g_vs_zivmus_zonal(nakx , - nzgrid:nzgrid, ntubes, vmu_lo% llim_proc:vmu_lo% ulim_alloc))
419415 g_vs_zivmus_zonal = 0.0
420416 end if
421417
@@ -464,28 +460,19 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
464460
465461 ! Zonals
466462 if (write_g_vs_zvpas_zonal) then
467- if (number_zonals_kxs == 1 ) then
463+ if (nakx == 1 ) then
468464 if (abs (akx(1 )) < epsilon (0 .)) then
469465 ikx_plot = 2
470466 else
471467 ikx_plot = 1
472468 end if
473- g_vs_zivmus_zonal(1 , 1 , :, :, ivmus) = real (g_vs_kykxztube(1 , ikx_plot, :, :, ivmus))
474- g_vs_zivmus_zonal(2 , 1 , :, :, ivmus) = aimag (g_vs_kykxztube(1 , ikx_plot, :, :, ivmus))
469+ g_vs_zivmus_zonal(1 , :, :, ivmus) = g_vs_kykxztube(1 , ikx_plot, :, :, ivmus)
475470
476471 else
477472
478473 ikx_plot = 0
479474
480- do ikx = 1 , nakx
481- if (any (zonal_iks == ikx)) then
482- ikx_plot = ikx_plot + 1
483-
484- g_vs_zivmus_zonal(1 , ikx_plot, :, :, ivmus) = real (g_vs_kykxztube(1 , ikx, :, :, ivmus))
485- g_vs_zivmus_zonal(2 , ikx_plot, :, :, ivmus) = aimag (g_vs_kykxztube(1 , ikx, :, :, ivmus))
486-
487- end if
488- end do
475+ g_vs_zivmus_zonal(:, :, :, ivmus) = g_vs_kykxztube(1 , :, :, :, ivmus)
489476 end if
490477
491478 end if
@@ -517,25 +504,28 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
517504 ! The velocity parallel integration takes |g|^2(ivmus) and returns int dvpa |g|^2(ivmus) = |g|^2(mu,s)
518505 ! There is a sum_reduce() inside of the velocity integration, so <g2_vs_tzmus> holds the total sum
519506 if (debug) write (* , * ) ' diagnostics::diagnostics_distribution::calculate_distribution::write_g2_vs_zvpas .or. write_g2_vs_zmus'
520- if (write_g2_vs_zvpas .or. write_g2_vs_zmus .or. write_g_vs_zvpas_zonal ) then
507+ if (write_g2_vs_zvpas .or. write_g2_vs_zmus) then
521508 do it = 1 , ntubes
522509 do iz = - nzgrid, nzgrid
523510 izp = iz + nzgrid + 1
524511 if (write_g2_vs_zvpas) call integrate_mu(iz, g2_vs_ztubeivmus(iz, it, :), g2_vs_zvpas(it, izp, :, :))
525- if (write_g_vs_zvpas_zonal) then
526- do ikx = 1 , number_zonals_kxs
527- do j = 1 , 2
528- call integrate_mu(iz, g_vs_zivmus_zonal(j, ikx, iz, it, :), g_vs_zvpas_zonal(j, ikx, it, izp, :, :))
529- end do
530- end do
531- end if
532512 if (write_g2_vs_zmus) call integrate_vpa(g2_vs_ztubeivmus(iz, it, :), g2_vs_tzmus(it, izp, :, :))
533513 if (write_g2_vs_zvpas) call integrate_mu(iz, g2nozonal_vs_ztubeivmus(iz, it, :), g2nozonal_vs_zvpas(it, izp, :, :))
534514 if (write_g2_vs_zmus) call integrate_vpa(g2nozonal_vs_ztubeivmus(iz, it, :), g2nozonal_vs_tzmus(it, izp, :, :))
535515 end do
536516 end do
537517 end if
538518
519+ if (write_g_vs_zvpas_zonal) then
520+ do it = 1 , ntubes
521+ do iz = - nzgrid, nzgrid
522+ do ikx = 1 , nakx
523+ call integrate_mu(iz, g_vs_zivmus_zonal(ikx, iz, it, :), g_vs_zvpas_zonal(ikx, iz, it, :, :))
524+ end do
525+ end do
526+ end do
527+ end if
528+
539529 ! For the field line average normalise to account for contributions from multiple flux tubes
540530 ! in a flux tube train, and sum the values on all processors and to send them to <proc0>
541531 if (debug) write (* , * ) ' diagnostics::diagnostics_distribution::calculate_distribution::sum_all_reduce'
@@ -552,6 +542,10 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
552542 if (nproc > 1 ) call sum_reduce(g2_vs_zkykxs, 0 )
553543 end if
554544
545+ if (write_g_vs_zvpas_zonal) then
546+ if (nproc > 1 ) call sum_reduce(g_vs_zvpas_zonal, 0 )
547+ end if
548+
555549 ! Deallocate local arrays
556550 if (write_g2_vs_zvpas) deallocate (g2nozonal_vs_ztubeivmus)
557551 if (write_g2_vs_zvpas) deallocate (g2_vs_ztubeivmus)
0 commit comments