#! /usr/bin/gawk -f # Last edited on 2015-03-03 18:35:52 by stolfilocal (abort >= 0) { exit(abort); } # Ignore blanks and comment lines /(^[ ]*([#]|$))|[!]/ \ { next; } # Remove inline comments, leading and trailing blanks: // \ { gsub(/[\#].*$/, "", $0); gsub(/^[ ]+/, "", $0); gsub(/[ ]+$/, "", $0); } /^20[01][0-9]-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) / \ { if (NF < srcIndex) { data_error("invalid field count"); } dy = $1; tm = $2; dy = usf_check_date(FILENAME,FNR,dy) if ((ody != "") && (! usf_dates_are_consecutive(ody,dy))) { data_error(("non-consecutive dates \"" ody "\" \"" dy "\"")); } if (tm != "00:00:00") { data_error(("invalid time = \"" tm "\"")); } printf "%s %s", dy, tm > bubFile; # Bubble component. printf "%s %s", dy, tm; # Remainder of price. psm = usf_check_num(FILENAME,FNR,$(srcIndex)); if (dy < dini) { # Before the next bubble, the price must be zero: if (psm != 0.0) { data_error(("price should be zero, is = \"" psm "\"")); } pbu = 0; # No bubble. } else if (dy <= dfin) { # Between {dini} and {dfin} inclusive, the bubble is the price: pbu = psm; pst = pbu; # Remember last price in bubble. dst = 0; } else { # After {dfin}, use an exponential: if (pst < 0) { data_error(("no prices in bubble")); } dst++; # One more day after {dfin}. pbu = pst * (drate == 1.0 ? 1.0 : exp(log(drate)*dst)); } printf " | %18.5f\n", pbu > bubFile; # Bubble component. prm = psm - pbu; # Price minus bubble if (prm < 0) { data_warning(("negative remainder price \"" prm "\"")); prm = 0; } printf " | %18.5f\n", prm; # Price minus bubble if (ndays == 0) { dy_first = dy; } dy_last = dy; ody = dy; ndays++; next; } // \ { data_error("invalid file list line format"); } END \ { if (abort >= 0) { exit(abort); } close(bubFile); printf "%d days found, from %s to %s\n", ndays, dy_first, dy_last > "/dev/stderr"; }