加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

fortran文件读取技巧

(2015-03-22 21:41:40)
标签:

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)   !在fortran的输入输出中'/'代表换行
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
  read(10,100) a(i,:)
  write(*,99) a(i,:)
end do
99 format(9(I4,1x))
100 format(10x,9(I4,1x),4x)
close(10)
end
!!!!这些技巧总结起来就是利用nX跳过不想要的东西。

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有