summaryrefslogtreecommitdiff
path: root/ipl/gpacks/weaving/weavutil.icn
blob: 1da608548c0f6fafb7cb0e5025d5a3c3cbee63b4 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
############################################################################
#
#	File:     weavutil.icn
#
#	Subject:  Procedures to support numerical weavings
#
#	Author:   Ralph E. Griswold
#
#	Date:     June 13, 1999
#
############################################################################
#
#  This file is in the public domain.
#
############################################################################
#
#  Links:  expander, patutils, tables, tieutils
#
############################################################################

link expander
link patutils
link tables
link tieutils

$include "weavdefs.icn"

#  PFL weaving parameters

record PflParams(P, T)

#  Sequence-drafting database record

record sdb(table, name)			# specification database

record ddb(table)			# definition database
record edb(table)			# expression database
record tdb(table)			# tie-up database

#  Weaving specification

record weaving(
   name,
   breadth,
   length,
   threading,
   treadling,
   shafts,
   treadles,
   palette,
   colors,
   warp_colors,
   weft_colors,
   tieup,
   defns,
   links,
   comments
   )

record draft(
   name,
   threading,
   treadling,
   warp_colors,
   weft_colors,
   shafts,
   treadles,
   palette,
   colors,
   tieup, 
   liftplan,
   drawdown
   )

procedure readpfd(input)		# read PFD
   local pfd

   pfd := draft()

   pfd.name := read(input) &
   pfd.threading := read(input) &
   pfd.treadling := read(input) &
   pfd.warp_colors := read(input) &
   pfd.weft_colors := read(input) &
   pfd.palette := read(input) &
   pfd.colors := read(input) &
   pfd.shafts := read(input) &
   pfd.treadles := read(input) &
   pfd.tieup := read(input)  | fail
   pfd.liftplan := read(input)			# may be missing

   return pfd

end

procedure writepfd(output, pfd)		#: write PFD

   write(output, pfd.name)
   write(output, pfd.threading)
   write(output, pfd.treadling)
   write(output, pfd.warp_colors)
   write(output, pfd.weft_colors)
   write(output, pfd.palette)
   write(output, pfd.colors)
   write(output, pfd.shafts)
   write(output, pfd.treadles)
   write(output, pfd.tieup)
   if *\pfd.liftplan > 0 then write(pfd.liftplan) else write()

   return

end

procedure expandpfd(pfd)		#: expand PFD

   pfd := copy(pfd)

   pfd.threading := pfl2str(pfd.threading)
   pfd.treadling := pfl2str(pfd.treadling)
   pfd.warp_colors := pfl2str(pfd.warp_colors)
   pfd.weft_colors := pfl2str(pfd.weft_colors)

   pfd.warp_colors := Extend(pfd.warp_colors, *pfd.threading)
   pfd.weft_colors := Extend(pfd.weft_colors, *pfd.treadling)

   return pfd

end

#  Write include file for seqdraft

procedure write_spec(name, spec, opt, sym)	#: write weaving include file
   local n, output
   static bar

   initial bar := repl("#", 72)

   /opt := "w"

   output := open(name, opt) | fail

   write(output, "$define Reflect ", image(sym))

   #  Literals are output with image().  Other definitions are
   #  Icon experssions, enclosed in parentheses.

   write(output, "$define Comments ", image(spec.comments))
   write(output, "$define Name ", image(spec.name))
   write(output, "$define Palette ", image(spec.palette))
   write(output, "$define PDB ", image(spec.palette))
   write(output, "$define Colors (", spec.colors, ")")
   write(output, "$define WarpColors (", check(spec.warp_colors), ")")
   write(output, "$define WeftColors (", check(spec.weft_colors), ")")
   write(output, "$define Breadth (", spec.breadth, ")")
   write(output, "$define Length (", spec.length, ")")
   write(output, "$define Threading (", check(spec.threading), ")")
   write(output, "$define Treadling (", check(spec.treadling), ")")
   write(output, "$define Shafts (", spec.shafts, ")")
   write(output, "$define Treadles (", spec.treadles, ")")
   write(output, "$define Tieup ", image(spec.tieup))
   
   every n := !keylist(spec.defns) do
      write(output, "$define ", n, " ", spec.defns[n])

   write(output, bar)

   close(output)

   return

end

procedure check(s)		#: check for pattern form

   if s[1] == "[" then s := "!pfl2str(" || image(s) || ")"

   return s

end

procedure display()

   write(&errout, "name=", name)
   write(&errout, "threading=", threading)
   write(&errout, "treadling=", treadling)
   write(&errout, "warp colors=", warp_colors)
   write(&errout, "weft colors=", weft_colors)
   write(&errout, "tie up=", limage(tieup))
   write(&errout, "palette=", palette)

   return

end

procedure sympos(sym)		#: position of symbol in symbol list
   static mask

   initial mask := Mask

   return upto(sym, mask)	# may fail

end

procedure possym(i)		#: symbol in position i of symbol list
   static mask

   initial mask := Mask

   return mask[i]		# may fail

end

#  Procedure to convert a tier to a list of productions

$define Different 2

procedure tier2prodl(tier, name)
   local rows, row, count, unique, prodl, prod

   unique := table()
   rows := []
   count := 0

   every row := !tier.matrix do {
      if /unique[row] then unique[row] := (count +:= 1)
      put(rows, unique[row])
      }

   prod := name || "->"
   every prod ||:= possym(!rows + Different)

   prodl := [
      "name:" || "t-" || name,
      "comment: ex pfd2wpg "  || &dateline,
      "axiom:2",
      "gener:1",
      prod
      ]
   unique := sort(unique, 4)

   while row := get(unique) do
      put(prodl, possym(get(unique) + Different) || "->" || row)

   put(prodl, "end:")

   return prodl

end