|
From: Leo B. <l_b...@us...> - 2013-09-19 13:54:08
|
> Date: Thu, 19 Sep 2013 04:51:31 -0700
> From: "atoms.h" <tho...@gm...>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi,
>
> I'm trying to make use of the iteration feature, so far unsuccessfully. I
> want to plot files in different directories with the same file name. All in
> one pdf documents. The way I construct my paths is by means of string
> variables:
>
> $ basefolder = '../data/scalePr/'
> $ folder1 = '0.90'
> $ folder2 = '0.95'
> $ folder3 = '0.97'
> $ folder4 = '1.00'
> $ file1 = basefolder.folder1."/".filename.".dat"
> $ file2 = basefolder.folder2."/".filename.".dat"
> $ file3 = basefolder.folder3."/".filename.".dat"
> $ file4 = basefolder.folder4."/".filename.".dat"
>
> I haven't figured out a way to iterate through variable names like
>
> $ file(n) = basefolder.folder.sprintf("%d",n)."/".filename.".dat"
>
> (which obviously doesn't work) to be able to do multiple plots in one
> command:
>
> $ do for [i=1:4]{
> $ splot file(i)
> $ }
>
> If anyone has an idea how to iterate variable names it would be most
> appreciated!
It is probably best to use strings with separators to implement a type
of read-only string array. Here is one such effort
gnuplot> directory="/home/user"
gnuplot> files="a0 a1 a2 a3 "
gnuplot> sep=" "
gnuplot> c=strstrt(files,sep);
gnuplot>
gnuplot> while (c) { w=sprintf("%s/%s",directory,files[0:c-1]);
more> print w;
more> files=files[c+1:*]
more> c=strstrt(files,sep);
more> }
/home/user/a0
/home/user/a1
/home/user/a2
/home/user/a3
With a bit more work you can make a custom iterator:
gnuplot> files="a0 a1 a2 a3 a4 a5 a6 "
gnuplot> iterate_over_(string,sep,cmd,s,c)=(c == 0 ? s :\
>iterate_over_(string[c+1:*],sep,cmd,s . (c == -1 ? "" : sprintf(cmd,string[0:with_iterate_over_c-1])), strstrt(string[c+1:*],sep)));
gnuplot> iterate_over(string,sep,cmd)=iterate_over_(string,sep,cmd,"",-1);
gnuplot>
gnuplot> print iterate_over(files,sep,"file='%s'; splot directory .'/'. file;\n")
file='a0'; splot directory .'/'. file;
file='a1'; splot directory .'/'. file;
file='a2'; splot directory .'/'. file;
file='a3'; splot directory .'/'. file;
file='a4'; splot directory .'/'. file;
file='a5'; splot directory .'/'. file;
file='a6'; splot directory .'/'. file;
Leo
|