Making PostScript from Vector Fields: avf2ps

The avf2ps utility creates a collection of color Encapsulated PostScript (.eps) or Scalable Vector Graphics (.svg) files from a collection of vector field files (e.g., .omf, .ovf). Third party tools can be used to convert .eps and .svg files into other formats such as the Portable Document Format that can be embedded into larger documents. An advantage of .eps and .svg files over bitmap images such as .png or .tiff is that arrows in the former scale without pixelization to any magnification. Operation of the avf2ps command is modeled after the avf2ppm command and the print dialog box in mmDisp.

Launching
The avf2ps launch command is:

tclsh oommf.tcl avf2ps [standard options] [-config file] [-f] \
   [-filter program] [-format fmt] [-ipat pattern] [-opatexp regexp] \
   [-opatsub sub] [-v level] [infile ...]
where
-config file
User configuration file that specifies image display parameters. This file is discussed in detail below.
-f
Force overwriting of existing (output) files. By default, if avf2ps tries to create a file, say foo.ps, that already exists, it generates instead a new name of the form foo.ps-000, or foo.ps-001, ..., or foo.ps-999, that doesn't exist and writes to that instead. The -f flag disallows alternate filename generation, and overwrites foo.ps instead.
-filter program
Post-processing application to run on each avf2ps output file. May be a pipeline of several programs.
-format fmt
Select output format, either EPS for Encapsulated PostScript (default) or SVG for Scalable Vector Graphics.
-ipat pattern
Specify input files using a pattern with “glob-style” wildcards. Mostly useful in DOS.
-opatexp regexp
Specify the “regular expression” applied to input filenames to determine portion to be replaced in generation of output filenames. The default regular expression is: (\.[^.]?[^.]?[^.]?$|$)
-opatsub sub
The string with which to replace the portion of input filenames matched by the -opatexp regexp during output filename generation. The default is .eps for Encapsulated PostScript output and .svg for Scalable Vector Graphics.
-v level
Verbosity (informational message) level, with 0 generating only error messages, and larger numbers generating additional information. The level value is an integer, defaulting to 1.
infile ...
List of input files to process.

The file specification options, -ipat, -opatexp, and -opatsub, are interpreted in the same manner as for the avf2ppm application.

If you have command line PostScript processing “filter” programs, e.g., ghostscript, then you can use the -filter option to pipe the output of avf2ps through that filter before it is written to the output file specified by the -opat* expressions. If the processing changes the format of the file, (e.g., from PostScript to PDF), then you will likely want to specify a -opatsub different from the default.

Here is an example that processes all files with the .ovf extension, sending the output through ps2pdf (part of the ghostscript package) before saving the results in files with the extension .pdf:

tclsh oommf.tcl avf2ps -ipat *.ovf -opatsub .pdf -filter "ps2pdf - -"
On Unix, either drop the -ipat flag, or use quotes to protect the input file specification string from expansion by the shell, as in -ipat '*.ovf'.

Configuration files
The details of the conversion process are specified by plain-text configuration files, in the same format as the mmDisp configuration file.

The arrays plot_config and print_config hold the configurable parameters. The default values for these arrays are read first from the main configuration file

oommf/app/mmdisp/scripts/avf2ps.config
followed by the local customization file
oommf/app/mmdisp/scripts/local/avf2ps.config
if it exists. Lastly, any files passed as -config options on the command line are input. Each of these parameters is interpreted as explained in the mmDisp documentation, except that avf2ps ignores the misc,defaultwindowwidth and misc,defaultwindowheight parameters, and the following additional parameters are available:
arrow,length
Full length of arrow, from tail to tip. All of the arrow dimensions, including this one, are measured relative to the sample cell size. The default value for arrow,length is 0.9, which being less than 1.0 ensures that arrows in neighboring cells don't overlap.
arrow,width
Width of the arrow shaft.
arrow,tipwidth
Width of the arrow at its tip
arrow,headwidth
Width of the arrowhead at its widest point.
arrow,headilength
Distance from the tip of the arrow back to the point where the arrowhead detaches from the shaft.
arrow,headolength
Distance along the shaft from the tip of the arrow back to the widest point of the arrowhead.
arrow,outlinewidth
Width of a colored outline around each arrow; this can improve visibility of an arrow when it is overlayed against a background with color similar to that of the arrow. Default value is zero, meaning no outline. Reasonable non-zero values are generally some fraction of the the arrow shaft width.
arrow,outlinecolor
If arrow,outlinewidth is positive, then this is the color of the arrow outline.
misc,boundarypos
Placement of the bounding polygon, either back or front, i.e., either behind or in front of the rendered arrows and pixel elements.
misc,matwidth
Specifies the width, in pixels, of a mat (frame) around the outer edge of the image. The mat is drawn inwards from the margin, in front of all other objects. To disable, set matwidth to 0.
misc,matcolor
Color of the mat.
misc,width, misc,height
Maximum width and height of the output, in pixels. One or both of these dimensions may be shortened if misc,croptomargin is enabled.
misc,croptomargin
If disabled (0), then any leftover space in the output (of dimensions misc,width by misc,height) after packing the image are filled with the background color. If enabled (1), then the output is cropped at the margins specified by misc,margin. NOTES: If the arrow or pixel glyphs are oversized (size bigger than 1), then they may extend beyond the margin. In this case the glyphs will be clipped by misc,croptomargin. If this is not desired, then either increase the margin size to compensate, or else disable misc,croptomargin and use third party tools such as epstool,
epstool --copy --bbox input.eps output.eps
or epstopdf + pdfcrop to obtain tight cropping.
misc,crop
Deprecated option replaced by misc,croptomargin.

The default configuration file can be used as a starting point for user configuration files. You may also use configuration files produced by the File|Write config... command in mmDisp, although any of the above avf2ps-specific parameters that you wish to use will have to be added manually, using a plain text editor. You may omit any entries that you do not want to change from the default. You may “layer” configuration files by specifying multiple user configuration files on the command line. These are processed from left to right, with the last value set for each entry taking precedence.

The misc,datascale and arrow,coloroffset, pixel,coloroffset configuration options can be used to control the mapping of values to the selected colormap. See the mmDisp documentation for details.



array set plot_config {
  arrow,status       1                  misc,background     #FFFFFF
  arrow,colormap     Red-Black-Blue     misc,drawboundary   1
  arrow,colorcount   100                misc,boundarywidth  1
  arrow,quantity     z                  misc,boundarycolor  #000000
  arrow,coloroffset  0                  misc,boundarypos    front
  arrow,colorreverse 0                  misc,matwidth       0
  arrow,autosample   1                  misc,matcolor       #FFFFFF
  arrow,subsample    10                 misc,margin         10
  arrow,size         1                  misc,width          640
  arrow,length       0.9                misc,height         480
  arrow,width        0.075              misc,croptomargin   1
  arrow,tipwidth     0.01875            misc,zoom           0
  arrow,headwidth    0.4                misc,rotation       0
  arrow,headilength  0.4                misc,datascale      0
  arrow,headolength  0.5                misc,relcenterpt {0.5 0.5 0.5}
  arrow,outlinewidth 0.0
  arrow,outlinecolor #000000            viewaxis            +z
                                        viewaxis,xarrowspan {}
  pixel,status       1                  viewaxis,xpixelspan {}
  pixel,colormap     Teal-White-Red     viewaxis,yarrowspan {}
  pixel,colorcount   225                viewaxis,ypixelspan {}
  pixel,opaque       1                  viewaxis,zarrowspan {}
  pixel,quantity     x                  viewaxis,zpixelspan {}
  pixel,coloroffset  0.
  pixel,colorreverse 0
  pixel,colorinvert  0
  pixel,autosample   1
  pixel,subsample    0
  pixel,size         1
}
array set print_config {
  orient   landscape                    tmargin   1.0
  paper    letter                       lmargin   1.0
  hpos     center                       pwidth    6.0
  vpos     center                       pheight   6.0
  units    in                           croptoview 1
}
Figure 16.2: Contents of default configuration file avf2ps.config. (description)



OOMMF Documentation Team
September 27, 2024