【问题标题】:assigning values to an integer array within a Fortran module为 Fortran 模块中的整数数组赋值
【发布时间】:2023-01-27 23:38:17
【问题描述】:

我在 Fortran 中有一个名为 QFoo 的模块。它定义了一个类型 QFooType。

我想将整数数组 'is_n' 的所有元素初始化为 0,并希望在模块内进行。有人可以帮忙吗?谢谢!

  module QFoo
      type QFooType              
          integer::i              
          integer, dimension(50) :: is_n                         
      end type QFooType

     !-----------
     ! I know the following code is wrong
     ! but I want to initialize all the is_n elements to 0
     !-----------
     ! do i = 1, 50
     !    is_n(i) = 0
     ! enddo
     !-----------
  end module QFoo

【问题讨论】:

    标签: arrays fortran


    【解决方案1】:
    integer, dimension(50) :: is_n = 0
    

    适用于最新版本的英特尔 Fortran 编译器。我对 Fortran 95 标准的阅读表明这是标准行为。

    【讨论】:

    • 伟大的!它有效..谢谢!我不认为我们用于非数组赋值的语法会在这里起作用!再次感谢
    猜你喜欢
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 2015-12-21
    相关资源
    最近更新 更多