Hello,
I have a loop on which I want to save different outputs for each loop value, I was trying the following syntax but it is not working, and I couldn't find in the Manuals an answer, how could I do it?
for W_Cons (1,6,1);
output file = "New_Code_80_FF_7_b_VFSS3_outerDIFF_GAMMA"$+ntos(W_Cons)".out" reset;
endfor;
best,
Mauricio.
3 Answers
0
To do this you need to:
- Create a string with the name of the file.
- Use this string and the caret operator (
^
) to specify the file name like this:
for W_Cons (1,6,1);
fname = "New_Code_80_FF_7_b_VFSS3_outerDIFF_GAMMA"$+ntos(W_Cons)$+".out";
output file = ^fname reset;
endfor;
0
Thank you, it worked. c\Could you briefly explain to me why is that?
0
The filename
parameter of the output
keyword is specified to take "a literal or a ^string".
Literals
Most GAUSS functions take variables. For example,
// Create a string variable
s = "Hello there!";
// Print the contents of 's'
print s;
In this case, print
acts on the contents of the variable s
. It does not print the letter s
.
With a literal, the text does not represent another value like a variable does.
// Send output to a file named my_results.txt
output file = my_results.txt reset;
In the example above, my_results.txt
is not a variable that represents a different value. It is the literal file name we want to use.
^strings
Literals work just fine unless you need to change its value during the run of your program. So we need a way to tell GAUSS, this filename is a string, don't use its literal value. That is what the caret (^) operator does with a string.
// Create string variable
filename = "my_results.txt";
// Tell the output command that filename
// is a string variable, not a literal
output file = ^filename reset;
Other commands which use literal and ^string
chdir
create
msym
open
save
saveall
shell
Your Answer
3 Answers
To do this you need to:
- Create a string with the name of the file.
- Use this string and the caret operator (
^
) to specify the file name like this:
for W_Cons (1,6,1);
fname = "New_Code_80_FF_7_b_VFSS3_outerDIFF_GAMMA"$+ntos(W_Cons)$+".out";
output file = ^fname reset;
endfor;
Thank you, it worked. c\Could you briefly explain to me why is that?
The filename
parameter of the output
keyword is specified to take "a literal or a ^string".
Literals
Most GAUSS functions take variables. For example,
// Create a string variable
s = "Hello there!";
// Print the contents of 's'
print s;
In this case, print
acts on the contents of the variable s
. It does not print the letter s
.
With a literal, the text does not represent another value like a variable does.
// Send output to a file named my_results.txt
output file = my_results.txt reset;
In the example above, my_results.txt
is not a variable that represents a different value. It is the literal file name we want to use.
^strings
Literals work just fine unless you need to change its value during the run of your program. So we need a way to tell GAUSS, this filename is a string, don't use its literal value. That is what the caret (^) operator does with a string.
// Create string variable
filename = "my_results.txt";
// Tell the output command that filename
// is a string variable, not a literal
output file = ^filename reset;
Other commands which use literal and ^string
chdir
create
msym
open
save
saveall
shell