18.8 Windows/Absoft Fortran 6.0

Making and using a DLL consists of three major steps

  1. Writing the Fortran code
  2. Generating the DLL
  3. Using DLL in XploRe


Let us consider a simple Fortran 77 program vecsum.f which sums up a vector:

C2345.7890123456789012345678901234567890123456789012345678901234567890
C
C
      function sum(x, nn, s)
      double precision nn,s
      double precision x(nn)
      integer i,n,sum
      n=int(nn)
      s=0.0

      do 10 i=0, n
         s=s+x(i)
10    continue

      sum=0
      return
      end


As a first step we create a project called vecsum.gui to generate a Windows DLL:

  1. copy vecsum.f to C:\vecsum
  2. start the Absoft Compiler Interface
  3. enter under Name the project name vecsum and under Location the directory C:\vecsum
  4. press OK
  5. choose under Target Type the radio button Dynamic-Link Library
  6. check in the registry card DLL the box Export All Routines and Data
  7. press OK
  8. get by the right mouse button the context menu and choose Add/Remove file(s)
  9. mark vecsum.f
  10. press Add and then Close


The second step consists of compiling the code:

  1. get again the context menu
  2. choose Build to compile the DLL


To use the DLL in XploRe requires the following simple steps.

  1. Define the vector x and initialize the result s

    x=1:10 s=0
    

  2. Open the DLL for use in XploRe

    h= 41992 dlopen ("vecsum.dll")


    Note that XploRe needs to be able to find this library. From XploRe you can set the path for DLLs by

    41995 setenv ("xpl4dll","/your_absolute_path_to_the_dll")


    Alternatively you can give the absolute path within the 41998 dlopen command.

  3. Call the function sum from the DLL for x

    42001 dlcall ("_sum",x, rows(x),s)


    As a result you should find s having the value 55 which is the sum for the numbers 1 to 10.