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, ...
- 06-24-2010 #1Just 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.
What is the best way to define cosd and sind? Should I use parameter?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)
- 06-25-2010 #2Just 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
- 06-25-2010 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 81
- 06-25-2010 #4Linux Engineer
- 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:
from WMS FORTRAN: what are SIND, COSD, etc? - RhinocerusCode:real function sind(x) sind=sin(x/180.0*3.141592) return end
Best wishes ... cheers, drlWelcome - 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 )
- 06-25-2010 #5Just 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:
However, now I receive the error: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)
This doesn't make sense to me because I assign REAL aet.Code:aet = -105.7*sind(al) + 596.2*sind(2*al) + 4.4*sind(3*al) - 1 Error: Unclassifiable statement at (1)
Suggestions? Thanks again!
- 06-25-2010 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
cheers, drlCode:parameter ( Re=6.37E3) sind(x) = sin(x/180.0*pi) cosd(x) = cos(x*pi/180.0) c = 2.*pi/360.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 )
- 06-28-2010 #7Just Joined!
- Join Date
- Nov 2007
- Posts
- 26
- 06-28-2010 #8Just 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.
- 06-29-2010 #9Linux Engineer
- 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:
producing: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
cheers, drlCode:% ./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.outWelcome - 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 )


Reply With Quote
