Skip to content

Commit d8a7d9d

Browse files
committed
eliminated a goto
minor refactoring for an error print
1 parent 65cbbd2 commit d8a7d9d

File tree

1 file changed

+54
-50
lines changed

1 file changed

+54
-50
lines changed

src/bspline_defc_module.F90

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,7 @@ subroutine dlsei (w, mdw, me, ma, mg, n, prgopt, x, rnorme, &
28022802
integer :: i, imax, j, jp1, k, key, kranke, last, lchk, link, m, &
28032803
mapke1, mdeqc, mend, mep1, n1, n2, next, nlink, nopt, np1, &
28042804
ntimes
2805-
logical :: cov
2805+
logical :: cov, done
28062806
character(len=8) :: xern1, xern2, xern3, xern4
28072807

28082808
! Set the nominal tolerance used in the code for the equality
@@ -2817,11 +2817,11 @@ subroutine dlsei (w, mdw, me, ma, mg, n, prgopt, x, rnorme, &
28172817
write (xern3, '(I8)') ma
28182818
write (xern4, '(I8)') mg
28192819
write(*,*) 'ALL OF THE VARIABLES N, ME,' // &
2820-
' MA, MG MUST BE >= 0$$ENTERED ROUTINE WITH' // &
2821-
'$$N = ' // xern1 // &
2822-
'$$ME = ' // xern2 // &
2823-
'$$MA = ' // xern3 // &
2824-
'$$MG = ' // xern4
2820+
' MA, MG MUST BE >= 0. ENTERED ROUTINE WITH: ' // &
2821+
'N = ' // trim(adjustl(xern1)) // &
2822+
', ME = ' // trim(adjustl(xern2)) // &
2823+
', MA = ' // trim(adjustl(xern3)) // &
2824+
', MG = ' // trim(adjustl(xern4))
28252825
return
28262826
endif
28272827

@@ -2857,7 +2857,7 @@ subroutine dlsei (w, mdw, me, ma, mg, n, prgopt, x, rnorme, &
28572857
endif
28582858

28592859
if (mdw<m) then
2860-
write(*,*) 'MDW<ME+MA+MG IS AN ERROR'
2860+
write(*,*) 'MDW < ME+MA+MG IS AN ERROR'
28612861
return
28622862
endif
28632863

@@ -2972,8 +2972,7 @@ subroutine dlsei (w, mdw, me, ma, mg, n, prgopt, x, rnorme, &
29722972
if (i/=imax) call dswap (np1, w(i,1), mdw, w(imax,1), mdw)
29732973
if (snmax>rnmax*tau**2) then
29742974
! Eliminate elements I+1,...,N in row I.
2975-
call dh12 (1, i, i+1, n, w(i,1), mdw, ws(i), w(i+1,1), mdw, &
2976-
1, m-i)
2975+
call dh12 (1, i, i+1, n, w(i,1), mdw, ws(i), w(i+1,1), mdw, 1, m-i)
29772976
else
29782977
kranke = i - 1
29792978
exit
@@ -3033,6 +3032,7 @@ subroutine dlsei (w, mdw, me, ma, mg, n, prgopt, x, rnorme, &
30333032
x(kranke+1), rnorml, mode, ws(n2), ip(2))
30343033

30353034
! Test for consistency of equality constraints.
3035+
done = .false.
30363036

30373037
if (me>0) then
30383038
mdeqc = 0
@@ -3051,62 +3051,66 @@ subroutine dlsei (w, mdw, me, ma, mg, n, prgopt, x, rnorme, &
30513051
size = dasum(n,w(i,1),mdw)*xnorm + abs(w(i,np1))
30523052
if (w(i,np1)>tau*size) then
30533053
mode = mode + 2
3054-
go to 290
3054+
done = .true.
3055+
exit
30553056
endif
30563057
end do
30573058
endif
30583059
endif
30593060

3060-
! Replace diagonal terms of lower trapezoidal matrix.
3061+
if (.not. done) then
3062+
! Replace diagonal terms of lower trapezoidal matrix.
30613063

3062-
if (kranke>0) then
3063-
call dcopy (kranke, ws(kranke+1), 1, w, mdw+1)
3064-
! Reapply transformation to put solution in original coordinates.
3065-
do i = kranke,1,-1
3066-
call dh12 (2, i, i+1, n, w(i,1), mdw, ws(i), x, 1, 1, 1)
3067-
end do
3064+
if (kranke>0) then
3065+
call dcopy (kranke, ws(kranke+1), 1, w, mdw+1)
3066+
! Reapply transformation to put solution in original coordinates.
3067+
do i = kranke,1,-1
3068+
call dh12 (2, i, i+1, n, w(i,1), mdw, ws(i), x, 1, 1, 1)
3069+
end do
30683070

3069-
! Compute covariance matrix of equality constrained problem.
3071+
! Compute covariance matrix of equality constrained problem.
30703072

3071-
if (cov) then
3072-
do j = min(kranke,n-1),1,-1
3073-
rb = ws(j)*w(j,j)
3074-
if (rb/=0.0_wp) rb = 1.0_wp/rb
3075-
jp1 = j + 1
3076-
do i = jp1,n
3077-
w(i,j) = rb*ddot(n-j,w(i,jp1),mdw,w(j,jp1),mdw)
3078-
end do
3079-
gam = 0.5_wp*rb*ddot(n-j,w(jp1,j),1,w(j,jp1),mdw)
3080-
call daxpy (n-j, gam, w(j,jp1), mdw, w(jp1,j), 1)
3081-
do i = jp1,n
3082-
do k = i,n
3083-
w(i,k) = w(i,k) + w(j,i)*w(k,j) + w(i,j)*w(j,k)
3084-
w(k,i) = w(i,k)
3073+
if (cov) then
3074+
do j = min(kranke,n-1),1,-1
3075+
rb = ws(j)*w(j,j)
3076+
if (rb/=0.0_wp) rb = 1.0_wp/rb
3077+
jp1 = j + 1
3078+
do i = jp1,n
3079+
w(i,j) = rb*ddot(n-j,w(i,jp1),mdw,w(j,jp1),mdw)
30853080
end do
3081+
gam = 0.5_wp*rb*ddot(n-j,w(jp1,j),1,w(j,jp1),mdw)
3082+
call daxpy (n-j, gam, w(j,jp1), mdw, w(jp1,j), 1)
3083+
do i = jp1,n
3084+
do k = i,n
3085+
w(i,k) = w(i,k) + w(j,i)*w(k,j) + w(i,j)*w(j,k)
3086+
w(k,i) = w(i,k)
3087+
end do
3088+
end do
3089+
uj = ws(j)
3090+
vj = gam*uj
3091+
w(j,j) = uj*vj + uj*vj
3092+
do i = jp1,n
3093+
w(j,i) = uj*w(i,j) + vj*w(j,i)
3094+
end do
3095+
call dcopy (n-j, w(j, jp1), mdw, w(jp1,j), 1)
30863096
end do
3087-
uj = ws(j)
3088-
vj = gam*uj
3089-
w(j,j) = uj*vj + uj*vj
3090-
do i = jp1,n
3091-
w(j,i) = uj*w(i,j) + vj*w(j,i)
3092-
end do
3093-
call dcopy (n-j, w(j, jp1), mdw, w(jp1,j), 1)
3094-
end do
3097+
endif
30953098
endif
3096-
endif
30973099

3098-
! Apply the scaling to the covariance matrix.
3100+
! Apply the scaling to the covariance matrix.
30993101

3100-
if (cov) then
3101-
do i = 1,n
3102-
call dscal (n, ws(i+n1-1), w(i,1), mdw)
3103-
call dscal (n, ws(i+n1-1), w(1,i), 1)
3104-
end do
3105-
endif
3102+
if (cov) then
3103+
do i = 1,n
3104+
call dscal (n, ws(i+n1-1), w(i,1), mdw)
3105+
call dscal (n, ws(i+n1-1), w(1,i), 1)
3106+
end do
3107+
endif
3108+
3109+
end if
31063110

31073111
! Rescale solution vector.
31083112

3109-
290 if (mode<=1) then
3113+
if (mode<=1) then
31103114
do j = 1,n
31113115
x(j) = x(j)*ws(n1+j-1)
31123116
end do
@@ -3891,7 +3895,7 @@ subroutine dwnlsm (w, mdw, mme, ma, n, l, prgopt, x, rnorm, mode, &
38913895
dope(2) = eanorm
38923896
dope(3) = tau
38933897
call dwnlit (w, mdw, m, n, l, ipivot, itype, h, scale, rnorm, &
3894-
idope, dope, done)
3898+
idope, dope, done)
38953899
me = idope(1)
38963900
krank = idope(2)
38973901
niv = idope(3)

0 commit comments

Comments
 (0)