Overloaded Functions...
You call cos once with a real and once with a real*8 argument. The compiler sees what you want and calls the right routine.
This is an overloaded function (in Fortran!)
You may have used this without much thought:
+------+---------+----------+------------+-------------+
| Args | Generic | Specific | Argument | Result Type |
+------+---------+----------+------------+-------------+
| 1 | COS | COS | REAL*4 | REAL*4 |
| | | DCOS | REAL*8 | REAL*8 |
| | | QCOS | REAL*16 | REAL*16 |
| | | CCOS | COMPLEX*8 | COMPLEX*8 |
| | | CDCOS | COMPLEX*16 | COMPLEX*16 |
| | | ZCOS | COMPLEX*16 | COMPLEX*16 |
+------+---------+----------+------------+-------------+
This is the specific function called for a given type of argument
Unfortunately, this works with the few Fortran intrinsic functions only.