CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Calling a gnuplot script with Perl



Feb 13, 2017, 2:56 AM

Post #1 of 4 (2358 views)
Calling a gnuplot script with Perl Can't Post


I'm trying to call a gnuplot script using perl, so I can plot around 30 .vec files. I am using the foreach loop to apply the gnuplot script on each file but I get an error when I run it.

My simple perl script:

#!/usr/bin/perl -w 

@files = </home/HF/files/*.vec>;

foreach $file (@files) {
system ("gnuplot gnuplotloop.script");

My gnuplotloop.script looks like this:

set term pdf 
set output 'test.pdf'
set size square
set xrange [1:38]
set yrange [1:37]
set palette defined (0 "black", 1 "red", 2 "orange", 3 "green", 4 "blue")
files= '/home/HF/files/*.vec'

plot files u 2:3:1 w l lc palette

My files are in this format:


When I run the perl script I get this error:

"gnuplotloop.script", line 11: warning: Cannot find or open file "/home/HF/files/*.vec"
"gnuplotloop.script", line 11: No data in plot

Can someone please help me if you can.
Thank you

(This post was edited by FishMonger on Feb 14, 2017, 6:50 AM)


Feb 13, 2017, 7:08 AM

Post #2 of 4 (2348 views)
Re: [goudeuk] Calling a gnuplot script with Perl [In reply to] Can't Post

I do not know anything about gnuplot, but I can offer a few observations which may help you solve your own problem.

Your error messages are from gnuplot, not perl. Try running your gnuplot script from the command line. Do you have to specify a file? How? I also notice that the messages refer to line 11. Your script is not that long. Are you sure that you are using the script that you posted?

Your perl script executes gnuplot once for each file, but does not pass the filename to it. This is almost certainly wrong. I have no idea how to fix it without knowing the answers to my previous questions. Ask your perl question again when you are able to post the commands that you want perl to create and execute.

Your perl style is poor. Fixing it will not help at all with your current problem, but could be a big help in the future.
You should always use use strict and use warnings. This requires you to declare all your variables with 'my'. Use of the glob function would be easier to understand than the diamond operator.
Good Luck,


Feb 14, 2017, 1:51 AM

Post #3 of 4 (2328 views)
Re: [BillKSmith] Calling a gnuplot script with Perl [In reply to] Can't Post

Hi Bill

Thank for pointing me to the right direction. I was using the wrong path. I corrected that now. gnuplot is used to plot graphs. You don't have to specify a file when you run the script but you do have to define a file inside it.

This is my gnuplot.script:

1- set term pdf 
2- set output 'test.pdf'
3- set size square
4- set xrange [1:38]
5- set yrange [1:37]
6- set palette defined (0 "black", 1 "red", 2 "orange", 3 "green", 4 "blue")
7- files= "HeliumFoil_23434_2346673_642345-43.vec"
8- pointsize = 1.5
9-plot files u 2:3:1 w l lc palette

The script above is located in the directory where all the .vec files are stored. So I when I run it, it plots a graph in pdf format of the file defined in line 7. I am trying to use Perl to create a loop so that it creates a separate pdf graph for each of the .vec files in the directory.

So having learned a bit of Perl in the past I wrote this small "for each" loop. It works but it only prints the graph of one file because only one file is specified in the gnuplot code.
I do admin that my perl knowledge is poor. It's been a long time since I used perl.

(This post was edited by FishMonger on Feb 14, 2017, 6:50 AM)

Veteran / Moderator

Feb 14, 2017, 2:08 AM

Post #4 of 4 (2323 views)
Re: [goudeuk] Calling a gnuplot script with Perl [In reply to] Can't Post

I don't know enough of gnuplot to know whether there is a simpler solution, but you could at least do the following:
- loop on the .vec files in your directory;
- for each .vec file in the directory, create a new version of the gnuplot.script with the right source file name (and probably output filename) in it and run gnuplot.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives