我有一些“参数是(1)中的一种类型,但在我的程序中会出现(2)错误的其他类型,但我不确定如何修改它。 是否有其他方式来编写论证而不是我所做的?
聚苯乙烯。我在g77中编译。但我也试过gfortran,其中出现的错误是“在(1)(标量和等级-1)中参数'z'中的排名不匹配”。
以下是出现的错误:
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)
答案 0 :(得分:2)
您没有为变量提供任何类型信息,而是依赖于隐式类型。在默认的隐式类型规则下,您的变量Z
和EFFG
被声明为:
real :: Z
real :: EFFG
Z
和EFFG
都是0级(标量)的实变量。您可以通过以下方式引用这些变量
EFFG(Z(J))
这是排名不匹配。您将Z
作为排名1变量访问,EFFG
作为排名1变量,但它们被隐式定义为排名0变量。
修复方法是将变量正确声明为rank 1数组。在注释中,您注意到切换到gfortran会将错误从通用的“类型不同”错误更改为特定的“排名不匹配”。这是一个更有用的错误消息,其他人已经注意到你应该能够(一旦你的问题都修复了)用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)
请注意,此更改不会修复您的错误,因为我没有咨询我的水晶球以确定Z
和EFFG
的尺寸。我所做的只是添加显式类型,古代g77编译器(以及固定格式的gfortran)应该理解这些类型。另请注意,我在确定上面使用的显式类型时假设了默认的隐式类型,如果它们不是您所期望的那样,那么这是采用显式类型的更好理由。