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

Home » Public Forums » archive » reading format data
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 format data [message #6582 is a reply to message #6503] Thu, 11 July 1996 00:00 Go to previous messageGo to previous message
hahn is currently offline  hahn
Messages: 108
Registered: November 1993
Senior Member
Hon Yee <yeek@boulder.colorado.edu> wrote:

> in my data file there are empty lines. I read data as structures, and
> and empty line gives values of zeros. How can avoid empty lines, or
> ignore them soon i don't have returning zeros. could someone help
> out,please?. Thank in advance.

There are several way to approach a solution, depending on the size
of your data sets and the amount of disk space.

Assumption 1: Each record is delimited by LF or CR LF or some other
delimiter. Then an empty record will be made up of two delimiters.
a) You can use some stream editor to replace two adjacent delimiter
by one. However, you have to the data twice on the disk during
compression.
b) If the data in the file is printable, you read your data set record
by record into a string variable. If the string variable is not
empty you read your structure from the string.
c) If the data is binary, no conversion will be required. Thus you
cannot READ from the buffer but need to transport the data
without conversion.
Assumption 2: There are no delimiters but fixed length records.
a) You can use some stream editor to replace the fixed length
blank records by nothing. This again requires storing the data
set twice on the disk.
b) You read your data set record by record into a string variable.
if the string variable is not empty you backspace the file and read
into the structure.

Example for Assuption 1 solution b:

stru = { ....... } ; your data structure

OpenR, iunit, dsn, /get_lun ; Open input file
buffer = '*'

while not eof(iunit) do begin
readf, iunit, buffer
if StrLen ( buffer ) gt 1 then ReadS, buffer, stru
end

Example for Assumption 1 solution c:

stru = { a:0L, b:fltarr(10), c:0B, d:'####' } ; your data structure

OpenR, iunit, dsn, /get_lun ; Open input file
buffer = '*'

while not eof(iunit) do begin
readf, iunit, buffer
if StrLen ( buffer ) gt 1 then begin
bbuffer = Byte(buffer)
stru.a = long(bbuffer,0)
stru.b = float(bbuffer(4:43),0,10)
stru.c = bbuffer(44)
stru.d = string(bbuffer(45:48))
end
end

Example for Assumption 2 b)

stru = { ....... } ; your data structure

OpenR, iunit, dsn, /get_lun ; Open input file
buffer = '*'

while not eof(iunit) do begin
point_lun, -iunit, pos ; remember current file position
readf, iunit, buffer
if StrLen ( buffer ) gt 1 then begin
point_lun, iunit, pos ; goto remembered file position
ReadU, iunit, stru
endif
end


Hope, this helps

Norbert
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: cubics & quartics
Next Topic: Resampling large satellite (AVHRR) images to a grid

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

Current Time: Wed Oct 08 17:29:01 PDT 2025

Total time taken to generate the page: 0.02113 seconds