Adjoint models are increasingly being developed for use in meteorology and
oceanography. Typical applications are data assimilation, model tuning, sen
sitivity analysis, and determination of singular vectors. The adjoint model
computes the gradient of a cost function with respect to control variables
. Generation of adjoint code may be seen as the special case of differentia
tion of algorithms in reverse mode, where the dependent function is a scala
r. The described method for adjoint code generation is based on a few basic
principles, which permits the establishment of simple construction rules f
or adjoint statements and complete adjoint subprograms. These rules are pre
sented and illustrated with some examples. Conflicts that occur due to loop
s and redefinition of variables are also discussed. Direct coding of the ad
joint of a more sophisticated model is extremely time consuming and subject
to errors. Hence, automatic generation of adjoint code represents a distin
ct advantage. An implementation of the method, described in this article, i
s the tangent linear and adjoint model compiler (TAMC).