How to perform control sequences under Gnuplot please?
I need to make something like
if (x == nan)
set xrange[]
else
set xrange[10:30]
I tried something like
( x > 100000 ) ? (set xrange[]) : (set xrange[10:30])
... buth without success! I spent hours trying to solve this!!
Any help please?
At worst I can create a shell script an manage this, but I think there should be some control sequences to fix this.
For gnuplot 4.4.4 the if statement must be on a single line:
if (x > 10000) set autoscale x; else set xrange [10:30]
or use \ to continue on the next line.
if (x > 10000) \
set autoscale x; \
else \
set xrange [10:30]
Since 4.6.0 gnuplot can use brackets to delimit the branches:
if (x > 10000) {
set autoscale x
} else {
set xrange [10:30]
}
Related
Need to find the index number of given value from list. I have a value from the list ,But i need to find the index number of of the value.
set i 0.0001646481396164745
set X [list 1.215647671415354e-7 1.1284486163276597e-6 4.538622670224868e-5 4.4706815970130265e-5 8.492852430208586e-6 6.077577836549608e-6 3.1041158763400745e-6 0.00015045881445985287 4.1016753016265284e-7 1.165599314845167e-6 1.8736355968940188e-6 2.9444883693940938e-5 2.5420340534765273e-5 2.0819682049477706e-6 9.529731869406532e-6 8.549810104341304e-7 1.558014082547743e-5 8.079621693468653e-6 4.868444739258848e-5 0.0001646481396164745]
have to find the index value of i from list X using TCL.
It can be easily solved with lsearch:
set c [lsearch $X $i]
If you're looking for a floating point value in a list where you only know the approximate value, you can't use lsearch. Instead you have to do it yourself:
proc findApprox {theList theValue {epsilon 1e-9}} {
set idx 0
foreach x $theList {
# Found if the difference between the list item and the target is less than epsilon
if {abs($theValue - $x) < $epsilon} {
return $idx
}
incr idx
}
return -1
# Or [error "not found"] if you prefer
}
set x [findApprox $X $i]
Note the epsilon optional argument. That's because how close you have to get depends on knowledge of the domain of the input data; it's not something that it is easy for a basic algorithm to determine for you.
I want to execute two commands as part of a single-line If -statement:
Though below snippet runs without error, variable $F_Akr_Completed is not set to 1, but the MsgBox() is displayed properly (with "F is 0").
$F_Akr_Completed = 0
$PID_Chi = Run($Command)
If $F_Akr_Completed = 0 And Not ProcessExists($PID_Chi) Then $F_Akr_Completed = 1 And MsgBox(1,1,"[Info] Akron parser completed. F is " & $F_Akr_Completed)
Any idea why there is no syntax-error reported when it's not functional?
There is no error, because
If x = x Then x And x
is a valid statement, and x And x is a logical expression. There are many ways you can do this, e.g.:
If Not ($F_Akr_Completed And ProcessExists($PID_Chi)) Then $F_Akr_Completed = 1 + 0 * MsgBox(1,1,"[Info] Akron parser completed. F is " & 1)
But that is a bad style of coding. AutoIt is a mostly verbose language and I recommend to seperate multiple statements.
You can also assign values using the ternary operator:
$F_Akr_Completed = (Not ($F_Akr_Completed And ProcessExists($PID_Chi))) ? 1 : 0
which is the same as
$F_Akr_Completed = Int(Not ($F_Akr_Completed And ProcessExists($PID_Chi)))
I am programming in bash and I try to make a graph out of 4 files using gnuplot.
My files contain in the first column the date and in the rest 10 columns the temperature of the ocean in various depths. I get the errors, line 0: invalid command and line 0: constant expression required.
MyVar="THO"
MySeas="Annual Win Spr Aut Sum"
MyWorkDir=/work/InterAnnual
echo "change dir"
cd $MyWorkDir
MyFileArx1=0001_field_${MyVar}.grb.regular
MyFileArx21=0021_field_${MyVar}.grb.regular
MyFileArx25=0025_field_${MyVar}.grb.regular
MyFileArx26=0026_field_${MyVar}.grb.regular
for MySeasName in ${MySeas} ;do
MyFile1=${MyFileArx1}_sm_${MySeasName}.col.dat
MyFile21=${MyFileArx21}_sm_${MySeasName}.col.dat
MyFile25=${MyFileArx25}_sm_${MySeasName}.col.dat
MyFile26=${MyFileArx26}_sm_${MySeasName}.col.dat
gnuplot << EOF
set term postscript eps enhanced color solid
set out 'InterAnnual.${MySeasName}.6.eps'
set key right top
set grid
set xrange [ 800:2000 ]
set size 1, 0.5
set xlabel "year"
set ylabel " T (C) "
plot "${MyFile1}" u 1:11 t 'Level-6 ${MySeasName} mil0001' w l lt, \
"${MyFile21}" u 1:11 t 'Level-6 ${MySeasName} mil0001' w l lt, \
"${MyFile25}" u 1:11 t 'Level-6 ${MySeasName} mil0001' w l lt, \
"${MyFile26}" u 1:11 t 'Level-6 ${MySeasName} mil0001' w l lt
EOF
done
`
The script works when I add in the gnuplot part: set multiplot.
For example:
gnuplot << EOF
set multiplot
... and then the rest of the lines.
I'm trying to figure out how I would go about formatting a large number to the shorter version by appending 'k' or 'm' using Lua. Example:
17478 => 17.5k
2832 => 2.8k
1548034 => 1.55m
I would like to have the rounding in there as well as per the example. I'm not very good at Regex, so I'm not sure where I would begin. Any help would be appreciated. Thanks.
Pattern matching doesn't seem like the right direction for this problem.
Assuming 2 digits after decimal point are kept in the shorter version, try:
function foo(n)
if n >= 10^6 then
return string.format("%.2fm", n / 10^6)
elseif n >= 10^3 then
return string.format("%.2fk", n / 10^3)
else
return tostring(n)
end
end
Test:
print(foo(17478))
print(foo(2832))
print(foo(1548034))
Output:
17.48k
2.83k
1.55m
Here a longer form, which uses the hint from Tom Blodget.
Maybe its not the perfect form, but its a little more specific.
For Lua 5.0, replace #steps with table.getn(steps).
function shortnumberstring(number)
local steps = {
{1,""},
{1e3,"k"},
{1e6,"m"},
{1e9,"g"},
{1e12,"t"},
}
for _,b in ipairs(steps) do
if b[1] <= number+1 then
steps.use = _
end
end
local result = string.format("%.1f", number / steps[steps.use][1])
if tonumber(result) >= 1e3 and steps.use < #steps then
steps.use = steps.use + 1
result = string.format("%.1f", tonumber(result) / 1e3)
end
--result = string.sub(result,0,string.sub(result,-1) == "0" and -3 or -1) -- Remove .0 (just if it is zero!)
return result .. steps[steps.use][2]
end
print(shortnumberstring(100))
print(shortnumberstring(200))
print(shortnumberstring(999))
print(shortnumberstring(1234567))
print(shortnumberstring(999999))
print(shortnumberstring(9999999))
print(shortnumberstring(1345123))
Result:
> dofile"test.lua"
100.0
200.0
1.0k
1.2m
1.0m
10.0m
1.3m
>
And if you want to get rid of the "XX.0", uncomment the line before the return.
Then our result is:
> dofile"test.lua"
100
200
1k
1.2m
1m
10m
1.3m
>
i have a database that contain some measure. The problem is that the measure are saved in the main units (for example, 1 mV is saved as 0.001 V).
Now I use crytal report to generate a report with these measure, but I want to convert 0.001V into 1mV.
How can i do this?
I tryed with:
if lcase({database.result_type})="eval" then
{#Test_Result}
else
(
if {database.measure}<0.001 then
{database.measure}*1000000 & "uV"
else if {database.measure}<1 then
{database.measure}*1000 & "mV"
else if {database.measure}<1000 then
{database.measure} & "V"
);
but it doesn't work. The first IF is to understand if it's a PASS/FAIL test or a measurement.
How can i do?
You formula needs to produce a consistent result, either a string or a number, but not both:
if lcase({database.result_type})="eval" then
// assuming that this is a string
{#Test_Result}
else
(
// assuming that `{database.measure}` is a number
if {database.measure}<0.001 then
ToText({database.measure}*1000000) & "uV"
else if {database.measure}<1 then
ToText({database.measure}*1000) & "mV"
else if {database.measure}<1000 then
ToText({database.measure}) & "V"
);