top_left_banner  SimCon logo


An Example of Inline Expansion

The linear interpolation routine:

REAL(kr4) FUNCTION interp1(input,bp,funtab) REAL(kr4) :: input REAL(kr4) :: bp(*) REAL(kr4) :: funtab(*) INTEGER(ki4) :: i i = 1 DO WHILE (bp(i) .lt. input) i = i+1 ENDDO interp1 = funtab(i-1)+(funtab(i)-funtab(i-1))* & (input-bp(i-1))/(bp(i)-bp(i-1)) RETURN END FUNCTION interp1

is called in a code fragment:

r = r0+alph(i1,i2,i3,cell) fr = interp1(tyrespeed,tyrevbp,tyrefrict) alph(i1,i2,i3,cell) = fr*t0

where the indices i1, i2, i3 and cell are all in a module. The compiler cannot predict whether the indices will be changed in the external routine interp and must therefore re-compute the offset of the array elemenmt in alph. FPT expands the code of interp in-line:

r = r0+alph(i1,i2,i3,cell) ! ******************************************************************** ! ! FPT fr = interp1(tyrespeed,tyrevbp,tyrefrict) ! i = 1 DO WHILE (tyrevbp(i) .lt. tyrespeed) i = i+1 ENDDO interp1_val = tyrefrict(i-1)+(tyrefrict(i)-tyrefrict(i-1))* & (tyrespeed-tyrevbp(i-1))/(tyrevbp(i)-tyrevbp(i-1)) ! FPT RETURN interp1 ! fr = interp1_val ! ! ********************************************************************* alph(i1,i2,i3,cell) = fr*t0

The formal arguments in the function have been replaced by the actual arguments in the function invocation. The overhead in invoking the function is saved, and now the compiler can keep and re-use the array offset within alph.

Note that fpt comments-out the original function invocation but leaves it in the code to indicate what has been done.

In this example, there was no variable named i' in the scope of the expanded statement, so the name of the variable i in the function was retained. Variables are renamed if name clashes occur. Declarations of variables used in the expansion are inserted in the routines which require them.

Please see EXPAND INLINE in the reference manual for a description of the fpt commands.

Copyright ©1995 to 2025 Software Validation Ltd. All rights reserved.