1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
############################################################################
#
# File: dd2unit.icn
#
# Subject: Program to get dimensions of unit motif of pattern
#
# Author: Ralph E. Griswold
#
# Date: June 12, 2002
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# The following command line option is supported:
#
# -p assume partial repeats may occur at edges of pattern;
# default complete repeats
#
############################################################################
#
# Links: options, patutils, seqops
#
############################################################################
link options
link patutils
link seqops
global switch
procedure main(args)
local rows, opts
opts := options(args, "p")
switch := opts["p"]
rows := unit(pat2rows(read()))
write(*rows[1], "x", *rows)
end
procedure rot90(rows) # rotate pattern 90 degrees clockwise
local columns, i, j
columns := list(*rows[1], "")
every i := 1 to *rows do
every j := 1 to *columns do
columns[j] ||:= rows[i][j]
return columns
end
procedure unit(grid)
grid := grepeat(grid)
grid := grepeat(rot90(grid))
return rot90(grid)
end
procedure grepeat(grid) #: reduce grid to smallest repeat
local periods, i, width
grid := copy(grid)
periods := []
width := *grid[1]
every i := 1 to *grid do
put(periods, speriod(str2lst(grid[i]), switch) | width)
width >:= lcml ! periods
every i := 1 to *grid do
grid[i] := left(grid[i], width)
return grid
end
|