小编com*_*ohn的帖子

读取由Python代码创建的Fortran中的二进制文件

我有一个使用Python代码创建的二进制文件.此代码主要编写一系列任务来预处理一组数据文件.我现在想在Fortran中读取这个二进制文件.二进制文件的内容是简单格式的点坐标,例如:点数,x0,y0,z0,x1,y1,z1,....

这些二进制文件是使用numpy中的'tofile'函数创建的.到目前为止,我在Fortran中有以下代码:

integer:: intValue
double precision:: dblValue
integer:: counter
integer:: check
open(unit=10, file='file.bin', form='unformatted', status='old', access='stream')

counter = 1

do 

  if ( counter == 1 ) then
    read(unit=10, iostat=check) intValue
    if ( check < 0 ) then
      print*,"End Of File"
      stop
    else if ( check > 0 ) then
      print*, "Error Detected"
      stop
    else if ( check == 0 ) then
      counter = counter + 1
      print*, intValue
    end if
  else if ( counter > 1 ) then
    read(unit=10, iostat=check) …
Run Code Online (Sandbox Code Playgroud)

python fortran binaryfiles

7
推荐指数
1
解决办法
1031
查看次数

Fortran 中用户定义的运算符

我有一个关于在 Fortran 中编写用户定义运算符的正确方法的问题。更具体地说,我将提供我的问题的示例。我正在致力于为称为“粒子”的球形粒子创建用户定义的数据类型。我想定义一个运算符,它采用现有的 Particle 对象数组并向其中添加一个新的 Particle 对象。我想知道如何定义用户定义的运算符来执行这样的操作。

目前,在 Particle 的类型定义中,我有以下几行:

procedure, public:: addNewParticleTo
generic:: operator(.spawn.) => addNewParticleTo
Run Code Online (Sandbox Code Playgroud)

接下来,我有一个定义如下的子例程:

subroutine addNewParticleTo(a_LHS, a_RHS)
  implicit none
  class(Particle), dimension(:), allocatable, intent(in):: a_LHS
  class(Particle), dimension(:), allocatable, intent(inout):: a_RHS
  <rest of the code>
end subroutine addNewParticleTo
Run Code Online (Sandbox Code Playgroud)

我打算将运算符调用为:

particle .spawn. particleArray
Run Code Online (Sandbox Code Playgroud)

我想知道这是否是执行此操作的正确方法。对此的任何建议或建议都会非常有帮助。

fortran user-defined-functions user-defined-types fortran90 fortran95

5
推荐指数
1
解决办法
1582
查看次数