Home > Archive > Fortran > January 2006 > Input format and NaNs
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Input format and NaNs
|
|
| Bruce Bowler 2006-01-30, 7:02 pm |
| 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
bbowler@bigelow.org |
+-------------------+---------------------------------------------------+
| |
| Richard E Maine 2006-01-30, 7:02 pm |
| Bruce Bowler <bbowler@bigelow.org> wrote:
> 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.
> 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.
> 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
| |
| Herman D. Knoble 2006-01-30, 7:02 pm |
| 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
On Mon, 30 Jan 2006 11:36:29 -0500, Bruce Bowler <bbowler@bigelow.org> wrote:
-|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
| |
| meek@skyway.usask.ca 2006-01-30, 7:02 pm |
| In a previous article, Bruce Bowler <bbowler@bigelow.org> wrote:
>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
| |
|
| Herman D. Knoble wrote in message ...
>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.
>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.
|
|
|
|
|