Question

I have a script (called: anim.sh) to read in my simulation data, plot each data file in gnuplot, and save each as a .gif file. The data is named: g000000, g000007, g000008, g000010....etc. My script reads in these 4 data files and makes a plot in gnuplot, then saves the output as a .gif file. My question is how do I read in this irregularly numbered data? I have:

do for [i=0:3] {
str_num=sprintf('%03d',i)  #Write integer to string
set term gif
set output 'my_output.'.str_num.'.gif'
set xr [-0.2:0.2]
set yr [-0.2:0.2]
plot 'g000'.str_num w d
}

This would work fine if my files were called g000000, g000001, g000002, g000003 but they are not! so I get an error:

line 8: warning: Skipping unreadable file "g000001"
line 8: No data in plot

How do I add to the code to skip missing files (e.g. g000001 - g000006) and continue the loop?

p.s. In reality i have hundreds of files and not just 4 so I don't want to rename them by hand.

Was it helpful?

Solution

You can generate a list of all files and iterate over them:

set terminal gif
set xrange[-0.2:0.2]
set yrange[-0.2:0.2]

filelist = system('ls g00*')
do for [file in filelist] {
    set output 'my_output.'.(file[2:*]).'.gif'
    plot file
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top