Fortran Coder

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

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

[复制链接]

1

帖子

1

主题

0

精华

新人

F 币
12 元
贡献
5 点
跳转到指定楼层
楼主
发表于 2016-1-7 14:51:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我写的代码:
[Fortran] 纯文本查看 复制代码
      implicit none
      integer yr,hr,min,mo,dy
      integer*4 trimlen,
     & narguments,iargc
      real mag
      real herr, verr, res
      character line*180, fn0*80 
      character  fn1*30
      logical ex
      logical iy2k        !T for y2k format, F for old format
      logical ipos1    !is P or S
      logical ipos2    !is P or S
      logical ipos3    !is P or S
      logical ipos4    !is P or S
      logical zc

      real t_time        ! travel time
      real p_wghtr        !P weight derived from assigned code
      real s_wghtr        !s weight derived from assigned code
      integer wghtr      !weight
      character sta*4        !full station code

      integer*4 cuspid, date,num

      real sec,lon, deglat, deglon, lat
      real depth
      character  str30*30
      character ph*4
      character ph1*1
      character ph2*1
      character ph3*1
      character ph4*1   
      character ew*1
      character ns*1
c  IFX
      integer*1 ifx
      integer*8 k
      

c-- get input file name:
      call getarg (1,str30)
      fn0= str30 (1:trimlen(str30))
      open (1,file=fn0, status='unknown') 

c-- open output file name: 
      call getarg (2,str30)
      fn1= str30(1:trimlen(str30))
      open (2,file=fn1,status='unknown')
      
c--  read header      
      num=1
      k=1
100   read(1,'(a)',end=200)line          ! read header line
      iy2k= (line(1:1).eq.'#')

c      iy2k= (line(3:4).eq.'19' .or. line(3:4).eq.'20')
      if(iy2k) then  
      read(line(5:6),'(i2)')yr
      read(line(8:9),'(i2)')mo
      read(line(11:12),'(i2)')dy
      read(line(14:15),'(i2)')hr
      read(line(17:18),'(i2)')min
      read(line(20:24),'(f5.2)')sec
      read(line(27:33),'(f6.3)')deglat
      read(line(36:42),'(f7.3)')deglon
      read(line(47:51),'(f5.2)')depth
      read(line(53:56),'(f3.1)')mag
      lat= deglat
      lon= deglon
      herr=0.00
      verr=0.00
      res=0.00
      cuspid=num
      num=num+1
      ns='N'
      ew='E'
      ifx=0
c--Write earthquake location line
      write (2,60) yr,mo,dy,hr,min,sec,lat,ns,lon,ew,depth,mag
      goto 100
      else
      goto 105
      endif
c--Form station code
105   sta=(line(1:4))
c      ph= (line(49:52))
c      ph1= (line(49:49))
c      ph2= (line(50:50))
c      ph3=(line(51:51))
c      ph4=(line(52:52))
      ph=(line(27:27))
      read (line(10:15),'(f7.2)') t_time        !min for both p & s
      wghtr=0

c      ipos1=((ph1.eq.'P').or.(ph2.eq.'P').or.(ph3.eq.'P'))
      ipos1=(ph.eq.'P')
      zc=(mod(k,6).eq.0)
      if(zc) then
      write (2,*)
      endif
      if(ipos1) then
      write (2,61) sta,'P',wghtr,t_time
      k=k+1
      endif
      
      goto 100
      
c--Earthquake location format.
60    format (/3i2,1x,2i2,1x,f5.2,1x,f7.4,a1,1x,f8.4,a1,1x,f7.2,
     1      2x,f5.2 )

c--Phase format
61    format (a4,a1,i1,1x,f5.2,$)
      
200   close(1)
      close(2)
      end



      integer function TRIMLEN(t)
c------------------------------------------------------------------
c     Author:  Urs Kradolfer, June 1986
c     Call:    nc=TRIMLEN(char)
c
c          --> nc says, how many characters the input-string has
c              (ignoring trailing blanks!).
c
      implicit none
c
      character t*(*)
      do 1 trimlen=LEN(t),1,-1
    1    if(t(trimlen:trimlen).ne.' ')RETURN
      trimlen=1
      end ! of integer function trimlen
c

运行完之后得到:
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

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

1967

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1370 元
贡献
581 点

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

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

本版积分规则

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

GMT+8, 2024-5-12 12:27

Powered by Tencent X3.4

© 2013-2024 Tencent

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