comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Mixed ASCII/Binary Files
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Mixed ASCII/Binary Files [message #9301] Wed, 25 June 1997 00:00 Go to next message
DALY is currently offline  DALY
Messages: 3
Registered: January 1997
Junior Member
Hi,

I'm running IDL 4.0.1 under Windows 95 and am having a heck of
a time doing anything with mixed ASCII/binary files (header/data)
files. I've tried all kinds of tricks to read the header and then
the data, but IDL's file pointer keeps getting lost. Does anybody
know of any fixes/patches? I know I can separate the header and
data with another package and then read into IDL, but that kind of defeats
the purpose of having a high-power package like IDL. Any
comments/suggestions will be greatly appreciated.

Thanks,
Chaz Daly
Re: Mixed ASCII/Binary Files [message #9434 is a reply to message #9301] Thu, 26 June 1997 00:00 Go to previous message
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
DALY wrote:
>
> Hi,
>
> I'm running IDL 4.0.1 under Windows 95 and am having a heck of
> a time doing anything with mixed ASCII/binary files (header/data)
> files. I've tried all kinds of tricks to read the header and then
> the data, but IDL's file pointer keeps getting lost. Does anybody
> know of any fixes/patches? I know I can separate the header and
> data with another package and then read into IDL, but that kind of defeats
> the purpose of having a high-power package like IDL. Any
> comments/suggestions will be greatly appreciated.

Chaz -

I'm not sure what kind of data you're trying to read, but I'll
include a code snippet from a program I have that will extract
individual 2D images out of a single file that contains a 3D array.
The file can have a header, and you can either specify the size of
the header to "skip" (and return as argument) or specify a specific
string that signifies the end of the flag. Here's the code, it may
serve as an example. Let me know if you'd be interested in the entire
program.

; Skip over header if HEADER_SIZE or HEADER_FLAG specified

if ( keyword_set( HEADER_SIZE ) ) then begin
header_array = bytarr( header_size )
readu, unit, header_array
endif else if ( keyword_set( HEADER_FLAG ) ) then begin

; Search file for flag signaling end of header

line = ''
temp = ''

while ( line ne header_flag and not eof( unit ) ) do begin
finfo = fstat( unit ) ; Get file position before read
readf, unit, line
if ( keyword_set( HEADER_ARRAY ) ) then $
temp = [ temp, line ]
endwhile

if ( keyword_set( HEADER_ARRAY ) ) then begin
header_array = temp( 1 : n_elements( temp ) - 1 )
temp = 0
endif

; Ensure that file pointer is just AFTER the header flag!
; (READF may have grabbed too many bytes)

point_lun, unit, finfo.cur_ptr + strlen( header_flag )

if ( line ne header_flag ) then begin
status = 1
message, 'Header flag ' + header_flag + $
' not found in file ' + fname, /continue
endif

Hope this helps.

Dave
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2200
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~

"I have this theory that if we're told we're bad,
then that's the only idea we'll ever have.
But maybe if we are surrounded in beauty,
someday we will become what we see." - Jewel Kilcher
Re: Mixed ASCII/Binary Files [message #9436 is a reply to message #9301] Thu, 26 June 1997 00:00 Go to previous message
DALY is currently offline  DALY
Messages: 3
Registered: January 1997
Junior Member
Hi Chaz Daly here,

I'm the originator of this thread. Thanks to all for the help...
Brian Jackel's fix worked best. Here are the specifics...

I created files using Labview 3.0.1. The files consist of
a 6 line ASCII header (the header values can be positive
or negative so the header length is variable) followed by
image data. The number of pixels being contained in the header.

I tried reading the header in in a variety of ways and then, using
FSTAT, tried to pick up reading the binary (image) data where the
header left off. Problem was that the pointer returned by FSTAT
would sometimes be way past the end of the header.

Brian told me to set my BUFSIZE = 0 on opening the file...it worked!
Again, thanks to everybody for the help...

Chaz Daly out

On Wed, 25 Jun 1997, DALY wrote:

> Hi,
>
> I'm running IDL 4.0.1 under Windows 95 and am having a heck of
> a time doing anything with mixed ASCII/binary files (header/data)
> files. I've tried all kinds of tricks to read the header and then
> the data, but IDL's file pointer keeps getting lost. Does anybody
> know of any fixes/patches? I know I can separate the header and
> data with another package and then read into IDL, but that kind of defeats
> the purpose of having a high-power package like IDL. Any
> comments/suggestions will be greatly appreciated.
>
> Thanks,
> Chaz Daly
>
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL and MPEG
Next Topic: VMS-Users! tell your problems with IDL 5.0!

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:45:29 PDT 2025

Total time taken to generate the page: 0.00592 seconds