爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
楼主: xiaohundanpipi

[求助] fortran读取txt文件 读取的时候怎么跳过开头数据信息

[复制链接]

新浪微博达人勋

发表于 2013-10-1 10:54:43 | 显示全部楼层

看了这个以后,觉得很有帮忙,可是我有一个疑问,怎么用FORTRAN读取一行数据时跳过之前几个字符呢?数据差不多如下:尝试过把空格看成分隔符,结果只把第一个数据提取出来了;或者把每个字符看成一列,从第18列开始读,也不太读得出后面那个矩阵数组。指针什么的不太会用,能麻烦您指点一下吗。
2013-04-14 23:42 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 成长值: 0
发表于 2013-10-1 11:25:48 | 显示全部楼层
嘟嘟鱼2013 发表于 2013-10-1 10:54
看了这个以后,觉得很有帮忙,可是我有一个疑问,怎么用FORTRAN读取一行数据时跳过之前几个字符呢?数据差 ...

跳过时间那一行么?或许应该直接
read(1,*)
就可以了,下面到直接read
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-1 12:48:06 | 显示全部楼层
虽然现在在学FORTRAN,但是我们还未真正学自我编程
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-1 14:28:51 | 显示全部楼层
言深深 发表于 2013-10-1 11:25
跳过时间那一行么?或许应该直接
read(1,*)
就可以了,下面到直接read

OO 不是 日期、时间和数据在同一行里面。那个应该怎么处理呢。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 成长值: 0
发表于 2013-10-1 21:30:08 | 显示全部楼层
嘟嘟鱼2013 发表于 2013-10-1 14:28
OO 不是 日期、时间和数据在同一行里面。那个应该怎么处理呢。

fortran可以通过记录进行跳读,但是记事本文件的建议直接通过读取释放,将变量全都定义为字符型的,前面读取释放两个数,生下来的写到文件里面就可以了。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-2 14:29:54 | 显示全部楼层
言深深 发表于 2013-10-1 21:30
fortran可以通过记录进行跳读,但是记事本文件的建议直接通过读取释放,将变量全都定义为字符型的,前面读 ...

不太明白您的意思。我的数据列出的是第一行,第一行数据用于计算。里面一共有四行。都把它理解成字符串。
integer::m,n
character::str(4,3000)
do m=1,4
do n=1,3000
  read(10,*)str(m,n)
end do
end do

do m=1,1
write(11,*)str(1,18:3000)
end do

end

这样试了一下,还是不对呢?能麻烦指点一下吗。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 成长值: 0
发表于 2013-10-2 22:36:08 | 显示全部楼层
try this

integer::m,n
character(len=1)::str(4,3000)
do m=1,4
  read(10,*)(str(m,n),n=1,3000)
end do

do n=18,3000
write(11,*)str(1,n)
enddo
end
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-3 14:21:10 | 显示全部楼层
本帖最后由 嘟嘟鱼2013 于 2013-10-3 14:29 编辑
言深深 发表于 2013-10-2 22:36
try this

integer::m,n

按您说的我试了一下,还是不行。运行以后是这样的,
forrtl: severe(24): end of file during read...
我把数据传在附件里,能麻烦您帮我看下吗。提取第一行除了日期、时间以外的数据。
我是把四行都理解成字符数组,只读第一行,跳过前17个字符。。。不知道这样对不对?主要是我自己没有试出来。麻烦指点一下,谢谢。我在想是不是第一个open语句里面要加一个IOSTAT的说明,或者每行得读到‘\n’才跳到下一行呢。

program main
implicit none

integer::m,n
character(len=1)::str(4,3000)

open(10,file='d:\PShadow_GD001.txt')
open(11,file='d:\Newfile.txt')

do m=1,4
  read(10,*)(str(m,n),n=1,3000)
end do

do n=18,3000
write(11,*)str(1,n)
enddo
end

PShadow_GD001.txt

2.56 KB, 下载次数: 2, 下载积分: 金钱 -5

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-10-22 09:15:42 | 显示全部楼层
6楼的方法真不错,学习啦!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-11 12:00:29 | 显示全部楼层
空读过去就行了,不用定义数据类型。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表