Fortran issue: Argument of "xx" is one type at (2) but is some other type at (1)

332 views Asked by At

I have a few "Argument is one type at (1) but is some other type at (2) errors coming up in my program, but I'm not sure how to modify it. Is there some other way of writing the arguments than what I've done?

Ps. I compile in g77. But I also tried in gfortran, where the error that comes up is of the kind "Rank mismatch in argument 'z' at (1) (scalar and rank-1)".

Here are the errors coming up:

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]

Part of the program:

      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

And earlier in the program this is how I call the subroutine:

      CALL ATMSETUP(NLEVEL,Z,RHCH4,FH2,FARGON,TEMP,PRESS,DEN,XMU,
     & CH4,H2,XN2,AR,IPRINT)
1

There are 1 answers

0
casey On BEST ANSWER

You do not provide any type information for your variables and instead rely on implicit typing. Under default implicit typing rules, your variables Z and EFFG are declared as:

real :: Z
real :: EFFG

Both Z and EFFG are real variables of rank 0 (scalar). You reference these variables in the following way

EFFG(Z(J))

This is a rank mismatch. You access Z as a rank 1 variable and EFFG as a rank 1 variable, but they were implicitly defined as rank 0 variables.

The fix is to properly declare the variables as rank 1 arrays. In the comments you note that switching to gfortran changed the error from a generic "types are different" error into a specific "rank mismatch". This is a much more helpful error message, and others have noted you should be able (once your issues are all fixed) to compile your code with gfortran with no (or only minor) changes over what g77 compiles. It is worthwhile to adopt modern practices and a simple start would be to change

       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)

into

       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)

Note that this change will not fix your error, as I have not consulted my crystal ball to determine the dimensions of Z and EFFG. All I have done is add explicit types, which should be understood by the ancient g77 compiler (and gfortran in fixed-form). Also note I've assumed default implicit types in determining the explicit types used above, and if they are not what you expected them to be then that is an even better reason to adopt explicit typing.