#! /usr/bin/gawk -f # Last edited on 2009-12-11 15:18:04 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; } } function data_error(msg, lin) { # Assumes original input line was saved in {lin}. printf "%s:%d: ** data error - %s\n", FILENAME, FNR, msg > "/dev/stderr"; printf " line = «%s»\n", lin > "/dev/stderr"; abort = 1; exit 1; } function data_warning(msg, lin) { # Assumes original input line was saved in {lin}. printf "%s:%d: !! data warning - %s\n", FILENAME, FNR, msg > "/dev/stderr"; printf " line = «%s»\n", lin > "/dev/stderr"; }