global line, bm_mo, bm_yr, bm_cnt, bm_seq, digit, it, pre_it, out_cnt, out_seq, it, pre_it, bm_cnt_mo, bm_seq_mo, bm_rec, bm_last, days_mo, eof, bms, first, once, tot_angle, ave_angle, bm_info, tot_angle_sav, rest_fd, last_mo, last_yr, bm_angle, count, tot_sz, tot_bm_sz, tot_bm_sz_sav, max_day, min_day procedure main() init() while get_next_bms() do { process_next_month() } finish() end procedure init() tot_bm_sz := 0 tot_bm_sz_sav := 0 first := 1 # &trace := -1 count := 0 bm_yr := 0 bm_mo := 0 bm_da := 0 tot_angle := 0 bm_angle := 0 tot_angle_sav := 0 last_mo := 0 last_yr := 0 min_day := 99 max_day := 0 bms := 0 digit :='1234567890' eof := 0 bm_info := open("bm_info.txt","w") rest_fd := open("rest.txt","r") days_mo := [31,28,31,30,31,30,31,31,30,31,30,31] it := "month" it2 := it || repl(" ", 12 - *it) it := "bms" it2a := it || repl(" ", 6 - *it) it := "ave angle" it3 := it || repl(" ", 16 - *it) it := "ave size" it4 := it || repl(" ", 16 - *it) write(bm_info, it2 || it2a || it3 || it4) end procedure finish() close(bm_info) close(rest_fd) end procedure process_next_month() it := bm_mo || "/" || bm_yr sz := *it it2 := it || repl(" ", 12 - sz) it := bms sz := *it it2a := it || repl(" ", 6 - sz) if (bms > 0 & \tot_angle) then ave_angle := tot_angle / bms else ave_angle := "NA" it := ave_angle sz := *it it3 := it || repl(" ", 20 - sz) if max_day > 0 then it := tot_bm_sz / (max_day - min_day) if it < 1.0 then it := "NA" sz := *it it4 := it || repl (" ", 20 - sz) it := it2 || it2a || it3 || it4 write(bm_info, it) min_day := 99 max_day := 0 # write(&errout, it) bms := 0 bm_angle := 0 last_yr := bm_yr last_mo := bm_mo tot_angle := tot_angle_sav tot_angle := 0 tot_bm_sz := tot_bm_sz_sav tot_bm_sz := 0 return 0 end procedure get_next_bms() local found while (eof = 0) do { if not (line := read(rest_fd)) then { found := 2 eof := 1 fail } count +:= 1 if count > 50000 then exit(0) if \line then if line ? ((bm_mo := tab(many(digit))) & tab(match("/")) & (bm_da := tab(many(digit))) & tab(match("/")) & (bm_yr := tab(many(digit))) & tab(many(' ')) & bm2 := tab(match(("BM")) ) & tab(many(' ,')) & (bm_angle := tab(many(digit))) & rest := tab(0)) then { # write(&errout, "bm_mo ", bm_mo, "last_mo" , last_mo, "bm_yr ", # bm_yr, "last_yr ", last_yr) if ((bm_mo = last_mo) & (bm_yr = last_yr)) | (first = 1) then { tot_angle +:= bm_angle first := 0 bms +:= 1 last_yr := bm_yr last_mo := bm_mo if bm_da < min_day then min_day := bm_da if bm_da > max_day then max_day := bm_da # write(&errout, rest) if rest ? ((one := tab(find("ff"))) & (two := tab(match("ff"))) & (three := (tab(many(" \t")))) & bm_sz_str := tab(many('XLMVS'))) then { # write(&errout, one) # write(&errout, two) # write(&errout, three) # write(&errout, bm_sz_str) bm_sz := bm_sz_fun(bm_sz_str) tot_bm_sz +:= bm_sz } next } else { tot_angle_sav := tot_angle tot_bm_sz_sav := tot_bm_sz found := 1 return 0 } } else { next } } fail end procedure bm_sz_fun(str) if find("L",str) then return(*str) else if find("M",str) then return(1) else if find("S",str) then return(1.0 / *str) end procedure no_days(mo,yr) days := days_mo[mo] if mo = 2 & ((yr % 4) = 0) then { days := 29 } return days end