clamping the index argument in multi-data-set file

  • Follow


i deal with multi-data-set files and use index to plot the different
data sets one at a time ... the number of data sets is however *not*
known in advance ...

a generic plot command that i use is as follows

plot "datafile" index ind u 1:2 w p

before issuing the above command i set ind to 0
i bind the `home' key as follows

bind home "ind=ind+1 ; set title sprintf(\"ind = %d\", ind) ; replot "

and the `end' key as follows

bind end "ind=ind<=0?0:ind-1 ; set title sprintf(\"ind = %d\", ind) ;
replot "

then i simply hit `home` and `end' to cycle between the data sets in a
serial fashion.

notice that the binding for `end' has a mechanism to clamp the value
of ind to 0 if i happen to hit `end' too often
however i was unable to clamp ind to its upper limit as i do not know
in advance how many data sets will be in the datafile.

i do notice that gnuplot warns me with

 warning: Skipping data file with no valid points

when i hit `home' more than necessary ... i was hoping to be able to
catch some error flag set by gnuplot when this happened and then to
clamp the value of ind at its maximum for the datafile in question.

is it possible ?

r there other ways of achieving the same effect ?

thanks in advance
0
Reply awimagic (10) 3/15/2010 3:21:05 AM

Awhan Patnaik wrote:

> i deal with multi-data-set files and use index to plot the different
> data sets one at a time ... the number of data sets is however *not*
> known in advance ...
> 
> a generic plot command that i use is as follows
> 
> plot "datafile" index ind u 1:2 w p
> 
> before issuing the above command i set ind to 0
> i bind the `home' key as follows
> 
> bind home "ind=ind+1 ; set title sprintf(\"ind = %d\", ind) ; replot "
> 
> and the `end' key as follows
> 
> bind end "ind=ind<=0?0:ind-1 ; set title sprintf(\"ind = %d\", ind) ;
> replot "
> 
> then i simply hit `home` and `end' to cycle between the data sets in a
> serial fashion.
> 
> notice that the binding for `end' has a mechanism to clamp the value
> of ind to 0 if i happen to hit `end' too often
> however i was unable to clamp ind to its upper limit as i do not know
> in advance how many data sets will be in the datafile.
> 
> i do notice that gnuplot warns me with
> 
>  warning: Skipping data file with no valid points
> 
> when i hit `home' more than necessary ... i was hoping to be able to
> catch some error flag set by gnuplot when this happened and then to
> clamp the value of ind at its maximum for the datafile in question.
> 
> is it possible ?

The most recent error message is stored in GPVAL_ERRMSG.
But your empty file message is only a warning, not an error, so that
doesn't help in your case.

> r there other ways of achieving the same effect ?

Maybe. 

First idea
----------
In the case that the plot is autoscaled and this is the only data
being plotted, an empty data set will also trigger a true error
message:
gnuplot> reset error
gnuplot> plot 'silver.dat' index 1
         warning: Skipping data file with no valid points
         x range is invalid                              
gnuplot> print GPVAL_ERRMSG
x range is invalid         

Second idea
-----------
If you can autoscale this data set even though there are other things
on the same plot, it might still work.  Plot everything else using the
y1 axis.  Plot your indexed data set using the y2 axis.  If the data set
is empty, it should trigger an error like  "invalid y2range".

Third idea
----------
[\me hunts around a bit]
I thought I recalled a contributed patch that allowed you to somehow
request specifically the last dataset in a file.  But now I can't find
that patch to see if the mechanism also reported back what was the index
of that last data set.  Maybe I'm not looking for it under the right name. 

Final thought
-------------
It might be possible to tweak the existing code that lets you
use a name rather than a number for the index of the data set you want.
Currently it only looks for the name if you request it by name.
But I imagine it would be possible to look for and store the name
of the data set even if it was requested by number rather than by name.
For example, if your data file looked like this

# == first ==
1 1 1


# == second ==
2 2 2


# == last ==
999 999 999


We could arrange things so that after a plotting a data set that
had a name, you could retrieve that name from a variable:
  plot 'foo' index 2
  if (GPVAL_DATASETNAME eq "== last ==") <do whatever>

I'm think thinking as I type here.  No such code currently exists.
But if you think this would be useful, perhaps you can develop the
idea a bit further and file a "Feature Request" describing it.
Better yet you could file a patch implementing it :-)
Anyhow a well thought-out request would be sufficient to put it on
a TODO list for development even in the absence of a preliminary patch.

> 
> thanks in advance

0
Reply sfeam 3/15/2010 6:52:36 AM


On Mar 15, 4:21=A0am, Awhan Patnaik <awima...@gmail.com> wrote:
> i deal with multi-data-set files and use index to plot the different
> data sets one at a time ... the number of data sets is however *not*
> known in advance ...
>

> r there other ways of achieving the same effect ?
>
> thanks in advance

You could use an external program (like perl or awk) to count the
number of contiguous blocks in the data file, for example

filename =3D "datafile"
perlcommand =3D"perl -ne'if(/^\\s+$/){$f++}else{$i++if$f>1;$f=3D0}}{print$i
+1' ".filename
maxindex =3D system(perlcommand)

Then you can use the value of maxindex to test whether you've reached
the end of the file.

Caveat: obviously the above works only if you have perl. On windows
you may have to modify the command a bit because of the retarded quote-
related behavior of cmd.exe.

P=E9ter Juh=E1sz
0
Reply ISO 3/15/2010 9:19:24 PM

2 Replies
180 Views

(page loaded in 0.08 seconds)

Similiar Articles:













7/27/2012 11:12:07 PM


Reply: