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

Error reading NaN in list-directed I/O

kevin2
Beginner
1,717 Views
I have a customer who can successfully read NaN values under XP/Intel 11, but when transferring the program to Win7/Intel 12, gets an I/O error.
Has the compiler changed or is there a switch he should be using to get around this?

I see from a Steve Lionel reply to a similar problem back in 2006, his answer was:

Some common causes of this are:

- Reading character strings that have blanks or punctuation in them that aren't enclosed in quotes
- NaN or Inf in the input file for reals


and I see elsewhere that being able to read NaNs is a 2003 feature.

Does anyone have any experience of this?
Thanks,

Kevin
0 Kudos
8 Replies
Steven_L_Intel1
Employee
1,717 Views
I just tried an experiment reading a NaN in list-directed input and had no problems. A test case would be appreciated.
0 Kudos
TimP
Honored Contributor III
1,717 Views
Is the data file written by the same compiler major version which is trying to read it? I don't know how much portability there should be, but I'm certain the list-directed format ifort used changed some time in the past.
0 Kudos
Steven_L_Intel1
Employee
1,717 Views
I don't think the handling of NaN changed at all. We did eliminate, by default, the free conversion between logical and numeric types in list-directed and namelist input.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,716 Views
Is the NaN read a signaling NaN (SNaN) or quiet NaN (QNaN)?

I am assuming you are using an unformatted (binary) read.
If formatted then B, O or Z edit descriptors.
If you are relying on junk text to produce QNAN with other edit descriptorsthen you may have a problem.

Jim Dempsey
0 Kudos
Steven_L_Intel1
Employee
1,717 Views
Jim, the thread title says list-directed I/O. Reading the string "NaN" in list-directed I/O gives you a QNaN.
0 Kudos
kevin2
Beginner
1,717 Views
Thanks for your comments so far.
A sample line from the datafile is:

4,"Quantam",T,"09193",0.0000,0.0000,0.0000,0.0000,0.00,0.00,0.00,0.00,"Monthly",0.0000,
T,0.00,0.00,0.00,0.00,0.00,"Quarter",0.0000,F,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.0000,0.00,-0.13,0.0000,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
NaN,NaN,NaN,NaN,0.00,0.00,0.25,0.,0.,0.,NaN,0.0000,0.0000,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.00,0.00,0.00,0.00,0.00,4,"Quantam",0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.00,0.00,"20100623","Blank","Blank","Blank","20100629","12153700","JH",28111

And an extract of the code is:

Type :: Feesheet_Record
Integer :: Feesheet_Number
Character (len= 32) :: Feesheet_Name
Logical :: Feesheet_Active
Character (len= 8) :: Feesheet_Account
Real (kind= 8) :: Feesheet_Fund_cash_retained
Real (kind= 8) :: Feesheet_Fund_leveraged
Real (kind= 8) :: Feesheet_Fund_proportion
Real (kind= 8) :: Feesheet_Afee_rate
Real (kind= 8) :: Feesheet_Afee_base
Real (kind= 8) :: Feesheet_Afee_calculated
.
.
.
Type(Feesheet_Record) :: Feesheet_Data

Character (len=2048) :: Data_string
open(unit=iFile,name='Datafile.txt',status='old')
read ( unit = iFile, fmt= "(A)", iostat= iErr ) Data_string
read (Data_string, fmt= * , iostat= iErr ) Feesheet_Data


expecting the NaNs to be read into some of the REALS of the record structure.

Unfortunately, when I narrow the code down to a small program on my machine, it works OK, so I was hoping that it could be a switch-setting on the customer's project that was causing the error.
0 Kudos
Steven_L_Intel1
Employee
1,717 Views
(I'm going to insert some line breaks in that record for formatting here...)

The only one I can think of that might be an issue is /fpe0. This will cause an exception on any reference of a NaN.
0 Kudos
kevin2
Beginner
1,717 Views
I'm afraid we've already tried that switch.
Thanks for your help - I assume there must be something else going on in the program that is affecting the read. I'll keep digging.
0 Kudos
Reply