#! /usr/bin/gawk -f # Last edited on 2025-05-08 22:46:04 by stolfi # Reads a table of weirdos as input. Ignores its {FRAGNUM}s and writes # it out with the fragment numbers reassigned sequentially from zero. # Lines with the same {IMGNAME}, {YPOS} and {XPOS} are assigned the same # {FRAGNUM}. The input must be sorted so that all lines with same values # in those three fields are in consecutive positions. # The file must not have any headers or comments. BEGIN { abort = -1; oimg = "?"; ox = -1; oy = -1; nfr = -1; } /[|]/ { if (NF < 14) { data_error(("bad NF")); } loc = $3; xev = $5; tex = $7; img = $9; x = $11; y = $13; rds = $15; obs = $17; for (i = 1; i <= 14; i++) { if (((i % 2) == 0) && ($(i) != "|")) { data_error(("bad format - bars")); } } obs = $0; gsub(/^.*[|] */,"", obs); gsub(/[ ]+$/,"", obs); if (obs == "") { obs = "-"; } if ((img != oimg) || (x != ox) || (y != oy)) { nfr++; oimg = img; ox = x; oy = y; } printf "w%06d | %s | %s | %s | %s | %d | %d | %s | %s\n", \ nfr, loc, xev, tex, img, x, y, rds, obs; next; } //{ data_error(("bad format - no bars")); } END { if (abort > 0) { exit(abort); } nfr++; printf "found %d distinct fragments\n", nfr > "/dev/stderr"; } function data_error(msg) { printf "** data error: %s\n", msg > "/dev/sdterr"; printf " [[%s]]\n", $0 > "/dev/sdterr"; abort = 1; exit(abort) }