Fortran Coder

unexpected junk after else statement at

查看数: 20307 | 评论数: 6 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2019-11-13 19:56

正文摘要:

[Fortran] 纯文本查看 复制代码MODULE MOD_FUNC ! module contains functions for P and S-wave velocities, density and ! quality factors in sediments (1st layer) IMPLICIT NONE CONTAINS !================ ...

回复

necrohan 发表于 2019-11-15 09:21:23

明白了,谢谢
vvt 发表于 2019-11-14 19:38:36
本帖最后由 vvt 于 2019-11-14 19:40 编辑

5<=z<18
等效于
(5<=z)<18
那么

情况1:
如果 5<=z 是 .true.
而.true. 一般在内存里是 0x01 或 0x0001 之类,或者 0xFF 之类的
.true. < 18 等效于 1<18 或 -1<18,结果是 .true.

情况2:
如果 5<=z 是 .false
而.false. 一般在内存里是 0x00 或 0x0000 之类的
.false. < 18 等效于 0<18,结果也是 .true.

所以,不管怎样,这个表达式的结果都是 .true.


18778386191 发表于 2019-11-14 15:44:58
fcode 发表于 2019-11-14 09:01
其实你的函数可以简化一下。
[mw_shl_code=fortran,true]  FUNCTION FUNCRHO (Z)
    USE NRTYPE, ONLY: WP ...

谢谢了。改了就对了
necrohan 发表于 2019-11-14 09:02:23
5<=z<18
这是新的写法吗?可以编译成功但是结果不对。
fcode 发表于 2019-11-14 09:01:23
其实你的函数可以简化一下。
[Fortran] 纯文本查看 复制代码
MODULE MOD_FUNC

! module contains functions for P and S-wave velocities, density and
! quality factors in sediments (1st layer)

IMPLICIT NONE

CONTAINS
!==================== 1D INHOMOGENEOUS MEDIUM =========================
!------------------------------------------------- P or S-wave velocity
  FUNCTION FUNCV (Z)

    USE NRTYPE, ONLY: WP

    REAL(WP), INTENT(IN) :: Z
    REAL(WP)             :: FUNCV

    if (z<5) then
      !layer
      funcv = 180
    else if(5<=z<18) then
      !layer
      funcv = 200
    else if(18<=z<54) then
      !layer
      funcv = 360
    else if(54<=z<92) then
      !layer
      funcv = 400
    else if(92<=z<130) then
      !layer
      funcv = 440
    else if(130<=z<165) then
      !layer
      funcv = 460

    else
      !halfspace
      funcv = 970
    end if

  END FUNCTION FUNCV

!--------------------------------------------------------------- Density
  FUNCTION FUNCRHO (Z)

    USE NRTYPE, ONLY: WP

    REAL(WP), INTENT(IN) :: Z
    REAL(WP)             :: FUNCRHO


    if(z<5) then
      !layer
      funcrho = 1220
    else if(5<=z<18) then
      !layer
      funcrho = 1487
    else if(18<=z<54) then
      !layer
      funcrho = 1945
    else if(54<=z<92) then
      !layer
      funcrho = 1966
    else if(92<=z<130) then
      !layer
      funcrho = 1966
    else if(130<=z<165) then
      !layer
      funcrho = 1966
    else
      !halfspace
      funcrho = 2123
    end if

  END FUNCTION FUNCRHO

!------------------------------------------- P or S-wave quality factor
  FUNCTION FUNCQ (Z)

    USE NRTYPE, ONLY: WP

    REAL(WP), INTENT(IN) :: Z
    REAL(WP)             :: FUNCQ

    if(z<165) then
      !layer
      funcq = 50
    else
      !halfspace
      funcq = 10000
    end if
  END FUNCTION FUNCQ

END MODULE


这样更易读、易修改、易扩展
fcode 发表于 2019-11-14 08:46:52
130<=z .and. z<165

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-11-23 19:49

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表