Intel Fortran和gfortran之间具有未格式化文件写/读兼容性的问题

问题描述 投票:0回答:1

我正在尝试在具有Intel编译器的Windows以及具有gfortran 6.5.0的Mac OS上使用代码,并且无法获得gfortran版本来读取Windows上编写的未格式化文件的部分。我编写了包含问题部分的测试代码,并验证了它可以在英特尔编译器和gfortran编译器上读写文件的方式工作。但是,如果我注释掉写入部分,而只是尝试读取使用gfortran版本在Windows(并行)计算机的Windows侧写入的文件,则某些数据将无法正确读取。我包括下面的测试代码。无法正确读取“ cel(1),f_ei,f_en,f_egyro,f_wall,f_ex,f_wallBC =“的数据(但是,之前的数据已正确读取)。未格式化的文件中是否存在某些不兼容?

PROGRAM Testo
  IMPLICIT NONE
  INTEGER, PARAMETER :: ncelMAX=6800
  REAL*8  :: dt
  LOGICAL :: MagON,BFmesh
  INTEGER :: nslice_Ver, nslice_verzr, nslice_Edg, nslice_edgzr
  INTEGER :: nFluid, nChrge, nCel, nBCs, nEdg, nVer , nCelzr, nBCszr, nEdgzr, &
       nVerzr, MinSliceCel, MaxSliceCel, MinSliceCelzr, MaxSliceCelzr
  TYPE cell_obj
     INTEGER*4 verNo(4),edgNo(4)
     INTEGER*4 Bln   !BField Mesh
     REAL*8 f_ei,f_en,f_egyro,f_wall,f_ex, f_wallBC
  END TYPE cell_obj
  TYPE(cell_obj) cel(ncelMAX)
  dt = 2.0E-8
  MagON = .TRUE.
  BFmesh = .TRUE.
  nslice_Ver = 1
  nslice_verzr = 2
  nslice_Edg = 3
  nslice_edgzr = 4
  nFluid = 3
  nChrge = 3
  nCel = 3000
  nBCs = 4000
  nEdg = 5000
  nVer = 6000
  nCelzr = 7000
  nBCszr = 8000
  nEdgzr = 9000
  nVerzr = 10000
  MinSliceCel = 100
  MaxSliceCel = 200
  MinSliceCelzr = 300
  MaxSliceCelzr = 400
  cel(1)%verNo(1) = 1
  cel(1)%verNo(2) = 2
  cel(1)%verNo(3) = 3
  cel(1)%verNo(4) = 4
  cel(1)%edgNo(1) = 1
  cel(1)%edgNo(2) = 2
  cel(1)%edgNo(3) = 3
  cel(1)%edgNo(4) = 4
  cel(1)%Bln = 1000
  cel(1)%f_ei = 2.0E6
  cel(1)%f_en = 2.0E7
  cel(1)%f_egyro = 2.0E8
  cel(1)%f_wall = 3.0E6
  cel(1)%f_ex = 3.0E7
  cel(1)%f_wallBC = 3.0E8
  OPEN(UNIT=10,FILE='restartData_TEST',FORM='UNFORMATTED')
  REWIND(10)
  WRITE(10) dt, MagON, nslice_Ver, nslice_Edg, nslice_verzr, nslice_edgzr, BFmesh
  WRITE(10) nFluid, nChrge, nCel, nBCs, nEdg, nVer , nCelzr, nBCszr, nEdgzr, nVerzr, MinSliceCel, MaxSliceCel,MinSliceCelzr,MaxSliceCelzr
  WRITE(10) cel
  CLOSE(10)
  OPEN(UNIT=10,FILE='restartData_TEST',FORM='UNFORMATTED')
  REWIND(10)
  READ(10) dt,MagON,nslice_Ver,nslice_Edg, nslice_verzr, nslice_edgzr, BFmesh
  PRINT *, "First line = ", dt,MagON,nslice_Ver,nslice_Edg, nslice_verzr, nslice_edgzr, BFmesh
  READ(10) nFluid, nChrge, nCel, nBCs, nEdg, nVer , nCelzr, nBCszr, nEdgzr, nVerzr, MinSliceCel, MaxSliceCel,MinSliceCelzr,MaxSliceCelzr
  PRINT *, "Second line = ", nFluid, nChrge, nCel, nBCs, nEdg, nVer , nCelzr, nBCszr, nEdgzr, nVerzr, MinSliceCel, MaxSliceCel,MinSliceCelzr,MaxSliceCelzr
  READ(10) cel
  PRINT *, "cel(1), verNo(4),edgNo(4) = ",cel(1)%verNo(1),cel(1)%verNo(2),cel(1)%verNo(3),cel(1)%verNo(4),cel(1)%edgNo(1),cel(1)%edgNo(2),cel(1)%edgNo(3),cel(1)%edgNo(4)
  PRINT *, "cel(1), Bln = ",cel(1)%Bln
  PRINT *, "cel(1), f_ei,f_en,f_egyro,f_wall,f_ex,f_wallBC = ",cel(1)%f_ei,cel(1)%f_en,cel(1)%f_egyro,cel(1)%f_wall,cel(1)%f_ex,cel(1)%f_wallBC
  PAUSE 'DONE'
END PROGRAM Testo
fortran compatibility gfortran intel-fortran
1个回答
0
投票

绝对不能保证Fortran未格式化文件的可移植性-如果您不使用完全相同的硬件和编译器组合(低至编译器版本),则所有选项都将关闭。如果需要可移植性,请使用格式化的文件,或者可能使用流I / O,或者最好使用可移植数据格式之一,例如netcdf(https://www.unidata.ucar.edu/software/netcdf/)或hdf5(https://www.hdfgroup.org/solutions/hdf5/

也请不要使用非标准实数* 8和整数* 4-有关如何正确执行的信息,请参见Fortran 90 kind parameter

© www.soinside.com 2019 - 2024. All rights reserved.