|
From: Leo B. <l_b...@us...> - 2013-09-19 15:31:19
|
> From: Leo Butler <l_b...@us...>
> CC: <gnu...@li...>
>
>
> > 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)));
That should have been:
iterate_over_(string,sep,cmd,s,c)=(c == 0 ? s :\
iterate_over_(string[c+1:*],sep,cmd,s . (c == -1 ? "" : sprintf(cmd,string[0:c-1])), strstrt(string[c+1:*],sep)));
I made a mistake copying from my work buffer, I guess.
To explain: iterate_over_ is a tail-recursive function that
recursively assembles a command string s, using the sprintf prototype
cmd, and the input string string which is separated by sep.
> gnuplot> iterate_over(string,sep,cmd)=iterate_over_(string,sep,cmd,"",-1);
You can eval the output of iterate_over, or you could define a 3rd
function that does that for you.
> 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
|