Hi
I am using the dsplp subroutine  (Linear Programming) from LINPACK. It is 
also in FORTRAN and I made a simple interface to use it in Julia. Although 
the data format used internally by the dsplp subroutine is diferent, I made 
the following function in julia to emulate the linpro package from Scilab 
(without the equality constraint, but it can be changed).

The julia function is 

<script 
src="https://gist.github.com/anonymous/9e4bcda40a5e66f9f104.js";></script>

and the fortran subroutine is 

<script 
src="https://gist.github.com/CodeLenz/223f3efe4b9e386059e2.js";></script>

To generate the .so, I use this fortran subroutine and some of the fortran 
functions from LINPACK;

The usage is simple like this

function Linpro_Test()

# Min 2x[1] + 3x[2]
# S.T 
#         -x[1] - x[2] <= -1.0
#
#       0<= x[1] <= 5
#       0<= x[2] <= 5
#
# Solution x = [1,0]

  n = 2
  m = 1
  p = [2.0, 3.0]
  C = [-1.0 -1.0]
  b = [-1.0]
  ci = [0.0 , 0.0]
  cs = [5.0 , 5.0]

  x,lagr,info = Linpro_Slatec(n,m,p,C,b,ci,cs)

  println("\n Result ",x)
  println("\n Lagr      ",lagr)
  println("\n Info      ",info)

end



On Saturday, May 30, 2015 at 10:52:03 PM UTC-3, Jiahao Chen wrote:
>
> It would be great if you could clean up your example and add it to the 
> documentation.
>
> Thanks,
>
> Jiahao Chen
> Research Scientist
> MIT CSAIL
>
> On Sun, May 31, 2015 at 3:17 AM, Andre Bieler <[email protected] 
> <javascript:>> wrote:
>
>> Ok so I have a few simple examples working for ccalling fortran functions 
>> and subroutines from Julia.
>> Maybe someone will find this useful examples when first looking into 
>> calling fortran from julia.
>>
>> compile the following fortran mod
>> ```
>> !fileName = simplemodule.f95
>> module simpleModule
>>
>> implicit none
>>
>> contains
>> function foo(x)
>>   integer :: foo, x
>>   foo = x * 2
>> end function foo
>>
>> subroutine bar(x, a, b)
>>   integer, intent(in) :: x
>>   integer, intent(out) :: a, b
>>   
>>   a = x + 3
>>   b = x * 3
>> end subroutine bar
>>
>> subroutine keg(x, a, b)
>>   real*8, intent(in) :: x
>>   real*8, intent(out) :: a, b
>>   
>>   a = x + 3.0
>>   b = x * 3.0
>> end subroutine keg
>>
>> subroutine ruf(x, y)
>>   real*8, dimension(3), intent(in) :: x
>>   real*8, dimension(3), intent(out) :: y
>>   integer :: i
>>   
>>   DO i = 1, 3
>>     y(i) = 2*x(i)
>>   END DO
>> end subroutine ruf
>>
>> end module simplemodule
>> ```
>>
>
>

Reply via email to