On Sat, 11 Jul 2009, Andrea Giusto wrote:
I was wondering if it's possible to call FORTRAN routines from a
gretl script, very much like it is possible to do in R? Of
course one could use gretl's understanding of R and from R call
some fortran routine inside of gretl but this seems unnecessary
lengthy and a direct call would be more convenient...
The only "foreign" code directly supported by gretl is interpreted
code (or code that has its own just-in-time compiler). You can't
embed C or Fortran or any other language that needs to be
compiled.
You can, however, use gretl's shell command to call compiled
programs written in any language. More ambitiously, you could
write out Fortran code from gretl ("outfile" command), use a
shell escape to compile and run the code, then grab the output
(either as CSV or via gretl's mread function).
Trivial proof of concept:
<script>
set echo off
outfile foo.c --write
print "#include <stdio.h>"
print "int main (void) {"
print "printf("Hello from gretl\n");
print "return 0; }"
outfile --close
! gcc -Wall foo.c && ./a.out > foo.out
string foo_out = readfile("foo.out")
printf "From foo.c, got:\n'%s'\n", foo_out
</script>
Come to think of it, we could add a "compiler=" flag to the
foreign command, such that you could write:
foreign language=C compiler=gcc
#include <stdio.h>
int main (void) {
printf("Hello from gretl\n");
return 0;
}
end foreign
In which case gretl would understand that the output from
compilation should be run as an executable in its own right
(and this could be given an automatic temporary name).
Hmm, interesting but not top of my list right now.
Allin Cottrell