77program example_hybrd1
88
99 use minpack_module, only: wp, hybrd1, dpmpar, enorm
10+ use iso_fortran_env, only: nwrite = > output_unit
11+
1012 implicit none
11- integer j, n, info, lwa, nwrite
12- real (wp) tol, fnorm
13- real (wp) x(9 ), fvec(9 ), wa(180 )
1413
15- ! > Logical output unit is assumed to be number 6.
16- data nwrite / 6 /
14+ integer , parameter :: n = 9
15+ integer , parameter :: lwa = (n * ( 3 * n +13 )) / 2
1716
18- n = 9
17+ integer :: j, info
18+ real (wp) :: tol, fnorm
19+ real (wp) :: x(n), fvec(n), wa(lwa)
1920
2021 ! > The following starting values provide a rough solution.
21- do j = 1 , 9
22- x(j) = - 1.d0
23- end do
24-
25- lwa = 180
22+ x = - 1.0_wp
2623
2724 ! > Set tol to the square root of the machine precision.
2825 ! > unless high precision solutions are required,
2926 ! > this is the recommended setting.
30- tol = dsqrt (dpmpar(1 ))
27+ tol = sqrt (dpmpar(1 ))
3128
3229 call hybrd1(fcn, n, x, fvec, tol, info, wa, lwa)
3330 fnorm = enorm(n, fvec)
34- write (nwrite, 1000 ) fnorm, info, (x(j), j= 1 , n)
3531
36- 1000 format ( 5x , " FINAL L2 NORM OF THE RESIDUALS " , d15.7 // &
37- 5x , " EXIT PARAMETER " , 16x , i10 // &
38- 5x , " FINAL APPROXIMATE SOLUTION " // &
39- ( 5x , 3d15 . 7 ))
32+ write (nwrite, ' (5x,a, d15.7//5x,a,16x,i10//5x,a//(5x,3d15.7)) ' ) &
33+ " FINAL L2 NORM OF THE RESIDUALS " , fnorm, &
34+ " EXIT PARAMETER " , info, &
35+ " FINAL APPROXIMATE SOLUTION " , x
4036
4137 ! > Results obtained with different compilers or machines
4238 ! > may be slightly different.
@@ -62,9 +58,13 @@ subroutine fcn(n, x, fvec, iflag)
6258 real (wp), intent (in ) :: x(n)
6359 real (wp), intent (out ) :: fvec(n)
6460
65- integer k
66- real (wp) one, temp, temp1, temp2, three, two, zero
67- data zero, one, two, three/ 0.0d0 , 1.0d0 , 2.0d0 , 3.0d0 /
61+ integer :: k
62+ real (wp) :: temp, temp1, temp2
63+
64+ real (wp),parameter :: zero = 0.0_wp
65+ real (wp),parameter :: one = 1.0_wp
66+ real (wp),parameter :: two = 2.0_wp
67+ real (wp),parameter :: three = 3.0_wp
6868
6969 do k = 1 , n
7070 temp = (three - two* x(k))* x(k)
0 commit comments