Fortran Coder

查看: 9716|回复: 1
打印 上一主题 下一主题

[输入输出] 关于输出隔六个换行的问题

[复制链接]

1

帖子

1

主题

0

精华

新人

F 币
12 元
贡献
5 点
跳转到指定楼层
楼主
发表于 2016-1-7 14:51:10 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
这是我写的代码:
[Fortran] 纯文本查看 复制代码
001      implicit none
002      integer yr,hr,min,mo,dy
003      integer*4 trimlen,
004     & narguments,iargc
005      real mag
006      real herr, verr, res
007      character line*180, fn0*80
008      character  fn1*30
009      logical ex
010      logical iy2k        !T for y2k format, F for old format
011      logical ipos1    !is P or S
012      logical ipos2    !is P or S
013      logical ipos3    !is P or S
014      logical ipos4    !is P or S
015      logical zc
016 
017      real t_time        ! travel time
018      real p_wghtr        !P weight derived from assigned code
019      real s_wghtr        !s weight derived from assigned code
020      integer wghtr      !weight
021      character sta*4        !full station code
022 
023      integer*4 cuspid, date,num
024 
025      real sec,lon, deglat, deglon, lat
026      real depth
027      character  str30*30
028      character ph*4
029      character ph1*1
030      character ph2*1
031      character ph3*1
032      character ph4*1  
033      character ew*1
034      character ns*1
035c  IFX
036      integer*1 ifx
037      integer*8 k
038       
039 
040c-- get input file name:
041      call getarg (1,str30)
042      fn0= str30 (1:trimlen(str30))
043      open (1,file=fn0, status='unknown')
044 
045c-- open output file name:
046      call getarg (2,str30)
047      fn1= str30(1:trimlen(str30))
048      open (2,file=fn1,status='unknown')
049       
050c--  read header     
051      num=1
052      k=1
053100   read(1,'(a)',end=200)line          ! read header line
054      iy2k= (line(1:1).eq.'#')
055 
056c      iy2k= (line(3:4).eq.'19' .or. line(3:4).eq.'20')
057      if(iy2k) then 
058      read(line(5:6),'(i2)')yr
059      read(line(8:9),'(i2)')mo
060      read(line(11:12),'(i2)')dy
061      read(line(14:15),'(i2)')hr
062      read(line(17:18),'(i2)')min
063      read(line(20:24),'(f5.2)')sec
064      read(line(27:33),'(f6.3)')deglat
065      read(line(36:42),'(f7.3)')deglon
066      read(line(47:51),'(f5.2)')depth
067      read(line(53:56),'(f3.1)')mag
068      lat= deglat
069      lon= deglon
070      herr=0.00
071      verr=0.00
072      res=0.00
073      cuspid=num
074      num=num+1
075      ns='N'
076      ew='E'
077      ifx=0
078c--Write earthquake location line
079      write (2,60) yr,mo,dy,hr,min,sec,lat,ns,lon,ew,depth,mag
080      goto 100
081      else
082      goto 105
083      endif
084c--Form station code
085105   sta=(line(1:4))
086c      ph= (line(49:52))
087c      ph1= (line(49:49))
088c      ph2= (line(50:50))
089c      ph3=(line(51:51))
090c      ph4=(line(52:52))
091      ph=(line(27:27))
092      read (line(10:15),'(f7.2)') t_time        !min for both p & s
093      wghtr=0
094 
095c      ipos1=((ph1.eq.'P').or.(ph2.eq.'P').or.(ph3.eq.'P'))
096      ipos1=(ph.eq.'P')
097      zc=(mod(k,6).eq.0)
098      if(zc) then
099      write (2,*)
100      endif
101      if(ipos1) then
102      write (2,61) sta,'P',wghtr,t_time
103      k=k+1
104      endif
105       
106      goto 100
107       
108c--Earthquake location format.
10960    format (/3i2,1x,2i2,1x,f5.2,1x,f7.4,a1,1x,f8.4,a1,1x,f7.2,
110     1      2x,f5.2 )
111 
112c--Phase format
11361    format (a4,a1,i1,1x,f5.2,$)
114       
115200   close(1)
116      close(2)
117      end
118 
119 
120 
121      integer function TRIMLEN(t)
122c------------------------------------------------------------------
123c     Author:  Urs Kradolfer, June 1986
124c     Call:    nc=TRIMLEN(char)
125c
126c          --> nc says, how many characters the input-string has
127c              (ignoring trailing blanks!).
128c
129      implicit none
130c
131      character t*(*)
132      do 1 trimlen=LEN(t),1,-1
133    1    if(t(trimlen:trimlen).ne.' ')RETURN
134      trimlen=1
135      end ! of integer function trimlen
136c

运行完之后得到:
92 6 4  4 5  4.20 30.3000N 101.5330E    0.00   2.20

GZA P0 11.60DFU P0 15.00XJI P0 18.30JLO P0 26.50HZS P0 36.80GZI P0 36.50
PXI P0 38.50RTD P0 40.60YGD P0 42.00
92 6 4  550 10.30 33.7330N 104.7170E    0.00   2.30
NPI P0 11.40PWU P0 23.90YTS P0 27.50

ZJG P0 35.70
92 6 5 1146 37.20 28.8000N 103.2500E    0.00   2.80
WMP P0 10.60LBO P0 11.70HZS P0 17.00SMI0P0 17.70RTD P0 24.40

NZS P0 24.70HWS P0 25.40SFS P0 26.60SFS P0 27.10JLO P0 30.90YGD P0 31.40


LZH P0 33.20LZH P0 35.60YZP P0 39.00YZP P0 40.20PXI P0 39.80XJI P0 45.80

JJS P0 43.80JJS P0 47.30LZZ P0 42.80LZZ P0 46.20CQI P0 49.60CQI P0 55.80

ZJG P0 61.30

不是6个空一行
希望得到的格式是这样的:
92 6 4  4 5  4.20 30.3000N 101.5330E    0.00   2.20
GZAOP0 11.60XJIOP0 18.30JLOOP0 26.50HZSOP0 36.80GZIOP0 36.50PXIOP0 38.50
RTDOP0 40.60YGDOP0 42.00

92 6 4  550 10.30 33.7330N 104.7170E    0.00   2.30
NPI P0 11.40PWUOP0 23.90YTSOP0 27.50ZJGOP0 35.70

9999

求大神看看我该如何修改
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

2038

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1676 元
贡献
715 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

沙发
发表于 2016-1-7 18:20:21 | 只看该作者
请把输入文件传上来。
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2025-5-1 09:58

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

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