octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnuplot image code


From: Bill Denney
Subject: Re: gnuplot image code
Date: Wed, 25 Oct 2006 16:27:53 -0400
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

John W. Eaton wrote:
What should happen if gnuplot_binary is called to specify a different
version of Octave?  Should we expect that to work without restarting
Octave?
Here is an update to the previous script that will hold the version persistently in a cache, but allow a different gnuplot_binary to be specified and (in case someone replaces their gnuplot during a session) allows for the version cache to be cleared. (Sorry it's not a diff, but I don't see it in my current cvs tree.)

Bill

scripts/ChangeLog:

2006-10-25  Bill Denney  <address@hidden>
* plot/__gnuplot_version__.m: keep a version number cache for different gnuplot_binary values, and allow that cache to be manually cleared by the user
## Copyright (C) 2006 Daniel Sebald
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, write to the Free
## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.

## -*- texinfo -*-
## @deftypefn {Function File} { @var{version} = } __gnuplot_version__
## @deftypefnx {Function File} { @var{version} = } __gnuplot_version__ ("clear")
## Returns the version of gnuplot.  If the "clear" option is given, then
## any cached version information is cleared and the version is
## re-detected.
## @end deftypefn

function version = __gnuplot_version__ (clr)

  persistent versionmap = cell (0, 2);
  ## allow a user to clear the version cache without restarting
  ## octave
  if nargin > 0
    versionmap = cell (0, 2);
  endif

  ## This assumes that they don't change the function that 
  version_mask = strcmp (gnuplot_binary (), versionmap(:,1));
  if any (version_mask)
    version = versionmap{find (version_mask, 1), 2};
  else
    versionmap{length (versionmap, 1)+1, 1} = gnuplot_binary ();
    ## If the function hasn't been called before with the current
    ## gnuplot binary, use this code to get the version from gnuplot.
    [status, output] = system([gnuplot_binary, " --version"]);
    words = split(output, " ");
    if ( (size (words,1) >= 2) && isdigit (words(2,1)) )
      version = sscanf(words(2,:), "%f", 1);
    else
      version = -1;
    endif

    versionmap{length (versionmap, 1), 2} = version;
  endif

endfunction

reply via email to

[Prev in Thread] Current Thread [Next in Thread]