Contents - Index


Example .FDL External Procedure in FORTRAN

 

Creating an external procedure with Digital Visual FORTRAN 6.5 or other FORTRAN compilers is most easily done within the Microsoft Developer Studio environment or other similar products. Click here to see how a FORTRAN External DLL can be written using the open source GNU Compiler Collection.   

 

A new project workspace is selected as a Dynamic Link Library.  The FORTRAN sources file(s) are inserted into the workspace and compiled with the standard options.  Note that the two !DEC$ATTRIBUTES directives should be included in the main program, as noted above. The output filename in the Link settings should be set to MYPROC.FDL where MYPROC is the name that will be used in the EES Call statement.  Alternatively, the default filename MYPROC.DLL should be changed to MYPROC.FDL after building the dynamic link library project.

 

The simple FORTRAN program listed below provides the product, dividend, sum, and difference of two input values.  This program should provide a model for writing EES procedures in FORTRAN.  The code for the GCC compiler differs slightly.

 

Listing of the FORTRAN MDASF Program

 

       SUBROUTINE MDASF(S,MODE,NINPUTS,INPUTS,NOUTPUTS,OUTPUTS)

C.  The following two lines are specific to Digital Visual Fortran 5 and Compaq Fortran Compilers

         !DEC$ATTRIBUTES ALIAS:'MDASF' :: MDASF

         !DEC$ATTRIBUTES DLLEXPORT :: MDASF

       INTEGER(4) MODE, NINPUTS, NOUTPUTS

       REAL(8) INPUTS(50), OUTPUTS(50)

       CHARACTER(255) S

C.

       IF (MODE.EQ.-1) GOTO 900

       IF (NINPUTS.NE.2) GOTO 100

       IF (NOUTPUTS.NE.4) GOTO 200

C.  DO CALCULATIONS

       X=INPUTS(1)

       Y=INPUTS(2)

       IF (ABS(Y).LE.1E-9) GOTO 300

       OUTPUTS(1)=X*Y

       OUTPUTS(2)=X/Y

       OUTPUTS(3)=X+Y

       OUTPUTS(4)=X-Y

       MODE=0

       S=''C

       RETURN

100    CONTINUE

C.  ERROR:  THE NUMBER OF INPUTS ISN'T WHAT THIS SUBROUTINE EXPECTS

C.  NOTE: SET MODE>0 IF AN ERROR IS DETECTED.  IF S IS EQUAL TO A

C.  NULL STRING, THEN EES WILL DISPLAY THE MODE NUMBER IN AN ERROR

C.  MESSAGE.  IF S IS DEFINED, EES WILL DISPLAY THE STRING IN THE

C.  ERROR MESSAGE.  THE C AT THE END OF THE STRING INDICATES C-STYLE

C.  S='MDASF REQUIRES 2 INPUTS'C

       MODE=1

       RETURN

200    CONTINUE

       S='MDASF EXPECTS TO PROVIDE 4 OUTPUTS'C

       MODE=2

       RETURN

300    CONTINUE

       S='DIVISION BY ZERO IN MDASF'C

       MODE=3

       RETURN

900    CONTINUE

C.  PROVIDE AN EXAMPLE OF THE CALLING FORMAT WHEN MODE=-1

       S='CALL MDASF(X,Y:A,B,C,D)'C

       RETURN

       END

 

The following statement in an EES program will call this file.

 

CALL MDASF(X,Y : M, D, A, S)