#! /usr/bin/gawk -f # Last edited on 2011-04-14 17:53:36 by stolfilocal BEGIN { FS = "|"; file1 = ( "uns/" dh "-flow-un1.txt" ); file2 = ( "uns/" dh "-flow-un2.txt" ); file3 = ( "uns/" dh "-flow-un3.txt" ); } /[\!]/ { next; } /^[ ]*($|[\#])/ { print > file1; print > file2; print > file3; next; } (NF != 5) { err("bad format"); } // { dt = rm($1); if (dt == "") { err(("bad date \"" dt "\"")); } hr = rm($2); if (hr == "") { hr = "99:99"; } tm = htim(dt, hr); F1 = flow($3); F2 = flow($4); F3 = flow($5); printf "%s | %5s | %5.1f | %5d | DAN |\n", dt, hr, tm, F1 > file1; printf "%s | %5s | %5.1f | %5d | DAN |\n", dt, hr, tm, F2 > file2; printf "%s | %5s | %5.1f | %5d | DAN |\n", dt, hr, tm, F3 > file3; next; } END { close(file1); close(file2); close(file3); } function rm(x) { gsub(/^[ ]+/, "", x); gsub(/[ ]+$/, "", x); return x; } function flow(r) { r = rm(r); if (r == "") { return 99999; } if (r ~ /^[-+]?[0-9]*([0-9]|[.][0-9]+)$/) { return int(1000.0*r/60.0); } err(("bad number \"" r "\"")); } function htim(dt,hr, yr,dy,hf,nf,dtx) { if (hr == "99:99") { hr = "12:00"; } dtx=(dt " 00 00 00"); gsub(/[\/-]/, " ", dtx); yr=substr(dt,1,4); dy=(yr-2011)*365 + strftime("%j", mktime(dtx)); nf=split(hr,hf,":"); if (nf != 2) { err(("bad hour \"" hr "\"")); } ht=hf[1]+(1.0/60.0)*hf[2]; return 24*dy+ht - 1680; } function err(msg) { printf "** %s\n %s\n", msg, $0 > "/dev/stderr"; exit 1; }