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

Home » Public Forums » archive » Re: Reading a set of data with string type entries
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 a set of data with string type entries [message #57077 is a reply to message #57073] Thu, 29 November 2007 23:32 Go to previous messageGo to previous message
AlbertoPaolo.Meroni is currently offline  AlbertoPaolo.Meroni
Messages: 1
Registered: November 2007
Junior Member
On 30 Nov, 08:07, izim...@gmail.com wrote:
> IDL> s = strjoin(['info', string(randomu(seed,10))], ' ')
> IDL> vals = float((strsplit(s, ' *', /regex, /extract))[1:*])
>
> For large files I sometimes read the whole thing into a bytarr and
> split on line breaks
> something like
>
> openr, lun, 'big.txt',/get_lun
> fs = fstat(lun)
> buf = bytarr(fs.size)
> readu, lun, buf
> free_lun, lun
> buf = strsplit(string(buf), string([13b,10b]),/extract) ; split on CR
> +LF

I suggest to use the following code:

; -----------------
FUNCTION ReadUnformattedAscii, FileName
COMPILE_OPT IDL2
IF ~FILE_TEST(FileName) THEN RETURN,0
; # of line
nLines = FILE_LINES(FileName)

OPENR,Lun,FileName,/Get_Lun
; Read First Line to establish # of Values inside the record
dummy = ''
READF,Lun,Dummy
POINT_LUN,Lun,0
Dummy = STRCOMPRESS(dummy)
void = STRSPLIT(dummy,Count=nFields)
nValues = NFields-1
; Define my output structure
str_out = {Text:'', $
Values: FLTARR(nValues)}
str_out = REPLICATE(str_out,nLines)
; Define Tmp Vars
TmpArr = FLTARR(nValues)
TmpStr = ''
FOR j = 0, nlines-1 DO BEGIN
READF,Lun,Dummy
dummy = STRCOMPRESS(dummy)
lText = STRPOS(dummy,' ')
rForm = '(A'+STRCOMPRESS(STRING(lText))+','+ $
STRCOMPRESS(STRING(nValues))+'F0)'
READS,dummy,TmpStr,TmpArr,FORMAT=rForm
str_out[j].Text = TmpStr
Str_out[j].Values = TmpArr
ENDFOR
FREE_Lun,Lun
RETURN,str_out
END
; ----------------------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: about widgets
Next Topic: Re: IDL 7.0 .... any new functions?

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

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

Total time taken to generate the page: 0.00996 seconds