comparison main/plot/gget.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children 131c0e0ec24f
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 1999 Daniel Heiserer
2 ##
3 ## This program is free software; it is distributed in the hope that it
4 ## will be useful, but WITHOUT ANY WARRANTY; without even the implied
5 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
6 ## the GNU General Public License for more details.
7 ##
8 ## You should have received a copy of the GNU General Public License
9 ## along with this file; see the file COPYING. If not, write to the
10 ## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
11 ## 02111-1307, USA.
12
13 ## usage: m = gget(option)
14 ##
15 ## returns gnuplot's setting of option.
16 ##
17 ## REQUIRES: unix piping functionality, grep, sed
18 ## COMMENT: would be much better to have the result directly from gnuplot,
19 ## but show/gshow deliver a human readable format, which cannot
20 ## be read by a machine clearly
21 ##
22
23 ## Author: Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de>
24
25 ## 2001-03-30 Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
26 ## * strip spaces
27 ## * use proper temporary files
28 ## 2001-04-04 Laurent Mazet <mazet@crm.mot.com>
29 ## * check if gnuplot very create a file
30
31 function gout = gget(option)
32
33 ## tell gnuplot to save all its options to a file, scan that file
34 ## for the option we are interested in, then delete it.
35 optfile = tmpnam;
36 graw (["save set \"", optfile, "\"\n"]);
37 f = fopen(optfile);
38 while f == -1
39 sleep (1);
40 f = fopen(optfile);
41 endwhile
42 fclose(f);
43
44 cmd = sprintf("grep \"[# ]*set %s\" %s | sed 's/.*set %s *//'; rm -f %s", ...
45 option, optfile, option, optfile);
46 gout = system(cmd);
47 if (length(gout) == 0)
48 error("gget: option %s not found", option);
49 endif
50
51 ## grab the first output line only, without newline
52 ## XXX FIXMEXXX --- some options (e.g., key) may return multiple lines
53 ## since the real options are actually "key title" and "key". Tricky...
54 idx = find(gout == "\n");
55 if !isempty(idx)
56 gout = gout(1:idx(1)-1);
57 if (length(gout) == 0) return; endif
58 endif
59
60 ## strip leading and trailing blanks
61 idx = find(gout != " ");
62 if isempty(idx)
63 gout = "";
64 else
65 gout = gout(min(idx) : max(idx));
66 endif
67
68 endfunction