在FORTRAN中写二进制文件而无需额外信息

时间:2017-05-06 10:44:56

标签: numpy fortran fortran90

我写了一个简单的子程序,应该写:

  1. 1字节= x93(十进制147)
  2. 5个字节= ASCII STRING(NUMPY)
  3. PEP 8

    Subroutine  write_int32_vec(filename, vec)
        Implicit None
        character(len=1000), intent(in)     :: filename
        integer(4), intent(in)              :: vec(:)
    
        open(unit=p_un, file=filename, form="unformatted", status="replace")
        write (p_un) magic_num
        write (p_un) magic_str
        close(unit=p_un)
    End Subroutine write_int32_ve
    

    如果我在十六进制编辑器中查看它,我会得到以下内容:

    01 00 00 00 93 01 00 00 00 05 00 00 00 4E 55 4D 50 59 05 00 00 00
    

    是ASCII

    �NUMPY
    

    似乎Fortran在每个写入命令之前和之后写入它的长度为4字节整数。我怎么能关掉这个?

1 个答案:

答案 0 :(得分:-1)

事实证明

for (int r = 0; r < rowAmount; ++r)
{
  for (int n = 0; n < numAmount; ++n)
  {
    userNum = lotRng.Next(1, numAmount * rngMult);

    for (int x = 0; x < coupon.GetLength(1); x++) //Iterate over your second dimension again
    {
      while (coupon[r,x] == userNum)
      {
        userNum = lotRng.Next(1, numAmount * rngMult);
      }
    }
    coupon[r, n] = userNum;
  }
}

诀窍。可悲的是,这似乎只适用于ifort,但不适用于gfortran。