[Date Index] [Thread Index] [Author Index]
Re: easiest way to display a plot from C to kernel using Mathlink?
In article <897eon$5to at smc.vnet.net>, dave linenberg <dlinenbe at home.com> writes: > I am interested in using Mathlink to display plots, calling it > externally. > > I am calling the Mathematica 4.0 kernel via C function calls in my own > program using Linux (Redhat 6.0) > > I have searched the newsgroups for the last few years, and have not > found much information. > I have Gayley's Mathlink tutorial, but it falls apart in addressing the > display of postscript files or graphics when > calling the Mathematica kernel from external programs. (No examples). > > I would like to know - > * how to generate postscript files using C code w/ Mathlink / > Mathematica 4.0 Linux Redhat 6.0, gcc/g++ The easiest way to generate pure PostScript files is to pipe the output of Display through a shell script called psfix. psfix is still installed by the Unix installers, but it resides in a directory that does not appear on the shell's PATH setting. You should be able to find it in: <path to Mathematica installation>/SystemFiles/Graphics/SystemResources The comments in the script provide information on the command line flags that you can supply. You can also use the comments in the script to learn more about how abbreviated Mathematica PostScript operators map to actual Adobe PostScript. > * as well as ... how to automatically open a separate window to > display such graphics You could write your own PostScript interpreter and renderer, or you could use motifps. You use Display to write the abbreviated Mathematica PostScript to a scratch file and then call a wrapper shell script to launch the motifps binary. You will need to adjust the topdir variable to reflect the actual path to the Mathematica installation on your system. [begin sample shell script] #!/bin/sh topdir=/usr/local/mathematica/4.0.1 sysid=Linux bindir=$topdir/SystemFiles/Graphics/Binaries/$sysid PATH=bindir:$PATH export PATH XFILESEARCHPATH=$topdir/SystemFiles/Graphics/TextResources/English/%N export XFILESEARCHPATH if [ ."$PSRESOURCEPATH" = . ]; then PSRESOURCEPATH=$topdir/SystemFiles/Graphics/SystemResources:$topdir/SystemFiles/Fonts/Type1 else PSRESOURCEPATH=$PSRESOURCEPATH:$topdir/SystemFiles/Graphics/SystemResources:$topdir/SystemFiles/Fonts/Type1 fi export PSRESOURCEPATH exec $bindir/motifps $@ [end sample shell script] The PSRESOURCEPATH variable is a list of directories where PostScript resource files (Type 1 fonts, procesets, etc.) reside. You can add your own Type 1 font directories to this list, provided that you generate a PostScript resource catalog (PSres.upr) with the makepsres utility in SystemFiles/Graphics/Binaries/Linux. -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.