files for plotting given by string function

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

files for plotting given by string function

Petr Mikulik
I tried to generate filename via a string function, and plot them (sometimes
filenames are very long). For example:

f(n)='a'.n.'.dat'
plot f(1), f(2)

=> it should be equivalent to plot 'a1.dat', 'a2.dat'. However, gnuplot
complains:

        warning: encountered a string when expecting a number
        NB: you cannot plot a string-valued function

I wish it behaves like I expect, i.e. string means filename.

Ethan, could you change this behaviour?

---
PM




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Petr Mikulik
> A workaround is the following:
>    plot ''.f(1), ''.f(2)

I wanted to simplify my life when plotting files a333.dat, a334.dat, ... not
to make it more difficult via ''.

> clear that a data file is being plotted, whereas `plot f(1)` could be a
> constant-valued function.

But it is clear whether the function returns string or scalar. If string,
then it is filename for (s)plot, otherwise scalar function its values to be
drawn. Otherwise, would it make sense draw a curve/surface with strings,
like  f(x,y)='point '.x.','.y; splot f(x,y) ? I don't think so.

BTW, in the recent addition: I would prefer "substr" function name (like in
awk) instead of the longer "substring".

---
PM




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Ethan Merritt
On Wednesday 15 June 2005 06:41 am, Petr Mikulik wrote:
>>> f(n)='a'.n.'.dat'
>>> plot f(1), f(2)
>>> NB: you cannot plot a string-valued function

> But it is clear whether the function returns string or scalar.

Well no, it is not clear. That is the heart of the problem.
There is nothing about a user-defined function that indicates
what type of value it returns. The only way to tell is to try
to evaluate it, and at the point the code must choose between
"plot function" and "plot data" it is not in general possible
to evaluate the function at all.

Part of the problem is that if the function is really a function
for plotting then it has dummy variables. But at the time the plot
command is parsed,  dummy variables have not been assigned values
and the evaluation returns an error.

Another part of the problem is that gnuplot's syntax allows function
definitions like:
   f(x) = x ? x : "NULL"
which *have* no intrinsic return type.

> If string, then it is filename for (s)plot, otherwise scalar function its
> values to be drawn. Otherwise, would it make sense draw a curve/surface
> with strings, like  f(x,y)='point '.x.','.y; splot f(x,y) ? I don't
> think so.

I agree with that part, but I do not see a way to test what type of value
is returned by a function before actually plotting it, by which time it
is too late. If you can figure out how to make that test, then I support
the resulting plot behavior you propose.

--
Ethan A Merritt
Biomolecular Structure Center
University of Washington 98195-7742


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Lutz Maibaum
In reply to this post by Petr Mikulik
On Wednesday 15 June 2005 05:51, Petr Mikulik wrote:
> f(n)='a'.n.'.dat'
> plot f(1), f(2)
>
> => it should be equivalent to plot 'a1.dat', 'a2.dat'. However, gnuplot

I was wondering if it would be feasible to include shell-like wildcard
expansion into gnuplot. For example, if there a two files a.1.dat and a.2.dat
in the current working directory,
  plot "a.*.dat"
should be interpreted as
  plot "a.1.dat", "a.2.dat"

Is it possible to do this in a platform-independent way? I currently use the
little script "pl" (http://www.phys.uni-paderborn.de/~stern/pl/) to use the
globbing features of the shell, but there are quite a few things that would
be much easier to do in an interactive gnuplot session.

  Lutz



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Ethan Merritt
On Wednesday 15 June 2005 09:43 am, Lutz Maibaum wrote:
>
> I was wondering if it would be feasible to include shell-like wildcard
> expansion into gnuplot. For example
>   plot "a.*.dat"
>
> Is it possible to do this in a platform-independent way? I currently use the
> little script "pl" (http://www.phys.uni-paderborn.de/~stern/pl/) to use the
> globbing features of the shell, but there are quite a few things that would
> be much easier to do in an interactive gnuplot session.

With the bleeding-edge cvs patch from Juergen Wieferink to implement a
system() call, you could use a similar perlscript to do something along
the lines of:

  set macros
  file_list = system("ls -1 a.*.dat | dirlist.pl")
  plot @file_list


where dirlist.pl is a cleaned up version of this quick perl hack
(which leaves a missing " at the start of the line and an extra ," at the end,
but you get the idea)

#!/usr/bin/perl -w
  while (<>) {
        s/\n/", "/;
        print;
  }


In fact, if you use the equally bleeding-edge substring manipulation code
you can do the cleanup inside gnuplot. The following actually works
when run in the source directory using yesterday's cvs version with
Juergen's patch:

  set macros
  file_list = system("ls -1 ../demo/?.dat | ./dirlist.pl")
  file_list = "\"".file_list
  file_list = file_list[0:strlen(file_list)-4]

  plot @file_list


--
Ethan A Merritt       [hidden email]
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Ethan Merritt
In reply to this post by Petr Mikulik
On Wednesday 15 June 2005 06:41 am, Petr Mikulik wrote:
>
> BTW, in the recent addition: I would prefer "substr" function name (like in
> awk) instead of the longer "substring".

OK by me.  I'll change it.

But I think awk uses substr(string, beg, length) rather than
substr(string, beg, end). Is that a problem?

--
Ethan A Merritt       [hidden email]
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Petr Mikulik
> > BTW, in the recent addition: I would prefer "substr" function name (like in
> > awk) instead of the longer "substring".
>
> But I think awk uses substr(string, beg, length) rather than
> substr(string, beg, end). Is that a problem?

I see, then I propose it to use the length, not end. (Further, awk starts
counting from 1...?)

---
PM





-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Jürgen Wieferink
In reply to this post by Ethan Merritt
On Wednesdy, 15 June 2005 23:36, Ethan Merritt wrote:
> With the bleeding-edge cvs patch from Juergen Wieferink to implement a
> system() call, you could use a similar perlscript to do something along
> the lines of:
>
>   set macros
>   file_list = system("ls -1 a.*.dat | dirlist.pl")
>   plot @file_list

In this special case, backtic substition will already do the job:

  plot `ls -1 a.*.dat | dirlist.pl`

But feel free to try the patch and report bugs or suggest
enhancements. :-)


Juergen



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Lutz Maibaum
On Thursday 16 June 2005 00:23, Jürgen Wieferink wrote:
> On Wednesdy, 15 June 2005 23:36, Ethan Merritt wrote:
> >   set macros
> >   file_list = system("ls -1 a.*.dat | dirlist.pl")
> >   plot @file_list
>
> In this special case, backtic substition will already do the job:
>
>   plot `ls -1 a.*.dat | dirlist.pl`

The problem with this is that it produces a plot with only a single item,
i.e., all the different files have the same (point|line)style. I was hoping
for a shortcut to automatically plot many files, each with a different style.

  Lutz



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Ethan Merritt
On Friday 17 June 2005 12:48 pm, Lutz Maibaum wrote:

> On Thursday 16 June 2005 00:23, Jürgen Wieferink wrote:
> > On Wednesdy, 15 June 2005 23:36, Ethan Merritt wrote:
> > >   set macros
> > >   file_list = system("ls -1 a.*.dat | dirlist.pl")
> > >   plot @file_list
> >
> > In this special case, backtic substition will already do the job:
> >
> >   plot `ls -1 a.*.dat | dirlist.pl`
>
> The problem with this is that it produces a plot with only a single item,
> i.e., all the different files have the same (point|line)style. I was hoping
> for a shortcut to automatically plot many files, each with a different style.

Huh?  No it doesn't.  It expands to
      plot "a.1.dat", "a.2.dat", "a.3.dat", ...

So each plot gets a new line/point style.
I know it works, because I actually tested it using the short script
in my previous Email. An even simpler demo of the principle is

gnuplot> plot `demo.pl`

where

#~/usr/bin/perl
# demo.pl
  print " '1.dat', '2.dat', '3.dat' "




--
Ethan A Merritt       [hidden email]
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Juergen Wieferink
In reply to this post by Lutz Maibaum
Am Freitag, 17. Juni 2005 21:48 schrieb Lutz Maibaum:
> On Thursday 16 June 2005 00:23, Jürgen Wieferink wrote:
> > In this special case, backtic substition will already do the job:
> >
> >   plot `ls -1 a.*.dat | dirlist.pl`
>
> The problem with this is that it produces a plot with only a single item,
> i.e., all the different files have the same (point|line)style. I was hoping
> for a shortcut to automatically plot many files, each with a different
> style.

Have you actually tried?  I get each file with its own line- and
pointstyle.

It may be possible to get the "dirlist.pl" simpler than the
following, though...

  #!/usr/bin/perl -w
  my $save = "\"";
  while (<>) {
      print $save;
      s/\n/", "/;
      $save = $_;
  }
  $save =~ s/, \"$//;
  print $save;


Juergen





-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: files for plotting given by string function

Lutz Maibaum
In reply to this post by Ethan Merritt
On Friday 17 June 2005 13:14, Ethan Merritt wrote:
> On Friday 17 June 2005 12:48 pm, Lutz Maibaum wrote:
> > The problem with this is that it produces a plot with only a single item,
> > i.e., all the different files have the same (point|line)style. I was
> > hoping for a shortcut to automatically plot many files, each with a
> > different style.
>
> Huh?  No it doesn't.  It expands to
>       plot "a.1.dat", "a.2.dat", "a.3.dat", ...

My apologies, I wrote my email before actually trying it out. My bad. This
might afterall be exactly what I'm looking for.

  Lutz


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta