Re: Need more than 32767 characters! [message #16555] |
Mon, 02 August 1999 00:00 |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Robert King wrote:
> I'm adding a file viewer to one of my programs, it reads an ASCII text file
> and displays the whole thing to a text widget.
>
> I'm using something like:
>
> _____________________
>
> line=''
> txt='File contents:' +STRING([13B,10B])
> WHILE NOT EOF(lun) DO BEGIN
> ReadF, lun, line
> txt = txt + line + STRING([13B,10B])
> ENDWHILE
> Widget_Control, mytext_id, SET_VALUE=txt
>
> _____________________
>
> The problem is that the file is longer than 32,767 characters (about 32
> times larger..). Is there a way of showing the whole file (other than using
> 32 different text widgets) ?
You need to read the file into a string array, rather than a string
variable, e.g.
;---cut here---
FUNCTION READTEXT, FILE
; Read a text file into a string array
; Usage: RESULT = READTEXT(FILE)
;- Open the file
openr, lun, file, /get_lun
;- Create string variables
maxlines = 100000L
data = strarr(maxlines)
line = ' '
nlines = 0
;- Read the file until EOF
while not eof(lun) do begin
readf, lun, line
data[nlines] = line
nlines = nlines + 1
endwhile
;- Truncate the string array
data = data[0 : (nlines - 1) > 0]
;- Close the file and return the result
free_lun, lun
return, data
END
;---cut here---
Or you could use XDISPLAYFILE, e.g.
xdisplayfile, file
Cheers,
Liam.
--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
|
|
|