As part of some maxima ramblings, a little script to take a fortan expression, which is used to generate efficiently computed list of function values.

A possible use for this is to generate heavy graphs from mathematica expressions, which can be converted into fortran expressions with the fortran command:


The idea is to have a easy to use C program call a little fortran subroutine with the fortran code in it, and that the whole operation is done by a tcl proc, which also takes care of the combined compilation of the fortran and C function value loop code, and the exec of the resulting executable:

 # Feed this Tcl proc a fortran expression
 proc formake {e} {
   global f
   set t "      subroutine sayhello(x,r)
        real a,r
        r = "
   append t $e
   append t "


   set f [open sub.f w]
   puts $f $t
   close $f
   exec gcc -o fm sub.f main.c -lm
   return [exec fm]

This, or an adapted, C program is needed in the current directory:

 /* This is file: main.c */

 extern void sayhello_(float *, float *);

 int main(argc, argv)
 int argc;
 char *argv[];
   float in, out;
   float x, start, stop, incr;

   if (argc == 1) {
      start = -10.0;
      stop = 10.0;
      incr = 2.0;
   } else exit(-1);
   for (x=start; x<=stop; x+=incr) {
      in = x;
      printf("%f %f\n", x, (float) out);

Calling the formake routine in this case returns a formatted list of 21 X Y values, but it could return more. Of course braces could be added to automatically create a Tcl list as result.

There is nothing against using these methods in Bwise blocks.