home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / softsys / matlab / 166 < prev    next >
Encoding:
Text File  |  1993-01-25  |  6.1 KB  |  231 lines

  1. Path: sparky!uunet!mcsun!sunic!chalmers.se!news.chalmers.se!tarski!exjob-17
  2. From: exjob-17@tarski.NoSubdomain.NoDomain (Niclas Mattsson)
  3. Newsgroups: comp.soft-sys.matlab
  4. Subject: Matlab graph -> Framemaker solution
  5. Message-ID: <C1FLCD.IJv@news.chalmers.se>
  6. Date: 25 Jan 93 22:33:48 GMT
  7. Sender: exjob-17@tarski (Niclas Mattsson)
  8. Organization: Chalmers University of Technology
  9. Lines: 219
  10. Nntp-Posting-Host: tarski.math.chalmers.se
  11.  
  12.  
  13. Hello out there!
  14.  
  15. I'm currently writing my Master's Thesis using MATLAB 3.5 and FrameMaker and
  16. had the same problem as everyone else. MATLAB can write graphs in EPS format
  17. which can be imported into FrameMaker, but to be able to view them, the graphs
  18. must be in EPSI format (almost the same format as EPS, but with a bitmap
  19. approximation to the picture).
  20.  
  21. My problem was solved by finding the following little filter program in
  22. comp.something.postscript. It uses Ghostscript to make the bitmap necessary
  23. in the EPSI format.
  24.  
  25. So, try this out:
  26.  
  27. 1.    Check so you have 'gs' (Ghostscript) by typing 'which gs' in UNIX.
  28.     An output of something like '/usr/pd/gnu/bin/gs' means you're in
  29.     business.
  30.  
  31. 2.    Cut out the script in this posting at the **** CUT HERE **** markings.
  32.  
  33. 3.    Type 'which perl' to see where you have your perl program (yes, you'll
  34.     need this one too).
  35.  
  36. 4.    Edit the first line of the script to match your perl file path.
  37.  
  38. 5.    Call the script 'eps2epsi' or whatever you like.
  39.  
  40. If you use MATLAB 4.0 you can just save a picture in EPS format and then use this
  41. filter. In MATLAB 3.5 you save the picture in META format and use 'gpp -deps'
  42. before using the EPS2EPSI filter.
  43.  
  44. Good Luck!
  45. Niclas Mattsson
  46.  
  47.  
  48.  
  49.  
  50. *********************** CUT HERE *************************
  51. #!/usr/pd/gnu/bin/perl
  52. 'di';
  53. 'ig00';
  54.  
  55. # EPSI file generator. Written by Gisle Aas, NR, 1991
  56. # Converts all types of EPS-files to the EPSI format where a bitmap preview
  57. # is included. You need GhostScript to render the bitmaps for you.
  58.  
  59. # $Log: eps2epsi,v $
  60. # Revision 1.1  1991/05/28  09:18:04  aas
  61. # Initial revision
  62. #
  63.  
  64. $prog_name = substr($0,rindex($0,"/")+1);
  65. require 'getopts.pl';
  66. unless (&Getopts('w:')) {
  67.   print STDOUT "Usage: $prog_name [-w <preview width>] [<file>]\n";
  68.   exit 1;
  69. }
  70.  
  71. die 'To many files' if ($#ARGV > 0);
  72.  
  73. @epsfile = <>;                  # slurp
  74. die 'Not PostScript file' unless ($epsfile[0] =~ /^%!/);
  75.  
  76. # Get the dimensions of the picture
  77. for (@epsfile) {
  78.    ($llx, $lly, $urx, $ury) =
  79.        /^%%BoundingBox:\s*(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/;
  80.    last if defined($llx);
  81. }
  82. die 'No %%BoundingBox found in file' unless defined($llx);
  83.  
  84. # Calculate 
  85. $preview_width = int(($opt_w || 79) / 2) * 8;
  86. $width  = $urx - $llx + 1;
  87. $height = $ury - $lly + 1;
  88. $scalefactor = $preview_width / $width;
  89. $width  = int($width * $scalefactor);
  90. $height = int($height * $scalefactor);
  91.  
  92. # Produce GhostScript program
  93. $gsfile = "/tmp/gs$$.tmp";
  94. open(GSFILE, ">$gsfile") || die "Can't write to file $gsfile";
  95. print GSFILE <<"---EndGhostScriptProgram---";
  96. %!GhostScript
  97. /BITIMAGE_WIDTH $width def
  98. /BITIMAGE_HEIGHT $height def
  99. /BITIMAGE_FILE (%stdout) def
  100.  
  101. %---- Setup a memory device --------
  102. [1 0 0 -1 0 BITIMAGE_HEIGHT]
  103. BITIMAGE_WIDTH BITIMAGE_HEIGHT
  104. %
  105. % [1 1 1 rgbcolor 0 0 0 rgbcolor] <-- 2.3 arguments
  106. % <ff 00>                         <-- 2.4 arguments from ghost@aladdin.com
  107. %
  108. <ff 00> 
  109. makeimagedevice
  110. setdevice
  111.  
  112. %--- Some transformations
  113. /showpage {} def
  114. $scalefactor dup scale
  115. $llx neg $lly neg translate
  116.  
  117. %--- The old EPS file
  118. @epsfile
  119.  
  120. %---- Print bitmap on a file -------
  121. /line BITIMAGE_WIDTH 8 idiv 1 add string def
  122. /output BITIMAGE_FILE (w) file def
  123. output (---------) writestring
  124. output 10 write
  125. 0  1  BITIMAGE_HEIGHT 1 sub { %for
  126.    output (%) writestring
  127.    currentdevice exch
  128.    line copyscanlines
  129.    output exch writehexstring
  130.    output 10 write
  131. } for
  132. output flushfile
  133. quit
  134. ---EndGhostScriptProgram---
  135.  
  136. close GSFILE;
  137. close STDIN;    # so that GhostScript can't read it.
  138.  
  139. @gsoutput = `gs -q -DNODISPLAY $gsfile`;   # run GhostScript
  140. die "Can't run GhostScript" unless $? == 0;
  141. unlink $gsfile;
  142.  
  143. @preview = grep(/^-----/ .. 1, @gsoutput);   # remove GhostScript garbage
  144. shift(preview);
  145. if ($#preview < 0) {
  146.   print STDERR "GhostScript gives no output for the specified file\n";
  147.   print STDERR @gsoutput;
  148.   exit 1;
  149. }
  150.  
  151. print shift(epsfile);
  152. $_ = shift(epsfile);
  153. while (/^%%/) {
  154.   if (/^%%BoundingBox:/) {
  155.     print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
  156.     $boundingbox = 1;
  157.   } elsif (/^%%EndComments/) {
  158.     last;
  159.   } else {
  160.     print;
  161.   }
  162.   $_ = shift(epsfile);
  163. }
  164. print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
  165. print "%%EndComments
  166. %%BeginPreview: $width $height 1 $height\n";
  167. print @preview;
  168. print "%%EndPreview\n";
  169.  
  170. print grep(!(/^%%BeginPreview:/ .. /^%%EndPreview/) && !/^%%BoundingBox:/,
  171.            @epsfile);
  172.  
  173.  
  174.  
  175.  
  176.  
  177. ###########################################################################
  178.         # These next few lines are legal in both Perl and nroff.
  179.  
  180. .00;                    # finish .ig
  181.  
  182. 'di                     \" finish diversion--previous line must be blank
  183. .nr nl 0-1              \" fake up transition to first page again
  184. .nr % 0                 \" start at page 1
  185. ';<<'.ex'; #__END__ #### From here on it's a standard manual page #########
  186. .TH EPS2EPSI 1 "May 1991"
  187. .SH NAME
  188. eps2epsi \- Filter for inclusion of a preview in an EPS file
  189. .SH SYNOPSIS
  190. .B eps2epsi
  191. [
  192. .B \-w
  193. .I preview_width
  194. ] [
  195. .I filename
  196. ]
  197. .SH DESCRIPTION
  198. .B Eps2epsi
  199. puts a preview section in a PostScript file (preferably EPSF).
  200. The preview produced
  201. is in the encapsulated PostScript interchange format (EPSI)
  202. suitable for import by FrameMaker and other document composing
  203. systems.
  204. .B Eps2epsi
  205. reads the file specified (or standard input) and sends the new file
  206. with the preview included to standard output.
  207. .PP
  208. .B Esp2epsi
  209. uses
  210. .B GhostScript
  211. to render the preview bitmap, which means that
  212. .B GhostScript
  213. must be installed at your system before you can use
  214. .B eps2epsi.
  215. .SH OPTIONS
  216. .TP 5
  217. .BI \-w " n"
  218. Set the width (in characters) of the preview section. This also specifies the
  219. resolution of the preview as
  220. .I n
  221. times 4 horizontally.
  222. .SH SEE ALSO
  223. .BR perl (1),
  224. .BR gs(1)
  225. .SH AUTHOR
  226. Gisle Aas, Norwegian Computing Center (NR), Oslo, Norway.
  227. <Gisle.Aas@nr.no>
  228. .ex
  229.  
  230. *************************** CUT HERE ****************************
  231.