1 ;;; Compiled by f2cl version:
2 ;;; ("f2cl1.l,v 1.215 2009/04/07 22:05:21 rtoy Exp $"
3 ;;; "f2cl2.l,v 1.37 2008/02/22 22:19:33 rtoy Exp $"
4 ;;; "f2cl3.l,v 1.6 2008/02/22 22:19:33 rtoy Exp $"
5 ;;; "f2cl4.l,v 1.7 2008/02/22 22:19:34 rtoy Exp $"
6 ;;; "f2cl5.l,v 1.200 2009/01/19 02:38:17 rtoy Exp $"
7 ;;; "f2cl6.l,v 1.48 2008/08/24 00:56:27 rtoy Exp $"
8 ;;; "macros.l,v 1.112 2009/01/08 12:57:19 rtoy Exp $")
10 ;;; Using Lisp CMU Common Lisp 19f (19F)
12 ;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls nil)
13 ;;; (:coerce-assigns :as-needed) (:array-type ':array)
14 ;;; (:array-slicing t) (:declare-common nil)
15 ;;; (:float-format double-float))
20 (let ((factor 100.0) (one 1.0) (zero 0.0))
21 (declare (type (double-float) factor one zero
))
22 (defun hybrd1 (fcn n x fvec tol info wa lwa
)
23 (declare (type (double-float) tol
)
24 (type (array double-float
(*)) wa fvec x
)
25 (type (f2cl-lib:integer4
) lwa info n
))
26 (f2cl-lib:with-multi-array-data
27 ((x double-float x-%data% x-%offset%
)
28 (fvec double-float fvec-%data% fvec-%offset%
)
29 (wa double-float wa-%data% wa-%offset%
))
30 (prog ((epsfcn 0.0) (xtol 0.0) (index$
0) (j 0) (lr 0) (maxfev 0) (ml 0)
31 (mode 0) (mu 0) (nfev 0) (nprint 0))
32 (declare (type (f2cl-lib:integer4
) nprint nfev mu mode ml maxfev lr j
34 (type (double-float) xtol epsfcn
))
39 '" the purpose of hybrd1 is to find a zero of a system of"
40 '" n nonlinear functions in n variables by a modification"
41 '" of the powell hybrid method. this is done by using the"
42 '" more general nonlinear equation solver hybrd. the user"
43 '" must provide a subroutine which calculates the functions."
44 '" the jacobian is then calculated by a forward-difference"
47 '" the subroutine statement is"
49 '" subroutine hybrd1(fcn,n,x,fvec,tol,info,wa,lwa)"
53 '" fcn is the name of the user-supplied subroutine which"
54 '" calculates the functions. fcn must be declared"
55 '" in an external statement in the user calling"
56 '" program, and should be written as follows."
58 '" subroutine fcn(n,x,fvec,iflag)"
60 '" double precision x(n),fvec(n)"
62 '" calculate the functions at x and"
63 '" return this vector in fvec."
68 '" the value of iflag should not be changed by fcn unless"
69 '" the user wants to terminate execution of hybrd1."
70 '" in this case set iflag to a negative integer."
72 '" n is a positive integer input variable set to the number"
73 '" of functions and variables."
75 '" x is an array of length n. on input x must contain"
76 '" an initial estimate of the solution vector. on output x"
77 '" contains the final estimate of the solution vector."
79 '" fvec is an output array of length n which contains"
80 '" the functions evaluated at the output x."
82 '" tol is a nonnegative input variable. termination occurs"
83 '" when the algorithm estimates that the relative error"
84 '" between x and the solution is at most tol."
86 '" info is an integer output variable. if the user has"
87 '" terminated execution, info is set to the (negative)"
88 '" value of iflag. see description of fcn. otherwise,"
89 '" info is set as follows."
91 '" info = 0 improper input parameters."
93 '" info = 1 algorithm estimates that the relative error"
94 '" between x and the solution is at most tol."
96 '" info = 2 number of calls to fcn has reached or exceeded"
99 '" info = 3 tol is too small. no further improvement in"
100 '" the approximate solution x is possible."
102 '" info = 4 iteration is not making good progress."
104 '" wa is a work array of length lwa."
106 '" lwa is a positive integer input variable not less than"
109 '" subprograms called"
111 '" user-supplied ...... fcn"
113 '" minpack-supplied ... hybrd"
115 '" argonne national laboratory. minpack project. march 1980."
116 '" burton s. garbow, kenneth e. hillstrom, jorge j. more"
121 '" check the input parameters for errors."
126 (< lwa
(the f2cl-lib
:integer4
(truncate (* n
(+ (* 3 n
) 13)) 2))))
131 (setf maxfev
(f2cl-lib:int-mul
200 (f2cl-lib:int-add n
1)))
133 (setf ml
(f2cl-lib:int-sub n
1))
134 (setf mu
(f2cl-lib:int-sub n
1))
137 (f2cl-lib:fdo
(j 1 (f2cl-lib:int-add j
1))
140 (setf (f2cl-lib:fref wa-%data%
(j) ((1 lwa
)) wa-%offset%
) one
)
143 (setf lr
(the f2cl-lib
:integer4
(truncate (* n
(+ n
1)) 2)))
144 (setf index$
(f2cl-lib:int-add
(f2cl-lib:int-mul
6 n
) lr
))
146 (var-0 var-1 var-2 var-3 var-4 var-5 var-6 var-7 var-8 var-9
147 var-10 var-11 var-12 var-13 var-14 var-15 var-16 var-17 var-18
148 var-19 var-20 var-21 var-22 var-23
)
149 (hybrd fcn n x fvec xtol maxfev ml mu epsfcn
150 (f2cl-lib:array-slice wa double-float
(1) ((1 lwa
))) mode factor
152 (f2cl-lib:array-slice wa double-float
((+ index$
1)) ((1 lwa
))) n
153 (f2cl-lib:array-slice wa
155 ((+ (f2cl-lib:int-mul
6 n
) 1))
157 lr
(f2cl-lib:array-slice wa double-float
((+ n
1)) ((1 lwa
)))
158 (f2cl-lib:array-slice wa
160 ((+ (f2cl-lib:int-mul
2 n
) 1))
162 (f2cl-lib:array-slice wa
164 ((+ (f2cl-lib:int-mul
3 n
) 1))
166 (f2cl-lib:array-slice wa
168 ((+ (f2cl-lib:int-mul
4 n
) 1))
170 (f2cl-lib:array-slice wa
172 ((+ (f2cl-lib:int-mul
5 n
) 1))
174 (declare (ignore var-0 var-2 var-3 var-4 var-5 var-6 var-7 var-8
175 var-9 var-10 var-11 var-12 var-15 var-16 var-17
176 var-18 var-19 var-20 var-21 var-22 var-23
))
180 (if (= info
5) (setf info
4))
184 '" last card of subroutine hybrd1."
187 (return (values nil n nil nil nil info nil nil
))))))
189 (in-package #:cl-user
)
190 #+#.
(cl:if
(cl:find-package
'#:f2cl
) '(and) '(or))
191 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
192 (setf (gethash 'fortran-to-lisp
::hybrd1
193 fortran-to-lisp
::*f2cl-function-info
*)
194 (fortran-to-lisp::make-f2cl-finfo
195 :arg-types
'(t (fortran-to-lisp::integer4
) (array double-float
(*))
196 (array double-float
(*)) (double-float)
197 (fortran-to-lisp::integer4
) (array double-float
(*))
198 (fortran-to-lisp::integer4
))
199 :return-values
'(nil fortran-to-lisp
::n nil nil nil
200 fortran-to-lisp
::info nil nil
)
201 :calls
'(fortran-to-lisp::hybrd
))))