1. IDL help中的描述
The EOF function tests the specified file unit(和上一个文章中的GET_LUN相关) for the end-of-file condition.
Note: The EOF function cannot be used with files opened with the RAWIO keyword to the OPEN routines.
Many of the devices commonly used with RAWIO signal their end-of-file by returning a zero transfer count
to the I/O operation that encounters the end-of-file.
经常和WHILE
一起使用
2. Syntax
Result = EOF(Unit)
3. Example
pro GET_LUN_TEST
COMPILE_OPT idl2
; Open the file readme.txt:
txtname="C:\Users\HP\Desktop\Temporary.txt"
OPENR, LUN, txtname,/GET_LUN;LUN只是GET_LUN获得的文件单元号的名称(可以任意指定这个名称LUN或者GE),此时LUN其实是一个数
;print,LUN;打印出来LUN为104
; Define a string variable:
A = ''
; Loop until EOF is found:
WHILE ~ EOF(LUN) DO BEGIN
; Read a line of text:
READF, LUN, A;READF, [Prompt,] Unit, Var1, ..., Varn
; Print the line:
PRINT, A
ENDWHILE
; Close the file:
CLOSE, LUN;如果不CLOSE会发生什么呢?【缓存的信息可能会意外丢失。文件可能会损坏】
END
注意: HELP,A的结果如下:
21 32
A STRING = '21 32'
33 32
A STRING = '33 32'