- 积分
- 70
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-11-28
- 最后登录
- 1970-1-1
|
GrADS
系统平台: |
|
问题截图: |
|
问题概况: |
fortran读取txt资料时不能正常读取文件,将txt资料文件最后的空格删去,可以正常运行。 |
我看过提问的智慧: |
看过 |
自己思考时长(天): |
5 |
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
部分程序如下:
open(unit=fileid1,file=filename,access="sequential", status="old")
do while(.true.)
read(unit=fileid1,fmt="(A79)",iostat=stat) buffer
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!对txt文本中的内容进行处理,读取资料
open(unit=fileid2,file=buffer,access="sequential",status="old")
NLINE=0
DO WHILE(.NOT.EOF(fileid2))
NLINE=NLINE+1
IF(NLINE.LT.4)THEN
READ(fileid2,*,end=100)
CYCLE
ENDIF
! write(*,*) nline !检查循环的次数,循环从4开始
!读取站号
READ(fileid2,*,end=100)ZH
!读取气压,温度,相对湿度,integrated precipitable water vapor
READ(fileid2,*,end=100)TEMP,PE
!输出
PRINT*,ZH
PRINT*,PE
WRITE(fileid3)ZH
WRITE(fileid3)PE
END DO
close(fileid2)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(stat/=0) exit ! 没有数据就跳出循环
write(*,"(A79)") buffer
END DO
100 continue
在使用end=100时,在读取有资料的txt文本是失败。
使用err=100时,错误end-of-file。
以下是数据资料:
GNSS observation,Chinese Academy of Meteorological Sciences,version 1.0
5,total zenith delay(m),pressure(hPa),temperature(degree),raelative humidity(%),integrated precipitable water vapor(cm)
4
56751 BFDI 100.17593 25.70729 1965.8127,1
2009 09 03 08 00 00 1.8690 798.9 24.8 57 0.701642
56951 BFLC 100.08996 23.88154 1472.2418,1
2009 09 03 08 00 00 2.1820 846.5 23.6 74 4.004144
56985 MNZI 103.38509 23.37595 1313.9340,1
2009 09 03 08 00 00 2.0690 864.1 28.8 47 1.545060
56969 MNLA 101.56890 21.48328 602.3500,1
2009 09 03 08 00 00 2.7102 934.3 32.1 52 9.504228

我把txt数据资料最后的空格(上面的小圆脸)删去,循环可以继续进行,但有上万个txt数据资料。
望高人指点,小弟不胜感激。
|
-
|