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

Home » Public Forums » archive » Re: Combine ascii and binary format (i.e. formatted and unformatted)
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
Re: Combine ascii and binary format (i.e. formatted and unformatted) [message #19742] Fri, 14 April 2000 00:00
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Vince Hradil" <hradilv@yahoo.com> writes:

> Won't this work?
[ see below ]

I think it won't. The point was that the first number, myInteger, was
printed with formatted I/O, while the data itself was unformatted
binary.

In this situation I believe it's best to dispense with format
statements and do it the hard way. Formatted I/O leaves the file
pointer in an unpredictable position (*before* or *after* the space?),
and there's no efficiency lost when you're reading a few characters.

My suggestion:

myInteger = 0
myBlank = 0B
myArray = dblarr(sizeOfMyArray)

openr, lun, 'filename', /get_lun
readf, lun, myInteger ;; Formatted I/O
point_lun, lun, 0L ;; Rewind
repeat readu, lun, myBlank until string(myBlank) EQ ' ' ;; Skip past space
readu, lun, myArray ;; Unformatted I/O
free_lun, lun

This is the first time I have ever used "repeat" by the way.

Craig


>
> myInteger = 0
> myBlank = 0B
> myArray = dblarr(sizeOfMyArray)
>
> openr, lun, 'filename', /get_lun
> readu, lun, myInteger
> readu, lun, myBlank
> readu, lun, myArray
> close, lun
>
> "Nicolas Decoster" <Nicolas.Decoster@Noveltis.fr> wrote in message
> news:38F74DBF.AEDC4EC@Noveltis.fr...
>> Hi !
>>
>> I have (once again) a newbie question.
>>
>> I need to read files I created using C. They have the following format:
>> an ascii integer, followed by a blank space followed (with no new line)
>> by a binary array of double. In C, these files are created like that:
>>
>> fprintf(fileID, "%d ", myInteger);
>> fwrite(myArray, sizeof(double), sizeOfMyArray, fileID);
>>
>> Does someone know how I can read such files with IDL ? I tried, but I
>> can't figure how to specify the format string to read my integer, the
>> space after it and nothing else, so that I can get my array with a
>> simple readu.
>>
>> Thanks for any help.
>>
>> Nicolas.
>>
>> --
>> T�l. : 00 (33) 5 62 88 11 16
>> Fax : 00 (33) 5 62 88 11 12
>> Nicolas.Decoster@Noveltis.fr
>>
>> Noveltis
>> Parc Technologique du Canal
>> 2, avenue de l'Europe
>> 31520 Ramonville Saint Agne - France
>
>

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Combine ascii and binary format (i.e. formatted and unformatted) [message #19743 is a reply to message #19742] Fri, 14 April 2000 00:00 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Vince Hradil" <hradilv@yahoo.com> writes:

> Won't this work?
[ see below ]

I think it won't. The point was that the first number, myInteger, was
printed with formatted I/O, while the data itself was unformatted
binary.

In this situation I believe it's best to dispense with format
statements and do it the hard way. Formatted I/O leaves the file
pointer in an unpredictable position (*before* or *after* the space?),
and there's no efficiency lost when you're reading a few characters.

My suggestion:

myInteger = 0
myBlank = 0B
myArray = dblarr(sizeOfMyArray)

openr, lun, 'filename', /get_lun
readf, lun, myInteger ;; Formatted I/O
point_lun, lun, 0L
repeat readu, lun, myBlank until string(myBlank) EQ ' ' ;; Skip past space
readu, lun, myArray ;; Unformatted I/O
free_lun, lun

This is the first time I have ever used "repeat" by the way.

Craig


>
> myInteger = 0
> myBlank = 0B
> myArray = dblarr(sizeOfMyArray)
>
> openr, lun, 'filename', /get_lun
> readu, lun, myInteger
> readu, lun, myBlank
> readu, lun, myArray
> close, lun
>
> "Nicolas Decoster" <Nicolas.Decoster@Noveltis.fr> wrote in message
> news:38F74DBF.AEDC4EC@Noveltis.fr...
>> Hi !
>>
>> I have (once again) a newbie question.
>>
>> I need to read files I created using C. They have the following format:
>> an ascii integer, followed by a blank space followed (with no new line)
>> by a binary array of double. In C, these files are created like that:
>>
>> fprintf(fileID, "%d ", myInteger);
>> fwrite(myArray, sizeof(double), sizeOfMyArray, fileID);
>>
>> Does someone know how I can read such files with IDL ? I tried, but I
>> can't figure how to specify the format string to read my integer, the
>> space after it and nothing else, so that I can get my array with a
>> simple readu.
>>
>> Thanks for any help.
>>
>> Nicolas.
>>
>> --
>> T�l. : 00 (33) 5 62 88 11 16
>> Fax : 00 (33) 5 62 88 11 12
>> Nicolas.Decoster@Noveltis.fr
>>
>> Noveltis
>> Parc Technologique du Canal
>> 2, avenue de l'Europe
>> 31520 Ramonville Saint Agne - France
>
>

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Combine ascii and binary format (i.e. formatted and unformatted) [message #19757 is a reply to message #19742] Fri, 14 April 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Vince Hradil (hradilv@yahoo.com) writes:

> Won't this work?
>
> myInteger = 0
> myBlank = 0B
> myArray = dblarr(sizeOfMyArray)
>
> openr, lun, 'filename', /get_lun
> readu, lun, myInteger
> readu, lun, myBlank
> readu, lun, myArray
> close, lun

Or, more likely,

openr, lun, 'filename', /get_lun
readu, lun, myInteger, myBlank, myArray
free_lun, lun

Cheers,

David

P.S. Closing logical unit numbers that are obtained from
GET_LUN will NOT free them. However, freeing them WILL
close them, too. :-)

--
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: Combine ascii and binary format (i.e. formatted and unformatted) [message #19759 is a reply to message #19742] Fri, 14 April 2000 00:00 Go to previous message
Vince Hradil is currently offline  Vince Hradil
Messages: 574
Registered: December 1999
Senior Member
Won't this work?

myInteger = 0
myBlank = 0B
myArray = dblarr(sizeOfMyArray)

openr, lun, 'filename', /get_lun
readu, lun, myInteger
readu, lun, myBlank
readu, lun, myArray
close, lun

"Nicolas Decoster" <Nicolas.Decoster@Noveltis.fr> wrote in message
news:38F74DBF.AEDC4EC@Noveltis.fr...
> Hi !
>
> I have (once again) a newbie question.
>
> I need to read files I created using C. They have the following format:
> an ascii integer, followed by a blank space followed (with no new line)
> by a binary array of double. In C, these files are created like that:
>
> fprintf(fileID, "%d ", myInteger);
> fwrite(myArray, sizeof(double), sizeOfMyArray, fileID);
>
> Does someone know how I can read such files with IDL ? I tried, but I
> can't figure how to specify the format string to read my integer, the
> space after it and nothing else, so that I can get my array with a
> simple readu.
>
> Thanks for any help.
>
> Nicolas.
>
> --
> T�l. : 00 (33) 5 62 88 11 16
> Fax : 00 (33) 5 62 88 11 12
> Nicolas.Decoster@Noveltis.fr
>
> Noveltis
> Parc Technologique du Canal
> 2, avenue de l'Europe
> 31520 Ramonville Saint Agne - France
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: object graphics symbols
Next Topic: Re: Object graphics polygons

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

Current Time: Sat Oct 11 03:46:22 PDT 2025

Total time taken to generate the page: 0.80170 seconds