Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Tuesday, July 12, 2011

Joining string variables

When defining file names or titles, is often useful to join string variables in order to make our scripts more comprehensible. To do so, you have to join this variables using dots.
Example:
  • DATA='satellite'
  • DATE='12/07/12'
  • EXTENSION='dat'
  • set title DATA.' measurements - '.DATE
  • plot DATA.'_data.'.EXTENSION
This will plot the file "satellite_data.dat" and will entitle the plot as "satellite measurements - 12/07/12"

Wednesday, July 6, 2011

Conditional statements

The syntaxis for writing conditional statements in GNUPLOT is:
  • if (<condition>) <command1>; <command2>; ...; else <command1>; <command2>; ...

List of conditions:
  eq  equal to (for strings)
  ne  non equal to (for strings)
  ==  equal to (for numbers)
  !=  non equal to (for numbers)
  <   lower than
  <=  lower than or equal to
  >   greater than
  >=  greater than or equal to

Combining several conditions:
  &&  and
  ||  or

Example:
  • if (FILE_NUM==1) \
  • 'whatever1.dat' u 1:2 w l lw 1 lt 3 notitle;\
  • 'whatever1.dat' u 1:3 w l lw 5 lt 1 notitle
  • if (FILE_NUM==2) \
  • 'whatever2.dat' u 1:2 w l lw 1 lt 3 notitle;\
  • 'whatever2.dat' u 1:3 w l lw 5 lt 1 notitle

Wednesday, June 29, 2011

Backslash at the end of a line

This tool is not essential for programming, but it can make our scripts more legible and easy to interpret. It is useful when you have to put several commands in the same script line but you preffer to separate them while working with your text editor. Then, the line:
  • plot 0 w l ls 0 notitle, 'whatever1.dat' u 1:2 w l lw 1 lt 3 notitle, 'whatever1.dat' u 1:3 w l lw 5 lt 1 notitle, 'whatever2.dat' u 1:2 w l lw 1 lt 3 notitle, 'whatever2.dat' u 1:3 w l lw 5 lt 1 notitle
is equivalent to:
  • plot \
  • 0 w l ls 0 notitle, \
  • 'whatever1.dat' u 1:2 w l lw 1 lt 3 notitle, \
  • 'whatever1.dat' u 1:3 w l lw 5 lt 1 notitle, \
  • 'whatever2.dat' u 1:2 w l lw 1 lt 3 notitle, \
  • 'whatever2.dat' u 1:3 w l lw 5 lt 1 notitle

This is not restricted to the plot command, but you can use it wherever you want. So:
  • set palette defined (0 "red", 1000 "orange", 1600 "dark-yellow", 1999 "yellow", 2000 "grey", 2001 "green", 2400 "dark-green", 3000 "cyan", 4000 "blue")
is again equivalent to:
  • set palette defined (\
  • 0 "red", \
  • 1000 "orange", \
  • 1600 "dark-yellow", \
  • 1999 "yellow", \
  • 2000 "grey", \
  • 2001 "green", \
  • 2400 "dark-green", \
  • 3000 "cyan", \
  • 4000 "blue")

Caution: Leaving a blank space after the backslash will result in a failure of the script.