首页 > 解决方案 > 将逻辑变量传递给 Fortran 子例程

问题描述

我有以下简单的 Fortran 代码。

program main
    implicit none
    call flag_test(.TRUE.)
    subroutine flag_test(flag)
        implicit none
        logical,intent(in) :: flag
        if(flag) then
            print*, "flag is true"
        else 
            print*, "flag is false"
        end if
    end subroutine flag_test
end program main

我想了解如何在 if 语句中传递逻辑变量。这段代码给出了以下错误:

main.F90:4:1:

  subroutine flag_test(flag)
 1
Error: Unclassifiable statement at (1)
main.F90:5:15:

   implicit none
               1
Error: Duplicate IMPLICIT NONE statement at (1)
main.F90:6:28:

   logical,intent(in) :: flag
                            1
Error: Unexpected data declaration statement at (1)
main.F90:12:4:

  end subroutine flag_test
    1
Error: Expecting END PROGRAM statement at (1)
main.F90:7:9:

   if(flag) then
         1
Error: Symbol ‘flag’ at (1) has no IMPLICIT type

你能帮我理解我哪里出错了吗?

标签: fortranlogical-operatorssubroutine

解决方案


推荐阅读