Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

To Compile and Run multiple Fortran codes in VS2013

Yadav__Geetanjali
1,761 Views

Hi,

I have 6 Fortran Subroutines named:

1. LU.f90
2. IDENTITY.f90
3. JACOBIAN.f90
4. BROY.f90
5. TR.f90
6. USER2.f90

The last one (USER2.f90) is the final one where all other subroutines have been called in one or other. I need to compile all of them and run the code. I compiled them in the Command prompt window using Intel (R) 64 Visual Studio 2013.

I DID THIS>          ifort LU.f90 IDENTITY.f90 JACOBIAN.f90 BROY.f90 TR.f90 USER2.f90 <enter>

This created the .obj files. I need to know the next steps to Run the code. Please help me.

Also, there is a message that comes when I compile the codes: error LNK2019: unresolved external symbol MAIN__ referenced in function main.

Please help me how to resolve this issue.  It's urgent but I am stuck at this step. Your help would be highly appreciated.

Thanks
Geetanjali

0 Kudos
10 Replies
Steve_Lionel
Honored Contributor III
1,761 Views

Please attach a copy of USER2.f90. What you have done should work, but none of the sources you compiled contain a Fortran main program. You can't run a collection of subroutines - there needs to be a main program (which is not a subroutine, function, module or BLOCK DATA subprogram) that calls one or more subroutines/functions.

If USER2.f90 is just a subroutine with no arguments that starts the process going, then you may be able to resolve it by simply removing the SUBROUTINE statement from that file.

I also recommend that you put the file with the main program first in the list of sources, as it will be used to name the executable.

0 Kudos
Yadav__Geetanjali
1,761 Views

Hi Steve,

The USER2.f90 has the following:

 

      SUBROUTINE USER2 (NMATI,  MSIN,    NINFI,   SINFI,  NMATO,& 
                 SOUT,   NINFO,  SINFO,   IDSMI,  IDSII,&
                 IDSMO,  IDSIO,  NTOT, NSUBS,  IDXSUB,&
                 ITYPE,  NINT,   INT,     NREAL,  REALs,&
                 IDS,    NPO,    NBOPST1,  NIWORK, IWORK,&
                 NWORK,  WORK,   NSIZE,   SIZE,   INTSIZ,&
                  LD)
 
!     This subroutine is a kinetic reactor for the transesterification of
!     triglycerides to FAME and calculation of phase equilibrium
      
!     This version of USER2 is for a block with one inlet stream
!     and one outlet stream.  Eventually, after the FLSH3 subroutine is 
!     used two additional outlet streams will be added.  Then the six species 
!     flow rates that solve the six mass balances (computed by BROY)
!     will be input to FLSH3 to obtain the species flow rates of the 
!     V, LI, and LII streams
 
      IMPLICIT NONE
      
!      #include "ppexec_user.cmn"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
      EXTERNAL :: TR
      
     !Declare variables
      INTEGER NMATI, NINFI, NMATO, NINFO, NTOT,&
              NSUBS, NINT,  NPO,   NIWORK,NWORK,&
              NSIZE
 
      INTEGER IDSMI(2,NMATI), IDSII(2,NINFI),&
              IDSMO(2,NMATO), IDSIO(2,NINFO),&
              IDXSUB(NSUBS),ITYPE(NSUBS), INT(NINT),&
              IDS(2,3), NBOPST1(6,NPO), NBOPST(6,NPO),&
              IWORK(NIWORK),INTSIZ(NSIZE),NREAL, LD
     
      REAL*8 MSIN(NTOT,NMATI), SINFI(NINFI),&
             SOUT(NTOT,NMATO),  SINFO(NINFO),&
             WORK(NWORK),  SIZE(NSIZE)
     REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: INSAVE
     REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: FAKE_ARRAY
      REAL*8, DIMENSION(:,:), ALLOCATABLE :: SOUT2
     
     !Declare Local Variables
      INTEGER, PARAMETER :: nvec = 7
      INTEGER  i, j,  jmax, imax, errors, n, counter, PHASES(3)
      INTEGER  DMS_KFORMC
      PARAMETER(jmax = 6)
      PARAMETER(imax = 3)
      INTEGER :: DMS_IFCMNC
      INTEGER, DIMENSION(nvec) :: NANTEST
      
      REAL*8, PARAMETER :: tol = 1E-03
      REAL*8 F(jmax)          
      REAL*8 FRES(jmax)
      REAL*8 FRES_new
      REAL*8 :: REALs(NREAL)
      
     !Take flow rates of feed stream to USER2 block
                                                                                                                                
      
     !Solves mass balances and residuals using TR and BROY
 
      counter = 0
 
      DO     
      CALL BROY(F, tol, nvec, TR)
              DO j = 1, (nvec)
              NANTEST(j) = ISNAN(F(j))     !Check this for F
              END DO
 
         IF (MINVAL(F) .GT. 0.0D0) THEN
            IF (MAXVAL(F) .LT. 1.0D3) THEN
              IF ((MAXVAL(NANTEST)) .EQ. 0) THEN
                 EXIT
              END IF
            END IF
         END IF
 
        IF (counter .GE. 100) THEN
    F(1:(nvec-1)) = F(j)                   !Check for F subscripts
            WRITE(*,*) 'Convergence Error'
 
            EXIT
        END IF
      counter = counter + 1    
      END DO
 
      WRITE(*,*) '      '
      WRITE(*,*) 'Post-Broyden Analysis'
      WRITE(*,*) '      '
      WRITE(*,*) 'Outlet vector is'
      DO j = 1, nvec
      WRITE(*,*) F(j)
      END DO
      WRITE(*,*) '      '
 
    
 
!      Add FLSH3 here
    
!      CALL FLSH3 (MSIN(:,1), SOUT, NTOT, NSUBS, 
!                       IDXSUB, ITYPE, NBOPST(:,1),ISTAT)
       
 
!      IF (ISTAT .NE. 0) THEN
 !     WRITE(MAXWRT_MAXBUF,*) 'FLASH calculation failed'
  !    CALL DMS_WRTTRM(1)
  !    END IF
 
   !   SOUT_SAVE = SOUT
 
  !    phases = 0
   !   phases(1) = 1
      
  !    IF((F(last iteration) - F(this iteration))/F(last iteration)) .LE. tol
    
  !     EXIT
      
       WRITE(*,*)"No Errors"
 
      STOP
      END SUBROUTINE USER2
 
 
 
Thanks
0 Kudos
Yadav__Geetanjali
1,761 Views

As far as creating a main program is concerned, how should I create one. 

 

Should I just create a Program named MAIN

PROGRAM Main

IMPLICIT NONE

Call USER2

 

END PROGRAM

 

Would this work?

 

Thakns

0 Kudos
Yadav__Geetanjali
1,761 Views

Hi Steve, 

 

I made a slight change in USER2. I renamed it from Subroutine User2 to Program USER2 and I compiled.

It compiled successfully creating the .obj files. (attaching the screenshot). Please guide me the next steps to run the code.

 

Thanks

Geetanjali

0 Kudos
Steve_Lionel
Honored Contributor III
1,761 Views

LU.exe is your executable. As I wrote earlier, the default is to name the executable after the first file listed in the build command. This is why I suggested putting USER2.f90 first in the list. As an alternative, you could add

/EXE:USER2.exe

to the ifort command you used to do the build.

Your suggested edit in post 4 would almost have worked, except that the END statement should not include the keyword PROGRAM. You could use just "END" or "END Main".

0 Kudos
Yadav__Geetanjali
1,761 Views

Hi Steve,

As you suggested, I placed USER2.f90 in the front like this:

ifort USER2.f90 LU.f90 IDENTITY.f90 JACOBIAN.f90 BROY.f90 TR.f90

It gave me USER2.exe too. attaching for you the screenshots.

 

What should I do next to run the code?

0 Kudos
Steve_Lionel
Honored Contributor III
1,761 Views

Just type "user2.exe" (without the quotes) at that command prompt.

0 Kudos
Yadav__Geetanjali
1,761 Views

I did that and obtained the screenshot attached. 

What should I expect now?

 

Thanks

0 Kudos
gib
New Contributor II
1,761 Views

You have a programming error, probably an array index is going outside of the dimension range.  I suggest you recompile all the source files with these two options added to the command:

/traceback /check:all

When you run the rebuilt program this should tell you where the error occurs.

0 Kudos
Steve_Lionel
Honored Contributor III
1,761 Views

I also suggest adding /warn:interface to the ifort command in addition to what gib suggested. This may reveal other errors.

It may be that you need to learn how to build and debug the application within Visual Studio. The documentation has a "Getting Started" section to lead you through this.

0 Kudos
Reply