# Copyright (C) 2023 Dennis J. Darland # This file is part of Dennis J Darland's Glucose Prediction Software. # It is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with it. If not, see . global fd_out class coefficient(file_name,elim_cnt,list_in,list_out,list_elim,ave) method init() list_in := [] fd := open(file_name,"r") while it := read(fd) do list_in := list_in ||| [real(it)] # write("*list_in = ", *list_in) # lister("list_in", list_in) end method dosort() list_out := sort(list_in) # write("*list_out = ", *list_out) # lister("list_out", list_out) end method eliminate() # write(file_name) # write("elim_cnt = ", elim_cnt) low := elim_cnt high := *list_out - elim_cnt + 1 # write("low = ", low) # write("high = ", high) list_elim := list_out[low : high] # write("*list_elim = ", *list_elim) # lister("list_elim", list_elim) end method doave() sum := 0 cnt := real(*list_elim) # write("cnt = ", cnt) while it := pop(list_elim) do sum +:= it ave := sum/cnt write(fd_out, ave) end method all() init() dosort() eliminate() doave() end end procedure lister(name,listed) i := 1 while i <= *listed do { # write(name,"[", i, "]", listed[i]) i +:= 1 } end procedure main() &dump := 0 fd_rec := open("recommended.txt","r") fd_ave := open("relate_ave.txt","w") recommended_ksteps := read(fd_rec) kstep_exponent := read(fd_rec) kstep_adj := read(fd_rec) recommended_fat := read(fd_rec) recommended_carb := read(fd_rec) recommended_prot := read(fd_rec) recommended_fiber := read(fd_rec) recommended_sugar := read(fd_rec) recommended_saturated := read(fd_rec) delta_method := read(fd_rec) kstep_method := read(fd_rec) order := read(fd_rec) factor1 := read(fd_rec) factor2 := read(fd_rec) result_file := read(fd_rec) recommended_fasted := read(fd_rec) prior_factor := read(fd_rec) fasted_factor := read(fd_rec) eliminate_extremes := read(fd_rec) if eliminate_extremes > 0 then { fd_out := open("results.txt","w") steps := coefficient("relate1_steps_out3.txt",eliminate_extremes) steps.all() fat_other := coefficient("relate2_fat_other_out3.txt",eliminate_extremes) fat_other.all() carb_other := coefficient("relate3_carb_other_out3.txt",eliminate_extremes) carb_other.all() protein := coefficient("relate4_protein_out3.txt",eliminate_extremes) protein.all() fiber := coefficient("relate5_fiber_out3.txt",eliminate_extremes) fiber.all() sugar := coefficient("relate6_sugar_out3.txt",eliminate_extremes) sugar.all() saturated := coefficient("relate7_saturated_out3.txt",eliminate_extremes) saturated.all() fasted := coefficient("relate8_fasted_out3.txt",eliminate_extremes) fasted.all() write(fd_ave, "--------------------------") write(fd_ave, "Averages Follow") write(fd_ave, "--------------------------") write(fd_ave, "First Order Coefficients") write(fd_ave, "--------------------------") write(fd_ave, "Ksteps = ", steps.ave) write(fd_ave, "fat other = ", fat_other.ave) write(fd_ave, "carb_other = ", carb_other.ave) write(fd_ave, "protein = ", protein.ave) write(fd_ave, "fiber = ", fiber.ave) write(fd_ave, "sugar = ", sugar.ave) write(fd_ave, "saturated = ", saturated.ave) write(fd_ave, "fasted = ", fasted.ave) close(fd_ave) close(fd_rec) } end