home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sunic!chalmers.se!news.chalmers.se!tarski!exjob-17
- From: exjob-17@tarski.NoSubdomain.NoDomain (Niclas Mattsson)
- Newsgroups: comp.soft-sys.matlab
- Subject: Matlab graph -> Framemaker solution
- Message-ID: <C1FLCD.IJv@news.chalmers.se>
- Date: 25 Jan 93 22:33:48 GMT
- Sender: exjob-17@tarski (Niclas Mattsson)
- Organization: Chalmers University of Technology
- Lines: 219
- Nntp-Posting-Host: tarski.math.chalmers.se
-
-
- Hello out there!
-
- I'm currently writing my Master's Thesis using MATLAB 3.5 and FrameMaker and
- had the same problem as everyone else. MATLAB can write graphs in EPS format
- which can be imported into FrameMaker, but to be able to view them, the graphs
- must be in EPSI format (almost the same format as EPS, but with a bitmap
- approximation to the picture).
-
- My problem was solved by finding the following little filter program in
- comp.something.postscript. It uses Ghostscript to make the bitmap necessary
- in the EPSI format.
-
- So, try this out:
-
- 1. Check so you have 'gs' (Ghostscript) by typing 'which gs' in UNIX.
- An output of something like '/usr/pd/gnu/bin/gs' means you're in
- business.
-
- 2. Cut out the script in this posting at the **** CUT HERE **** markings.
-
- 3. Type 'which perl' to see where you have your perl program (yes, you'll
- need this one too).
-
- 4. Edit the first line of the script to match your perl file path.
-
- 5. Call the script 'eps2epsi' or whatever you like.
-
- If you use MATLAB 4.0 you can just save a picture in EPS format and then use this
- filter. In MATLAB 3.5 you save the picture in META format and use 'gpp -deps'
- before using the EPS2EPSI filter.
-
- Good Luck!
- Niclas Mattsson
-
-
-
-
- *********************** CUT HERE *************************
- #!/usr/pd/gnu/bin/perl
- 'di';
- 'ig00';
-
- # EPSI file generator. Written by Gisle Aas, NR, 1991
- # Converts all types of EPS-files to the EPSI format where a bitmap preview
- # is included. You need GhostScript to render the bitmaps for you.
-
- # $Log: eps2epsi,v $
- # Revision 1.1 1991/05/28 09:18:04 aas
- # Initial revision
- #
-
- $prog_name = substr($0,rindex($0,"/")+1);
- require 'getopts.pl';
- unless (&Getopts('w:')) {
- print STDOUT "Usage: $prog_name [-w <preview width>] [<file>]\n";
- exit 1;
- }
-
- die 'To many files' if ($#ARGV > 0);
-
- @epsfile = <>; # slurp
- die 'Not PostScript file' unless ($epsfile[0] =~ /^%!/);
-
- # Get the dimensions of the picture
- for (@epsfile) {
- ($llx, $lly, $urx, $ury) =
- /^%%BoundingBox:\s*(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/;
- last if defined($llx);
- }
- die 'No %%BoundingBox found in file' unless defined($llx);
-
- # Calculate
- $preview_width = int(($opt_w || 79) / 2) * 8;
- $width = $urx - $llx + 1;
- $height = $ury - $lly + 1;
- $scalefactor = $preview_width / $width;
- $width = int($width * $scalefactor);
- $height = int($height * $scalefactor);
-
- # Produce GhostScript program
- $gsfile = "/tmp/gs$$.tmp";
- open(GSFILE, ">$gsfile") || die "Can't write to file $gsfile";
- print GSFILE <<"---EndGhostScriptProgram---";
- %!GhostScript
- /BITIMAGE_WIDTH $width def
- /BITIMAGE_HEIGHT $height def
- /BITIMAGE_FILE (%stdout) def
-
- %---- Setup a memory device --------
- [1 0 0 -1 0 BITIMAGE_HEIGHT]
- BITIMAGE_WIDTH BITIMAGE_HEIGHT
- %
- % [1 1 1 rgbcolor 0 0 0 rgbcolor] <-- 2.3 arguments
- % <ff 00> <-- 2.4 arguments from ghost@aladdin.com
- %
- <ff 00>
- makeimagedevice
- setdevice
-
- %--- Some transformations
- /showpage {} def
- $scalefactor dup scale
- $llx neg $lly neg translate
-
- %--- The old EPS file
- @epsfile
-
- %---- Print bitmap on a file -------
- /line BITIMAGE_WIDTH 8 idiv 1 add string def
- /output BITIMAGE_FILE (w) file def
- output (---------) writestring
- output 10 write
- 0 1 BITIMAGE_HEIGHT 1 sub { %for
- output (%) writestring
- currentdevice exch
- line copyscanlines
- output exch writehexstring
- output 10 write
- } for
- output flushfile
- quit
- ---EndGhostScriptProgram---
-
- close GSFILE;
- close STDIN; # so that GhostScript can't read it.
-
- @gsoutput = `gs -q -DNODISPLAY $gsfile`; # run GhostScript
- die "Can't run GhostScript" unless $? == 0;
- unlink $gsfile;
-
- @preview = grep(/^-----/ .. 1, @gsoutput); # remove GhostScript garbage
- shift(preview);
- if ($#preview < 0) {
- print STDERR "GhostScript gives no output for the specified file\n";
- print STDERR @gsoutput;
- exit 1;
- }
-
- print shift(epsfile);
- $_ = shift(epsfile);
- while (/^%%/) {
- if (/^%%BoundingBox:/) {
- print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
- $boundingbox = 1;
- } elsif (/^%%EndComments/) {
- last;
- } else {
- print;
- }
- $_ = shift(epsfile);
- }
- print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
- print "%%EndComments
- %%BeginPreview: $width $height 1 $height\n";
- print @preview;
- print "%%EndPreview\n";
-
- print grep(!(/^%%BeginPreview:/ .. /^%%EndPreview/) && !/^%%BoundingBox:/,
- @epsfile);
-
-
-
-
-
- ###########################################################################
- # These next few lines are legal in both Perl and nroff.
-
- .00; # finish .ig
-
- 'di \" finish diversion--previous line must be blank
- .nr nl 0-1 \" fake up transition to first page again
- .nr % 0 \" start at page 1
- ';<<'.ex'; #__END__ #### From here on it's a standard manual page #########
- .TH EPS2EPSI 1 "May 1991"
- .SH NAME
- eps2epsi \- Filter for inclusion of a preview in an EPS file
- .SH SYNOPSIS
- .B eps2epsi
- [
- .B \-w
- .I preview_width
- ] [
- .I filename
- ]
- .SH DESCRIPTION
- .B Eps2epsi
- puts a preview section in a PostScript file (preferably EPSF).
- The preview produced
- is in the encapsulated PostScript interchange format (EPSI)
- suitable for import by FrameMaker and other document composing
- systems.
- .B Eps2epsi
- reads the file specified (or standard input) and sends the new file
- with the preview included to standard output.
- .PP
- .B Esp2epsi
- uses
- .B GhostScript
- to render the preview bitmap, which means that
- .B GhostScript
- must be installed at your system before you can use
- .B eps2epsi.
- .SH OPTIONS
- .TP 5
- .BI \-w " n"
- Set the width (in characters) of the preview section. This also specifies the
- resolution of the preview as
- .I n
- times 4 horizontally.
- .SH SEE ALSO
- .BR perl (1),
- .BR gs(1)
- .SH AUTHOR
- Gisle Aas, Norwegian Computing Center (NR), Oslo, Norway.
- <Gisle.Aas@nr.no>
- .ex
-
- *************************** CUT HERE ****************************
-