I want to use some printf
to print to a file.
I can use
for{i in set1} printf '%10.5f\n',var1[i] >> ('a' & 'very' & 'long' & 'string' & 123 & sprintf('%5d', foo));
for{i in set2} printf '%10.5f\n',var2[i] >> ('a' & 'very' & 'long' & 'string' & 123 & sprintf('%5d', foo));
for{i in set3} printf '%10.5f\n',var3[i] >> ('a' & 'very' & 'long' & 'string' & 123 & sprintf('%5d', foo));
But I don't want to repeat the file each time.
It seems option log_file
should do the trick, but doesn't work for me: the file is created but empty, and the output is printed in the console.
I have discovered that I must change
option log_file
after printing, because it seems that AMPL doesn't close the file, even if I useclose
.Then, the following works: