[Maxima] with_stdout, streams, & strings, was: f90 language translation example
robert.dodier at gmail.com
Tue Jul 17 09:10:12 CDT 2007
On 7/13/07, Todd Hay <haymeister at gmail.com> wrote:
> I'd like to be able to write a file from maxima that I can paste directly
> into a fortran 90 subroutine. The 'f90' module seems to be suited for this
> but I don't know how to gain access to the string that f90(expr); prints to
> the screen (f90 always returns 'done' by design). I need access to the
> string so that I can manipulate it and concatenate another string to the
> expression before writing to the file.
Todd, I've (1) modified with_stdout to accept an argument which is a
Lisp stream (more or less an open file), and (2) made a simple-minded
interface to the Lisp functions for string output streams.
With those changes together, I think you can get what you've
described above, as shown in the example session below.
I've appended the changes as a patch, which I'll commit if I
don't hear any complaints.
PS. Example session:
(%i1) s : make_string_output_stream ();
(%o1) #<OUTPUT STRING-OUTPUT-STREAM>
(%i2) load (f90);
(%i3) with_stdout (s, f90 (expand ((sin(a) - sin(b))^3)));
(%i4) s1 : get_output_stream_string (s);
(%i5) with_stdout (s, f90 (expand ((cos(a) - cos(b))^3)));
(%i6) s2 : get_output_stream_string (s);
(%i7) concat (s1, s2);
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3484 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20070717/a23272d7/attachment.obj
More information about the Maxima