Input format and NaNs 
Author Message
 Input format and NaNs

I have a datafile that I'm trying to read that has NaNs in it, on
occasion, where the result of a calculation in another language was a NaN.
Where there aren't NaNs there are floating point numbers.

Is there a format specifier I can use that won't puke on NaN in the input
stream, or do I have to read things into a string, check for NaN and then
using an internal read if there isn't a NaN or preprocess the file with
something else to replace the NaNs with a "known bad value" that fortran
can read on it's own?

Using Salford f95 compiler, if it makes a difference.

TIA,
Bruce

--
+-------------------+---------------------------------------------------+
Bruce Bowler        | A person is never happy except at the price of some
1.207.633.9600      | ignorance.  - Anatole France  

+-------------------+---------------------------------------------------+



Sat, 19 Jul 2008 00:36:29 GMT  
 Input format and NaNs

Quote:

> I have a datafile that I'm trying to read that has NaNs in it...
...
> Is there a format specifier I can use that won't puke on NaN in the input
> stream,

First a wordng quibble. If you are talking about formats, then you don't
have a file with NaN's in it. A NaN is an internal form in a real
variable. You can have an unformatted file with NaNs in it, but a
formatted file has nothing but characters. Presumably your formatted
file has characters like "NaN". But on to the real answer instead of the
qording quibble.

Quote:
> or do I have to read things into a string, check for NaN and then
> using an internal read if there isn't a NaN or preprocess the file with
> something else to replace the NaNs with a "known bad value" that FORTRAN
> can read on it's own?

In standard<=f95, I'm afraid those are your options. The first time that
anything directly relating to NaNs was introduced to the Fortran
standard was the IEEE TR to f95. Your f95 compiler might or might not
support that TR. But even if your compiler does support the TR, that
doesn't address formatted I/O of NaNs. F2003 added stuff for such
formatted I/O. With f2003, the "normal" edit descriptors handle NaNs.

Short of f2003, and NaN-related I/O is compiler-dependent.

Quote:
> Using Salford f95 compiler, if it makes a difference.

And I'm afraid I don't know what possible compiler-dependent features
that particular compiler might have.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Sat, 19 Jul 2008 01:22:59 GMT  
 Input format and NaNs
First, I'd recommend trying to talk to the folks where this data
(and program?) originated, and find out if they knew that some
of the output file were NaN's and whether that makes sense with
the program(s) being used to process this data. Assuming that
NaN is "valid" output data...

If what you're saying is that the actual characters, "NaN" appear in
an ASCII input file, and you want them to take on a NaN value,
then you may be able to use a text editor to change that
three character string to a real value that would not normally occurr
in the input. For example if 777 or -99 would not occur, you could
change "NaN" to "777" or to "-99", and then after the data
was input change these special values to a NaN. For example, if these are
single precision reals set them to XXX where XXX has been initialized to
a NaN like B'1111111100000100000000000000000'

In this very crude way you'd end up some data values being NaN as
they were on the previous platform - which may or may not make
sense to the original algorithm.

Skip Knoble

-|I have a datafile that I'm trying to read that has NaNs in it, on
-|occasion, where the result of a calculation in another language was a NaN.
-|Where there aren't NaNs there are floating point numbers.
-|
-|Is there a format specifier I can use that won't puke on NaN in the input
-|stream, or do I have to read things into a string, check for NaN and then
-|using an internal read if there isn't a NaN or preprocess the file with
-|something else to replace the NaNs with a "known bad value" that FORTRAN
-|can read on it's own?
-|
-|Using Salford f95 compiler, if it makes a difference.
-|
-|TIA,
-|Bruce



Sat, 19 Jul 2008 02:31:37 GMT  
 Input format and NaNs

Quote:
>I have a datafile that I'm trying to read that has NaNs in it, on
>occasion, where the result of a calculation in another language was a NaN.
>Where there aren't NaNs there are floating point numbers.

>Is there a format specifier I can use that won't puke on NaN in the input
>stream, or do I have to read things into a string, check for NaN and then
>using an internal read if there isn't a NaN or preprocess the file with
>something else to replace the NaNs with a "known bad value" that FORTRAN
>can read on it's own?

>Using Salford f95 compiler, if it makes a difference.

>TIA,
>Bruce

Yes  - I had that problem when using ncdump.exe to write
contents of a netcdf file in ascii -
  (An earlier version of ncdump.exe - with no distinguishing
features except smaller size! gave extra unsolicited numbers!!
Beware of netcdf !)

  I assumed that NaN stood for gap, and edited it accordingly
in the DOS editor.

Chris



Sat, 19 Jul 2008 03:20:59 GMT  
 Input format and NaNs

Quote:

>First, I'd recommend trying to talk to the folks where this data
>(and program?) originated, and find out if they knew that some
>of the output file were NaN's and whether that makes sense with
>the program(s) being used to process this data. Assuming that
>NaN is "valid" output data...

>If what you're saying is that the actual characters, "NaN" appear in
>an ASCII input file, and you want them to take on a NaN value,
>then you may be able to use a text editor to change that
>three character string to a real value that would not normally occurr
>in the input. For example if 777 or -99 would not occur, you could
>change "NaN" to "777" or to "-99", and then after the data
>was input change these special values to a NaN. For example, if these are
>single precision reals set them to XXX where XXX has been initialized to
>a NaN like B'1111111100000100000000000000000'

If the executable doesn't handle NaNs, there's no point in doing that.
Using an editor, the NaN can be replaced by any valid value,
such as 10**(-30) or 0 or whatever is appropriate.
Or you can read in the whole line in your fortran program and
re-process it to handle the NaNs, again, in whatever
way you want.

- Show quoted text -

Quote:
>In this very crude way you'd end up some data values being NaN as
>they were on the previous platform - which may or may not make
>sense to the original algorithm.



Sat, 19 Jul 2008 10:21:16 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Formatted Input in APL

2. Smoother input formats for long J program sets

3. Awk Problem: Changing Input Data Format

4. Using different input formats

5. Changing input field picture format at runtime?

6. Formatted input field

7. Input test vectors formats

8. FAQ *formatting* input

9. user-specified delimiters for formatted input

10. FORMATTED INPUT

11. List directed input/Formatted READ statement

12. Formatted input using READ (UNIT=1,FMT=something) in F77

 

 
Powered by phpBB® Forum Software