help reading fortran generated binary data...



Hi All,

First, for those not interested in the "long" story (below), here's my
basic problem...

I've read a value from binary file using the following code:

binary scan $binaryData @${offset}d1 theData (1 double-precision floating
point value)

The value *should* be any of 0, 90, 180, or 270.

What I get instead is 4 variations of an *extreme* (large or small) number,
such as:

5.4388530464437965e+185

So, is there some magic that needs to be performed on the above to extract
the value I'm actually after?

Details below...

--------------------------------------------------------------------------------------

I have a tcl program designed to read an old Fortran Unformatted Sequential
file format (as described in (much) earlier threads). Up until know, I
have only needed certain data from the file - which I have been able to
successfully retrieve. Up until now, I have just "read through" data that
I didn't care about. Now, I have a need to use a few pieces of data that I
used to just ignore. Ultimately, I'm having trouble pulling "sensible"
data from this section of the file and thought someone could give me a push
in the right direction...

Basically, I have some old FORTRAN code that is capable of reading the same
file - which I have used as a guide when writing my tcl version. In the
case of the data in question, the FORTRAN code reads the data into a common
block defined as follows:

INTEGER NUMEX2,EXTNUM
REAL*8 EXTORI,EXTX,EXTY,EXTZ
LOGICAL EXTMIR
INTEGER*2 EXTASM,EXTSUB,EXTPAR,EXTJOB
CHARACTER*1 EXTSTK(MAXSTK)
INTEGER EXTDUM(MAXSTK+12)
EQUIVALENCE(EXTORI,EXTDUM)
COMMON/NSTEXT/EXTORI,EXTX,EXTY,EXTZ,EXTMIR,EXTASM,EXTSUB,
* EXTPAR,EXTJOB,EXTNUM,EXTSTK,NUMEX2

The FORTRAN reads the data into the above common block by reading a known
number of INTEGER values into the EXTDUM array as defined above. The code
for the read is as follows:

IF (NUMEX2.GT.0)
* READ(FIL,ERR=900,END=900)(EXTDUM(I),I=1,NUMEX2)

Again, currently I am successfully "reading through" this data (which is
required so the read process doesn't get lost), but now I need to "keep"
some of it. What I'm currently after is the data stored in the EXTORI
variable above - which is defined as a REAL*8.

So, once I'm looking at the proper section of the file, it seems to me that
the following should return the proper data:

binary scan $binaryData @${offset}d1 theData

While this seems to read the proper "amount" of data (again, I know this
because if I don't account for the data, the read "gets lost" and the
process will hang), the resulting value is not sensible. The values stored
at this location in the file are angles, and are basically 0, 90, 180, or
270 (as returned by the original FORTRAN reader). The value stored my the
tcl "theData" variable above contains *huge* exponent values, both positive
and negative (depending upon the file being read). For example, I might
get the following back:

5.4388530464437965e+185

Interestingly, I only get 4 different values back (which again should
equate to 0, 90, 180, and 270), so I *think* I'm getting the correct data,
and likely just not interpreting it correctly.

So, is there some mathematical magic that needs to performed on the above
value to reveal the number I'm really after?

Thanks for any input, as I'm really stumped here...

Jeff



.



Relevant Pages

  • Re: help reading fortran generated binary data...
    ... I have a tcl program designed to read an old Fortran Unformatted Sequential file format earlier threads). ... I have some old FORTRAN code that is capable of reading the same file - which I have used as a guide when writing my tcl version. ...
    (comp.lang.tcl)
  • Re: Unformatted, big-endian files and fseek
    ... don't think it has F2003 support. ... F2003 I/O will improve the reading speed versus reading the whole ... The natural recommendation, from my biased viewpoint anyway, is Intel Visual Fortran, the successor to Compaq Visual Fortran. ...
    (comp.lang.fortran)
  • Re: When will this ng come to accept that Fortran needs to go "back to the future" ?
    ... why I asked the counter-question about C. Personally, I would guess that reading the contents of a directory in C is more portable in Fortran only to the extent that there are fewer compiler-related issues in accessing system interfaces in C than Fortran. ... struct for directory entries. ... Since not all unix file systems allow direct reading of directories, ... The C struct used for directory entries may use features that F2003 ...
    (comp.lang.fortran)
  • blank in assignment Fortran IV
    ... I am studying an ancient source written in Fortran IV (it is the ... Also I assume by reading the theoretical text, ... I always get for HX the value HINF and not what I ... someone please explain what the above assignment in Fortran IV means? ...
    (comp.lang.fortran)
  • Re: sorting command
    ... While $ is not standard in Fortran in an identifier, ... Standard Fortran also doesn't have a LOCfunction. ... with extended characters sort in proper order, ...
    (comp.lang.fortran)