Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #976 > unrolled thread

How to know total number of blocks in a file?

Started byampbox@gmail.com
First post2012-03-15 07:43 -0700
Last post2012-03-15 11:34 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  How to know total number of blocks in a file? ampbox@gmail.com - 2012-03-15 07:43 -0700
    Re: How to know total number of blocks in a file? sfeam <sfeam@users.sourceforge.net> - 2012-03-15 09:53 -0700
      Re: How to know total number of blocks in a file? sfeam <sfeam@users.sourceforge.net> - 2012-03-15 11:34 -0700

#976 — How to know total number of blocks in a file?

Fromampbox@gmail.com
Date2012-03-15 07:43 -0700
SubjectHow to know total number of blocks in a file?
Message-ID<5661512.256.1331822623825.JavaMail.geo-discussion-forums@ynhs12>
Hi all,

I have a data file with multiple data blocks (groups of data lines separated by blank lines). I want to plot only the last block. 

I can do it like 

      plot 'filename' every :::<blockNO>::<blockNO> 

where <blockNO> is the block number, and since it is the last block, this number equals the total number of blocks in my data file.

The problem is, I don't know how many blocks are there in my data file. (Because my simulation adds a new block every few hours and the longer simulation runs, the more number of frames (block) I get.)

Is there a built-in variable like GPVAL_DATA_X_MAX etc. to give me this information? 

Another possible solution: can I get the number of lines etc. by a bash command (I am in Linux) INSIDE my gnuplot script and give it to a variable? I mean something like:

NBLOCKS = `!wc -l filename`

Thanks in advance,
Masoud.

[toc] | [next] | [standalone]


#977

Fromsfeam <sfeam@users.sourceforge.net>
Date2012-03-15 09:53 -0700
Message-ID<jjt6pj$prg$1@dont-email.me>
In reply to#976
ampbox@gmail.com wrote:

> Hi all,
> 
> I have a data file with multiple data blocks (groups of data lines
> separated by blank lines). I want to plot only the last block.
> 
> I can do it like
> 
>       plot 'filename' every :::<blockNO>::<blockNO>
> 
> where <blockNO> is the block number, and since it is the last block,
> this number equals the total number of blocks in my data file.
> 
> The problem is, I don't know how many blocks are there in my data
> file. (Because my simulation adds a new block every few hours and the
> longer simulation runs, the more number of frames (block) I get.)
> 
> Is there a built-in variable like GPVAL_DATA_X_MAX etc. to give me
> this information?

Not currently.  There is a contributed patch on the SourceForge 
tracker that claims to add something like this (I haven't looked at it
so I don't know the details). 

> Another possible solution: can I get the number of lines etc. by a
> bash command (I am in Linux) INSIDE my gnuplot script and give it to a
> variable? I mean something like:
> 
> NBLOCKS = `!wc -l filename`

Sure. 
But wc unfortunately returns a line that contains also the filename. 
So you need:

  WC = `wc -l filename`
  NBLOCKS = word(WC,1)


> 
> Thanks in advance,
> Masoud.

[toc] | [prev] | [next] | [standalone]


#978

Fromsfeam <sfeam@users.sourceforge.net>
Date2012-03-15 11:34 -0700
Message-ID<jjtcn6$uv8$1@dont-email.me>
In reply to#977
sfeam wrote:

> ampbox@gmail.com wrote:
> 
>> Hi all,
>> 
>> I have a data file with multiple data blocks (groups of data lines
>> separated by blank lines). I want to plot only the last block.
>> 
>> I can do it like
>> 
>>       plot 'filename' every :::<blockNO>::<blockNO>
>> 
>> where <blockNO> is the block number, and since it is the last block,
>> this number equals the total number of blocks in my data file.
>> 
>> The problem is, I don't know how many blocks are there in my data
>> file. (Because my simulation adds a new block every few hours and the
>> longer simulation runs, the more number of frames (block) I get.)
>> 
>> Is there a built-in variable like GPVAL_DATA_X_MAX etc. to give me
>> this information?
> 
> Not currently.  There is a contributed patch on the SourceForge
> tracker that claims to add something like this (I haven't looked at it
> so I don't know the details).

I forgot! Now that version 4.6 has been released,there is a
way to do this. In version 4.6 you can use the "stats" command
to find the number of blocks first, and then use that value in 
a subsequent plot command.

gnuplot> stats 'filename' 
gnuplot> print STATS_blocks
gnuplot> plot 'filename' every :::STATS_blocks::STATS_blocks

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web