Find the answer to your Linux question:
Results 1 to 3 of 3
Hey guys, I'm having issues using some of the Fortran 90 Numerical Recipe modules. Specifically I just wanted to try use the hello_bessel program on page 936. The code for ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    15

    Problems with Fortran 90 NR


    Hey guys,

    I'm having issues using some of the Fortran 90 Numerical Recipe modules. Specifically I just wanted to try use the hello_bessel program on page 936. The code for the program is as follows:

    Code:
          PROGRAM hello_bessel
          USE nrtype
          USE nr, ONLY: flmoon, bessj0
          IMPLICIT NONE
          INTEGER(I4B) :: n=200,nph=2,jd
          REAL(SP) :: x,frac,ans
          call flmoon(n,nph,jd,frac)
          x=jd**0.24_sp
          ans=bessj0(x)
          write(*,*) 'Hello, Bessel: ', ans
          END PROGRAM
    the nr module is very long but the flmoon and the bessj0 interfaces look like this:

    Code:
          INTERFACE
                  SUBROUTINE flmoon(n,nph,jd,frac)
                  USE nrtype
                  INTEGER(I4B), INTENT(IN) :: n,nph
                  INTEGER(I4B), INTENT(OUT) :: jd
                  REAL(SP), INTENT(OUT) :: frac
                  END SUBROUTINE flmoon
          END INTERFACE
    Code:
         INTERFACE bessj0
                  FUNCTION bessj0_s(x)
                  USE nrtype
                  REAL(SP), INTENT(IN) :: x
                  REAL(SP) :: bessj0_s
                  END FUNCTION bessj0_s
    !BL
                  FUNCTION bessj0_v(x)
                  USE nrtype
                  REAL(SP), DIMENSION(:), INTENT(IN) :: x
                  REAL(SP), DIMENSION(size(x)) :: bessj0_v
                  END FUNCTION bessj0_v
          END INTERFACE
    When I try and compile I've tried a number of different commands but I'm pretty sure the right way to do it would be to do:

    Code:
    ifort nrtype.f90 nr.f90 hello_bessel.f90
    But whenever I do that I get:

    Code:
    /tmp/ifortzYtJmW.o(.text+0x2f): In function `MAIN__':
    : undefined reference to `flmoon_'
    /tmp/ifortzYtJmW.o(.text+0x54): In function `MAIN__':
    : undefined reference to `bessj0_s_'

    Any suggestions on where I'm going wrong?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,533
    I'm not familiar with ifort - is that an Intel compiler? Usually I and my physicist wife use the gnu f77 compiler. Have you tried that?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi.

    I created stub routines for flmoon, and bessj0_[sv] based on the interfaces. Here is a driver script that shows the high points:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate compile with ifort, link, stub, execute.
    
    # Utility functions: print-as-echo, print-line-with-visual-space, debug.
    # export PATH="/usr/local/bin:/usr/bin:/bin"
    pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
    db() { : ; }
    C=$HOME/bin/context && [ -f $C ] && $C
    version ifort
    
    rm -f *.o *.mod a.out
    pl " Source files present:"
    ls *.f90
    
    pl " Sample stub, flmoon.f90:"
    cat flmoon.f90
    
    pl " Compile, link:"
    ifort nrtype.f90 nr.f90 hello_bessel.f90 bessj0_s.f90 bessj0_v.f90 flmoon.f90
    
    pl " Results:"
    ./a.out
    
    # Cleanup.
    rm -f *.o *.mod a.out
    
    exit 0
    producing:
    Code:
    % ./s1
    
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
    GNU bash 3.2.39
    ifort (IFORT) 11.1 20090827
    
    -----
     Source files present:
    bessj0_s.f90  bessj0_v.f90  flmoon.f90	hello_bessel.f90  nr.f90  nrtype.f90
    
    -----
     Sample stub, flmoon.f90:
    
    	  SUBROUTINE flmoon(n,nph,jd,frac)
    	  USE nrtype
    	  INTEGER(I4B), INTENT(IN) :: n,nph
    	  INTEGER(I4B), INTENT(OUT) :: jd
    	  REAL(SP), INTENT(OUT) :: frac
    	  jd =0
    	  frac = 0.0
    	  END SUBROUTINE flmoon
    
    
    -----
     Compile, link:
    
    -----
     Results:
     Hello, Bessel:   0.000000000000000E+000
    So if your results are missing routines, how is my procedure different from yours? Perhaps that mine included the compile of flmoon, etc? ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •