Find the answer to your Linux question:
Results 1 to 9 of 9
I'm using Fortran g95 to compile my code and receive a 'undefined reference' error to sind and cosd. Code: real glong,glat,utsec,tau, season, cos tau, alpha, phi real pi,c,theta, Sx, Sz, ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    2

    cosd and sind

    I'm using Fortran g95 to compile my code and receive a 'undefined reference' error to sind and cosd.

    Code:
          real glong,glat,utsec,tau, season, cos tau, alpha, phi
          real pi,c,theta, Sx, Sz, Nx, Nz, hgraze,Re,al,aet
          real sind, cosd
          integer*4 day
          data alpha/.4089/                  
          data pi/3.14159265/
          data Re/6.37E3/                    
          c = 2.*pi/360.
    
          al = 278.895 + 0.985647*day
          aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) -
         % 12.7*sind(4*al) - 429.1*cosd(al) - 2.1*cosd(2*al) +
         % 19.3*cosd(3*al)
          season = 2.*pi*(day-173.21+((utsec-aet)/86400.))/365.25
          phi = c*(glong + (utsec-aet)/240.)
          theta = c*(90. - glat)
    What is the best way to define cosd and sind? Should I use parameter?

  2. #2
    Just Joined!
    Join Date
    Jun 2010
    Posts
    2

    what compiler and suggestion

    which compiler is this for (Intel, I assume)

    I have not used Fortran in many years, but recently used Intel, and I'm wondering if "cosd" and "sind" are library functions - have your checked (eg, are they "reserved" symbols)? If so, perhaps try changing the variable identifier to something like mysined and mycosd.

    After re-reading the code, I noticed the variables cosd, and sined, are not initialized. Is this important?? Different languages auto-initialize differently (some do not!)
    Last edited by evansbw; 06-25-2010 at 01:11 AM. Reason: update text

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    Quote Originally Posted by evansbw View Post
    which compiler is this for (Intel, I assume)

    I have not used Fortran in many years, but recently used Intel, and I'm wondering if "cosd" and "sind" are library functions - have your checked (eg, are they "reserved" symbols)? If so, perhaps try changing the variable identifier to something like mysined and mycosd.

    After re-reading the code, I noticed the variables cosd, and sined, are not initialized. Is this important?? Different languages auto-initialize differently (some do not!)
    Back in the olden days these functions were named dcos and dsin. Who wrote the code that you are trying to compile?

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    At a quick glance, this looks like non-standard functions for sin/cos with degree arguments.

    If so, you could Google for fortran sind cosd degree function and you will find some references, for example:
    Code:
    real function sind(x)
    sind=sin(x/180.0*3.141592)
    return
    end
    from WMS FORTRAN: what are SIND, COSD, etc? - Rhinocerus

    Best wishes ... 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 )

  5. #5
    Just Joined!
    Join Date
    Jun 2010
    Posts
    2
    Thanks for the help, all!

    Just as a note, I'm using gfortran, not g95. I'm simply modifying this code for a project. The original code was written in 1985 (I wasn't even born then).

    My new code looks like this:
    Code:
          real glong,glat,utsec,tau, season, cos tau, alpha, phi
          real pi,c,theta, Sx, Sz, Nx, Nz, hgraze,Re,al,aet,sind,cosd,x
          integer*4 day
          parameter (alpha=.4089)                  
          parameter (pi=3.14159265)
          parameter ( Re=6.37E3)                   
          c = 2.*pi/360.
          sind = sin(x/180.0*pi)
          cosd = cos(x*pi/180.0)
    
          al = 278.895 + 0.985647*day
          aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) -
         % 12.7*sind(4*al) - 429.1*cosd(al) - 2.1*cosd(2*al) +
         % 19.3*cosd(3*al)
          season = 2.*pi*(day-173.21+((utsec-aet)/86400.))/365.25
          phi = c*(glong + (utsec-aet)/240.)
          theta = c*(90. - glat)
    However, now I receive the error:
    Code:
          aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) -       
         1
    Error: Unclassifiable statement at (1)
    This doesn't make sense to me because I assign REAL aet.
    Suggestions? Thanks again!

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.
    Code:
          parameter ( Re=6.37E3)                   
          sind(x) = sin(x/180.0*pi)
          cosd(x) = cos(x*pi/180.0)
          c = 2.*pi/360.
    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 )

  7. #7
    Just Joined!
    Join Date
    Nov 2007
    Posts
    26
    Quote Originally Posted by McCoder View Post
    Thanks for the help, all!

    Just as a note, I'm using gfortran, not g95. I'm simply modifying this code for a project. The original code was written in 1985 (I wasn't even born then).

    My new code looks like this:
    Code:
          real glong,glat,utsec,tau, season, cos tau, alpha, phi
          real pi,c,theta, Sx, Sz, Nx, Nz, hgraze,Re,al,aet,sind,cosd,x
          integer*4 day
          parameter (alpha=.4089)                  
          parameter (pi=3.14159265)
          parameter ( Re=6.37E3)                   
          c = 2.*pi/360.
          sind = sin(x/180.0*pi)
          cosd = cos(x*pi/180.0)
    
          al = 278.895 + 0.985647*day
          aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) -
         % 12.7*sind(4*al) - 429.1*cosd(al) - 2.1*cosd(2*al) +
         % 19.3*cosd(3*al)
          season = 2.*pi*(day-173.21+((utsec-aet)/86400.))/365.25
          phi = c*(glong + (utsec-aet)/240.)
          theta = c*(90. - glat)
    However, now I receive the error:
    Code:
          aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) -       
         1
    Error: Unclassifiable statement at (1)
    This doesn't make sense to me because I assign REAL aet.
    Suggestions? Thanks again!
    Just a guess. Looks like the error occurs at the line break.

  8. #8
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    Good catch.

    If that doesn't fix everything, I would try not using % as the continuation marker in column 6. Maybe simple integers like 1 and 2, as has been Fortran standard since the late 1950's.

  9. #9
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    The original problem was due to the use of non-standard trig functions sind & cosd.

    The OP added statement functions to handle those. However, the syntax was wrong, and the placement was wrong (statement functions cannot appear after executable statements).

    Correcting these with the 4 lines as noted in post # 6 results in a code that can compile without syntax errors. The following script lists the environment, the source code, and results from compiling with 3 compilers:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate Fortran-77 statement function syntax, placement.
    
    # Infrastructure details, environment, commands for forum posts. 
    # Uncomment export command to run script as external user.
    # export PATH="/usr/local/bin:/usr/bin:/bin"
    set +o nounset
    pe() { for i;do printf "%s" "$i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    LC_ALL=C ; LANG=C ; export LC_ALL LANG
    pe ; pe "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
    pe "(Versions displayed with local utility \"version\")"
    c=$( ps | grep $$ | awk '{print $NF}' )
    version >/dev/null 2>&1 && s=$(_eat $0 $1) || s=""
    [ "$c" = "$s" ] && p="$s" || p="$c"
    version >/dev/null 2>&1 && version "=o" $p printf specimen gfortran g95 ifort
    set -o nounset
    pe
    
    FILE=${1-t1.f}
    
    # Display sample of data file, with head & tail as a last resort.
    pe " || start [ first:middle:last ]"
    specimen 10:0:10 $FILE \
    || { pe "(head/tail)"; head -n 5 $FILE; pe " ||"; tail -n 5 $FILE; }
    pe " || end"
    
    pl " Results, gfortran:"
    gfortran $FILE
    ls -lgG a.out
    
    pl " Results, g95:"
    g95 $FILE
    ls -lgG a.out
    
    pl " Results, ifort (Intel):"
    ifort $FILE
    ls -lgG 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 
    GNU bash 3.2.39
    printf - is a shell builtin [bash]
    specimen (local) 1.17
    gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
    G95 (GCC 4.0.3 (g95 0.92!) Jun 24 2009)
    ifort (IFORT) 11.1 20090827
    
     || start [ first:middle:last ]
    Whole: 10:0:10 of 19 lines in file "t1.f"
          real glong,glat,utsec,tau, season, cos tau, alpha, phi
          real pi,c,theta, Sx, Sz, Nx, Nz, hgraze,Re,al,aet,sind,cosd,x
          integer*4 day
          parameter (alpha=.4089)                  
          parameter (pi=3.14159265)
          parameter ( Re=6.37E3)                   
          sind(x) = sin(x/180.0*pi)
          cosd(x) = cos(x*pi/180.0)
          c = 2.*pi/360.
    
          al = 278.895 + 0.985647*day
          aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) -
         % 12.7*sind(4*al) - 429.1*cosd(al) - 2.1*cosd(2*al) +
         % 19.3*cosd(3*al)
          season = 2.*pi*(day-173.21+((utsec-aet)/86400.))/365.25
          phi = c*(glong + (utsec-aet)/240.)
          theta = c*(90. - glat)
          end
    
     || end
    
    -----
     Results, gfortran:
    -rwxr-xr-x 1 10899 Jun 29 09:45 a.out
    
    -----
     Results, g95:
    -rwxr-xr-x 1 578949 Jun 29 09:45 a.out
    
    -----
     Results, ifort (Intel):
    -rwxr-xr-x 1 723014 Jun 29 09:45 a.out
    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
  •  
...