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

Home » Public Forums » archive » Reading in a binary file in IDL - based on fortran reader?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Reading in a binary file in IDL - based on fortran reader? [message #88899 is a reply to message #88897] Wed, 02 July 2014 06:09 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 07/02/14 07:55, rjp23@le.ac.uk wrote:
> I have (quite a complicated) binary file that I need to read in.
>
> I have a fortran reader for it but would like to re-write this in IDL.
>
> I assume for most of the variables I can just use the corresponding one in IDL but how would I define a string of a specific size in IDL?
>
> The data needs to be:
>
> CHARACTER(len=16) :: description
>
> Can I just use the string format code to define a 16 character string like
>
> a=string('', format='(A16)')
>
> Or do I need to do something differently?

I use BYTARR for this.

For your example, assuming the file has already been opened
appropriately, I would do something like:

strlen = 16 ; Define the string length
a = bytarr(strlen) ; Create a temporary byte array
readu, fid, a ; Read the string into the byte array
description = string(a) ; Convert the bytes to an actual string


cheers,

paulv


p.s. Here's an example from one of my Fortran-file readers:

; Read the sensor info
sensor_id = BYTARR(SENSOR_ID_STRLEN)
wmo_satellite_id = 0L
wmo_sensor_id = 0L
sensor_channel = 0L

READU, fid, $
sensor_id , $
wmo_satellite_id, $
wmo_sensor_id , $
sensor_channel

self->Set_Property, $
Debug = debug, $
Sensor_Id = STRING(sensor_id), $
WMO_Satellite_Id = wmo_satellite_id , $
WMO_Sensor_Id = wmo_sensor_id , $
Sensor_Channel = sensor_channel


; Read the algorithm name
algorithm = BYTARR(ALGORITHM_STRLEN)

READU, fid, algorithm

self->Set_Property, $
Debug = debug, $
Algorithm = STRING(algorithm)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: band selection
Next Topic: Label dots in a Ternary plot

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

Current Time: Wed Oct 08 19:03:51 PDT 2025

Total time taken to generate the page: 0.00487 seconds