Prev Next

OMhelp in Source Code Using One Line Comments

begin, end
Source Code Languages
newlinech
near_equal_f.f
ok_near_equal_f.f
Execute Example
Example In This Web Site

begin, end
OMhelp is designed to be embedded in computer source code. In fact, it is language independent and can be can combine source code files in multiple languages to form one documentation system. Only the text between a begin and a $end is processed by OMhelp. It is intended that these commands be comments in the language.

Source Code Languages
This example covers languages that only have one line comments; e.g., Matlab, Fortran, R. (The R language uses the $ character, this it may be necessary to change the OMhelp KeyCharacter .)

newlinech
The newlinech command is used to specify which character is used for one line comments.

near_equal_f.f
Use the editor of your choice to create the file near_equal_f.f in the xam directory with the following contents:
 
     c $begin near_equal_f$$ $newlinech c$$
     c $spell
     c $$
     c
     c $section Determine if Two Values Are Nearly Equal$$
     c
     c $head Syntax$$
     c $icode%e% = near_equal_f(%x%, %y%, %r%, %a%)%$$
     c
     c $head Purpose$$
     c Returns true,
     c if $icode x$$ is nearly equal to $icode y$$ and false otherwise.
     c
     c $head x$$
     c The argument $icode x$$ has prototype
     c $codei%
     c	double precision %x%
     c %$$
     c
     c $head y$$
     c The argument $icode y$$ has prototype
     c $codei%
     c	double precision %y%
     c %$$
     c
     c $head r$$
     c The relative error criteria $icode r$$ has prototype
     c $codei%
     c	double precision %r%
     c %$$
     c It must be greater than or equal zero.
     c The relative error condition is satisfied if
     c $latex \[
     c	| x - y | \leq r ( |x| + |y| )
     c \] $$
     c where $latex \leq$$ denotes less than or equal.
     c
     c $head a$$
     c The absolute error criteria $icode a$$ has prototype
     c $codei%
     c	double precision %a%
     c %$$
     c It must be greater than or equal zero.
     c The absolute error condition is satisfied if
     c $latex \[
     c	| x - y | \leq a
     c \] $$
     c
     c $head e$$
     c The return value $icode e$$ has prototype
     c $codei%
     c	logical %e%
     c %$$
     c If either the relative or absolute error condition is satisfied,
     c it is true.
     c Otherwise, it is false.
     c
     c
     c $head Example$$
     c The following is an example and test of $code near_equal_f$$.
     c It returns true if the test succeeds and false if it fails.
     c
     c $comment no indent, start output at text following END COPYRIGHT$$
     c $code
     c $verbatim%omh/getstarted/ok_near_equal_f.f%
     c       5%c BEGIN_OK_NEAR_EQUAL_F%c END_OK_NEAR_EQUAL_F%0
     c %$$
     c $$
     c
     c $end
     c ---------------------------------------------------------------------------
           logical function near_equal_f(x, y, r, a)
           double precision x, y, r, a
           double precision ax, ay, d
           ax = dabs(x);
           ay = dabs(y);
           ad = dabs(x - y);
           near_equal_f = (ad .le. a) .or. (ad .le. r * (ax + ay));
           end
You can also just copy near_equal_f.f from the omh/getstarted directory .

ok_near_equal_f.f
Copy omh/getstarted/ok_near_equal_f.f from the omh/getstarted Directory to the xam directory . In the copy of near_equal_f.f, change omh/getstarted/ok_near_equal_f.f to ok_near_equal_f.f.

Execute Example
Once you have copied the files mentioned above, you can execute omhelp with example_name equal to near_equal_f and example_extension equal to f.

Example In This Web Site
You can view the result of making near_equal_f.f part of the OMhelp help web site by selecting near_equal_f .
Input File: omh/getstarted/start_oneline.omh