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

Home » Public Forums » archive » Read ASCII
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: read ascii [message #63626 is a reply to message #10591] Mon, 17 November 2008 04:32 Go to previous messageGo to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
julia.walterspiel@gmail.com schrieb:
> hi
>
> i've been fiddling about this problem the whole morning and it seems I
> can't get it done properly:
>
> I'm trying to read in a huge (!) ascii-file ('test.dat') where the
> first column is a string (name of station), followed by 2 columns with
> integer values (second row date in the format yymmddhourminute, third
> row integer numbers between 0 and 10).
>
> example 'test.dat':
> SMA 200001010010 0
> SMA 200001010020 0
> SMA 200001010030 1
> SMA 200001010040 0
> SMA 200001010050 3
> SMA 200001010100 4
> SMA 200001010110 5
> SMA 200001010120 0
> SMA 200001010130 0
> SMA 200001010140 0
>
> no header.
>
> I don't know how many rows I got, but I'm sure it's a LOT, since excel
> crashes when trying to copy the file :)
>
> I'm using David's Code like this:
>
> OPENR, lun, '/filepath/test.dat', / GET_LUN
>
> station = strarr (1000000)
> time = fltarr (1000000)
> sunshine_duration = fltarr(1000000)
>
> s = '???' --> not sure what to insert here
> t = 0.0
> sd = 0.0
> count = 0
>
> WHILE (NOT EOF(lun)) DO BEGIN
> READF, lun, s, t, sd
> station(count) = s
> time (count) = t
> sunshine_duration(count) = sd
> count = count+1
> ENDWHILE
>
> station = station(0:count-1)
> time = time(0:count-1)
> sunshine_duration = sunshine_duration(0:count-1)
>
> FREE_LUN, lun
>
> then I get the error
> "READF: Input conversion error. Unit: 101"
> I tried to google this error but couldnt find any useful
> information...
>
> I figure, I don't understand 100% what I'm doing here, that's why I
> don't see where I make the mistake...
> furthermore, I'm not sure how the file is delimited (tab or white
> space) if this is crucial to anything..?
>
> any help appreciated!
> cheers,
> juls

hi

you can read the file once as byte data file and then do a conversion to
the types you want for each column. That tool can be brought to
perfection if you involve pointers ;)

cheers
Reimar

e.g.

file = 'test.dat'
lines = file_lines(file)
struct = replicate(create_struct('var1', bytarr(5),$
'var2', bytarr(13),$
'var3', bytarr(11)), lines)
openu,lun,file,/get_lun
readu,lun,struct
free_lun,lun

; example usage of the data
print, strtrim(struct.var1, 2)
print, long64(strtrim(struct.var2, 2))
print, long(strtrim(struct.var3, 2))

; or
result = create_struct('var1', strtrim(struct.var1, 2),$
'var2', long64(strtrim(struct.var2, 2)),$
'var3', long(strtrim(struct.var3, 2)))

print, result.var1

end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: idl for solaris
Next Topic: IDL and sqlite

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

Current Time: Fri Oct 10 05:39:18 PDT 2025

Total time taken to generate the page: 0.47892 seconds