Using matwrap, the entire pgplot plotting library
can be called from octave. (Actually, it uses the cpgplot interface.)
Each function which you can call from C is available to be called from
octave. Since I just took the cpgplot.h file and ran it
through the wrapper generator, the interface is as low level as the C
subroutines themselves (e.g., it doesn't autoscale, etc.). Perhaps
someone wouldn't mind writing and distributing some higher level
plotting functions make it easier to use?
To install and test it, perform the following steps:
Make sure your octave program supports dynamic loading of
compiled functions. Some binary distributions do not. If you have the
mkoctfile script, then you're probably ok.
Also, the pgplot wrapper code won't work with versions of octave before 2.0.0. Upgrade your octave if you have such an old version.
Install the pgplot libraries (libpgplot and
libcpgplot somewhere on your system. These libraries must
either be shared libraries (usually with an extension of
.so) or else compiled in a format suitable for linking into
a shared library. On some systems, this means you must use the
-fPIC option to gcc, for example. Some systems, such as
Digital Unix, do not require any special options for compilation. Check
your system's documentation for producing shared libraries.
Fetch the pgplot wrapper code. The pgplot wrapper is included with the matwrap distribution. If you just want the code and don't want the wrapper generator itself, then you need several things:
Create a .oct file using the mkoctfile
script. Various versions of octave have different problems. What you
have to do depends on the version of octave:
pgplot_octave.cc for version 2.1
(see above). Then issue the command:
mkoctfile pgplot_octave.cc -lcpgplot -lpgplot -lX11 -lmOther libraries may be necessary, depending on your system. For example, on my linux system with g77, I found that I had to add an additional library (
-lg2c):
mkoctfile pgplot_octave.cc -L/usr/X11R6/lib -lcpgplot -lpgplot -lX11 -lg2c -lm
mkoctfile script is documented to accept the -llib
option but it doesn't work. To fix it, apply the patch contained in the
file mkoctfile.patch to the
mkoctfile script, like this:
cd dir_containing_mkoctfile patch < mkoctfile.patch(You may need to copy your mkoctfile script into a different directory to apply the patch.)
Now execute mkoctfile like this:
mkoctfile pgplot_octave.cc -lcpgplot -lpgplot -lX11 -lmOther libraries may be necessary, depending on your system. (E.g., you might have to add
-lf2c or other fortran libraries,
especially if octave is linked statically to them. The above works fine
for me on Digital Unix 4.0. I'd appreciate comments on what works on
other systems.) You may also have to add -L/dir/of/pgplot
if you installed pgplot in a nonstandard location.
If you get this to work, I'd appreciate it if you would email me comments on exactly what your system type is, what libraries are necessary for your system, and any tweaks you had to make in compiling pgplot, and any other details or problems you found. This seems to be a difficult step and I currently have access to only one operating system type (linux).
$SH_LD $SH_LDFLAGS -o $octfile $objfile -lcpgplot -lpgplot -lX11 -lm
If you didn't install your pgplot libraries and include files in a
standard directory, you'll have to also add
-L/your/path/to/pgplot before the -l options
in the above line.
Once you've done that, now just type:
mkoctfile pgplot_octave
This step should succede in building the file
pgplot_octave.oct. Ignore warning messages about
_put_pointer and _get_pointer being defined
but not used, if they should appear.
Now you're ready to try it. Access it like this:
% setenv PGPLOT_DIR /where/you/put/pgplot
% octave
octave:1> pgplot_stub # You must do this first.
octave:2> pgopen('/xserv'); # Must specify the output device.
octave:3> pgdemo4_for_octave