1### VALUE = g_config (NAME, [, NEW_VALUE]) - Get/set settings of g_XYZ functions 2### 3### NAME can be one of 4### 5### "gnuplot_version" : Gnuplot version, e.g. [MAJOR, MINOR, PATCHLEVEL] 6### This parameter cannot be set. 7### "gnuplot_program" : Gnuplot program that is called in g_plot() 8### Default is "gnuplot" 9### "eps_viewer" and "png_viewer" : Programs called to view eps or png plots. 10### Defaults are "gv" and "eog". 11 12function res = g_config (varargin) 13 14persistent g_config_struct = \ 15 struct ("gnuplot_program", "gnuplot",\ 16 "png_viewer", "eog",\ 17 "eps_viewer", "gv",\ 18 "gnuplot_version", nan); 19 20if all (numel (varargin) != [1 2]) 21 help g_config 22 return 23end 24 25switch varargin{1} 26 case {"gnuplot_program", "png_viewer", "eps_viewer"} 27 28 varName = varargin{1}; 29 30 # Reset gnuplot_version if needed 31 if strcmp (varName, "gnuplot_program") && !strcmp (varName, g_config_struct.gnuplot_program) 32 gnuplot_version = nan; 33 end 34 35 if numel (varargin) > 1 36 g_config_struct.(varName) = varargin{2}; 37 end 38 res = g_config_struct.(varName); 39 case "gnuplot_version" 40 if numel (varargin) > 1 41 error ("gnuplot_version cannot be set"); 42 end 43 if isnan (g_config_struct.gnuplot_version) 44 g_version_cmd = [g_config_struct.gnuplot_program, " --version"]; 45 [status, output] = system (g_version_cmd); 46 if status 47 error ("Can't run '%s'", g_version_cmd) 48 end 49 if output(end) == "\n" 50 output = output (1:end-1); 51 end 52 va = toascii (output); 53 va(va < toascii("0") | va > toascii("9")) = toascii (" "); 54 try 55 vn = eval (["[", char(va),"]"]); 56 catch 57 error ("Can't get gnuplot version number from output '%s'", output) 58 end 59 g_config_struct.gnuplot_version = vn; 60 if numel (vn) < 2 61 error ("Gnuplot version looks strange: '%s'", output); 62 end 63 end 64 res = g_config_struct.gnuplot_version; 65 otherwise 66 help g_config 67 error (["Don't know what to do with ", varargin{1}]) 68endswitch 69 70 71