Fortran Coder

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

[文件读写] 导出来的文件出现乱码,请问是什么原因呢?

[复制链接]

1

帖子

1

主题

0

精华

新人

F 币
17 元
贡献
5 点
跳转到指定楼层
楼主
发表于 2018-5-3 09:01:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[Fortran] 纯文本查看 复制代码
C     **********************************************************
C            Moving T_TEST program                                 
C      Written by SUN Xuguang in Jan 8, 2003                
C      Modified by SUN Xuguang in Sep 24, 2004              
C      **********************************************************
C   NOTE :
C   n -- the total sample number of the time series
C   n1,n2 -- the sample numbers of the subtime series  
C   ta -- the critical value of t for 0.01 significance (a=0.01)
C   iv -- temporal parameter
C@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
C   this program is used to
C
      parameter(n=54,n1=11,n2=11,ta=2.85)
      parameter(undef=-9999.)
      real x(n),t(n)
      integer irec                !used to indicate rec number
      character*80 input,output   !in and out files

      input='tnj7.txt'
      output= 'MovingttestTnj7-8.txt'
      open(1,file=input)
C        ,form='unformatted',status='old',
C     &access='direct',recl=1)
      open(2,file=output,form='unformatted',status='unknown',
     &access='direct',recl=1)
C==========================================================
C       read data
C==========================================================
      do i=1,n
       irec=i
C       read(1,rec=irec)x(i)
        read(1,*)x(i)
      enddo
C&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
C         let's begin to do moving_t_test
C         note: the first n1 and the last n2 are null
Cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
C
      do i = 1,n
       t(i)=undef          !initialize t values
      enddo

      do 10 i=n1,n-n2     !calculate t values in this section

          x1=0.0           !initialize x1 mean value by zero
          do j1=i-n1+1,i
           x1=x1+x(j1)
          enddo
          x1=x1/real(n1)   !calculate x1 mean value

          s1=0.0           !initialize x1 ms(mean square)
          do j1=i-n1+1,i
          s1=s1+(x(j1)-x1)**2
          enddo
          s1=s1/real(n1)   !calculate x1 mean square value

          x2=0.0           !initialize x2 mean value by zero
          do j2=i,i+n2-1
          x2=x2+x(j2)
          enddo
          x2=x2/real(n2)   !calculate x2 mean value

          s2=0.0           !initialize x2 ms(mean square)
          do j2=i,i+n2-1
          s2=s2+(x(j2)-x2)**2
          enddo
          s2=s2/real(n2)   !calculate x2 mean square value

          s=sqrt((n1*s1+n2*s2)/real(n1+n2-2))
          t(i)=(x1-x2)/s/sqrt(real(n1+n2)/real(n1*n2))

10     continue           
C============================================================
C        output data
C============================================================
       do i=1,n
C       do i=n1,n-n2
          irec=(i-1)*2+1
         write(2,rec=irec)t(i)

          irec=(i-1)*2+2
          write(2,rec=irec)ta

       enddo

        close(1)
        close(2)        
        end

用的是FORTRAN的fixed格式。同学好像只改了路径,就可以读取出来,但是我每次运行导出来的文件都是乱码,请大神赐教...

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

6

帖子

0

主题

0

精华

入门

腐女

F 币
76 元
贡献
49 点
沙发
发表于 2018-5-3 09:37:56 | 只看该作者
你用无格式存,是二进制文件,用文本编辑器打开当然就是乱码。
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-4-25 10:15

Powered by Tencent X3.4

© 2013-2024 Tencent

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