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

Home » Public Forums » archive » Re: Extracting variables from ascii files that are not in columnar format
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: Extracting variables from ascii files that are not in columnar format [message #70382] Fri, 09 April 2010 13:31 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Apr 9, 3:51 pm, Gray <grayliketheco...@gmail.com> wrote:
> On Apr 9, 3:21 pm, nata <bernat.puigdomen...@gmail.com> wrote:
>
>
>
>
>
>> I'll try something like that
>
>> aux=''
>> OPENR, un$lun, file, /GET_LUN
>
>> WHILE ~EOF(un$lun) DO BEGIN
>
>> READF, un$lun, aux
>
>> aux_str=STRSPLIT(aux,' ',/EXTRACT)
>
>> PRINT, 'label', aux_str[0:1]
>> PRINT, 'values', aux_str[2:*]
>
>> ;; Then you can concatenate, etc...
>
>> ENDWHILE
>
>> FREE_LUN, un$lun
>
> Or, you can read everything at once with file_lines and a string
> array, then loop through the array and strsplit.  If you know that
> every line has the same format, you can use astrolib's gettok to pick
> out the header names.  Printing in columns like that is a little more
> complicated, and requires padding.  Example:
>
> n = file_lines(file)
> data = strarr(n)
> heads = strarr(n)
> openr, unit, file, /get_lin
> readf, unit, data
> close, unit & free_lun, unit
> heads = gettok(data,'=')
> print, heads, format='('+n+'A12)'
> lens = intarr(n)
> for i=0L,n-1 do lens[i] = n_elements(strsplit(data[i],/regex))
> npad = max(lens)
> padded_data = strarr(n,npad)
> for i=0L,n-1 do padded_data[i,0] = strsplit(data[i],/regex)
> print, transpose(padded_data), format='('+n+'A12)'

Oops, forgot /extract in the 2nd strsplit call. Also, you may need to
strtrim n for the format codes.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Extracting variables from ascii files that are not in columnar format
Next Topic: warp_tri vs. polywarp/poly_2d

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

Current Time: Sun Oct 12 02:03:43 PDT 2025

Total time taken to generate the page: 1.36172 seconds