Reputation: 57
I am digging in gnuplot script. I am trouble with handling of variables.
My calculated variables sometimes are real , sometimes string ("outrange" etc).
Next step i want to put them into a long string after some calculations, but I cannot do.
For example,
my_return_var="1.2 3.4 5 outrange 9 20 3 4"
newstr=""
do for [tmp in my_return_var]{
newstr=newstr.sprintf("%7.3f ",tmp*4)
print newstr
}
Because fourth value is "outrange", sprintf return error: f_sprintf: attempt to print string value with numeric format
Thus, if gnuplot has a function checking if the input is string or not and return 1 or 0, like isstring() in C, I could skip this.
Is there any other idea?
Upvotes: 1
Views: 165
Reputation: 48420
No, gnuplot doesn't have a string checking function. But you can do string comparison with eq
or ne
to check against a fixed placeholder:
my_return_var="1.2 3.4 5 outrange 9 20 3 4"
newstr=""
do for [tmp in my_return_var] {
if (tmp ne "outrange") {
newstr=newstr.sprintf("%7.3f ",tmp*4)
print newstr
}
}
Upvotes: 1