In cases where it’s necessary to interpolate a continuous value from a list of tabulated x/y values, Magnolia provides the TABLE statement:

• The TABLE statement allows tabular 1, 2, or 3-dimensional data to be linearly interpolated based on a supplied value of an independent variable (or variables).  The tabular independent and dependent data lists are supplied using array or matrix CONSTANTs.
• The TABLE statement essentially gives a name to the table for subsequent lookups, and assigned two or more CONSTANT arrays to the table name.
• Lookups (interpolations) of table values are performed by using the TABLE name as if it were a function call, supplying any required independent values as arguments.
• The CONSTANT arrays can be treated as any other constant values in CSL; that is, their values may be adjusted prior to runtime without need for recompilation of the model code.


model TableExample

derivative

! The data which is to be interpolated via a TABLE statement
! is defined in 2 or more arrays

! Dimension the arrays
dimension ageData[10], bwData[10]

! Populate the arrays with data
constant ageData = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
constant bwData  = 0.1, 0.13, 0.17, 2, 3, 5, 8, 11, 15, 20

! Define the table.  First arg after the equal sign is the ind var data
table BodyWeightForAge = ageData, bwData

! This is where table lookups (interpolation) is done
bw = BodyWeightForAge(t)

constant tstop = 10.0
termt(t >= tstop, 'Stopped on time limit')

end ! derivative

end ! program