error in if-statement, requires scalar logical expression

前端 未结 2 2015
刺人心
刺人心 2020-12-11 14:29

Within a subroutine I try to create a statement, however it will only work if I enter a number directly, as soon as I replace the number with a variable, it will give the er

2条回答
  •  鱼传尺愫
    2020-12-11 15:07

    You try to use a DIMENSION(1, 1) type as a REAL.

    You shoul add (1, 1) to access to yout REAL contained in the DIMENSION(1, 1)

    Use :

      IF ( var%type3(1, 1) < 0.5 ) THEN
         print *, 'IT WORKS'
      END IF
    

    Exemple to get this error :

    MODULE vardef
      TYPE vartype
         REAL :: type3(1, 1)
      END TYPE vartype
    END MODULE vardef
    
    PROGRAM test
      USE vardef
    
      TYPE(vartype) var
    
      var%type3(1, 1) = 0
    
      IF ( var%type3 < 0.5 ) THEN
         print *, 'IT WORKS'
      END IF
      RETURN
    
    END PROGRAM test
    

提交回复
热议问题