[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading file into structure?




Appending to my previous query, a quick work-around seems to be to read
the file into an array and then define data.values to point to the
array. This seems a little dirty?

i.e.

pro testread, file, data
    sgas = '*TEST'
    l = STRLEN(sgas)
    OPENR, 1, file
    header = '!'
    nlev = 0

    WHILE STRMID(header,0,1) EQ '!' DO READF, 1, header
    READS, header, nlev

    array = fltarr(nlev)
    data = {basic_struct, comment: ' ', values: fltarr(nlev)}

    WHILE STRMID(header,0,l) NE sgas DO BEGIN
      READF, 1, header
      IF STRLEN(header) LT l THEN header = header + ' '
      header = STRUPCASE(header)
    ENDWHILE
    READF, 1, array
    data.values = array          ; <-- dirty cheat
    CLOSE, 1
END


> pro testread, file, data
>     sgas = '*TEST'
>     l = STRLEN(sgas)
>     OPENR, 1, file
>     header = '!'
>     nlev = 0
> 
>     WHILE STRMID(header,0,1) EQ '!' DO READF, 1, header
>     READS, header, nlev
> 
>     ;data = fltarr(nlev)           ;change comments if testing array
>     data = {basic_struct, comment: ' ', values: fltarr(nlev)}
> 
>     WHILE STRMID(header,0,l) NE sgas DO BEGIN
>       READF, 1, header
>       IF STRLEN(header) LT l THEN header = header + ' '
>       header = STRUPCASE(header)
>     ENDWHILE
>     ;READF, 1, data                 ;<-- this works.
>     READF, 1, data.values           ;<-- why doesn't this work?
>     CLOSE, 1
> END

[snip]