Plotting in Octave

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting in Octave

Ted.Harding
Dear All,
1. I have been trying to find source for a VGA console driver for GNUPLOT
so as to use Gnuplot to view 'octave' graphs on my Linux console
(I'm not using X), with the graphics handled by svgalib.
I see references to "the Linux Driver" which suggest that this does
the job, but I can't find source. Can anyone help?

2. This is a tip for octave users who may find it impossible, difficult
or inconvenient to use 'gnuplot' to view graphs on their own screens
(especially non-users of X), or who would like access to greater control
over the plot, or far more enhancements, than 'gnuplot' provides.
  The package GLE as distributed for Linux includes a VGA option (binary
file 'gle_vga', evoked by the command "gle -dvga"), which uses [s]vgalib
to display graphics on the screen.

GLE can be found in the sunsite.unc.edu Linux mirror as
apps/math/gle-3.3g-bin.tar.gz (include the binary files for vga)
apps/math/gle-3.3g-src.tar.gz (this does not include source for 'gle_vga')
apps/math/gle.lsm
apps/math/gle-postscript.docs.tar.gz

  The following three files, the first a skeleton command file for GLE,
the second a minimal m-file for 'octave', the third an 'octave' utility
to write column vectors and matrices out to a file, are all you need to
plot the columns 2..k of an Nxk matrix X as curves against column 1.
  The octave command for this would be "glplot(X);" This function as
written returns value "1".
  As written, you first see the GLE command-file for the plot. Press
F10 (or ^F 0) to see the graph. From the graph, "RETURN" gets you back
to the command file which you can edit to your taste and save under
another name for future reference. While viewing the graph, you can use
keys to move a cursor round the screen, draw lines, boxes; place text; etc.
All such changes cause corresponding commands to be automatically entered
into the command file you are viewing, and these too can be edited.
  As the need arises and the mood takes me, I shall be making similar
arrangements to use GLE's surface-plotting and contouring functions
within 'octave', and will post these; if anyone beats me to it (quite
likely) it would be nice if they would do the same!

Ted Harding                                        [hidden email]
=======================================================================
file gle_plot.gle
=================
This is a skeleton GLE file to plot columns 2..k of an Nxk data file
severally against column 1. There are various empty "sockets" for assorted
furniture: Ttitle, Xtitle, Ytitle, X2Title, Y1Title, box, table, key.
See the GLE Manual for the various options and enhancements which can be used.
Note that any textual item (e.g. Title) can include TeX-like specials
to get Greek, Math, sup/sub, etc.
========================================================================
size 24 18 box
set font pldr
begin scale 1 1
  begin graph
    size 24 18
    Title ""
    Xtitle ""
    Ytitle ""
    X2Title ""
    Y2Title ""
    data gle_temp.dat
    dn line marker square
  end graph
  begin box
  end box
  begin table
  end table
  begin key
  end key
end scale
=========================================================================
File glplot.m
=============
This file drives GLE as the plotting software under Octave. The work-space
throughout is the current working directory.
Data must be in columns (you could modify the file to check this).
The first shell_cmd copies the above file 'gle_plot.gle' to the current
working directory (This seems necessary because GLE tends to treat "/"
as a switch, so doesn't recognise UNIX paths properly).
Replace the pathname in this command with wherever you decide to store
the file gle_plot.gle permanently.
=============================================
function s = glplot(X)
% Plots the data in matrix X as graphs using 'gle'.
% The column X(:,1) is the set of x'values;
% the columns X(:,i) i=2..k give the y-values for the several curves.
write("gle_temp.dat","%.4f",X);
shell_cmd("cp /usr/local/lib/octave/1.0/ted/gle_plot.gle .");
shell_cmd("gle -dvga gle_plot.gle > /dev/tty");
shell_cmd("rm gle_temp.dat");
s=1;
=========================================================================
file write.m
============
function write(file,fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)
#H
#H      write('filename','format',x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)
#H
#H      writes the data in the rows of matrices x1,x2,...
#H      side-by-side into the rows of <filename> (APPEND mode).
#H
#H      'format' is a C f,e or g format (e.g.'%7.4f') for a single number.
#H      'format' is mandatory, 'filename' is optional and, if omitted,
#H      output is to the screen. If <filename> exists it is over-written
#H      (to change this, change the commented line below)
#H
#H      There must be at least one matrix argument x1, and at most 10.
#H      The matrices x1, x2, ... are output side by side; all must have the
#H      same number of rows.
#H
strargs=1;
if isstr(fmt), strargs=2; end
if strargs==1, FIL="stdout"; X=fmt; FMT=file; P=1;
  else X=[]; FMT=fmt; FIL=file; P=0; end

if (nargin-strargs)>P+0, X=[X x1]; end
if (nargin-strargs)>P+1, X=[X x2]; end
if (nargin-strargs)>P+2, X=[X x3]; end
if (nargin-strargs)>P+3, X=[X x4]; end
if (nargin-strargs)>P+4, X=[X x5]; end
if (nargin-strargs)>P+5, X=[X x6]; end
if (nargin-strargs)>P+6, X=[X x7]; end
if (nargin-strargs)>P+7, X=[X x8]; end
if (nargin-strargs)>P+8, X=[X x9]; end
if (nargin-strargs)>P+9, X=[X x10]; end
S=size(X); R=S(1); C=S(2);
fopen(FIL,"w");  % Change this to "a" to APPEND to an existing file
for i=1:R
  for j=1:C
    fprintf(FIL,FMT,X(i,j)), fprintf(FIL,' '), end, fprintf(FIL,'\n')
end
fflush(FIL);
if (strargs==2) fclose(FIL); end
=========================================================================
Ted Harding                                        [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Plotting in Octave

Ludger Kunz
Hi,

here is my linux-svgalib driver i am using with gnuplot. I
hope it is the one you are looking for.

Ludger Kunz


----------------snip------------------------------------
/* GNUPLOT - linux.trm */
/*
 * Copyright (C) 1993
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the modified code.  Modifications are to be distributed
 * as patches to released version.
 *
 * This software  is provided "as is" without express or implied warranty.
 *
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *  SVGA 1024x768x256 for PC's running the Linux Operating System
 *  (also VGA 640x480x16, and SVGA 800x600x256)
 *
 * AUTHOR
 *  Scott Heavner ([hidden email])
 *  based on original linux.trm by Tommy Frandsen ([hidden email])
 *
 * send your comments or suggestions to (pixar![hidden email]).
 *
 */

/* If SVGALIB is defined, it will compile with the Linux SVGAlib
 * mainatained by Harm Hanemaayer ([hidden email]).  SVGAlib 0.6
 * supports Tridents, Tseng, Cirrus, Oak (?), and generic vga.
 *
 * If SVGALIB is not defined, it will attempt to use the trident
 * tvgalib [hidden email].
 */

#undef LINUX_SVGALIB
#define LINUX_SVGALIB

#define _STRING_H_
#ifdef LINUX_SVGALIB
#include <vga.h>
#else
#include "/term/new/tvgalib/src/tvga.h"

#define VGA 1

int vga_setchipset(x)
int x;
{
return 0;
}

int vga_hasmode(x)
int x;
{
if (vga_setmode(x)) {
        vga_setmode(TEXT);
        return 1;
}
return 0;
}

#endif

#define LINUX_XMAX 1024
#define LINUX_YMAX 768

#define LINUX_XLAST (LINUX_XMAX - 1)
#define LINUX_YLAST (LINUX_YMAX - 1)

#define LINUX_VCHAR FNT5X9_VCHAR
#define LINUX_HCHAR FNT5X9_HCHAR

#define LINUX_VTIC 5
#define LINUX_HTIC 5

static int graphics_on = FALSE;

int startx, starty;
int linux_angle;

static int linux_vmode=G1024x768x256;
static int linux_xlast=LINUX_XLAST;
static int linux_ylast=LINUX_YLAST;

static int vgacolor[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};

LINUX_options( )
{
#ifdef LINUX_SVGLIB
        if (!END_OF_COMMAND) {
                if (almost_equals(c_token,"T$VGA8900")||
                        almost_equals(c_token,"t$vga8900")) {
                        vga_setchipset(TVGA8900);
                        c_token++;
                }
                else if (almost_equals(c_token,"E$T4000")||
                        almost_equals(c_token,"e$t4000")) {
                        vga_setchipset(ET4000);
                        c_token++;
                }
                else if (almost_equals(c_token,"O$AK")||
                        almost_equals(c_token,"o$ak")) {
                        vga_setchipset(OAK);
                        c_token++;
                }
                else if (almost_equals(c_token,"C$IRRUS")||
                        almost_equals(c_token,"c$irrus")) {
                        vga_setchipset(CIRRUS);
                        c_token++;
                }
        }
#endif

        if (!END_OF_COMMAND) {
                if (almost_equals(c_token,"v$ga")||
                        almost_equals(c_token,"V$GA")) {
                        vga_setchipset(VGA);
                        linux_vmode = G640x480x16;
                        c_token++;
                }
                else if (almost_equals(c_token,"s$vga")||
                        almost_equals(c_token,"S$VGA")) {
                        vga_setchipset(UNDEFINED);
                        if ( vga_hasmode(G1024x768x256) ) {
                                linux_vmode = G1024x768x256;
                                term_tbl[term].xmax = 1024;
                                term_tbl[term].ymax = 768;
                                linux_xlast = 1023;
                                linux_ylast = 767;
                        }
                        else {
                                printf("Cannot use 1024x768 mode, using 640x480x16\n");
                                linux_vmode = G640x480x16;
                        }
                        c_token++;
                }
                else if (almost_equals(c_token,"s8$00")||
                        almost_equals(c_token,"S8$00")) {
                        vga_setchipset(UNDEFINED);
                        if ( vga_hasmode(G800x600x256) ) {
                                linux_vmode = G800x600x256;
                                term_tbl[term].xmax = 800;
                                term_tbl[term].ymax = 600;
                                linux_xlast = 799;
                                linux_ylast = 599;
                        }
                        else {
                                printf("Cannot use 800x600 mode, using 640x480x16\n");
                                linux_vmode = G640x480x16;
                        }
                        c_token++;
                }

                /********  SVGALIB doesn't support 16 color modes (yet?)
                else if (almost_equals(c_token,"s81$6")||
                        almost_equals(c_token,"S81$6")) {
                        vga_setchipset(UNDEFINED);
                        if ( vga_hasmode(G800x600x256) ) {
                                linux_vmode = G800x600x256;
                                term_tbl[term].xmax = 800;
                                term_tbl[term].ymax = 600;
                                linux_xlast = 799;
                                linux_ylast = 599;
                        }
                        else {
                                printf("Cannot use 800x600 mode, using 640x480x16\n");
                                linux_vmode = G640x480x16;
                        }
                        c_token++;
                }
                ***************************************************************************/

        }

        if ( linux_vmode == G640x480x16 ) {
                term_tbl[term].xmax = 640;
                term_tbl[term].ymax = 480;
                linux_xlast = 639;
                linux_ylast = 479;
        }

        sprintf(term_options,"%s" ,
                ( linux_vmode == G1024x768x256 ) ? "svga" : (
                        ( linux_vmode == G800x600x256) ?  "800x600x256" : (
                        ( linux_vmode == G320x240x256) ?  "800x600x16" :"vga" ) ) );

}
LINUX_text()
{
        int c;

        if (graphics_on) {
                graphics_on = FALSE;
                vga_getch();
        }
        vga_setmode(TEXT);
}


LINUX_reset()
{
        vga_setmode(TEXT);
}


LINUX_putc(x,y,c,ang,line_func)
unsigned int x,y;
char c;
int ang;
FUNC_PTR line_func;
{
int i, j, k;
unsigned int pixelon;
        i = (int)(c) - 32;
        for (j=0; j<FNT5X9_VBITS; j++) {
                for (k=0; k<FNT5X9_HBITS; k++) {
                        pixelon = (((unsigned int)(fnt5x9[i][j])) >> k & 1);
                        if (pixelon) {
                                switch(ang) {
                                        case 0 : (*line_func)(x+k+1,y-j,x+k+1,y-j);
                                                        break;
                                        case 1 : (*line_func)(x-j,y-k-1,x-j,y-k-1);
                                                        break;
                                }
                        }
                }
        }
}


int LINUX_text_angle(ang)
int ang;
{
        linux_angle=ang;
        return TRUE;
}


LINUX_init()
{
        if ( ! vga_hasmode(linux_vmode) ) {
                linux_vmode == G640x480x16;
                if ( ! vga_hasmode(linux_vmode) ) {
                        printf("Error, cannot find any valid display modes.\n");
                        return 1;
                }
                term_tbl[term].xmax = 640;
                term_tbl[term].ymax = 480;
                linux_xlast = 639;
                linux_ylast = 479;
        }
}


LINUX_graphics()
{
        graphics_on = TRUE;
        vga_setmode(linux_vmode);
}


LINUX_linetype(linetype)
{
        if (linetype >= 13)
                linetype %= 13;
        vga_setcolor(vgacolor[linetype+2]);
}

LINUX_move(x,y)
{
        startx = x;
        starty = y;
}


LINUX_vector(x,y)
{
        vga_drawline(startx,linux_ylast-starty,x,linux_ylast-y);
        startx = x;
        starty = y;
}


LINUX_put_text(x,y,str)
unsigned int x, y;
char *str;
{
int i;
        switch(linux_angle) {
                case 0 : y -= LINUX_VCHAR/2;
                                break;
                case 1 : x += LINUX_VCHAR/2;
                                break;
        }
        for (i=0;str[i];i++) {
                LINUX_putc(x,linux_ylast-y,str[i],linux_angle,vga_drawline);
                switch(linux_angle) {
                        case 0 : x+=LINUX_HCHAR ;
                                        break;
                        case 1 : y+=LINUX_HCHAR ;
                                        break;
                }
        }
}

--
Ludger Kunz           |    ____________|Tel.: 02371/566-230
FernUniversitaet Hagen|   /| /   / \   |FAX:  02371/52212          
Lehrgebiet ES         |  / |/   /_  \  |EMAIL:                      
Frauenstuhlweg 31     | /  |\  /     \ |[hidden email]
58644 Iserlohn        |/___|_\/_______\|