plotlib
Overview & Purpose
plotlib (authored by Guy Carpenter, September 1989) is the Ocean Mapping Groupβs device-independent 2D vector plotting library. Scientific and diagnostic tools across the OMG repository call plotlib routines to emit an ASCII vector metafile of floating-point drawing primitives (STR, MOV, LNE, TXT, PEN, CLP, etc.), which can then be rendered on screen or converted to PostScript/HPGL by backend drivers in code/plotlib/ (such as viewmeta, plotdriver, hpgl, pensort, and penstat).
Key Data Structures, Constants & Macros
Types & Global State
boolean:typedef unsigned char booleanwithfalse(0x00) andtrue(0xff).- Internal Module State (
plotlib.c):FILE *plot_file: Active file stream for the output ASCII metafile.boolean plot_opened: Guards against duplicateplot_opencalls or drawing before opening a metafile.short pen_number: Caches the currently active pen number (0indicates no pen selected) to suppress redundantPENcommands.
Metafile Command Protocol
Every plotlib function writes a single line-oriented ASCII command to plot_file:
STR <dx> <dy>: Initializes the plot canvas dimensions.END: Terminates the plot stream.ROT: Rotates the coordinate axes by 90 degrees (landscape/portrait toggle).MOV <x> <y>: Moves the pen to(x, y)with the pen up.LNE <x> <y>: Draws a straight line segment from the current position to(x, y)with the pen down.TXT "<string>": Draws a null-terminated text label at the current position.TRT <angle>: Sets the text rotation angle in degrees.TSZ <x> <y>: Sets the character width (x) and height (y) in centimeters.PEN <pen>: Selects pen/color index<pen>.CLP <x0> <y0> <x1> <y1>: Sets the rectangular clipping window in centimeters.
Public Functions & Signatures
Canvas & State Control
int plot_open(float dx, float dy, char *metafile)- Opens
metafilefor writing. IfmetafileisNULLor empty, automatically generates the first unused filename matching"plotfile_%d"(plotfile_0,plotfile_1, β¦) usingaccess(). Writes"STR %.3f %.3f\n"with dimensions(dx, dy)and flushes the stream. Returns1on success,0on failure.
- Opens
int plot_close()- Writes
"END\n", closesplot_file, and resetsplot_opened = false.
- Writes
int plot_rotate()- Emits
"ROT\n"to rotate the plot coordinate axes.
- Emits
int plot_pen(int pen)- Emits
"PEN %d\n"and updatespen_numberifpen != pen_number.
- Emits
int plot_clip(float x0, float y0, float x1, float y1)- Sorts
(x0, x1)and(y0, y1)so thatx0 <= x1andy0 <= y1, then emits"CLP %.3f %.3f %.3f %.3f\n".
- Sorts
Vector & Text Primitives
int plot_move(float x, float y)- Emits
"MOV %.3f %.3f\n"(pen-up move).
- Emits
int plot_line(float x, float y)- Emits
"LNE %.3f %.3f\n"(pen-down line draw).
- Emits
int plot_text(char *text)- Emits
"TXT \"%s\"\n".
- Emits
int plot_textrot(float angle)- Emits
"TRT %.3f\n"to set text baseline angle in degrees.
- Emits
int plot_textrunrise(float run, float rise)- Computes the slope angle in degrees from
(run, rise)usingatan(rise / run) * 180.0 / 3.14159(handling verticalrun == 0.0and negativerunquadrants) and callsplot_textrot(angle).
- Computes the slope angle in degrees from
int plot_textsize(float x, float y)- Emits
"TSZ %.3f %.3f\n"to configure character cell width and height (cm).
- Emits
Higher-Order Symbol Helpers
void plot_diamond(float x, float y, float rad)- Draws a closed 4-vertex diamond centered at
(x, y)with half-width/radiusradusingplot_moveand fourplot_linecalls.
- Draws a closed 4-vertex diamond centered at
void plot_cross(float x, float y, float rad)- Draws a
+crosshair centered at(x, y)with arm radiusradand returns the pen to(x, y).
- Draws a
How It Fits Into the OMG Architecture
plotlib is used by over 35 plotting and diagnostic tools across code/plot/ (plotBP, plotAngular, plotSwath, plotTides, plotRoll, plotDelayHeave, plotFoot, plotDump, plot2D, asciiplot), code/ray/ (plotSVP, traceRay, plotSOLN), code/grid/ (plotProfile, plotADCPgridcurrents), code/sidescan/ (mapmos, binplot), code/vers/ (lineplot), and code/plotlib/ (viewmeta, plotdriver, hpgl).