Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
3 Views

Fortran code Error explanantions

Jump to solution

Hi,

I ran the following code on Fortran. These were my results:

 

FUNCTION PKLEQ(XLO, XHI)

 

DOUBLE PRECISION A,B,C,D,E,F,H, O,P,Q,R,S,T,U,V,W,X,Y,Z

 

INTEGER I,J,K,L,M,N

 

DIMENSION XI(5), WI(6)

 

C

 

XI(1) = 0.148874338981631

 

XI(2) = 0.433395394129247

 

XI(3) = 0.679409568299024

 

XI(4) = 0.865063366688985

 

XI(5) = 0.973906528517172

 

C

 

WI(1) = 0.295524224714753

 

WI(2) = 0.269266719309996

 

WI(3) = 0.219086362515982

 

WI(4) = 0.149451349150581

 

WI(5) = 0.066671344308688

 

C

 

PKLEQ = 0.0

 

C

 

XM = (XHI + XLO) / TWO

 

XR = (XHI – XLO) / TWO

 

C

 

DO 10 I = 1 TO 5

 

C

 

DX = XR * XI(I)

 

PKLEQ = PKLEQ + WI(I) * (FUNC(XM + DX) + FUNC(XM - DX))

 

C

 

10 CONTINUE

 

C

 

PKLEQ = PKLEQ * XR

 

C

 

RETURN

 

END

 

Error Messages:

Error 1 error #5078: Unrecognized token 'XHI?' skipped C:\Users\FortranCompiler\Desktop\Cost Uncertainty Codes\PKLEQ.f 41

 

Error 2 error #5082: Syntax error, found IDENTIFIER 'TO5' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ... C:\Users\FortranCompiler\Desktop\Cost Uncertainty Codes\PKLEQ.f 45

 

Error 3 error #6385: The highest data type rank permitted is INTEGER(KIND=8). [TO5] C:\Users\FortranCompiler\Desktop\Cost Uncertainty Codes\PKLEQ.f 45

 

Error 4 Compilation Aborted (code 1) C:\Users\FortranCompiler\Desktop\Cost Uncertainty Codes\PKLEQ.f 1

 

Please let me know your thoughts on these few errors and how I could approach fixing them. Thanks!

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor II
3 Views

Could you use the code button

Jump to solution

Could you use the code button to post your code? The layout was lost completely and since you appear to be using fixed form, the layout is much more important than might otherwise be the case.

View solution in original post

0 Kudos
14 Replies
Highlighted
Valued Contributor II
4 Views

Could you use the code button

Jump to solution

Could you use the code button to post your code? The layout was lost completely and since you appear to be using fixed form, the layout is much more important than might otherwise be the case.

View solution in original post

0 Kudos
Highlighted
Beginner
3 Views

 FUNCTION PKLEQ(XLO, XHI)

Jump to solution
 FUNCTION PKLEQ(XLO, XHI)

      DOUBLE PRECISION A,B,C,D,E,F,H, O,P,Q,R,S,T,U,V,W,X,Y,Z

      INTEGER I,J,K,L,M,N

      DIMENSION XI(5), WI(6)

C

      XI(1) = 0.148874338981631

      XI(2) = 0.433395394129247

      XI(3) = 0.679409568299024

      XI(4) = 0.865063366688985

      XI(5) = 0.973906528517172

C

      WI(1) = 0.295524224714753

      WI(2) = 0.269266719309996

      WI(3) = 0.219086362515982

      WI(4) = 0.149451349150581

      WI(5) = 0.066671344308688

C

      PKLEQ = 0.0

C

      XM = (XHI + XLO) / TWO

      XR = (XHI – XLO) / TWO

C

      DO 10 I = 1 TO 5

C

      DX = XR * XI(I)

      PKLEQ = PKLEQ + WI(I) * (FUNC(XM + DX) + FUNC(XM - DX))

C

   10 CONTINUE

C

      PKLEQ = PKLEQ * XR

C

      RETURN

      END    

 

0 Kudos
Highlighted
Beginner
3 Views

Hi,

Arjen, does that work for you? I am sorry about the way I initially formatted this.

0 Kudos
Highlighted
Valued Contributor II
3 Views

Error 2 is obvious. On your

Jump to solution

Error 2 is obvious. On your DO statement you need a space between "TO" and "5" otherwise it thinks TO5 is a variable.

Les

<edit> doh! It is the end of a long day and I'm tired, and ....  That's my excuse and I am sticking to it :-)   - replace TO with a comma./<edit>

0 Kudos
Highlighted
Black Belt
3 Views

As Arjen hinted, your code,

Jump to solution

As Arjen hinted, your code, including the use of C comments, implies that you must use fixed format.  If you have changed this code to free format (not observing the requirements for column 7-73 fields) you must change the C comments to !.

I would guess that you have lost IMPLICIT prefixes from your DOUBLE PRECISION and INTEGER statements.  That style was typical of IBM360 extended Fortran 66 programming 40 to 45 years ago.

You have omitted definition of TWO; in current Fortran you might have something like

          use iso_fortran_env

          real(real64) parameter :: TWO = 2

0 Kudos
Highlighted
Valued Contributor II
3 Views

Much better, thank you :).

Jump to solution

Much better, thank you :).

The DO statement is wrong:

 DO 10 I =1,5

Fortran does not use a keyword in DO statements (or it is an extension I am not aware of)

I see nothing wrong with liine 41, but the message is about 'XHI?' - some hidden character perhaps?

 

0 Kudos
Highlighted
3 Views

You may need to replace "TO"

Jump to solution

You may need to replace "TO" with "," in your DO loop. The "TO" format may have been valid in very old FORTRAN compilers from some vendors. Note, IVF may (I do not know) support TO syntax provided you supply an appropriate option (perhaps /f66, or /vms compatibility).

Jim Dempsey

0 Kudos
Highlighted
Beginner
3 Views

Thanks for your input Arjen

Jump to solution

Thanks for your input Arjen and Jim. I noticed the incorrect phrasing of the DO line as well and I just fixed it. I will continue checking on the remaining error thanks for taking the time to answer this!

0 Kudos
Highlighted
Black Belt
3 Views

I gather that this function

Jump to solution

I gather that this function calculates the integral of FUNC(x) from XLO to XHI using the 10-point Gauss-Legendre quadrature formula, see http://dlmf.nist.gov/3.5#v .

None of the explicitly declared local variables other than I are used in the code -- what is the point of the declarations? The quadrature points and weights are given to 15 significant digits, but these will be truncated to 7 digits because the default precision is REAL, for the literals as well as the variables XI and WI. Nor are 15 digits adequate if you are using DOUBLE PRECISION using some compiler option to promote REAL to DOUBLE PRECISION.

 

0 Kudos
Highlighted
3 Views

I think the code was meant to

Jump to solution

I think the code was meant to have IMPLICIT

IMPLICIT DOUBLE PRECISION A,B,C,D,E,F,H, O,P,Q,R,S,T,U,V,W,X,Y,Z

Also, for double precision initialization, append _8 to your literals. Otherwise they are inputted into real(4) then promoted to real(8):

XI(1) = 0.148874338981631_8

Jim Dempsey

0 Kudos
Highlighted
Beginner
3 Views

Hi,

As per most of you suggestions I was able to correct most of the errors and ran the following code:

      FUNCTION PKLEQ(XLO, XHI)

      IMPLICIT DOUBLE PRECISION (A-H, O-Z)

      IMPLICIT INTEGER (I-N)

      DIMENSION XI(5), WI(6)

C

      XI(1) = 0.148874338981631

      XI(2) = 0.433395394129247

      XI(3) = 0.679409568299024

      XI(4) = 0.865063366688985

      XI(5) = 0.973906528517172

C

      WI(1) = 0.295524224714753

      WI(2) = 0.269266719309996

      WI(3) = 0.219086362515982

      WI(4) = 0.149451349150581

      WI(5) = 0.066671344308688

C

      PKLEQ = 0.0

C

      XM = (XHI + XLO) / TWO

      XR = (XHI + XLO) / TWO

C

      DO 10 I = 1, 5

C

      DX = XR * XI(I)

      PKLEQ = PKLEQ + WI(I) * (FUNC(XM + DX) + FUNC(XM - DX))

C

   10 CONTINUE

C

      PKLEQ = PKLEQ * XR

C

      RETURN

      END    

I now only have the following error message:

Error 1 error LNK2019: unresolved external symbol _FUNC referenced in function _PKLEQ PKLEQ.obj

 

Please let me know your thoughts on this error and how I could approach fixing it. Thanks!

0 Kudos
Highlighted
Black Belt
3 Views

If this function is called

Jump to solution

If this function is called with a third argument, passing a user defined EXTERNAL DOUBLE PRECISION function, that function must appear in the corresponding position in the argument list here.  In more modern Fortran, it could be defined in a MODULE.

It will still fail disastrously if you fail to define TWO.  If the code looks too obscure, simply replace / TWO by * 0.5 .

Not all past compilers made IMPLICIT DOUBLE PRECISION apply to the function name. This must match the function you supply.  If you don't apply Jim's correction, you may as well let everything go to default REAL and INTEGER.

0 Kudos
Highlighted
Black Belt
3 Views

Quote:Aravind wrote:

Jump to solution

Aravind wrote:

I now only have the following error message:

Error 1 error LNK2019: unresolved external symbol _FUNC referenced in function _PKLEQ PKLEQ.obj

Please let me know your thoughts on this error and how I could approach fixing it. Thanks!

Sometimes, it helps to step out of the programming jungle and back into the mathematical garden. Your program has the purpose of integrating a function over an interval. Can you do so without specifying the interval and the integrand? The integrand is represented by FUNC. Where is that defined?

0 Kudos
Highlighted
Valued Contributor III
3 Views

Quote:jimdempseyatthecove

Jump to solution

jimdempseyatthecove wrote:

.. Also, for double precision initialization, append _8 to your literals. Otherwise they are inputted into real(4) then promoted to real(8):

XI(1) = 0.148874338981631_8 ..

Given the use of the standard token 'DOUBLE PRECISION' from the language, it will be better if OP used D0 to append to the literal constant, instead of _8, as in

XI(1) = 0.148874338981631D0

The above will be standard Fortran consistent with DOUBLE PRECISION notation (from FORTRAN 77 days) and portable across implementations that provide standard support.  Even otherwise, it will be better for coders not to use a literal 8 (or 4) to denote kinds, for there is no guarantee these literals will always correspond to intended precision.  Instead do something along the lines of

..
   use, intrinsic :: iso_fortran_env, only : R8 => real64
..
   real(R8) :: XI(..)
..
   XI(1) = 0.148874338981631_r8
..

if modern style is desired; else stick to DOUBLE PRECISION and D0.

0 Kudos