User-Written Subroutines
User-written subroutines, while a little more difficult to use, provide a degree of generality, efficiency and flexibility that function expressions do not. Subroutines allow you to use FORTRAN-77 features to define functions not otherwise available with Adams Solver, and to tailor Adams Solver to your needs. By linking in user-written subroutines, you don't lose any efficiency or decrease the simulation speed.
Subroutines and function expressions serve essentially the same purpose: they both allow you to define non-standard input to Adams.
Function expressions are easier to work with, because you don't have to compile or link programs. Also, they work on every machine on which Adams Solver is available. User-written subroutines, however, are much more general. The power of the programming language is available to define modeling elements or special output.
On the other hand, function expressions support a limited set of programming constructs. Therefore, complicated phenomena, especially those involving a lot of logic, cannot be easily described using function expressions.
You use user-written subroutines when:
■Dataset functions become awkward.
■You need to define functions used by a group of users.
■Statements, such as GSE and UCON, require them.
■You want to control the running of complex simulations that require decision-making logic.
Write user-written subroutines with care because incorrectly coded subroutines are very difficult to debug. Follow a crawl-walk-run approach for developing user subroutines. Start with simple versions of a user-written subroutine, make sure it works as desired, then gradually increase the complexity of the subroutine. Make sure that there are no compiler or linker warnings when your subroutine is linked into Adams.
The "C" style interface to user subroutines has been enhanced to replace some of the arguments with a pointer to a structure. This will require changes to your user subroutine source code. If you are using the fortran style interface to user subroutines you will not be effected and no changes will be required.
The new argument list to the "C" style interface replaces some of the arguments with a pointer to a structure. This structure contains the replaced arguments plus additional information. Old arguments such as ID, PAR, and NPAR have been incorperated into the structure. New arguments such as marker id's have been added to the structure.