Skip to content

Commit

Permalink
Fix gg_fit_mod.f90 code array set before allocation of zero_vec. (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Jun 28, 2024
1 parent aa5f859 commit 546ed09
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions tao/code/tao_show_this.f90
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ subroutine tao_show_this (what, result_id, lines, nl)
bmad_nf => tao_branch%bmad_normal_form
ptc_nf => tao_branch%ptc_normal_form

nl=nl+1; lines(nl) = ' Note: Calculation is done with RF off.'
nl=nl+1; lines(nl) = ' N chrom_ptc.a.N chrom_ptc.b.N spin_tune_ptc.N'

do i = 0, ptc_private%taylor_order_ptc-1
Expand All @@ -855,6 +856,8 @@ subroutine tao_show_this (what, result_id, lines, nl)
s0 = real(ptc_nf%spin_tune .sub. expo)
if (i == 0) then
nl=nl+1; write (lines(nl), '(i3, 3es18.7, a)') i, z1, z2, s0, ' ! 0th order are the tunes'
elseif (i == 1 .and. .not. bmad_com%spin_tracking_on) then
nl=nl+1; write (lines(nl), '(i3, 3es18.7, a)') i, z1, z2, s0, ' ! Spin tracking off so spin tune not calculated'
else
nl=nl+1; write (lines(nl), '(i3, 3es18.7)') i, z1, z2, s0
endif
Expand Down Expand Up @@ -4539,6 +4542,28 @@ subroutine tao_show_this (what, result_id, lines, nl)
else
tao_branch%spin_map_valid = .false.
call tao_spin_polarization_calc (branch, tao_branch, excite_zero, veto)
if (.not. u%calc%one_turn_map) call tao_ptc_normal_form (.true., u%model, branch%ix_branch)

!

nl=nl+1; lines(nl) = ''
nl=nl+1; lines(nl) = ' N chrom_ptc.a.N chrom_ptc.b.N spin_tune_ptc.N'

ptc_nf => tao_branch%ptc_normal_form
do i = 0, ptc_private%taylor_order_ptc-1
expo = [0, 0, 0, 0, 0, i]
z1 = real(ptc_nf%phase(1) .sub. expo)
z2 = real(ptc_nf%phase(2) .sub. expo)
s0 = real(ptc_nf%spin_tune .sub. expo)
if (i == 0) then
nl=nl+1; write (lines(nl), '(i3, 3es18.7, a)') i, z1, z2, s0, ' ! 0th order are the tunes'
else
nl=nl+1; write (lines(nl), '(i3, 3es18.7)') i, z1, z2, s0
endif
enddo

!

nl=nl+1; lines(nl) = ''
nl=nl+1; write (lines(nl), '(a, es18.7)') 'spin_tune: ', tao_branch%spin%tune / twopi
if (tao_branch%spin%valid) then
Expand Down
6 changes: 3 additions & 3 deletions util_programs/generalized_gradient_fit/gg_fit_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module gg_fit_mod
real(rp) :: z_min = real_garbage$, z_max = real_garbage$, core_weight = 1, outer_plane_weight = 1
real(rp) :: lmdif_eps = 1d-12

real(rp), allocatable :: var_vec(:), merit_vec(:), dB_dvar_vec(:,:)
real(rp) merit

logical printit
Expand Down Expand Up @@ -414,6 +413,7 @@ subroutine fit_field()
type (gg1_struct), pointer :: gg

real(rp), allocatable :: vec0(:), weight(:), zero_vec(:), xy(:,:)
real(rp), allocatable :: var_vec(:), merit_vec(:), dB_dvar_vec(:,:)
real(rp) merit0, x, y, v, chisq, a_lambda, r2, r2_max, p_wgt

integer i, iloop, im, id, n_gg, n, ig, nx, ny, n3
Expand Down Expand Up @@ -454,7 +454,6 @@ subroutine fit_field()

n_var = 0
n_gg = 0
zero_vec = 0

do im = 1, size(m_cos)
if (m_cos(im) /= -1) then
Expand Down Expand Up @@ -512,11 +511,12 @@ subroutine fit_field()
!

allocate (merit_vec(n_merit), dB_dvar_vec(n_merit, n_var), zero_vec(n_merit))

allocate (fit(iz_min:iz_max))
allocate (var_vec(n_var), vec0(n_var), weight(n_merit))

vec0 = 0
var_vec = 0
zero_vec = 0

r2_max = max(abs(Nx_min*del_meters(1) + r0_meters(1)), abs(Nx_max*del_meters(1) + r0_meters(1)))**2 + &
max(abs(Ny_min*del_meters(2) + r0_meters(2)), abs(Ny_max*del_meters(2) + r0_meters(2)))**2
Expand Down

0 comments on commit 546ed09

Please sign in to comment.