Coding Standards are guidelines and recommendations for writing and maintaining source code. The purpose of standards is to improve readability and to help insure that code written by multiple authors has the same appearance. ADMB uses some rules from
The most important principles are the first 2 from Misfeldt et al
Place opening and closing braces on their own lines to avoid having to search for them. For example.
y = a;
y = b * x;
Many linux-like systems have the indent utility. The following bash script produces nice-looking code, but it is not perfect, and some additional work with an editor may be required. See.
# reformats source code to ADMB style using indent
# see http://www.gnu.org/software/indent/
# Author: John Sibert
cp -v $1 $1.bak
indent -nbad -bap -bbo -nbc -bl -blf -bli0 -bls -c33\
-cd33 -ncdb -ce -ci3 -cli0 -cp33 -cs -d0 -di1 -nfc1\
-nfca -hnl -i3 -ip0 -l75 -lp -npcs -nprs -npsl -saf\
-sai -saw -nsc -nsob -nss $1 -o indent.out
cp -v indent.out $1
Adding a new function
When you write a function involving df1b2 objects as arguments (and return type) there always needs to be a complimentary function of ordinary ADMB/autodif variable type. An example of a set of complimentary functions is:
df1b2vector sin(const df1b2vector&);
dvar_vector sin(const dvar_vector&);
When a new cpp file is added to a directory it must be listed in the “objects.lst” file in that directory in order to be compiled into the libraries.
ADMB Foundation © 2007–2023