Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Problem with ISNAN()

tethys_meszi
Beginner
2,223 Views
Hi,

I have a series of Fortran codes written in Solaris and I am trying to compile them in Ubuntu linux using both the 10.2 and 11 version of the Intel fortran compiler.
It goes well till it reaches this subroutine:

subroutine IS_BAD
$(VALUE,YES)

save

real*8 VALUE
integer K, id_isinf, id_isnan
logical YES

external id_isnan, id_isinf

K = id_isnan (VALUE)
if(K.eq.0) then
K = id_isinf (VALUE)
end if
YES = K.eq.1

return
end

Where the compiler fails with the error message:
/tmp/ifortsXoLgG.o: In function `is_bad_':
aaa.f:(.text+0x7): undefined reference to `id_isnan_'
aaa.f:(.text+0x12): undefined reference to `id_isinf_'

As I know id_isnan and id_isinf is not usable in Linux, so I tried to use isnan() and/or ieee_is_nan() functions instead, but every time it give me the same error message. I read that ieee_is_nan() is included in 11 version, but I am not really good at Fortran unfortunatelly, so I may be doing something very wrong. Could someone please point me into the good direction?:)

Thanks.
0 Kudos
10 Replies
TimP
Honored Contributor III
2,223 Views
If you kept the external and substituted the names of the intrinsics, you would be telling the compiler that you intend to supply your own version of those functions. The Fortran standard intrinsic version of ieee_is_nan is defined (in ifort 11.0) by USE ieee_arithmetic
Likewise, the old Intel ISNAN would be defined by USE ifport.
Ifort 11.0 documentation seems not to have caught up with ieee_arithmetic, so you would have to rely on other references, such as MR&C "Fortran 2003 explained'
0 Kudos
tethys_meszi
Beginner
2,223 Views
Thanks for the help. I tried to define ieee_is_nan() using USE ieee_arithmetic. Here is my updated code:

subroutine IS_BAD
$(VALUE,YES)

USE INTRINSIC IEEE_ARITHMETIC

real*8 VALUE
integer K
logical YES

K = ( IEEE_IS_NAN( VALUE ) )
if(K.eq.0) then
K = ( IEEE_IS_INF( VALUE ) )
end if
YES = K.eq.1

return
end

But when I compile it I get the same old error message:

is_bad.f:(.text+0x7): undefined reference to `ieee_is_nan_'
is_bad.f:(.text+0x12): undefined reference to `ieee_is_inf_'

Did I do something wrong?

0 Kudos
TimP
Honored Contributor III
2,223 Views
See Steve's reply about the syntax of your USE. The compiler should have given you better diagnostics, in my opinion. Then, don't be surprised if the compiler reports a conflict between the logical values returned by the intrinsic functions and the integer type you have given K.
0 Kudos
Steven_L_Intel1
Employee
2,223 Views
I'm astonished this compiled at all. The correct syntax would be:

USE, INTRINSIC :: IEEE_ARITHMETIC

What switches are you compiling with, and what command are you using to do the link?
0 Kudos
tethys_meszi
Beginner
2,223 Views
To tim18: I tried it without using INTRINSIC, but no success.


Quoting - Steve Lionel (Intel)
I'm astonished this compiled at all. The correct syntax would be:

USE, INTRINSIC :: IEEE_ARITHMETIC

What switches are you compiling with, and what command are you using to do the link?

I replaced this line using the correct syntax, but then new error messages came, and it aborted. This is what I got (the whole messages):


/home/meszi/program
/home/meszi/program/SYS
is_bad.f(13): error #5082: Syntax error, found '::' when expecting one of: , ;
USE, INTRINSIC :: IEEE_ARITHMETIC
--------------------^
compilation aborted for is_bad.f (code 1)
/home/meszi/program/ZOO
/home/meszi/program/PAN
/home/meszi/program/MAIN
/home/meszi/program/SYS/syslib.a(is_bad.o): In function `is_bad_':
is_bad.f:(.text+0x7): undefined reference to `ieee_is_nan_'
is_bad.f:(.text+0x12): undefined reference to `ieee_is_inf_'


Using the old syntax, the first error message disappears and just the last, the usual one remains.

This program has about 4000 different fortran files in several directories. All of them compiles well except the program I inserted earlier. This is the script I am using to compile and link everything together:


cd /home/meszi/program/SYS/
pwd
/opt/intel/Compiler/11.0/074/bin/ia32/ifort -c *.f
ar r syslib.a *.o
rm -f *.o
cd /home/meszi/program/ZOO
pwd
/opt/intel/Compiler/11.0/074/bin/ia32/ifort -c *.f
ar r zoolib.a *.o
rm -f *.o
cd /home/meszi/program/PAN
pwd
/opt/intel/Compiler/11.0/074/bin/ia32/ifort -c [a-k]*.f
ar r panlib.a *.o
rm -f *.o
/opt/intel/Compiler/11.0/074/bin/ia32/ifort -c [l-z]*.f
ar r panlib.a *.o
rm -f *.o

cd /home/meszi/program/MAIN
pwd
ar x /home/meszi/program/PAN/panlib.a program.o box.o
/opt/intel/Compiler/11.0/074/bin/ia32/ifort -o program.pro program.o box.o /home/meszi/program/PAN/panlib.a /home/meszi/program/ZOO/zoolib.a /home/meszi/program/SYS/syslib.a
rm -f program.o box.o
0 Kudos
Steven_L_Intel1
Employee
2,223 Views
Since this is a .f file, make sure the statement starts in column 7.
0 Kudos
tethys_meszi
Beginner
2,223 Views
Since this is a .f file, make sure the statement starts in column 7.

It starts in column 6 for me, where I got the error message:

is_bad.f(12): error #5082: Syntax error, found '::' when expecting one of: , ;
USE, INTRINSIC :: IEEE_ARITHMETIC
--------------------^
compilation aborted for is_bad.f (code 1)


Now if I start it in column 7, I get this:

is_bad.f(12): error #6278: This USE statement is not positioned correctly within the scoping unit.
USE, INTRINSIC :: IEEE_ARITHMETIC
------^
compilation aborted for is_bad.f (code 1)

For column 5:

is_bad.f(12): error #5149: Illegal character in statement label field
USE, INTRINSIC :: IEEE_ARITHMETIC
----^
is_bad.f(12): error #5082: Syntax error, found '::' when expecting one of: , ;
USE, INTRINSIC :: IEEE_ARITHMETIC
-------------------^
compilation aborted for is_bad.f (code 1)


0 Kudos
TimP
Honored Contributor III
2,223 Views
The compiler says you don't have the statement order correct, as if your USE follows some declarations. At least now you've got the compiler seeing it.
0 Kudos
Steven_L_Intel1
Employee
2,223 Views
Quoting - tethys_meszi

It starts in column 6 for me, where I got the error message:

is_bad.f(12): error #5082: Syntax error, found '::' when expecting one of: , ;
USE, INTRINSIC :: IEEE_ARITHMETIC
--------------------^
compilation aborted for is_bad.f (code 1)



Ok - this is a good time for me to repeat my advice to use free-form source (.f90 file type) and not fixed-form source (.f file type). With fixed-form source, columns 1-5 are for statement labels, column 6 is for the continuation indicator and columns 7-72 are the statement field. If you start your statement in colums 1-6, you'll get bizarre-looking parsing errors.

As noted, the USE statement must come before all other declarations except for IMPLICIT.
0 Kudos
tethys_meszi
Beginner
2,223 Views
I put the statement before any declarations. After that I realized that I made a mistake and put a $ sign in column 6, start the USE at column 7. When I deleted the $ sign and use a space, then I could compile the program. These 2 mistakes gave the syntax error messages.

So my problem is fixed now.

Thank you very much for the help!
0 Kudos
Reply