How can I use single integer arguments in CFX-5.7.1 user CEL user Fortran subroutines?
Arguments of user CEL functions are usually used to pass variable fields, but it can often be useful to use single integer arguments in CFX-5.7.1 user CEL user Fortran subroutines. There are many examples, but a common application is in a user defined function to return a component of the gradient of a variable. In this case, it may be necessary to specify which direction should be used to calculate the gradient. In the CEL the expression might look something like:
gradpx = gradphi(Pressure, 1)
In this case the pressure component in the first coordinate direction would be returned.
In the Fortran, all arguments are converted to REAL type variables. However, where a component of a variable is to be returned, this will often be used to index an array. A common pitfall is to perform the conversion using the INT intrinsic function or worse still, to index the array with a REAL variable.
The code below shows how the conversion should be done, using the NINT intrinsic function. In this case, the second CEL argument is converted.
ICOMPT = NINT(ARGS(1,2))
In these cases, NINT should be used instead of INT to avoid floating point round-off problems. If INT were used, 2.99999 would be converted to 2, but with NINT 2.99999 would be converted to 3.
In the above example ICOMPT would be declared as type INTEGER. Variables of type REAL should never be used to index an array; the result of doing so is undefined. The use of the IMPLICIT NONE statement is strongly recommended to trap any undeclared variables at compile time which might otherwise be implicitly declared as the wrong type.