These are chat archives for nightscout/intend-to-bolus
So for me, it all starts with the WinBUGS code published in "Estimating postprandial glucose fluxes using hierarchical Bayes modelling" or in the publicly viewable dissertation, "External Artificial Pancreas for Type 1 Diabetes: Modeling and Control" (search in Google). This solves for parameters based on CHO intake, including endogenous glucose production EGP0. Not all of the code is available, but all of the information needed for implementation, however it is done, is in the papers, in general. It is going to involve passing function to function to solve for things.
This is going to require open-source WinBUGS (with WBDiff, GeoBUGS, and WBDev installed as patches). All of this can be interfaced with MATLAB, via toolbox extensions, as an inline function calling WinBUGS, which will be used for the model predictive control.
This belongs in a gist/blog/whatever, like @bewest has recommended in the past, and I am doing so right now.