Results 1 to 10 of 14
Hi there,
I'm new to this forum and hope you can help me. Several years ago I made some experience with gnuplot, shell-scripting, fortran ... however most of it seems ...
- 06-01-2011 #1Just Joined!
- Join Date
- Jun 2011
- Posts
- 7
gnuplot and shell-script
Hi there,
I'm new to this forum and hope you can help me. Several years ago I made some experience with gnuplot, shell-scripting, fortran ... however most of it seems to be lost somewhere in an unreacheable corner of my brain
My problem is the following:
I'm trying to write a shell-script that automatically plots several files into one graph, saves it as eps and converts it to pdf. So far the script is functioning. I also know that I can add files by using the backslash. However, I'm wondering whether there is a way without typing all the file names.
The files are all named the same, only an increasing number at the end is different - like: name_001.txt, name_002.txt ... Is there an option like, let's say, a *-ending. Or can I do it with variables?
Another issue would be: how could I make a script asking me for the file, if for example I only want one file / or asking me how many/which files I want to plot, maybe even which column. I know that somehow it must be done with read ... yet I can't remember and my time is running out (I'm currently in the last semester of my Master Thesis), so I can't read hundreds of pages ...
as much as I'd like to - I'm currently really enjoying my time (back) with linux having vista send to nowhere.
I hope you're sympathetic and help me.
Thank you very much!
leanne_s
PS.: I hope my spelling / grammar isn't that bad - unfortunately, English is not my mothertongue
- 06-02-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
Yeah, you can use wildcards and ranges, e.g.:
would assign the following files to the $files, if they existed:Code:files=$(ls *-00[1-3]*)
file-001.txt
file-002.txt
file-003.txt
you can get args from the command line (of bash anyway) by using the $1, $2, $3, etc., e.g.:
and yes, you can use bash's read built-in function to prompt for user input with something like:Code:#!/bin/bash arg1=$1 arg2=$2 echo "first arg: $arg1" echo "seconds arg: $arg2"
Code:read -p "Give me a filename: " myfile echo "You gave me: $myfile"
- 06-02-2011 #3Just Joined!
- Join Date
- Jun 2011
- Posts
- 7
Hi atreyu,
thank you very much! The last two tips worked immedediately.However, I'm somehow encountering problems with the wildcard option, or rather with plotting my files. It seems that gnuplot recognizes which files I am referring to (tried it with different name-variations), yet when it comes to plotting them, it only plots the first file and then says:
(the same when I try gnu_002.txt ...)PHP Code:gnuplot> gnu2.txt' using 2:1 lt 1 pt 13 w p ti 'test''
^
line 0: invalid command
I think my plot command is wrong. I tried different variations, too, but none worked; e.g.:
orPHP Code:plot '$FILES' using 2:1 lt 1 pt 13 w p ti 'test'
I'd like to have all files in oneplot. By the way, right now my input is the following:PHP Code:plot '$FILES' using 2:1 lt 1 pt 13 w p ti 'test', \
Furthermore, after using wildcards it is not really plotting 'using 2:1'. It plots my y-values but puts them all at the 'zero' of my x-axis, so that I'm only getting a vertical line (or rather vertically aligned points). Not using wildcards, gnuplot plots everything perfectly ...PHP Code:FILES=$(ls gnu[1-2].txt)
Any idea? I'm sure, it's my plot command ...
Thank you very much.
leanne_s
- 06-02-2011 #4Just Joined!
- Join Date
- Jun 2011
- Posts
- 7
of course it's no PHP code ...
- 06-02-2011 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
as to your wildcard question, i'm not sure why you'd have problems. just do "echo $FILES" in your script, does it echo back your list of files? can you show an example of the script?
as to gnuplot questions, i'm no gnuplot guru, so off the top of my head, i don't know what's wrong. i do have a gnuplot script at home which i can't access right now, so i can back to you later, if nobody else jumps in to help before then.
- 06-02-2011 #6Just Joined!
- Join Date
- Jun 2011
- Posts
- 7
Hi,
here's my code: (it's also echoing the right files - only two in this case as I'm still testing)
You MIGHT not be a gnuplot guru, but you already helped me a lot! Right now, I'm also using your other tips not only to read in the names, but also variables/lines/output-file/ranges ... So,I'm really grateful! Also thank you for your fast replies!Code:#!/bin/bash FILES=$(ls gnu[1-2].txt) echo $FILES gnuplot -persist <<PLOT set xrange [0:115] set yrange [0:2.6] set xtics 0,10,115 set ytics 0,0.2,2.6 set grid xtics ytics set title "correlation of pressure differences" set xlabel "{/Symbol D} p (prechamber)" set ylabel "{/Symbol D} p (testsection)" set key box outside #In case for building an eps-file ... #set terminal postscript enhanced color solid eps 15 #set output "gnu.eps" plot '$FILES' using 2:1 lt 1 pt 13 w p ti 'test' #replot quit PLOT #epstopdf gnu.eps echo "Like it or hate it!"
- 06-02-2011 #7Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
np.
yeah, can't tell what is wrong by looking at the code - must be related to how you're calling gnuplot. will check back in l8r 2nite...
- 06-02-2011 #8Just Joined!
- Join Date
- Jun 2011
- Posts
- 7
Thx!
Just in case you want dummies:
gnu1.txt
gnu2.txtCode:0.020692 0.045158 0 0.02087 0.047993 0 0.018751 0.050429 0 0.036829 0.823043 110 0.06224 2.412641 162 0.124688 5.37927 219 0.285597 14.776962 320 0.539672 30.24578 422 1.059578 61.727639 558 1.865092 110.931687 699 0.024265 0.061796 0 0.01728 0.060176 0 0.022022 0.057191 0
The first column is the pressure difference before and after my test section, the second is the pressure difference of the prechamber (wind tunnel) and normal air pressure and the third is the frequency of the wind turbine [1/min] ... I'm a meteorologist ^^Code:0.022206 0.052979 0 0.020244 0.052795 0 0.027779 0.058449 0 0.03785 0.81835 110 0.063518 2.346761 160 0.126946 5.397205 219 0.288854 14.642722 320 0.544868 30.088113 420 1.059355 61.596884 558 1.8512 110.74555 700 0.030991 0.064493 0 0.021839 0.054339 0 0.024429 0.065023 0
- 06-03-2011 #9Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
okay, for starters, try this dumbed down version:
it doesn't do everything you want, per your original script, but at least it plots!Code:#!/bin/sh gnuplot -persist <<PLOT plot 'gnu1.txt' using 1:2 title 'data A' with lines, \ 'gnu2.txt' using 1:3 title 'data B' with lines quit PLOT
- 06-03-2011 #10Just Joined!
- Join Date
- Jun 2011
- Posts
- 7
Thank you, however, I already have a functioning script when typing all files manually (or asking what files, variables ... to plot). The problem is, that I don't want to do the first option as it's neither efficient nor elegant
So far, my official script contains 20 of
But there are many more data files to come and I fear that the script might get confusing/cluttered.Code:plot 'gnu1.txt' using 2:1 title 'data A' w p, \ 'gnu2.txt' using 2:1 title 'data B' w p


Reply With Quote