19、EOF

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'
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值