18.7 SUN Solaris/Fortran 77

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


The function SUN Solaris/Fortran 77 can be compiled to a shared library for instance with the SUN Fortran-Compiler

 f77 -G -o vecsum.so vecsum.f


from the Unix shell prompt.


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= 41896 dlopen ("vecsum.so")


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

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


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

  3. Call the function sum from the DLL for x

    41905 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.