#! /bin/bash
# Last edited on 2023-09-16 10:26:28 by stolfi

# Reads from {stdin} an ".okys" file with coordiantes of two key feature
# points for each occurrence of some glyph. Writes to {stderr} the
# length {d[i]} and direction angle {s[i]} of the segment connecting the
# two points of each occurrence, as well as the average {ave}, the
# standard deviation {dev}, and the occurrence with largest discrepancy
# {d[i]-ave}. Also plots the discrepancies {d[i]-ave} as a function of
# {a[i]}.

sg="$1"; shift

tmp="/tmp/$$"

pfile="${tmp}.dat"

cat \
  | analyze_feature_vectors.gawk \
  | sort -k2g \
  > ${pfile}
  
np=`cat ${pfile} | wc -l`

if [[ ${np} -ge 2 ]]; then
  ( plot_glyph_feature_distances.sh ${sg} ${pfile} ) < /dev/null
fi

rm -v ${pfile}
