EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
cgsub.f90
Go to the documentation of this file.
1 
27 subroutine subroutine_cg(method,n,epsin,x)
28 !
29 ! Change the maximum size of the problem dimension here
30 !
31 implicit none
32 integer, parameter :: rk = kind(1.0d0)
33 
34 integer, intent(in) :: method
35 integer, intent(in) :: n
36 real(kind=rk), intent(in) :: epsin
37 real(kind=rk), dimension(n), intent(inout) :: x
38 
39 real(kind=rk), dimension(n) :: g,d,gold,w
40 real(kind=rk) :: f,eps,tlev
41 real(kind=rk) :: time1,time2,tottime
42 real(kind=rk), parameter :: one=1.0d0
43 logical :: finish
44 integer :: iprint(2),iflag,icall,i!mp,lp,i
45 integer :: iter,nfun,irest
46 
47 
48 finish= .false.
49 !
50 ! Read problem input information
51 !
52 irest = 0 !no restarts
53 !irest = 1 !restarts every n steps
54 
55 ! IPRINT = FREQUENCY AND TYPE OF PRINTING
56 ! IPRINT(1) < 0 : NO OUTPUT IS GENERATED
57 ! IPRINT(1) = 0 : OUTPUT ONLY AT FIRST AND LAST ITERATION
58 ! IPRINT(1) > 0 : OUTPUT EVERY IPRINT(1) ITERATIONS
59 ! IPRINT(2) : SPECIFIES THE TYPE OF OUTPUT GENERATED;
60 ! THE LARGER THE VALUE (BETWEEN 0 AND 3),
61 ! THE MORE INFORMATION
62 ! IPRINT(2) = 0 : NO ADDITIONAL INFORMATION PRINTED
63 ! IPRINT(2) = 1 : INITIAL X AND GRADIENT VECTORS PRINTED
64 ! IPRINT(2) = 2 : X VECTOR PRINTED EVERY ITERATION
65 ! IPRINT(2) = 3 : X VECTOR AND GRADIENT VECTOR PRINTED
66 ! EVERY ITERATION
67 iprint(1) = 1
68 iprint(2) = 0
69 !
70 ! Check for correct dimension value n
71 !
72 if (n .lt. 0) then
73  iflag = -3
74  write(*,850)
75  go to 50
76 end if
77 
78 
79 !
80 ! Print parameters
81 !
82 if (iprint(1) .ge. 0) then
83  write(*,820)
84  write(*,840) n, method, irest
85 end if
86 
87 icall=0
88 !
89 ! This is the convergence constant
90 !
91 eps= epsin
92 
93 ! IFLAG=0 indicates an initial entry to program
94 
95 iflag=0
96 
97 !
98 ! Begin counting CPU time.
99 ! (Note: This function may not work on all operating systems.)
100 !
101 
102 
103 20 CONTINUE
104 !
105 ! Calculate the function and gradient values here
106 !
107 ! Rosenbrock test function
108 call fcn(n,x,f,g)
109 30 CONTINUE
110 !
111 ! Call the main optimization code
112 !
113 CALL cgfam(n,x,f,g,d,gold,iprint,eps,w,iflag,irest,method,finish )
114 !
115 ! IFLAG=
116 ! 0 : successful termination
117 ! 1 : return to evaluate F and G
118 ! 2 : return with a new iterate, try termination test
119 ! -i : error
120 !
121 IF(iflag.LE.0.OR.icall.GT.10000) go to 50
122 IF(iflag.EQ.1) THEN
123  icall=icall + 1
124  go to 20
125 ENDIF
126 IF(iflag.EQ.2) THEN
127 !
128 ! Termination Test. The user may replace it by some other test. However,
129 ! the parameter 'FINISH' must be set to 'TRUE' when the test is satisfied.
130 !
131  tlev= eps*(one + dabs(f))
132  i=0
133 40 i=i+1
134  IF(i.GT.n) THEN
135  finish = .true.
136  go to 30
137  ENDIF
138  IF(dabs(g(i)).GT.tlev) THEN
139  go to 30
140  ELSE
141  go to 40
142  ENDIF
143 
144 ENDIF
145 
146 50 continue
147 
148 !
149 ! Code has terminated; print final results
150 !
151 if (iprint(1).ge.0.and.iflag.ge.0) then
152  write (*,890) f
153 end if
154 return
155 !
156 ! Formatting
157 !
158 800 format (12x, i3)
159 820 format (//, ' Conjugate Gradient Minimization Routine', /)
160 840 format (/, ' n =', i6, /,' method =', i6,/,' irest =', i6,/)
161 850 format (/,' Error: negative N value'/)
162 890 format (/,' f(x*) =', 1pd16.8)
163 
164 
165 end subroutine subroutine_cg
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
subroutine subroutine_cg(method, n, epsin, x)
Nonlinear Conjugate gradient method as callable subroutine.
Definition: cgsub.f90:27
subroutine fcn(n, x, f, g)
This is the subroutine which the optimization routines call to get the objective function value and i...
Definition: 4denvar_fcn.f90:31