Fortran 问题:"xx" 的参数在 (2) 处是一种类型,但在 (1) 处是其他类型
Fortran issue: Argument of "xx" is one type at (2) but is some other type at (1)
我有几个“参数在 (1) 处是一种类型,但在 (2) 处是另一种类型”错误出现在我的程序中,但我不确定如何修改它。
除了我所做的,还有其他写论点的方法吗?
Ps。我在 g77 中编译。但我也在 gfortran 中尝试过,其中出现的错误是 "Rank mismatch in argument 'z' at (1) (scalar and rank-1)".
以下是出现的错误:
geomalb.f: In subroutine `atmsetup':
geomalb.f:1083:
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
1
geomalb.f:1122: (continued):
SUMT=SUMT+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*XMU(J)
2
Invalid declaration of or reference to symbol `z' at (2) [initially seen at (1)]
geomalb.f:80: warning:
COLDEN(J)=RHOP*(PRESS(J+1)-PRESS(J))/EFFG(Z(J))
1
geomalb.f:1122: (continued):
SUMT=SUMT+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*XMU(J)
2
Argument #1 of `effg' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
geomalb.f:80: warning:
COLDEN(J)=RHOP*(PRESS(J+1)-PRESS(J))/EFFG(Z(J))
1
geomalb.f:1124: (continued):
SUMB=SUMB+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*28.01340
2
Argument #1 of `effg' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
geomalb.f:72: warning:
CALL ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
1
geomalb.f:1083: (continued):
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
2
Argument #2 (named `z') of `atmsetup' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
部分节目:
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
PARAMETER (NMAX=201)
DIMENSION CH4(1),H2(1),XN2(1),AR(1)
DIMENSION TLINAL(NMAX),DLINAL(NMAX),PLINAL(NMAX)
DIMENSION DEN(1), PRESS(1), TEMP(1), XMU(1)
CALL LINDAL(NLEVEL,Z,TLINAL,DLINAL,PLINAL)
DO J=1,NLEVEL
TEMP(J)= TLINAL(J)
DEN(J)= DLINAL(J)
PRESS(J)=PLINAL(J)
ENDDO
DO 1000 ITS =1,20
CH4(NLEVEL)=PCH4(TEMP(NLEVEL))*RHCH4/PRESS(NLEVEL)
DO 134 J=NLEVEL-1,1,-1
CH4SAT=PCH4(TEMP(J))/PRESS(J)
CH4(J)=AMIN1(CH4SAT,CH4(NLEVEL),CH4(J+1))
134 CONTINUE
DO 20 J=1,NLEVEL
H2(J)=FH2
IF (FARGON .LT. 0.) THEN
AR(J)=(-FARGON-28.0134+25.8554*H2(J)+11.9708*CH4(J))/11.9346
ELSE
IF (FARGON .EQ. 0.) THEN
AR(J)=0.0
ELSE
AR(J)=FARGON
ENDIF
ENDIF
XN2(J)=1.0 - H2(J) - CH4(J) -AR(J)
XMU(J)=28.0134*XN2(J)+2.158*H2(J)+16.0426*CH4(J)+39.948*AR(J)
20 CONTINUE
SUMT=PLINAL(1)*6.02E23/10.
SUMB=SUMT
TLAST=TEMP(NLEVEL)
DO J=2,NLEVEL
DENF=294.1/(XN2(J)*294.1 + CH4(J)*410. + H2(J)*136. + AR(J)*277.8)
DEN(J) = DLINAL(J)*DENF
ADEN=(DEN(J)-DEN(J-1))/ALOG(DEN(J)/DEN(J-1))
SUMT=SUMT+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*XMU(J)
ADEN=(DLINAL(J)-DLINAL(J-1))/ALOG(DLINAL(J)/DLINAL(J-1))
SUMB=SUMB+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*28.01340
PRESS(J)=PLINAL(J)*SUMT/SUMB
TEMP(J) =TLINAL(J)*(SUMT/SUMB)*(1./DENF)
ENDDO
30 CONTINUE
DT= ABS(TEMP(NLEVEL)-TLAST)
IF (DT .LT. 0.001) GO TO 1001
1000 CONTINUE
1001 IF (IPRINT .LT. 0) RETURN
WRITE (6,139)RHCH4,FH2,FARGON,DT
DO 135 J=1,NLEVEL-1
WRITE(6,140)J,Z(J),PRESS(J),DEN(J),TEMP(J),
& CH4(J)*PRESS(J)/PCH4(TEMP(J))
& ,CH4(J)*100.,XN2(J)*100.,H2(J)*100.,AR(J)*100.,XMU(J)
& ,(TEMP(J+1)-TEMP(J))/(Z(J+1)-Z(J))
135 CONTINUE
J=NLEVEL
WRITE(6,140)J,Z(J),PRESS(J),DEN(J),TEMP(J),
& CH4(J)*PRESS(J)/PCH4(TEMP(J))
& ,CH4(J)*100.,XN2(J)*100.,H2(J)*100.,AR(J)*100.,XMU(J)
139 FORMAT(///' BACKGROUNG ATMOSPHERE AT LEVELS'/
& ' SURFACE HUMIDITY OF CH4:',F5.3,' H2 MIXING RATIO:',F6.4,
& ' ARGON SETTING:',F8.4/' FINAL CONVERGENCE ON TEMP:',F10.5
& , ' LINDAL ET AL SCALING'/
&' LVL ALTITUDE P(BARS) DEN(CM-3) TEMP RH-CH4'
& , ' %CH4 %N2 %H2 %AR MU DT/DZ' )
140 FORMAT(1X,I3,F8.3,1P2E10.3,0PF7.2,F5.2,2F6.2,2F5.2,4F6.2)
RETURN
END SUBROUTINE
END
在程序的前面,我是这样调用子程序的:
CALL ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
您不为变量提供任何类型信息,而是依赖于隐式类型。在默认隐式类型规则下,您的变量 Z
和 EFFG
声明为:
real :: Z
real :: EFFG
Z
和 EFFG
都是 0 阶实变量(标量)。您通过以下方式引用这些变量
EFFG(Z(J))
这是排名不匹配。您将 Z
作为等级 1 变量访问,将 EFFG
作为等级 1 变量访问,但它们被隐式定义为等级 0 变量。
解决方法是将变量正确声明为等级 1 数组。在评论中,您注意到切换到 gfortran 将错误从一般 "types are different" 错误更改为特定 "rank mismatch"。这是一个更有帮助的错误消息,其他人已经注意到您应该能够(一旦您的问题全部解决)使用 gfortran 编译您的代码,而不会对 g77 编译的内容进行任何(或仅次要)更改。采用现代实践是值得的,一个简单的开始就是改变
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
PARAMETER (NMAX=201)
DIMENSION CH4(1),H2(1),XN2(1),AR(1)
DIMENSION TLINAL(NMAX),DLINAL(NMAX),PLINAL(NMAX)
DIMENSION DEN(1), PRESS(1), TEMP(1), XMU(1)
进入
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
implicit none
integer NMAX
real CH4, H2, XN2, AR, TLINAL, DLINAL, PLINAL, DEN, PRESS, TEMP
real xmu, Z, EFFG, RHCH4, FH2, FARGON, ADEN, CH4SAT, DENF, DT
real SUMB, SUMT, TLAST, PCH4
integer NLEVEL, IPRINT, ITS, J
PARAMETER (NMAX=201)
DIMENSION CH4(1),H2(1),XN2(1),AR(1)
DIMENSION TLINAL(NMAX),DLINAL(NMAX),PLINAL(NMAX)
DIMENSION DEN(1), PRESS(1), TEMP(1), XMU(1)
请注意,此更改不会修复您的错误,因为我没有参考我的 crystal 球来确定 Z
和 EFFG
的尺寸。我所做的只是添加显式类型,古老的 g77 编译器(和固定形式的 gfortran)应该可以理解这些类型。另请注意,我在确定上面使用的显式类型时假设了默认隐式类型,如果它们不是您期望的类型,那么这是采用显式类型的更好理由。
我有几个“参数在 (1) 处是一种类型,但在 (2) 处是另一种类型”错误出现在我的程序中,但我不确定如何修改它。 除了我所做的,还有其他写论点的方法吗?
Ps。我在 g77 中编译。但我也在 gfortran 中尝试过,其中出现的错误是 "Rank mismatch in argument 'z' at (1) (scalar and rank-1)".
以下是出现的错误:
geomalb.f: In subroutine `atmsetup':
geomalb.f:1083:
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
1
geomalb.f:1122: (continued):
SUMT=SUMT+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*XMU(J)
2
Invalid declaration of or reference to symbol `z' at (2) [initially seen at (1)]
geomalb.f:80: warning:
COLDEN(J)=RHOP*(PRESS(J+1)-PRESS(J))/EFFG(Z(J))
1
geomalb.f:1122: (continued):
SUMT=SUMT+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*XMU(J)
2
Argument #1 of `effg' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
geomalb.f:80: warning:
COLDEN(J)=RHOP*(PRESS(J+1)-PRESS(J))/EFFG(Z(J))
1
geomalb.f:1124: (continued):
SUMB=SUMB+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*28.01340
2
Argument #1 of `effg' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
geomalb.f:72: warning:
CALL ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
1
geomalb.f:1083: (continued):
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
2
Argument #2 (named `z') of `atmsetup' is one type at (2) but is some other type at (1) [info -f g77 M GLOBALS]
部分节目:
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
PARAMETER (NMAX=201)
DIMENSION CH4(1),H2(1),XN2(1),AR(1)
DIMENSION TLINAL(NMAX),DLINAL(NMAX),PLINAL(NMAX)
DIMENSION DEN(1), PRESS(1), TEMP(1), XMU(1)
CALL LINDAL(NLEVEL,Z,TLINAL,DLINAL,PLINAL)
DO J=1,NLEVEL
TEMP(J)= TLINAL(J)
DEN(J)= DLINAL(J)
PRESS(J)=PLINAL(J)
ENDDO
DO 1000 ITS =1,20
CH4(NLEVEL)=PCH4(TEMP(NLEVEL))*RHCH4/PRESS(NLEVEL)
DO 134 J=NLEVEL-1,1,-1
CH4SAT=PCH4(TEMP(J))/PRESS(J)
CH4(J)=AMIN1(CH4SAT,CH4(NLEVEL),CH4(J+1))
134 CONTINUE
DO 20 J=1,NLEVEL
H2(J)=FH2
IF (FARGON .LT. 0.) THEN
AR(J)=(-FARGON-28.0134+25.8554*H2(J)+11.9708*CH4(J))/11.9346
ELSE
IF (FARGON .EQ. 0.) THEN
AR(J)=0.0
ELSE
AR(J)=FARGON
ENDIF
ENDIF
XN2(J)=1.0 - H2(J) - CH4(J) -AR(J)
XMU(J)=28.0134*XN2(J)+2.158*H2(J)+16.0426*CH4(J)+39.948*AR(J)
20 CONTINUE
SUMT=PLINAL(1)*6.02E23/10.
SUMB=SUMT
TLAST=TEMP(NLEVEL)
DO J=2,NLEVEL
DENF=294.1/(XN2(J)*294.1 + CH4(J)*410. + H2(J)*136. + AR(J)*277.8)
DEN(J) = DLINAL(J)*DENF
ADEN=(DEN(J)-DEN(J-1))/ALOG(DEN(J)/DEN(J-1))
SUMT=SUMT+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*XMU(J)
ADEN=(DLINAL(J)-DLINAL(J-1))/ALOG(DLINAL(J)/DLINAL(J-1))
SUMB=SUMB+(EFFG(Z(J))*ADEN)*( Z(J-1)-Z(J))*28.01340
PRESS(J)=PLINAL(J)*SUMT/SUMB
TEMP(J) =TLINAL(J)*(SUMT/SUMB)*(1./DENF)
ENDDO
30 CONTINUE
DT= ABS(TEMP(NLEVEL)-TLAST)
IF (DT .LT. 0.001) GO TO 1001
1000 CONTINUE
1001 IF (IPRINT .LT. 0) RETURN
WRITE (6,139)RHCH4,FH2,FARGON,DT
DO 135 J=1,NLEVEL-1
WRITE(6,140)J,Z(J),PRESS(J),DEN(J),TEMP(J),
& CH4(J)*PRESS(J)/PCH4(TEMP(J))
& ,CH4(J)*100.,XN2(J)*100.,H2(J)*100.,AR(J)*100.,XMU(J)
& ,(TEMP(J+1)-TEMP(J))/(Z(J+1)-Z(J))
135 CONTINUE
J=NLEVEL
WRITE(6,140)J,Z(J),PRESS(J),DEN(J),TEMP(J),
& CH4(J)*PRESS(J)/PCH4(TEMP(J))
& ,CH4(J)*100.,XN2(J)*100.,H2(J)*100.,AR(J)*100.,XMU(J)
139 FORMAT(///' BACKGROUNG ATMOSPHERE AT LEVELS'/
& ' SURFACE HUMIDITY OF CH4:',F5.3,' H2 MIXING RATIO:',F6.4,
& ' ARGON SETTING:',F8.4/' FINAL CONVERGENCE ON TEMP:',F10.5
& , ' LINDAL ET AL SCALING'/
&' LVL ALTITUDE P(BARS) DEN(CM-3) TEMP RH-CH4'
& , ' %CH4 %N2 %H2 %AR MU DT/DZ' )
140 FORMAT(1X,I3,F8.3,1P2E10.3,0PF7.2,F5.2,2F6.2,2F5.2,4F6.2)
RETURN
END SUBROUTINE
END
在程序的前面,我是这样调用子程序的:
CALL ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
您不为变量提供任何类型信息,而是依赖于隐式类型。在默认隐式类型规则下,您的变量 Z
和 EFFG
声明为:
real :: Z
real :: EFFG
Z
和 EFFG
都是 0 阶实变量(标量)。您通过以下方式引用这些变量
EFFG(Z(J))
这是排名不匹配。您将 Z
作为等级 1 变量访问,将 EFFG
作为等级 1 变量访问,但它们被隐式定义为等级 0 变量。
解决方法是将变量正确声明为等级 1 数组。在评论中,您注意到切换到 gfortran 将错误从一般 "types are different" 错误更改为特定 "rank mismatch"。这是一个更有帮助的错误消息,其他人已经注意到您应该能够(一旦您的问题全部解决)使用 gfortran 编译您的代码,而不会对 g77 编译的内容进行任何(或仅次要)更改。采用现代实践是值得的,一个简单的开始就是改变
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
PARAMETER (NMAX=201)
DIMENSION CH4(1),H2(1),XN2(1),AR(1)
DIMENSION TLINAL(NMAX),DLINAL(NMAX),PLINAL(NMAX)
DIMENSION DEN(1), PRESS(1), TEMP(1), XMU(1)
进入
SUBROUTINE ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
& CH4,H2,XN2,AR,IPRINT)
implicit none
integer NMAX
real CH4, H2, XN2, AR, TLINAL, DLINAL, PLINAL, DEN, PRESS, TEMP
real xmu, Z, EFFG, RHCH4, FH2, FARGON, ADEN, CH4SAT, DENF, DT
real SUMB, SUMT, TLAST, PCH4
integer NLEVEL, IPRINT, ITS, J
PARAMETER (NMAX=201)
DIMENSION CH4(1),H2(1),XN2(1),AR(1)
DIMENSION TLINAL(NMAX),DLINAL(NMAX),PLINAL(NMAX)
DIMENSION DEN(1), PRESS(1), TEMP(1), XMU(1)
请注意,此更改不会修复您的错误,因为我没有参考我的 crystal 球来确定 Z
和 EFFG
的尺寸。我所做的只是添加显式类型,古老的 g77 编译器(和固定形式的 gfortran)应该可以理解这些类型。另请注意,我在确定上面使用的显式类型时假设了默认隐式类型,如果它们不是您期望的类型,那么这是采用显式类型的更好理由。