Wrote a reply already... seems not to have turned up :(
Yes, actually that seems to work fine - it's especially useful that it
can handle mixed-type tables. I take back (some of) the bad things I
said about read_ascii! You can use this to generate the code for
copy/paste:
pro what_ascii_template
t=ascii_template()
tags=tag_names(t)
n=n_tags(t)
print,'template={$'
for i=0,n-1 do begin
if size(t.(i),/type) eq 7 then s="'"+t.(i)+"'" else
s=strtrim(t.(i),2)
s=strjoin(s,',')
if n_elements(t.(i)) gt 1 then s='['+s+']'
print,' ',tags[i],'=',s,(i lt n-1)?',$':'}'
endfor
end
IDL> what_ascii_template
template={$
VERSION=1.00000,$
DATASTART=0,$
DELIMITER=,$
MISSINGVALUE=NaN,$
COMMENTSYMBOL='#',$
FIELDCOUNT=7,$
FIELDTYPES=[4,3,4,4,3,4,4],$
FIELDNAMES=['FIELD1','FIELD2','FIELD3','FIELD4','FIELD5','FI ELD6','FIELD7'],$
FIELDLOCATIONS=[0,18,22,34,52,58,70],$
FIELDGROUPS=[0,1,2,3,4,5,6]}
Think I'm converted - thanks! Solves Rick's problem, too, since you can
modify or generate the field names yourself.
Greg
Maarten wrote:
> greg michael wrote:
>> The problem with read_ascii is the template. If your file has anything
>> other than a trivial format (as this one does) - i.e. a header of some
>> sort, or mixed types, you need to use a template. And you can't
>> (reasonably) generate this programmatically, but only via the
>> ascii_template GUI function. Try it, then you'll want to learn the
>> other way...
>
> Nah, use it once, use 'help, /structure, template' to figure out what
> the
> returned struct looks like, and then put that struct in your code.
> Works
> like a charm.
>
> There are some formats that require more coding, but read_ascii() with
> ascii_template() _once_ isn't too bad.
>
> Maarten
|