Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

FORTRAN subroutine not running from VBA call

$
0
0

Hello, dear fellow developers!

Well, I have kind of a weird problem. I have a Module in FORTRAN with several subroutines, some of which are called from a Main and others that are called from other subroutines within the module. That worked really fine (amazing, I would say :) ). But I transformed my main into a subroutine and complied the project into a .dll so that I could call it from an Excel VBA macro... There isn't any problem with this part, until a subroutine calls another subroutine. More or less, the subroutines are:

SUBROUTINE FirstOne(VarX, VarY)

            REAL(DP), INTENT(IN),  DIMENSION(:) :: VarX

            REAL(DP) :: Var1[ALLOCATABLE](:),Var2[ALLOCATABLE](:)

            REAL(DP) ::Var3[ALLOCATABLE](:)

            INTEGER (KIND(1)) :: i

      

            ALLOCATE (VAR1(N), STAT=R)

                IF(R.NE.0) CALL some-other-subroutine

            ALLOCATE (VAR2(N) , STAT=R)  

                IF(R.NE.0) CALL some-other-subroutine

            ALLOCATE (VAR3(N) , STAT=IERROR)  

                IF(IERROR.NE.0) CALL some-other-subroutine

      !N is a global variable in the module, that indicates the length of the arrays troughout the program

       

            DO i=1,NC

                Var1(i)=0.D0

                Var2(i)=0.D0

                Var3(i)=0.D0

            END DO

      

            CALL SecondOne(Var1,Var2,Var3)

            DEALLOCATE(Var1 , STAT=R)

                IF(R.NE.0) CALL some-other-subroutine

            DEALLOCATE(Var2 , STAT=R)

                IF(R.NE.0) CALL some-other-subroutine

            DEALLOCATE(Var3 , STAT=R)     

                IF(R.NE.0) CALL some-other-subroutine

            RETURN

 END SUBROUTINE

SUBROUTINE SecondOne(Var1,Var2,Var3)

            REAL (DP), INTENT(OUT), DIMENSION(:) :: Var1,Var2,Var3

           DO i=1,N

                Var1(i)=Some Arithmetic Operation     <-----------------------Here is the problem... allegedly

                Var2(i)=Some Arithmetic Operation

                Var3(i)=Some Arithmetic Operation

            END DO

 

            RETURN

 END SUBROUTINE

And then I get "fortl: severe(408): fort: (2): Subscript #1 of the array Var1 has value 1 which is greater than the upper bound of 0"

I already tried writing Intent(inout), changing to dimension(N), transferring to other variables (Var12, Var22, Var32) and several combinations. As far as I know, I can't make it allocatable, but I'm not sure wether it's going to solve my problem

Please, my friends... Any suggestions? It worked before I linked it to Excel VBA


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>