;;; -*- Mode: lisp -*-

(mk:defsystem odepack-package
  :source-pathname (maxima::maxima-load-pathname-directory)
  :binary-pathname (maxima::maxima-objdir "share" "odepack")
  :source-extension "lisp"
  :components
  ((:module "package"
    :source-pathname "."
    :components
    ((:file "package")))
   (:module "common-block"
    :source-pathname "src"
    :source-extension "cmn"
    :components
    ((:file "dls001")))))

(mk:defsystem odepack-dlsode
  :source-pathname (maxima::maxima-load-pathname-directory)
  :binary-pathname (maxima::maxima-objdir "share" "odepack")
  :source-extension "lisp"
  :depends-on ("odepack-package")
  :components
  ((:module "src"
    :components
    ((:file "dlsode"
      :depends-on ("dstode" "xerrwd" "dintdy" "dvnorm" "dewset"))
     (:file "dintdy"
      :depends-on ("xerrwd"))
     (:file "dstode"
      :depends-on ("dvnorm" "dcfode"))
     (:file "dgbfa"
      :depends-on ("idamax" "dscal" "dvnorm"))
     (:file "dcfode")
     (:file "dprepj"
      :depends-on ("dgbfa" "dgefa" "dvnorm"))
     (:file "dsolsy"
      :depends-on ("dgbsl" "dgesl"))
     (:file "dewset")
     (:file "dvnorm")
     (:file "dsrcom")
     (:file "dgefa"
      :depends-on ("idamax" "dscal" "daxpy"))
     (:file "dgesl"
      :depends-on ("daxpy" "ddot"))
     (:file "dgbsl"
      :depends-on ("daxpy" "ddot"))
     (:file "dscal")
     (:file "ddot")
     (:file "idamax")
     (:file "dumach"
      :depends-on ("dumsum"))
     (:file "xerrwd"
      :depends-on ("ixsav"))
     (:file "xsetun"
      :depends-on ("ixsav"))
     (:file "xsetf"
      :depends-on ("ixsav"))
     (:file "ixsav")
     (:file "iumach")
     (:file "daxpy")
     (:file "dumsum")))))

(mk:defsystem maxima-odepack
  :source-pathname (maxima::maxima-load-pathname-directory)
  :binary-pathname (maxima::maxima-objdir "share" "odepack")
  :depends-on ("odepack")
  :components
  ((:file "dlsode-interface")))

(mk:defsystem maxima-dlsode
  :source-pathname (maxima::maxima-load-pathname-directory)
  :binary-pathname (maxima::maxima-objdir "share" "odepack")
  :depends-on ("odepack-dlsode")
  :source-extension "lisp"
  :components
  ((:file "dlsode-interface")))

#+nil
(mk:defsystem odepack
  :source-pathname (maxima::maxima-load-pathname-directory)
  :binary-pathname (maxima::maxima-objdir "share" "odepack")
  :components
  ((:module package
    :source-pathname ""
    :components
    ((:file "package")))
   (:module src
    :depends-on ("package")
    :components
	    ((:file "adjlr"
	      :depends-on ("nroc" "nsfc" "nnfc" "nnsc"))
	     (:file "cdrv"
	      :depends-on ("nntc"))
	     (:file "cntnzu")
	     (:file "daigbt"
	      :depends-on ("ddecbt" "dsolbt"))
	     (:file "dainvg"
	      :depends-on ("dgefa" "dgesl" "dgbfa" "dgbsl"))
	     (:file "dainvgs")
	     (:file "datp"
	      :depends-on ("dvnorm" "dcopy"))
	     (:file "datv"
	      :depends-on ("dcopy" "dnrm2" "dcopy"))
	     (:file "daxpy")
	     (:file "dbnorm")
	     (:file "dcfode")
	     (:file "dcopy")
	     (:file "ddecbt"
	      :depends-on ("dgefa" "dgesl" "ddot"))
	     (:file "ddot")
	     (:file "dewset")
	     (:file "dfnorm")
	     (:file "dgbfa"
	      :depends-on ("idamax" "dscal" "daxpy"))
	     (:file "dgbsl"
	      :depends-on ("daxpy"))
	     (:file "dgefa"
	      :depends-on ("idamax" "dscal" "daxpy"))
	     (:file "dgesl"
	      :depends-on ("daxpy" "ddot"))
	     (:file "dhefa"
	      :depends-on ("idamax"))
	     (:file "dhels")
	     (:file "dheqr")
	     (:file "dhesl")
	     (:file "dintdy"
	      :depends-on ("xerrwd"))
	     (:file "diprep"
	      :depends-on ("dprep"))
	     ;; This routine takes a slice of a double precision array and
	     ;; passes it to dprepi as a integer array. That won't work in
	     ;; Lisp!
	     (:file "diprepi"
	      :depends-on ("dprepi"))
	     (:file "dlhin"
	      :depends-on ("dvnorm"))
	     (:file "dlsoda"
	      :depends-on ("xerrwd" "dmnorm" "dstoda"))
	     (:file "dlsodar"
	      :depends-on ("drchek"))
	     (:file "dlsode"
	      :depends-on ("dstode"))
	     (:file "dlsodes"
	      :depends-on ("dstode" "dewset"))
	     (:file "dlsodi"
	      :depends-on ("dstodi" "dainvg"))
	     (:file "dlsodis"
	      :depends-on ("dstodi" "dainvgs"))
	     (:file "dlsodkr"
	      :depends-on ("drchek" "dstoka"))
	     (:file "dlsodpk"
	      :depends-on ("dstodpk"))
	     (:file "dlsoibt"
	      :depends-on ("dstodi"))
	     (:file "dmnorm")
	     (:file "dnrm2")
	     (:file "dorthog")
	     (:file "dpcg")
	     (:file "dpcgs")
	     (:file "dpjibt")
	     (:file "dpkset")
	     (:file "dprep"
	      :depends-on ("jgroup" "odrv"))
	     (:file "dprepi"
	      :depends-on ("jgroup" "odrv"))
	     (:file "dprepj")
	     (:file "dprepji")
	     (:file "dprja")
	     (:file "dprjis")
	     (:file "dprjs")
	     (:file "drchek"
	      :depends-on ("droots"))
	     (:file "droots")
	     (:file "dscal")
	     (:file "dsetpk")
	     (:file "dslsbt")
	     (:file "dsolbt")
	     (:file "dsolpk"
	      :depends-on ("dspiom" "dspigmr" "dusol"))
	     (:file "dsolss")
	     (:file "dsolsy")
	     (:file "dspigmr")
	     (:file "dspiom")
	     (:file "dsrcar")
	     (:file "dsrckr")
	     (:file "dsrcma")
	     (:file "dsrcms")
	     (:file "dsrcom")
	     (:file "dsrcpk")
	     (:file "dstoda")
	     (:file "dstode")
	     (:file "dstodi")
	     (:file "dstodpk"
	      :depends-on ("dpkset" "dsolpk"))
	     (:file "dstoka"
	      :depends-on ("dsetpk" "dsolpk"))
	     (:file "dumach"
	      :depends-on ("dumsum"))
	     (:file "dumsum")
	     (:file "dusol")
	     (:file "dvnorm")
	     (:file "idamax")
	     (:file "iumach")
	     (:file "ixsav")
	     (:file "jgroup")
	     (:file "md"
	      :depends-on ("mdi" "mdm" "mdp" "mdu"))
	     (:file "mdi")
	     (:file "mdm")
	     (:file "mdp")
	     (:file "mdu")
	     (:file "nnfc")
	     (:file "nnsc")
	     (:file "nntc")
	     (:file "nroc")
	     (:file "nsfc")
	     (:file "odrv"
	      :depends-on ("sro" "md"))
	     (:file "sro")
	     (:file "xerrwd"
	      :depends-on ("ixsav"))
	     (:file "xsetf")
	     (:file "xsetun")))))


#|
;;; Demo programs
;;;
;;; Note: Each of the demos should probably be run in a separate Lisp
;;; instance because some of the demos define functions with the same
;;; name but different parameters.  This will really confuse the
;;; generated code, because the generated code uses knowledge of the
;;; function to generate the call.

;; (opkdemo1)
;;
;; Output matches Fortran code.
(mk:defsystem odedemo-lsode
    :source-pathname (translate-logical-pathname "odepack:demo1")
    :binary-pathname (translate-logical-pathname "odepack:demo1")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo1")
     (:file "f1")
     (:file "jac1")
     (:file "f2")
     (:file "jac2")
     (:file "edit2")))


;; This won't work because opkdemo2 equivalences two arrays together.
;; f2cl doesn't know how to handle that yet.
(mk:defsystem odedemo-lsodes
    :source-pathname (translate-logical-pathname "odepack:")
    :binary-pathname (translate-logical-pathname "odepack:lib")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo2")))

;; (opkdemo3)
;;
;; Output matches Fortran code.
(mk:defsystem odedemo-lsoda
    :source-pathname (translate-logical-pathname "odepack:demo3")
    :binary-pathname (translate-logical-pathname "odepack:demo3")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo3")
     (:file "f1")
     (:file "jac1")
     (:file "f2")
     (:file "jac2")
     (:file "edit2")))

;; (opkdemo4)
;;
;; Output matches Fortran code.
(mk:defsystem odedemo-lsodar
    :source-pathname (translate-logical-pathname "odepack:demo4")
    :binary-pathname (translate-logical-pathname "odepack:demo4")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo4")
     (:file "f1")
     (:file "gr1")
     (:file "f2")
     (:file "jac2")
     (:file "gr2")))

;; (opkdemo5)
;;
;; This test takes quite a while to run.  Probably could be optimized
;; more if we were more careful about array declarations.  Assumption
;; untested, though.
;;
;; This seems to work, and the output matches the Fortran output,
;; except the test with mf = 29 isn't printed out.  Don't know why.
;;
;; The output is placed in demout in the directory where this is run.
;; Compare this to demo-lsodpk.out
(mk:defsystem odedemo-lsodpk
    :source-pathname (translate-logical-pathname "odepack:demo5")
    :binary-pathname (translate-logical-pathname "odepack:demo5")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t :declare-common t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo5")
     (:file "setpar")
     (:file "gset")
     (:file "cinit")
     (:file "outweb")
     (:file "fweb")
     (:file "webr")
     (:file "jacbg")
     (:file "fbg")
     (:file "solsbg")
     (:file "gs")))

;; This seems to work.
(mk:defsystem odedemo-lsodkr
    :source-pathname (translate-logical-pathname "odepack:")
    :binary-pathname (translate-logical-pathname "odepack:lib")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t :declare-common t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo6")))


;; This runs and the expected output seems ok.
(mk:defsystem odedemo-lsodi
    :source-pathname (translate-logical-pathname "odepack:demo7")
    :binary-pathname (translate-logical-pathname "odepack:demo7")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t :declare-common t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo7"
	    :depends-on ("elkup"))
     (:file "gfun")
     (:file "res"
	    :depends-on ("gfun"))
     (:file "addabd")
     (:file "addafl")
     (:file "jacbd")
     (:file "jacfl")
     (:file "elkup")))

;; This seems to work
(mk:defsystem odedemo-lsoibt
    :source-pathname (translate-logical-pathname "odepack:demo8")
    :binary-pathname (translate-logical-pathname "odepack:demo8")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t :declare-common t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo8"
	    :depends-on ("setic"
			 "edit"
			 "maxerr"))
     (:file "addabt")
     (:file "edit")
     (:file "gfun")
     (:file "jacbt")
     (:file "maxerr")
     (:file "res"
	    :depends-on ("subav"
			 "gfun"))
     (:file "setic")
     (:file "subav")
     ))

;; Doesn't work.  DIPREPI takes a double precision array and slices it
;; up and passes it to DPREPI which wants integer arrays.  That ain't
;; gonna work in Lisp!
(mk:defsystem odedemo-lsodis
    :source-pathname (translate-logical-pathname "odepack:")
    :binary-pathname (translate-logical-pathname "odepack:lib")
    :source-extension "f"
    :language :f2cl
    :compiler-options (:common-as-array t :declare-common t)
    :depends-on ("odepack")
    :components
    ((:file "opkdemo9")))
|#