On 2/8/12, Pawe? Cesar Sanjuan Szklarz <paweld2 at gmail.com> wrote:
> My question is: how to generate dq(i) in stand of dq(1,i)?? I am
> using f90mx inside generateOctaveFunction.
I've committed the following changes to f90mx and fortmx,
so now assignments to a 1-dimensional array are generated
when the argument is a list (which caused an error before).
A matrix is treated the same as before. In particular, no attempt
is made to treat a 1-row or 1-column matrix as 1-dimensional.
You can apply this patch to your local Maxima installation,
or you can wait for the next release (sometime in April).
Hope this helps,
Robert Dodier
PS.
$ git diff d3f131579^..d3f131579
diff --git a/share/contrib/f90.lisp b/share/contrib/f90.lisp
index 6c80b1e..4a0ce80 100644
--- a/share/contrib/f90.lisp
+++ b/share/contrib/f90.lisp
@@ -90,26 +90,34 @@
;; Takes a name and a matrix and prints a sequence of F90 assignment
;; statements of the form
;; NAME(I,J) = <corresponding matrix element>
+;; or, when the second argument is a list,
+;; NAME(I) = <list element>
(defmfun $f90mx (name mat)
(cond ((not (symbolp name))
- (merror "~%First argument to `f90mx' must be a symbol."))
- ((not ($matrixp mat))
- (merror "Second argument to `f90mx' not a matrix: ~M" mat)))
- (do ((mat (cdr mat) (cdr mat)) (i 1 (1+ i)))
- ((null mat))
- (do ((m (cdar mat) (cdr m)) (j 1 (1+ j)))
- ((null m))
- (f90-print `((mequal) ((,name) ,i ,j) ,(car m)))))
+ (merror "f90mx: first argument must be a symbol; found: ~M" name))
+ ((not (or ($matrixp mat) ($listp mat)))
+ (merror "f90mx: second argument must be a list or matrix;
found: ~M" mat)))
+ (cond
+ (($matrixp mat)
+ (do ((mat (cdr mat) (cdr mat)) (i 1 (1+ i)))
+ ((null mat))
+ (do ((m (cdar mat) (cdr m)) (j 1 (1+ j)))
+ ((null m))
+ (f90-print `((mequal) ((,name) ,i ,j) ,(car m))))))
+ (($listp mat)
+ (do ((mat (cdr mat) (cdr mat)) (i 1 (1+ i)))
+ ((null mat))
+ (f90-print `((mequal) ((,name) ,i) ,(car mat))))))
'$done)
(defmspec $f90 (expr)
(dolist (l (cdr expr))
(let ((value (strmeval l)))
(cond ((msetqp l) (setq value `((mequal) ,(cadr l) ,(meval l)))))
- (cond ((and (symbolp l) ($matrixp value))
+ (cond ((and (symbolp l) (or ($matrixp value) ($listp value)))
($f90mx l value))
((and (not (atom value)) (eq (caar value) 'mequal)
- (symbolp (cadr value)) ($matrixp (caddr value)))
+ (symbolp (cadr value)) (or ($matrixp (caddr value))
($listp (caddr value))))
($f90mx (cadr value) (caddr value)))
(t (f90-print value))))))
diff --git a/src/fortra.lisp b/src/fortra.lisp
index 21da838..847a3e1 100644
--- a/src/fortra.lisp
+++ b/src/fortra.lisp
@@ -30,17 +30,17 @@
(defmvar $fortfloat nil "Something JPG is working on.")
;; This function is called from Macsyma toplevel. If the argument is a
-;; symbol, and the symbol is bound to a matrix, then the matrix is printed
+;; symbol, and the symbol is bound to a matrix or list, then the
value is printed
;; using an array assignment notation.
(defmspec $fortran (l)
(setq l (fexprcheck l))
(let ((value (strmeval l)))
(cond ((msetqp l) (setq value `((mequal) ,(cadr l) ,(meval l)))))
- (cond ((and (symbolp l) ($matrixp value))
+ (cond ((and (symbolp l) (or ($matrixp value) ($listp value)))
($fortmx l value))
((and (not (atom value)) (eq (caar value) 'mequal)
- (symbolp (cadr value)) ($matrixp (caddr value)))
+ (symbolp (cadr value)) (or ($matrixp (caddr value))
($listp (caddr value))))
($fortmx (cadr value) (caddr value)))
(t (fortran-print value)))))
@@ -144,17 +144,25 @@
;; Takes a name and a matrix and prints a sequence of Fortran assignment
;; statements of the form
;; NAME(I,J) = <corresponding matrix element>
+;; or, when the second argument is a list,
+;; NAME(I) = <list element>
(defmfun $fortmx (name mat &optional (stream *standard-output*) &aux
($loadprint nil))
(cond ((not (symbolp name))
(merror (intl:gettext "fortmx: first argument must be a
symbol; found: ~M") name))
- ((not ($matrixp mat))
- (merror (intl:gettext "fortmx: second argument must be a
matrix; found: ~M") mat)))
- (do ((mat (cdr mat) (cdr mat)) (i 1 (1+ i)))
- ((null mat))
- (do ((m (cdar mat) (cdr m)) (j 1 (1+ j)))
- ((null m))
- (fortran-print `((mequal) ((,name) ,i ,j) ,(car m)) stream)))
+ ((not (or ($matrixp mat) ($listp mat)))
+ (merror (intl:gettext "fortmx: second argument must be a list
or matrix; found: ~M") mat)))
+ (cond
+ (($matrixp mat)
+ (do ((mat (cdr mat) (cdr mat)) (i 1 (1+ i)))
+ ((null mat))
+ (do ((m (cdar mat) (cdr m)) (j 1 (1+ j)))
+ ((null m))
+ (fortran-print `((mequal) ((,name) ,i ,j) ,(car m)) stream))))
+ (($listp mat)
+ (do ((mat (cdr mat) (cdr mat)) (i 1 (1+ i)))
+ ((null mat))
+ (fortran-print `((mequal) ((,name) ,i) ,(car mat)) stream))))
'$done)
;; Local Modes: