-1

I'm making a function call to a fortran subroutine:

CALL EGFpar(T_e,X_e,Y_e,cpi(1:nx,1:Nspec),WEG,IWEG)

Here IWEG is initialized with integer values in an initialization routine. IWEG and WEG are declared in an include file:

  INTEGER  LIWEGmax, LWEGMAX
  PARAMETER (LIWEGmax=400, LWEGMAX=6000000)
  INTEGER IWEG(LIWEGmax)
  DOUBLE PRECISION WEG(LWEGmax)
  COMMON/EGINI/    IWEG, WEG

While debugging with VSCode, I can see the values I have initialized it with. However, when I step into EGFpar, all the passed arrays have their initialized values except IWEG. IWEG has nothing. Not zeros, but just blank. The subroutine EGFpar is given below

C-----------------------------------------------------------------------
      SUBROUTINE EGFPAR ( NP, T, X, Y, CP, WEG, IWEG )
C-----------------------------------------------------------------------
C
C     This subroutine initializes the thermomolecular
C     parameters that are needed in order to evaluate
C     the transport linear systems.
C     The parameters that have to be evaluated depend on the transport
C     coefficients that will be subsequently computed, as indicated
C     by JFLAG. This flag has been initialized when calling EGINI.
C
C     Input
C     -----
C        NP           number of nodes
C        T(NP)        temperature
C        X(NP,NS)     species mole fractions
C        Y(NP,NS)     species mass fractions
C        CP(NP,NS)    species heat capacities at constant pressure
C                     per unit mass
C        WEG          double precision work array for EGLIB
C        IWEG         integer work array for EGLIB
C
C-----------------------------------------------------------------------
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      DIMENSION WEG(*), IWEG(*)
C-----------------------------------------------------------------------
      INCLUDE 'eg.cmn'
C-----------------------------------------------------------------------
      CALL LFPAR ( NP, JFLAG, WEG(IEGPA), 
     &       T, WEG(IDLT1), WEG(IDLT2), WEG(IDLT3), 
     &       WEG(IDLT4), WEG(IDLT5), WEG(IDLT6),
     &       WEG(IEGRU), NS, WEG(IAAA), WEG(IBBB),
     &       WEG(IEGWT), WEG(IBIN), WEG(IETA), 
     &       WEG(IETALG), WEG(ICTAIJ), WEG(IFITA), 
     &       WEG(ICINT), CP, WEG(ICXI), 
     &       WEG(IEPSIJ), WEG(IEGEPS), WEG(IEGCFD), WEG(IEGCFE), 
     &       WEG(IEGZRT), WEG(IEGDIP), IWEG(IEGLIN) )
C-----------------------------------------------------------------------
      CALL EGFXY ( NP, NS, WEG(IXTR), WEG(IYTR), WEG(IAUX), X, Y )
C-----------------------------------------------------------------------
      RETURN
      END

What is going wrong here?

  • 1
    I think we need more information. What is the actual code you get? How exactly does the initialization code look like? We need to see the declaration of all your variables. See [mcve]. Especially `WEG` and `IWEG`. What is in the include file? – Vladimir F Героям слава Jan 11 '21 at 08:49
  • The initialization routine is quite large. However, my question is why an array that has values suddenly loses data when it enters that subroutine. IWEG and WEG are initialized in an include file. – random_dude Jan 11 '21 at 09:19
  • 1
    In your first line above `CALL EGFpar(T_e,X_e,Y_e...` is it just a typo or did you not supply the argument `NP`? – jack Jan 11 '21 at 09:31
  • OMG, that was stupid. Thanks for picking that up jack. I cant mark your comment as the accepted answer – random_dude Jan 11 '21 at 09:32
  • 1
    Another example of why you should have an interface in scope when you call a subprogram ... – Ian Bush Jan 11 '21 at 09:36

1 Answers1

0

The subroutine call

CALL EGFpar(T_e,X_e,Y_e,cpi(1:nx,1:Nspec),WEG,IWEG)

misses its first integer argument NP and should rather be

CALL EGFpar(NP, T_e,X_e,Y_e,cpi(1:nx,1:Nspec),WEG,IWEG)

This error could have been captured by the compiler if you would had an explicit interface. This can be done in various ways:

  • manually defining an interface block
  • in modern Fortran by placing the procedure in a module
  • placing the procedure in a contains section (e.g. sub-program, sub-subroutine)

Check out this answer for more in-depth info about explicit interfaces.

jack
  • 1,658
  • 1
  • 7
  • 18