| 查看: 1046 | 回复: 24 | |||
| 当前主题已经存档。 | |||
| 当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖 | |||
[交流]
【求助】新手求助,不知道文件中数据有多少行怎么半?
|
|||
|
新手求助!! 我要写一段程序,读取文件中的每一行数据,调用子程序进行计算,可是我并不知道这个文件有多少行,这段程序应该怎么写,请大家帮忙... program main implicit none integer i, nrow ! nrow是文件的行数 character*10 atomname open(1,file='co2.gro',status='unknown') do i=1, nrow !读取文件中的每一行数据,可是我并不知道这个nrow的具体数值. read(1,*) atomname,x(i),y(i),z(i) if (atomname .eq. 'cb') then call sub(x(i),y(i),z(i)) 请大家帮忙,另外我想读取每一行数据后,调用子程序进行运算,我想知道把文件中的每一行数值赋值给子程序sub(x,y,z),像我这样写可以吗?? |
» 猜你喜欢
299求调剂
已经有8人回复
一志愿北京理工大学本科211材料工程294求调剂
已经有6人回复
300求调剂,材料科学英一数二
已经有8人回复
招收生物学/细胞生物学调剂
已经有5人回复
070305高分子化学与物理 304分求调剂
已经有7人回复
289求调剂
已经有13人回复
一志愿哈尔滨工业大学材料与化工方向336分
已经有9人回复
081200-11408-276学硕求调剂
已经有6人回复
调剂求院校招收
已经有5人回复
调剂310
已经有8人回复

tjyl
金虫 (正式写手)
- 程序强帖: 2
- 应助: 0 (幼儿园)
- 金币: 3218.1
- 红花: 2
- 帖子: 576
- 在线: 156.6小时
- 虫号: 765184
- 注册: 2009-05-07
- 专业: 生物无机化学
- 管辖: 程序语言
★ ★
nono2009(金币+2,VIP+0):谢谢应助! 11-18 13:21
nono2009(金币+2,VIP+0):谢谢应助! 11-18 13:21
|
使用函数EOF。 eof(file_id)如果为真则说明到达文件末尾了,就不读了。 下面是编译器手册上的说明和范例: EOF Inquiry Intrinsic Function (Generic): Checks whether a file is at or beyond the end-of-file record. Syntax result = EOF (unit) unit (Input) Must be of type integer. It represents a unit specifier corresponding to an open file. It cannot be zero unless you have reconnected unit zero to a unit other than the screen or keyboard. Results The result type is default logical. The value of the result is .TRUE. if the file connected to unit is at or beyond the end-of-file record; otherwise, .FALSE.. Example ! Creates a file of random numbers, reads them back REAL x, total INTEGER count OPEN (1, FILE = 'TEST.DAT') DO I = 1, 20 CALL RANDOM_NUMBER(x) WRITE (1, '(F6.3)') x * 100.0 END DO CLOSE(1) OPEN (1, FILE = 'TEST.DAT') DO WHILE (.NOT. EOF(1)) count = count + 1 READ (1, *) value total = total + value END DO 100 IF ( count .GT. 0) THEN WRITE (*,*) 'Average is: ', total / count ELSE WRITE (*,*) 'Input file is empty ' END IF STOP END See Also ENDFILE BACKSPACE REWIND |
8楼2009-11-18 13:05:37
maomao1210
金虫 (正式写手)
- 程序强帖: 5
- 应助: 2 (幼儿园)
- 金币: 1432.8
- 散金: 242
- 红花: 16
- 沙发: 1
- 帖子: 991
- 在线: 442.1小时
- 虫号: 253215
- 注册: 2006-05-20
- 性别: MM
- 专业: 考古理论
2楼2009-11-17 16:19:06

4楼2009-11-17 17:02:53
maomao1210
金虫 (正式写手)
- 程序强帖: 5
- 应助: 2 (幼儿园)
- 金币: 1432.8
- 散金: 242
- 红花: 16
- 沙发: 1
- 帖子: 991
- 在线: 442.1小时
- 虫号: 253215
- 注册: 2006-05-20
- 性别: MM
- 专业: 考古理论
5楼2009-11-17 19:35:32














回复此楼
5