Skip to content

Commit

Permalink
purify dsclb
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMVale committed Jul 5, 2024
1 parent 3e10b8c commit 4c71463
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 103 deletions.
103 changes: 0 additions & 103 deletions src/odrpack.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11208,106 +11208,3 @@ subroutine dscale &
!
return
end subroutine
!DSCLB
subroutine dsclb &
( np, beta, ssf)
!***Begin Prologue DSCLB
!***Refer to ODR
!***Routines Called (NONE)
!***Date Written 860529 (YYMMDD)
!***Revision Date 920304 (YYMMDD)
!***Purpose Select scaling values for BETA according to the
! algorithm given in the ODRPACK95 reference guide
!***End Prologue DSCLB
!
!...Used modules
use odrpack_kinds,only: wp
!
!...Scalar arguments
integer &
np
!
!...Array arguments
real(kind = wp) &
beta( np), ssf( np)
!
!...Local scalars
real(kind = wp) &
bmax, bmin, one, ten, zero
integer &
k
logical &
bigdif
!
!...Data statements
data &
zero, one, ten &
/0.0E0_wp,1.0E0_wp,10.0E0_wp/
!
!...Variable Definitions (alphabetically)
! BETA: The function parameters.
! BIGDIF: The variable designating whether there is a significant
! difference in the magnitudes of the nonzero elements of
! BETA (BIGDIF=.TRUE.) or not (BIGDIF=.FALSE.).
! BMAX: The largest nonzero magnitude.
! BMIN: The smallest nonzero magnitude.
! K: An indexing variable.
! NP: The number of function parameters.
! ONE: The value 1.0E0_wp.
! SSF: The scaling values for BETA.
! TEN: The value 10.0E0_wp.
! ZERO: The value 0.0E0_wp.
!
!
!***First executable statement DSCLB
!
!
bmax = abs( beta(1))
do 10 k = 2, np
bmax = max( bmax,abs( beta( k)))
10 continue
!
if ( bmax .eq. zero) then
!----------------------^-------------------------------------------------------
!!! FPT - 3087 REAL or COMPLEX quantity tested for exact equality/inequality
!------------------------------------------------------------------------------
!
! All input values of BETA are zero
!
do 20 k = 1, np
ssf( k) = one
20 continue
!
else
!
! Some of the input values are nonzero
!
bmin = bmax
do 30 k = 1, np
if ( beta( k) .ne. zero) then
!--------------------------------^---------------------------------------------
!!! FPT - 3087 REAL or COMPLEX quantity tested for exact equality/inequality
!------------------------------------------------------------------------------
bmin = min( bmin,abs( beta( k)))
endif
30 continue
bigdif = log10( bmax)-log10( bmin) .ge. one
do 40 k = 1, np
if ( beta( k) .eq. zero) then
!--------------------------------^---------------------------------------------
!!! FPT - 3087 REAL or COMPLEX quantity tested for exact equality/inequality
!------------------------------------------------------------------------------
ssf( k) = ten/ bmin
else
if ( bigdif) then
ssf( k) = one/abs( beta( k))
else
ssf( k) = one/ bmax
endif
endif
40 continue
!
endif
!
return
end subroutine
73 changes: 73 additions & 0 deletions src/odrpack2.f90
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,76 @@ pure subroutine dscld(n, m, x, ldx, tt, ldtt)
end do

end subroutine dscld

pure subroutine dsclb(np, beta, ssf)
!! Select scaling values for BETA according to the algorithm given in the ODRPACK95 reference guide
!***Routines Called (NONE)
!***Date Written 860529 (YYMMDD)
!***Revision Date 920304 (YYMMDD)

use odrpack_kinds, only: wp, zero, one, ten

integer, intent(in) :: np
!! The number of function parameters.
real(kind=wp), intent(in) :: beta(np)
!! The function parameters.
real(kind=wp), intent(out) :: ssf(np)
!! The scaling values for `beta`.

! Local scalars
real(kind=wp) :: bmax, bmin
integer :: k
logical ::bigdif

! Variable Definitions (alphabetically)
! BETA: The function parameters.
! BIGDIF: The variable designating whether there is a significant
! difference in the magnitudes of the nonzero elements of
! BETA (BIGDIF=.TRUE.) or not (BIGDIF=.FALSE.).
! BMAX: The largest nonzero magnitude.
! BMIN: The smallest nonzero magnitude.
! K: An indexing variable.
! NP: The number of function parameters.
! SSF: The scaling values for BETA.

bmax = abs(beta(1))
do k = 2, np
bmax = max(bmax, abs(beta(k)))
end do

if (bmax .eq. zero) then
!------------------------------------------------------------------------------
!!! FPT - 3087 REAL or COMPLEX quantity tested for exact equality/inequality
!------------------------------------------------------------------------------
! All input values of BETA are zero
ssf(1:np) = one
else
! Some of the input values are nonzero
bmin = bmax
do k = 1, np
if (beta(k) .ne. zero) then
!--------------------------------^---------------------------------------------
!!! FPT - 3087 REAL or COMPLEX quantity tested for exact equality/inequality
!------------------------------------------------------------------------------
bmin = min(bmin, abs(beta(k)))
end if
end do
bigdif = log10(bmax) - log10(bmin) .ge. one
do k = 1, np
if (beta(k) .eq. zero) then
!--------------------------------^---------------------------------------------
!!! FPT - 3087 REAL or COMPLEX quantity tested for exact equality/inequality
!------------------------------------------------------------------------------
ssf(k) = ten/bmin
else
if (bigdif) then
ssf(k) = one/abs(beta(k))
else
ssf(k) = one/bmax
end if
end if
end do

end if

end subroutine dsclb

0 comments on commit 4c71463

Please sign in to comment.