Re: Problems reading binary files - pointer at 4096 gives EOF [message #19470] |
Thu, 23 March 2000 00:00 |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
David Fanning wrote:
> P.S. Just for the record, on Windows machines reading
> binary data, the EOF function can cause weird file pointer
> errors. The work-around is to add the /BINARY keyword to
> the OPENR statement.
>
... and for the sake of platform independent programming, even Unixers
should
add this keyword (it doesn't hurt). And don't forget to include it if
you are opening F77_UNFORMATTED files.
Martin
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|
Re: Problems reading binary files - pointer at 4096 gives EOF [message #19473 is a reply to message #19470] |
Wed, 22 March 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
David Fanning (davidf@dfanning.com) writes:
> This is that same old file pointer bug Wayne Landsman
> alerted us to on at least two occasions now. I have
> *got* to make time to write some more articles for my
> web page. I'm forgetting more IDL these days than I
> have learned. :-(
Whoops! In digging through my old notes on this subject
I see that it was really Peter Mason who first reported
this to us about a year ago. My apologies to Peter,
along with my thanks to both Peter and Wayne for their
(apparently vain) attempt to keep us all up to date.
Cheers,
David
P.S. Just for the record, on Windows machines reading
binary data, the EOF function can cause weird file pointer
errors. The work-around is to add the /BINARY keyword to
the OPENR statement.
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Problems reading binary files - pointer at 4096 gives EOF [message #19475 is a reply to message #19473] |
Wed, 22 March 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Liam Gumley (Liam.Gumley@ssec.wisc.edu) writes:
> A simple test case worked fine for me in IDL 5.3 / Windows98:
>
> IDL Version 5.3 (Win32 x86). (c) 1999, Research Systems, Inc.
>
> IDL> openw, 1, 'zzz.dat' & writeu, 1, bytarr(16384) & close, 1
> IDL> openr, lun, 'zzz.dat', /get_lun
> IDL> point_lun, lun, 4096L
> IDL> print, eof(lun)
> 0
> IDL> info = fstat(lun)
> IDL> print, info.cur_ptr
> 4096
>
> Am I missing something?
You know what this is? It just occurred to me.
This is that same old file pointer bug Wayne Landsman
alerted us to on at least two occasions now. I have
*got* to make time to write some more articles for my
web page. I'm forgetting more IDL these days than I
have learned. :-(
Anyway, this program can be fixed by adding a BINARY
keyword to the OPENR statement when you are reading the
data.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Problems reading binary files - pointer at 4096 gives EOF [message #19476 is a reply to message #19473] |
Wed, 22 March 2000 00:00  |
Liam E. Gumley
Messages: 378 Registered: January 2000
|
Senior Member |
|
|
David Fanning <davidf@dfanning.com> wrote in message
news:MPG.1342aea03d2e7a00989aa3@news.frii.com...
> Oliver Smith (osmith@dera.gov.uk) writes:
>
>> I'm working on a program which loads data from a structured binary file.
>> Each
>> file contains many sets of different data types, each data field is
>> preceeded by a header(int) and fieldlength (long) before the data
itself.
>> In order to read the files, I use a WHILE NOT EOF(file) loop as there is
no
>> indication of the last field in the file. I've hit a major problem with
>> this, the EOF test reports end of file whenever the file pointer is at
4096.
>
> Yikes! And I find the same problem in IDL 5.1, IDL 5.2.1, and IDL 5.3.1.
> I even find it if I use FSTAT to report the file pointer position.
>
> Please let us know what you find out, Oliver.
A simple test case worked fine for me in IDL 5.3 / Windows98:
IDL Version 5.3 (Win32 x86). (c) 1999, Research Systems, Inc.
IDL> openw, 1, 'zzz.dat' & writeu, 1, bytarr(16384) & close, 1
IDL> openr, lun, 'zzz.dat', /get_lun
IDL> point_lun, lun, 4096L
IDL> print, eof(lun)
0
IDL> info = fstat(lun)
IDL> print, info.cur_ptr
4096
Am I missing something?
Cheers,
Liam.
PS: You might want to check out my binread and binwrite programs for reading
and writing binary data:
http://cimss.ssec.wisc.edu/~gumley/binarytools.html
|
|
|
Re: Problems reading binary files - pointer at 4096 gives EOF [message #19481 is a reply to message #19473] |
Wed, 22 March 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Oliver Smith (osmith@dera.gov.uk) writes:
> I'm working on a program which loads data from a structured binary file.
> Each
> file contains many sets of different data types, each data field is
> preceeded by a header(int) and fieldlength (long) before the data itself.
> In order to read the files, I use a WHILE NOT EOF(file) loop as there is no
> indication of the last field in the file. I've hit a major problem with
> this, the EOF test reports end of file whenever the file pointer is at 4096.
Yikes! And I find the same problem in IDL 5.1, IDL 5.2.1, and IDL 5.3.1.
I even find it if I use FSTAT to report the file pointer position.
Please let us know what you find out, Oliver.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|