Debugging a Program With dbx

Fortran 90 Generic Functions

To work with Fortran 90 generic functions:


(dbx) list 1,99 
    1   MODULE cr 
    2     INTERFACE cube_root
    3       FUNCTION s_cube_root(x)
    4         REAL :: s_cube_root
    5         REAL, INTENT(IN) :: x
    6       END FUNCTION s_cube_root
    7       FUNCTION d_cube_root(x)
    8         DOUBLE PRECISION :: d_cube_root
    9         DOUBLE PRECISION, INTENT(IN) :: x
   10       END FUNCTION d_cube_root
   11     END INTERFACE
   12   END MODULE cr
   13   FUNCTION s_cube_root(x)
   14       REAL :: s_cube_root
   15       REAL, INTENT(IN) :: x
   16       s_cube_root = x ** (1.0/3.0)
   17   END FUNCTION s_cube_root
   18   FUNCTION d_cube_root(x)
   19       DOUBLE PRECISION :: d_cube_root
   20       DOUBLE PRECISION, INTENT(IN) :: x
   21       d_cube_root = x ** (1.0d0/3.0d0)
   22   END FUNCTION d_cube_root
   23   USE cr
   24     REAL :: x, cx
   25     DOUBLE PRECISION :: y, cy
   26     WRITE(*,"('Enter a SP number: ')")
   27     READ (*,*) x
   28     cx = cube_root(x)
   29     y = x
   30     cy = cube_root(y)
   31     WRITE(*,'("Single: ",F10.4, ", ", F10.4)') x, cx
   32     WRITE(*,'("Double: ",F12.6, ", ", F12.6)') y, cy
   33     WRITE(*,"('Enter a DP number: ')")
   34     READ (*,*) y
   35     cy = cube_root(y)
   36     x = y
   37     cx = cube_root(x)
   38     WRITE(*,'("Single: ",F10.4, ", ", F10.4)') x, cx
   39     WRITE(*,'("Double: ",F12.6, ", ", F12.6)') y, cy
   40     END

To use dbx with a generic function, cube root.






If asked "What is cube_root?", select one.




If asked for cube_root(8), dbx asks you to select which one.


If told to stop in cube_root, dbx asks you to select which one.





From inside s_cube_root,
show current value of x.
 (dbx) stop at 26
 (2) stop at "Generic.f90":26
 (dbx) run
 Running: Generic 
 (process id 14633)
 stopped in main at line 26 in file "Generic.f90"
    26     WRITE(*,"('Enter a SP number : ')")
 (dbx) whatis cube_root
 More than one identifier 'cube_root.'
 Select one of the following names:
  1) `Generic.f90`cube_root s_cube_root ! real*4 s_cube_root
  2) `Generic.f90`cube_root s_cube_root ! real*8 d_cube_root
 > 1
  real*4 function cube_root (x)
  (dummy argument) real*4 x
 (dbx) print cube_root(8.0)
 More than one identifier 'cube_root.'
 Select one of the following names:
  1) `Generic.f90`cube_root ! real*4 s_cube_root
  2) `Generic.f90`cube_root ! real*8 d_cube_root
 > 1
 cube_root(8) = 2.0
 (dbx) stop in cube_root
 More than one identifier 'cube_root.'
 Select one of the following names:
  1) `Generic.f90`cube_root ! real*4 s_cube_root
  2) `Generic.f90`cube_root ! real*8 d_cube_root
 > 1
 (3) stop in cube_root
 (dbx) cont
 continuing
 Enter a SP number: 
 8
 stopped in cube_root at line 16 in file "Generic.f90"
    16       s_cube_root = x ** (1.0/3.0)
 (dbx) print x
 x = 8.0