On Thu, 14 Jul 2011, Ignacio Diaz-Emparanza wrote:
 El 14/07/11 08:52, Pietro Battiston escribió:
> 
> I'm trying to have a rapid way to output numbers to files, and wrote the
> following:
> 
> # A function to dump numbers to files:
> function scalar to_file(scalar numb, string format, string filename)
>      set echo off
>      set messages off
>      outfile filename --write
>      printf format, numb
>      outfile --close
>      set echo on
>      set messages on
>      return 0
> end function
> 
> which however doesn't work. By trying different specifications, I think
> I have understood that the "filename" parameter of "outfile" and
the
> "format" parameter of "printf" cannot be variables, they are
parsed
> directly as strings by the interpreter.
> 
> Did I understand correctly?
> Is there anything I can do to solve my problem?
> 
> I do not care too much, in the end, about "format", but if there is no
> way to pass an arbitraray string to "outfile" I'm clearly trying
> something stupid.
 I think that only adding  "@" to the filename of the 'outfile' command
as in:
 outfile @filename --write
 your function should work. (not tested) 
Yes, "outfile" is a gretl command, not a function that accepts 
a string variable as input. But you can use gretl's string 
substitution mechanism, with the '@' operator preceding the 
name of a string variable to "cash it out".
The same goes for the "printf" command: you could do
printf "@format", numb
-- 
Allin Cottrell
Department of Economics
Wake Forest University, NC