help-octave
[Top][All Lists]
Advanced

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

Re: To parametrize a file location


From: Joao Cardoso
Subject: Re: To parametrize a file location
Date: Thu, 25 Feb 1999 13:40:34 +0000

Daniel Tourde wrote:
> 
> Hi !
> 
> I would like to parametrize where I could store a plot with Octave.
> I tried something like this after having ploted what I want on the
> screen but it does not work.
> 
>         gset term postscript eps color
>         cmdoutput = sprintf("/home/lorient/ffa/ase/Mach_%.2f/OL.eps",Mach);
>         gset output eval(cmdoutput)
>         replot
> 
> Does anyone has an idea ?
> 
> Thanks in advance
> 
>                         Daniel

This is an old script file that save a plot in a location specified by a
global variable specified in my .octaverc.

Enjoy,
Joao

# save_plot( name, opt), where opt can be, in this order,
#       landscape | portrait | eps | default
#       color | monochrome
#       solid | dashed
#       "fontname" 
#       fontsize
#
#       NOTE: last settings are retained between invocations.
#       as the plot window disapears during the saving and then reapers,
it
#       is convenient to have a Gnuplot resource file in the
app-defaults dir
#       with a geometry and position specification, such as
#       *geometry: 500x400-0+0

#       file.ps         postscript
#       file.eps        encapsulated postscript (default)
#       file.fig        fig

function save_plot( name, opt)
global PS_DIR

        ext = extension(name);
        if isempty(ext)
                ext = 'eps';
                name = sprintf("%s.%s",name,ext);
        endif

        if strcmp(ext,"ps")
                typ = "postscript landscape";
        elseif strcmp(ext,"fig")
                typ = "fig";
        elseif strcmp(ext, "eps");
                typ = "postscript eps";
        endif
        
        if (nargin == 2)
                cmd = sprintf("gset \"terminal %s\"", opt);
        else
                cmd = sprintf("gset \"terminal %s monochrome dashed\"",
typ); # change for your default
        endif
        eval (cmd)
        name = [PS_DIR '/' name]
        
        cmd = sprintf("gset \"output '%s'\"", name);
        eval(cmd)

        greplot
        gset "terminal X11"
        greplot
end

the extension() and related script files:

function ext = extension( s, c, f)

#       ext = extension( string, char, flag)
#
#       ext is the extension of string, excluding all before character
char
#       if char is not defined, the default is '.'
#       if flag = 1, char is searched from the beginning
#       if flag = 0 or inexistent char is searched from the end
#
#       see also basename

if (nargin == 1)
        c = '.';
        f = 0;
elseif (nargin == 2)
        f = 0;
endif

if (f == 0)
        i = strrchr (s, c);
else
        i = strchr (s, c);
endif

l = columns (s);

if (i == 0)
        i = l;
endif

#s = toascii (s);       # 19.3
#ext = setstr (s(i+1:l));
ext = s(i+1:l);

endfunction

function ix = strchr(s, c)

#       ix = strchr(s, c)
#
#       ix is index of the first occurence of character 'c' in string
's'
#       or 0 if not found;
#
#       seel also strrchr

#as = toascii(s);       # 1.93 doesn't need toascii
#ac = toascii(c);
#ix = min(find(as == ac));
ix = min(find(s == c));
if (isempty (ix))
        ix = 0;
endif

endfunction

function ix = strrchr(s, c)

#       ix = strchr(s, c)
#
#       ix is index of the last occurence of character 'c' in string 's'
#       or 0 if not found;

#as = toascii(s);       # 1.93 doesn't need toascii
#ac = toascii(c);
#ix = max(find(as == ac));
ix = max(find(s == c));
if (isempty (ix))
        ix = 0;
endif

endfunction

-- 
Joao Cardoso                |   e-mail: address@hidden
INESC, R. Jose Falcao 110   |   tel:    + 351 2 2094322
4050 Porto, Portugal        |   fax:    + 351 2 2008487



reply via email to

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