Pass command line arguments to Gnuplot script

Gnuplot is a light-weight and easy to use  scientific plotting tool. Its has enough functionalities to deal with most of my demands on visualizing experimental data. If heavy computation is needed, GNU Octave can be used, of which the plotting backend is still Gnuplot. Originally, when I had a set of data files with the same structure to be plotted, I would write a Gnuplot script which could process only one file. After verifying and adjusting the script to function correctly, I would make copies of this template for each of the data files and then correspondingly change the data file name in each copy. Although, this is not elegant, it actually does the work.

Today, I thought about if I could automate the above process by writing only one general script which could process the specific file prescribed in the command line option. Because a Gnuplot script run from the command line cannot be passed any arguments, I have to think other ways. Luckily, the command gnuplot has an option -e, with its function described as follows:

-e "command list" executes the requested commands before loading the next input file.

Therefore, variable definitions can be given in the above "command list", which can be accessed from within the Gnuplot script. Multiple commands can be listed which should be separated by semicolon. For example, the following command can be run from the terminal to pass data file‘s base name and another parameter into the script plot.gpl:

gnuplot -e "basename=‘2013-10-18 sample A‘; legend_str=‘RMS‘" plot.gpl

In plot.gpl, there can be something like this:

set output basename." voltage.eps"

plot basename." raw.dat" using 1:3 lt 1 lc rgb "red" lw 1 title legend_str with lines

set output

system "eps2png \"".basename." voltage.eps\""

In the above, the period symbol is used to concatenate strings. Once we can pass arguments into the Gnuplot script, we can further use bash script or other high level script languages to process all the data files in batch. For example, the one used for plotting dc conductivity data files is as follows, which utilizes bash programming and the powerful gawk.

#! /bin/bash

# Batch plot all the data files

for dat_file in *\ processed.dat; do

formulation=`cat "${dat_file}" | grep -i formulation | gawk ‘{gsub(/^.*: */, ""); print}‘`

dat_file=`echo "${dat_file}"|gawk ‘{print $1,$2,$3}‘`

echo "Start processing ${dat_file} for ${formulation}"

gnuplot -e "basename=‘${dat_file}‘; formulation=‘${formulation}‘" plot_single_data.gpl

echo "Finished processing ${dat_file} for ${formulation}"

done

Pass command line arguments to Gnuplot script

时间: 2024-11-05 07:02:20

Pass command line arguments to Gnuplot script的相关文章

[Node.js] Pass command line arguments to node.js

Command line arguments are often used to modify the behavior of an application or specify needed parameters for operation. In this lesson, you will learn how to access the command line arguments passed to your node.js application as well as different

msiexec command line arguments

Documented command line arguments Type MSIEXEC /? and you'll get the following on-screen help: Windows ® Installer. V 5.0.7601.17514 msiexec /Option <Required Parameter> [Optional Parameter] Install Options </package | /i> <Product.msi>

An annotation based command line parser

JCommander star1000+ This is an annotation based parameter parsing framework for Java 8. The full doc is available at http://jcommander.org. Java port of Python's famous argparse command-line argument parser. https://argparse4j.github.io/ Argparse4j

[Linux Command Line and Shell Scripting Bible] basic shell script

1 #!/bin/bash 2 ############################################ 3 # @content chapter 8,9 of Linux Command Line and Shell Scripting Bible 4 # @reader gavin 5 # @date 2014/12/14 6 ############################################ 7 CHAPTER 8 8 9 + user varriab

How to build .apk file from command line(转)

How to build .apk file from command line Created on Wednesday, 29 June 2011 14:32 If you don’t want to install a number of programs for building your Android project, this article is for you. You will need only JDK, the Android SDK platform tools and

【转载】Data Science at the Command Line

Data Science at the Command Line Data Science at the Command Line is a new book written by Jeroen Janssens. This website contains information about the upcoming workshop in London, the webcast from August 20th, instructions on how to install the Data

Command Line Skills

Part 1: Command Line Interface(CLI) The Command Line Interface (CLI), is a text-based interface to the computer, where the user types in a command and the computer then executes it. The CLI environment is provided by an application on the computer kn

Chrome-Console( Command Line API Reference)

来源于:https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference The Command Line API contains a collection of convenience functions for performing common tasks: selecting and inspecting DOM elements, displaying data in read

Appendix D. Gradle Command Line

http://www.gradle.org/docs/current/userguide/gradle_command_line.html Appendix D. Gradle Command Line The gradle command has the following usage: gradle [option...] [task...] The command-line options available for the gradle command are listed below: