Silverfrost Forums

Welcome to our forums

The first argument (A) to intrinsic DABS must be of REAL?

14 Dec 2012 9:13 #11296

I have a line of command as follows'

DIX(I) = DABS((DIXR + DIXL)/2.0)

Compiler gives the following error message

The first argument (A) to the intrinsic DABS must be of REAL(KIND=2) type, not REAL(KIND=1)

What is the meaning of this message? Where can I afind info on FORTRAN commands from SilverFrost on DABS? I don't understand the what does it mean by first argument (A) and also the kind 1 and 2 on Real.

14 Dec 2012 11:59 #11299

The generic function is 'ABS()', whereas 'DABS' is expecting a double precision/real*8 variable. The following would work:

      REAL*8 DIXR, DIXL
      DIX(I) = DABS((DIXR + DIXL)/2.0)

Your code must be using single precision for the variable, i.e. 'REAL4' and therefore only has about 7 digits precision, REAL8 is a much better option for all your variables. The '/DREAL' compilation option can help otherwise define every real variable as REAL*8.

      IMPLICIT REAL*8 (A-H,O-Z)

as the first statement of a routine will ensure that the standard Fortran assignments of real variables uses the higher precision.

Actually, you don't need to use 'DABS()' at all these days, just use 'ABS()' for any numeric variable and the compiler will sort it out. The same really goes for other functions that at one time requred preceding by a D or an I, e.g. IABS, DCOS etc.

In your case, the first argument is everything in the brackets '(DIXR + DIXL)/2.0' as there is only one argument for this function. An argument being an input/output variable or and input value/expression.

Real kind 1 is a real number stored in 4 bytes. Real kind 2 is a real number stored in 8 bytes. Real kind 3 is a real number stored in 10 bytes for FTN95.

Ian

14 Dec 2012 4:03 #11303

Quoted from IanLambley The generic function is 'ABS()', whereas 'DABS' is expecting a double precision/real*8 variable. The following would work:

      REAL*8 DIXR, DIXL
      DIX(I) = DABS((DIXR + DIXL)/2.0)

Your code must be using single precision for the variable, i.e. 'REAL4' and therefore only has about 7 digits precision, REAL8 is a much better option for all your variables. The '/DREAL' compilation option can help otherwise define every real variable as REAL*8.

      IMPLICIT REAL*8 (A-H,O-Z)

as the first statement of a routine will ensure that the standard Fortran assignments of real variables uses the higher precision.

Actually, you don't need to use 'DABS()' at all these days, just use 'ABS()' for any numeric variable and the compiler will sort it out. The same really goes for other functions that at one time requred preceding by a D or an I, e.g. IABS, DCOS etc.

In your case, the first argument is everything in the brackets '(DIXR + DIXL)/2.0' as there is only one argument for this function. An argument being an input/output variable or and input value/expression.

Real kind 1 is a real number stored in 4 bytes. Real kind 2 is a real number stored in 8 bytes. Real kind 3 is a real number stored in 10 bytes for FTN95.

Ian

Dear Ian

Thanks a lot for your valuable information. Now I understand what is the issue.

Just one more question. In the beginning of my code, it is declared as

IMPLICIT Real*8 (A-H,O-Z)

As you have mentioned. I supposed having this declaration, it should work, but it didn't. Also I have to add that after compilation it gets error and stops in the IMPLICIT line.

Will be happy to know your opinion

14 Dec 2012 4:05 #11305

[quote='IanLambley']The generic function is 'ABS()', whereas 'DABS' is expecting a double precision/real8 variable. The following would work:[code] REAL8 DIXR, DIXL DIX(I) = DABS((DIXR + DIXL)/2.0) [/code] Your code must be using single precision for the variable, i.e. 'REAL4' and therefore only has about 7 digits precision, REAL8 is a much better option for all your variables. The '/DREAL' compilation option can help otherwise define every real variable as REAL8. [code] IMPLICIT REAL8 (A-H,O-Z) [/code] as the first statement of a routine will ensure that the standard Fortran assignments of real variables uses the higher precision.

Actually, you don't need to use 'DABS()' at all these days, just use 'ABS()' for any numeric variable and the compiler will sort it out. The same really goes for other functions that at one time requred preceding by a D or an I, e.g. IABS, DCOS etc.

In your case, the first argument is everything in the brackets '(DIXR + DIXL)/2.0' as there is only one argument for this function. An argument being an input/output variable or and input value/expression.

Real kind 1 is a real number stored in 4 bytes. Real kind 2 is a real number stored in 8 bytes. Real kind 3 is a real number stored in 10 bytes for FTN95.

Ian[/quote]

Dear Ian

Thanks a lot for your valuable information. Now I understand what is the issue.

Just one more question. In the beginning of my code, it is declared as

IMPLICIT Real*8 (A-H,O-Z)

As you have mentioned. I supposed having this declaration, it should work, but it didn't. Also I have to add that after compilation it gets error and stops in the IMPLICIT line.

Will be happy to know your opinion

14 Dec 2012 8:12 #11307

The problem is the type of the expression. If A and B are of type REAL8,and the constant 2.0 is of type REAL4, then it is possible that (A+B)/2.0 is REAL4, and indeed, (A+B)/2 might turn out to be INTEGER! (Before anyone blasts me over this, I can never remember the exact rules). However, if A and B are definitely REAL8, then (A+B)/2.0D0 (where the constant is also definitely REAL8) will evaluate to a REAL8 result.

Back in 1980 when your program was written, your REAL variables could easily have been 32 bits, 48 bits, or 60 bits long on the target computer, and if the standard length of a REAL was 48 bits or more, then single precision might have given a reasonable result. Also, it is quite possible that the compiler used was Fortran-66 and not Fortran 77, and so you had REAL and DOUBLE PRECISION and not REAL*4 or 8, and certainly none of the KIND stuff that came in the Fortran-90.

Eddie.

14 Dec 2012 9:23 #11308

Quoted from LitusSaxonicum The problem is the type of the expression. If A and B are of type REAL8,and the constant 2.0 is of type REAL4, then it is possible that (A+B)/2.0 is REAL*4, and indeed, (A+B)/2 might turn out to be INTEGER! (Before anyone blasts me over this, I can never remember the exact rules).

The rule is that a mixed precision expression like (A+B)/2.0 has the highest precision amongst the variables and constants. So if A or B are REAL8 (double precision, kind=2) then the result will be REAL8. BAsically, all REAL4 variables/constants are promoted to REAL8 before the calculation is performed.

Having said this, I tend not to use mixed mode very much, and would prefer to write the above as (A + B) / 2.0D0 or (A + B)*0.5D0 or (A+B)*0.5_wp where integer, parameter :: wp=kind(0.0d0).

14 Dec 2012 11:23 #11309

Thanks David (I said I could never remember). Certainly, if ever one assigns intermediate results to variables, you get the precision of the variable, not of the calculation ...

Not remembering the rules is a good reason to avoid mixed mode.

Eddie

21 Dec 2012 9:58 #11323

Quoted from LitusSaxonicum Thanks David (I said I could never remember). Certainly, if ever one assigns intermediate results to variables, you get the precision of the variable, not of the calculation ...

Not remembering the rules is a good reason to avoid mixed mode.

Eddie

Above problem is solved thanks for all replies. Now it gives following error message: StackOverflowException was unhandled. An unhandled exception of type 'system.StackOverflowException' occured in filename.exe.

It referes to following line in the code: IMPLICIT REAL*8(A-H,O-Z)

Do you have any idea what is problem?

21 Dec 2012 12:36 #11327

The IMPLICIT type of statement would need to be in each program segment where it is to apply. This type of statement, generally needs to be the first statement in the program segment after the 'subroutine' or 'function' statements.

Other definitions can override this and consistency is vital.

The error does not really appear to be caused by that statement as it is a run time error rather than a compilation error. It is something elsewhere in the overall program assembly. We would need to see the code. Send me a private message with your e-mail so we can communicate.

Regards Ian

21 Dec 2012 5:30 #11329

[quote='IanLambley']The IMPLICIT type of statement would need to be in each program segment where it is to apply. This type of statement, generally needs to be the first statement in the program segment after the 'subroutine' or 'function' statements.

Other definitions can override this and consistency is vital.

The error does not really appear to be caused by that statement as it is a run time error rather than a compilation error. It is something elsewhere in the overall program assembly. We would need to see the code. Send me a private message with your e-mail so we can communicate.

Regards Ian[/quote]

Dear Ian

You are correct. Visual Studio stops at this line (IMPLICIT), because it is the first line of the code just after the comments. Also it is repeated at all subroutines.

My email is: khoshravan at gmail.com

I couldn't find any button to attach the code. Shall I copy/paste it here? Or I will wait for your email add to send as attachment.

Your cooperation is highly appreciated.

21 Dec 2012 5:31 #11330

Dear Ian

I faced an error sending a pm to you. Also another error occurred while sending reply to your post. But apparently has been sent despite getting error as I can see it in the list. It is a bit strange but anyway I am waiting your reply or email.

BR Khoshravan

Please login to reply.