Compacting WIF Arrays
Compacting WIF Arrays
Extracts and cleans structural weaving data from Weaver's Interface File (WIF) text dumps, stripping bracket syntax and formatting cruft to produce mobile-readable numerical lists and binary grids.
Input (pasted WIF section):
[TREADLING]
1=1
2=2,3
3=1
4=4
Output:
1
2,3
1
4
No brackets, no section header, no N= prefixes — just the raw sequence, one row per line, ready for mobile reading or re-pasting into pattern software.
Progress:
- Identify which section(s) the user wants:
[TREADLING],[WARP],[WEFT],[TIEUP],[THREADING], etc. - Locate the section header and extract only lines until the next
[SECTION]header or end of input - Strip the header line itself
- For each data line, remove the
key=prefix (the row/thread number before=) - Preserve comma-separated values on a line as-is (these represent multiple shafts/treadles firing together)
- If the section is
[TIEUP], convert to binary grid (see below) - Output as plain line-separated text, no markdown table unless requested
Tie-Up Binary Matrix Conversion
WIF tie-up data is stored as shaft-number lists per treadle:
[TIEUP]
1=1,3
2=2,4
This means treadle 1 lifts shafts 1 and 3; treadle 2 lifts shafts 2 and 4. Convert to a grid — determine shaft count from the highest number referenced (or ask if ambiguous), then output:
Treadle 1: 1 0 1 0
Treadle 2: 0 1 0 1
Rows = treadles, columns = shafts, in shaft-number order left to right.
Example 1: Input:
[WARP]
1=1
2=1
3=2
4=2
5=1
Output:
1
1
2
2
1
Example 2: Input:
[TIEUP]
1=1,2
2=3,4
3=1,4
4=2,3
(4 shafts detected — max value is 4)
Output:
Treadle 1: 1 1 0 0
Treadle 2: 0 0 1 1
Treadle 3: 1 0 0 1
Treadle 4: 0 1 1 0
Example 3:
Input: full multi-section WIF paste with [WARP], [WEFT], [TIEUP], and [TEXT] blocks, user asks only for TIEUP.
Output: only the binary grid for TIEUP — all other sections silently ignored.
- Always confirm shaft/treadle count from the data itself (highest number seen) rather than assuming a standard 4-shaft or 8-shaft loom, unless the WIF header (
[WEAVING]section,Shafts=/Treadles=keys) is present in the paste — use those values if available, they're authoritative. - Keep multi-value entries (
2,3) comma-separated with no space, matching common pattern-software copy/paste expectations, unless the user's mobile-reading context implies they want spaced-out values — default to compact. - If multiple sections are pasted but the user didn't specify which one, ask once, briefly, or process all and label each block clearly with its section name as a plain-text divider (no brackets).
- Treat blank lines and comment lines (starting with
;) inside a section as noise — drop them silently.
- Don't renumber or reorder rows — preserve original row order even if numbering in the source is non-sequential or has gaps.
- Don't assume shaft count defaults to 4 or 8 — infer from data or header, never guess silently on ambiguous input.
- Don't output the section header (
[TREADLING]) in the final result — it's metadata, not data. - Don't convert non-TIEUP sections into binary grids — only TIEUP represents an on/off matrix; TREADLING/WARP/WEFT are sequential lists.