#! /usr/bin/gawk -f # Last edited on 2009-12-04 03:05:24 by stolfi # GAWK library meant to be included in other GAWk programs with "-f". # Defines some functions that are part of the WP growth model. function window_factor(tc,b,e,wb) { # Basically 1 between {b} and {e} inclusive, 0 outside; # but smoothed over a range of {± wb} days. if (tc < b - wb) { return 0; } else if (tc <= b + wb) { return sigmoid((tc - b + 0.0)/(wb + 1.0)); } else if (tc < e - wb) { return 1; } else if (tc <= e + wb) { return sigmoid((e - tc + 0.0)/(wb + 1.0)); } else { return 0; } } function sigmoid(x) { # A sigmoid function that goes from 0 to 1 as {x} goes from -1 to +1. if (x <= -1.0) { return 0; } else if (x < +1.0) { x = sin(0.5*pi*x); x = sin(0.5*pi*x); return 0.5*(x + 1); } else { return 0; } }