fortran文件读取技巧

标签:
fortran文件读取 |
分类: fortran |
最近专业课海洋要素计算作业需要用fortran编程读取验潮站资料(如下,是txt,其中数据是有62行,限于篇幅,我只截取了前5行数据外加验潮站的4行头信息)
!要注意的是最后一列数据后面没有空格
http://s2/mw690/003cvAxDzy6QU6uYPL371&690
program ex1
!**********************************************
!* written by 潘海东, 2015,3,20
!*一次性读取744个数据,放入一维数组中
!*(如果一次性读取太多的话可能会对系统造成某些影响)
!**********************************************
INTEGER :: b(62*12),i
character(len=20) time,location,u1,u2
open(10, file =
'C:\Users\Administrator\Desktop\sjs_t_97aug_m(harmonic).txt',
status = 'old')
!********读取头信息
read(10,"(A3)") u1
read(10,"(A18)") time
read(10,"(A13)") location
read(10,"(A2)") u2
!********读取数据
read(10,100) b(:)
100
format(61(11(I4,1x),I4,/),11(I4,1x),I4)
close(10)
end
program ex2
!**********************************************
!* written by 潘海东, 2015,3,20
!*读取第3列至第11列
!**********************************************
INTEGER ::
a(62,9),i
character(len=20) time,location,u1,u2
open(10, file =
'C:\Users\Administrator\Desktop\sjs_t_97aug_m(harmonic).txt',
status = 'old')
!***读取头信息
read(10,"(A3)") u1
read(10,"(A18)") time
read(10,"(A13)") location
read(10,"(A2)") u2
!***读取验潮站数据
do i=1,62
end do
99 format(9(I4,1x))
100 format(10x,9(I4,1x),4x)
close(10)
end
!!!!这些技巧总结起来就是利用nX跳过不想要的东西。