为什么直接访问 I/O 在英特尔 Visual Fortran 中无法正常工作 [英] Why direct access I/O works incorrectly with Intel Visual Fortran

查看:18
本文介绍了为什么直接访问 I/O 在英特尔 Visual Fortran 中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个程序

  program test

  real a(10)

  open(1, file='f1',access='direct', recl=20)
  do i=1, 10
      a(i) = i-1
  end do
  write(1, rec=1)(a(i),i=1,5)
  write(1, rec=2)(a(i),i=6,10)
  close(1)
  open(1, file='f1',access='direct',recl=8)
  read(1, rec=4)(a(i),i =5,9,4)
  print*,a
  end

在视觉 Fortran 中工作不正确(不正确):

works incorrect in visual Fortran (incorrect):

  0.0000000E+00   1.000000       2.000000       3.000000       9.000000
   5.000000       6.000000       7.000000      0.0000000E+00   9.000000

WATCOM 中的结果(正确):

Result in WATCOM (correct):

  0.0000000   1.0000000       2.0000000       3.0000000       6.0000000
  5.0000000   6.0000000       7.0000000       7.0000000       9.0000000

为什么?

推荐答案

Visual Fortran中RECL的默认单位长度是一个字(4bytes).如果您使用选项使用字节作为 RECL= 未格式化文件的单位"(/assume:byterecl)进行编译,您将得到您所期望的.

The default unit length of RECL in Visual Fortran is a word (4bytes). If you compile with option 'Use bytes as RECL= unit for unformatted file' (/assume:byterecl), you will get what you expect.

这篇关于为什么直接访问 I/O 在英特尔 Visual Fortran 中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆