sgfutils

The package sgfutils contains a few command line utilities that help working with SGF files that describe go (igo, weiqi, baduk) games. This page is about sgftf.

See also sgf, sgfcharset, sgfcheck, sgfcmp, sgfdb, sgfdbinfo, sgfinfo, sgfmerge, sgfsplit, sgfstrip, sgftopng, sgfvarsplit, sgfx, ugi2sgf.

sgftf

% sgftf [options] < input > output

The utility sgftf reads an SGF file, transforms it (e.g. by rotation or horizontal or vertical flip) and writes it to stdout. The default transformation is a rotation by 180 degrees. Recognized transformations are -swapcolors, -rot90, -rot180, -rot270, -hflip, -vflip, -dflip, -aflip with meanings as follows.

board operation effect
initial board -tra0, -rot0 do nothing
transformed board -tra1, -vflip vertical flip
(reflect in horizontal line)
transformed board -tra2, -rot1, -rot90 rotate one turn (90 degrees) left
(counterclockwise)
transformed board -tra3, -bflip back-diagonal flip
(reflect in main diagonal)
transformed board -tra4, -rot2, -rot180 rotate 180 degrees
transformed board -tra5, -hflip horizontal flip
(reflect in vertical line)
transformed board -tra6, -rot3, -rot270 rotate 90 degrees right (clockwise)
transformed board -tra7, -dflip diagonal flip
(reflect in back-diagonal)
transformed board -swapcolors interchange black and white

(This is spelled out in detail because life is confusing: a reflection in a horizontal line is a vertical flip. The name indicates the direction of movement. There are several aliases for each option: some are easier for humans, some for software.)

Options:

--
Following parameters are filenames, not options.
-e .sgf
Extension to use when traversing a file hierarchy.
-i
Ignore SGF errors.
-o outfile
Specify output file (instead of stdout).
-q
Quiet: suppress some informative messages.
-r dir
Use as input files all files with the specified extension (see the -e option) below the directory dir.
-rotN
Apply rotation left over N*90 degrees (with N in 0..3). Apply rotation left over N degrees (with N in 0, 90, 180, 270).
-swapcolors
Interchange Black and White.
-t
Trace input read.
-traN
Apply transformation N (with N in 0..7).

Example

% sgftf -rot180 < in.sgf > out.sgf
Rotate 180 degrees. (The option -rot2 has the same effect.)

Discussion

This utility knows about the SGF properties B, W, AB, AW, AE, TR, CR, MA, SL, SQ, TB, TW, DD, VW, LB that have a move or (e)list of point as value (or first part of their composed value), and about AR, LN that have a list of pairs of points as value. So, not only the moves, but also the handicap or setup stones, the labels etc. are rotated.

With -swapcolors the properties B, W and AB, AW are interchanged.