|
From: ivana r. <iva...@mf...> - 2017-08-05 14:38:55
|
Hi Theo,
> 1. The multiplot will not finish, e.g. when none of Data_E-files exist.
> How to cope with this?
As told before, you may use empty plots.
> It looks like a threefold nested "for loop" is also possible. But how to
> move on to the next multiplot and place "label 1 Data_<Index1>"
> in every plot?
It would be sometimes useful if "title NONE" does the same as
"notitle" and if one could alter iteration variable inside the loop.
Anyhow, there are few possible solutions. The following code shows one
of them.
### start gnuplot code
# DataFile name scheme: Data_<Index1>_<Index2>_<Index3>.dat
# Plot all <Index1> into one plot
# Plot all <Index2> with same color
#
# test a version
if ( GPVAL_VERSION < 5.2 ) {
printerror "Need at least version 5.2"
exit 1
}
# clear session, set favorite colors
reset
set colorsequence classic
# OS-dependence
___system = strstrt(GPVAL_SYSNAME, "Windows") #1: Windows; 0: others
__list = ___system ? "dir /b " : "ls "
__nowhere = ___system ? "NUL" : "/dev/null"
__silent = ' 2> '.__nowhere
# Indexes
array Index1[9] = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
array Index2[6] = ["a", "b", "c", "d", "e", "f"]
array first[|Index2|]
MinIndex3 = 1
MaxIndex3 = 3
if ( MaxIndex3 < MinIndex3 || MaxIndex3 > 9 ) {
printerror "Limits for Index3 are not set properly."
exit 2
}
# data files (at the 3rd position accepts strings and integers, both length 1)
FileName(i, j, k) = sprintf("Data_%s_%s_%.1s.dat", i, j, "".k)
# go on
set multiplot layout 3,3
set key right
#the main loop
do for [i=1:|Index1|] {
# something to plot?
# preprocessing init
NoFile = 1
# try to find sets and first files in them
do for [j=1:|Index2|] {
# list all files in the current "i-j" set
first[j] = files = system(__list.FileName(Index1[i], Index2[j], "?").__silent)
# get Index3 of the first existing file in the given range
do for [k=1:words(files)] {
flen = strlen(first[j] = word(files, k))
first[j] = first[j][flen-4:flen-4]
if ( first[j] >= MinIndex3 && first[j] <= MaxIndex3 ) {
break
} else {
first[j]=""
}
}
# proceed the result
if ( first[j] eq "" ) {
# minimize warning for empty sets
first[j] = MaxIndex3
} else {
# at least one set was found for current "i"
NoFile = 0
}
}
# preprocessing ended
# Choose what to plot
if (NoFile) {
set notics
set key title "Nothing to plot for Data_".Index1[i]
plot [0:10] [0:10] 1/0 not
} else {
set tics
set key title "Data_".Index1[i]
plot \
for [j=1:|Index2|] FileName(Index1[i], Index2[j], first[j]) \
w l lc j title sprintf("%s", Index2[j]), \
for [j=1:|Index2|] for [k=(first[j]):MaxIndex3] \
FileName(Index1[i], Index2[j], k) w l lc j not
}
}
unset multiplot
### end gnuplot code
So, the first file of set is find and plot with the title, while
remaining items are plotted without (actually the first one is also
repeated to prevent some limit trouble cases).
Another solution is, e.g., to plot real sets of files only and
determine the linecolor from the file name.
The above code was never tested on Windows, so you may need to tune
some system specific variables.
> It looks like a threefold nested "for loop" is also possible. But how to
> move on to the next multiplot and place "label 1 Data_<Index1>"
> in every plot?
I'm not sure what would like to code. Could you give an example?
Iva
|