Procedural Sections
In some cases, the default sorting of statements by Magnolia is not the sorting intended by the modeler. This sometimes happened with heavy use of array or matrix variables/constants. In these cases the input/out dependencies of a section of code may be explicitly specified for sorting purposes using the PROCEDURAL statement:
- The PROCEDURAL section looks somewhat like any other code section (it’s delimited by the PROCEDURAL and associated END keywords), with the exception that the PROCEDURAL keyword is followed by a parenthesized list of variable names.
- The variable names are arranged on either side of and equals sign. Variables on the left side of the equals sign are treated as outputs of the enclosed equations, for sorting purposes; variables on the right side are considered as inputs.
- The entire PROCEDURAL section is treated as a single statement, for sorting purposes, with the designated list of inputs and outputs replacing any input/output dependencies detected by Magnolia.
- PROCEDURAL sections are only necessary in DERIVATIVE section code, as that’s the only section where sorting in employed.
model ProceduralExample
derivative
dimension x
dimension integer n
constant L = 5, Pi = 3.1415927
! Compute x using first 10 terms in Fourier series for square wave,
! Wrap the sum in a procedurak so that the value of x can be
! reinitilized to zero each time the sum is computed
procedural(x = )
x = 0
for n = 1,19,2
x = x + (4/(Pi*n))*sin(Pi*n*t/L)
end
end
constant tstop = 10.0
termt(t >= tstop, 'Stopped on time limit')
end ! derivative
end ! program