如何使用Fortran读取二进制文件并保存到文本文件?

时间:2016-04-19 01:44:22

标签: binary fortran

我有一个包含以下信息的二进制文件:

ifile.dat
big_endian sequential, nx=530, ny= 427, t=1, 4 variables

我想用Fortran程序阅读它并写入文本文件。我的试用f90计划是:

bin_read.f90:

  INTEGER,PARAMETER :: nx=530, ny=427
  REAL :: v1(nx,ny),v2(nx,ny),v3(nx,ny),v4(nx,ny)

  OPEN(10, file= 'ifile.dat', form = 'unformatted', &
 &access='sequential',convert='big_endian')
  OPEN(11, file= 'ofile.txt', form = 'formatted', &
 &status='unknown')

  DO j = 1, ny
    DO i = 1, nx
      READ(10,*)v1(i,j),v2(i,j),v3(i,j),v4(i,j)
      WRITE(11,1)v1(i,j),v2(i,j),v3(i,j),v4(i,j)
1     FORMAT(4(1X,f8.3))
    ENDDO
  ENDDO

  STOP
  END

当我在编译后执行它时,我收到以下消息:

At line 11 of file bin_read.f90 (unit = 10, file = 'ifile.dat')
Fortran runtime error: Format present for UNFORMATTED data transfer

0 个答案:

没有答案