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

Home » Public Forums » archive » Re: How to read data with format codes?
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: How to read data with format codes? [message #70070 is a reply to message #70069] Sat, 13 March 2010 17:19 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
The easiest way I see is not with format codes, but with read_ascii
with a template:

templ=ascii_template(file)
a=read_ascii(file,template=templ)

If you want it to be non-interactive, you can either use
ascii_template once, then save the resulting template, or generate one
yourself, as in:

template={version:1.0,datastart:0L,delimiter:byte('|'),missi ngvalue:!
values.d_nan,$
commentsymbol:'',fieldcount:[4L],fieldtypes:[0L,5L,5L,5L],$
fieldnames:['FIELD1','FIELD2','FIELD3','FIELD4'],$
fieldlocations:[0L,0L,0L,0L],fieldgroups:[0L,1L,2L,3L]}

The most relevant here being delimiter, fieldcount and fieldtype.

If you had commas instead of "|" separating the columns, none of that
would be needed, you would be able to just use read_csv.

Another way would be to read the file into a string array, then use
strsplit to separate each line at the "|":

nlines=file_lines(file)
a=strarr(nlines)
openr,unit,file,/get_lun
readf,unit,a
free_lun,unit
a=strtrim(a,2)
b=dblarr(3,nlines)
for i=0,nlines-1 do b[*,i]=strsplit(a[i],'|',/extract)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Calculate gradient
Next Topic: Re: Find out which area is covered in a map plot

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

Current Time: Sat Nov 29 03:37:14 PST 2025

Total time taken to generate the page: 0.24026 seconds