Commit 5919f09d authored by ulrich_y's avatar ulrich_y
Browse files

Added mathlink interface

parent eeac56a6
......@@ -9,6 +9,9 @@
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
build/mcc*
build/*.c
gpl
*.out
*.o
*.mod
......
......@@ -31,6 +31,34 @@ build/%.o: src/%.f90
@echo "F90 $@"
@$(FC) $(FFLAGS) -c $< -J build -o $@
# Mathlink related
build/mcc.internals.tmp:
@echo "MCC --internals"
@$(MCC) --internals > $@
build/mcc.internals:build/mcc.internals.tmp
@echo "Base path" > $@
@cat $@.tmp | grep "MLDK Directory" | cut -f2 -d":" >> $@
@echo "Compiler" >> $@
@arch=`cat $@.tmp | grep "Library Bit Type:" | cut -f2 -d":"` ; \
cat $@.tmp | grep "Compile Flags$$arch:" | cut -f2 -d":" >> $@
@echo "Linker" >> $@
@cat $@.tmp | grep "Linker Libraries" | cut -f2 -d":" >> $@
build/%.tm.c: src/%.tm build/mcc.internals
@echo "MPREP $@"
@$(shell sed -n '2p' build/mcc.internals)/mprep $< -o $@
build/gpl.o: build/gpl.tm.c build/mcc.internals
@echo "CC $<"
@$(CC) $(shell sed -n '4p' build/mcc.internals) -o $@ -c $<
gpl: build/gpl.o libgpl.a build/mcc.internals
@echo "LD $@"
@$(LD) $< libgpl.a -o $@ $(shell sed -n '6p' build/mcc.internals) -lgfortran
eval: libgpl.a build/eval.o
@echo "LD $@"
@$(LD) -o $@ build/eval.o -L. -lgpl
......@@ -43,5 +71,5 @@ check: test
./$<
clean:
@rm -f build/*.o build/*.mod
@rm -f test eval
@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
@rm -f test eval libgpl.a gpl
:Begin:
:Function: gpl
:Pattern: G[a__]/;And @@ (NumberQ /@ ({a} /. SubPlus | SubMinus -> Identity))
:Arguments: {Re@N[{a}], Im@N[{a}]}
:ArgumentTypes: {RealList,RealList}
:ReturnType: Manual
:End:
#include "mathlink.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
typedef struct {double r,i;} complex;
extern complex __gpl_module_MOD_g_superflatn(complex*,long*);
void gpl(double * re, long nr, double * im, long ni)
{
assert(nr==ni);
complex input[nr], ans;
for(long i=0;i<nr;i++)
{
input[i].r = *(re+i);
input[i].i = *(im+i);
}
ans = __gpl_module_MOD_g_superflatn(&input[0],&nr);
if(ans.i == 0)
MLPutReal(stdlink, ans.r);
else
{
MLPutFunction(stdlink, "Complex", 2);
MLPutReal(stdlink, ans.r);
MLPutReal(stdlink, ans.i);
}
}
int main(int argc, char **argv)
{
return MLMain(argc, argv);
}
......@@ -445,5 +445,14 @@ CONTAINS
res = (-1)**k * MPL(m,x)
END FUNCTION G_condensed
FUNCTION G_SUPERFLATN(c0,n)
integer, intent(in) :: n
complex(kind=prec), intent(in) :: c0(n)
complex(kind=prec) g_superflatn
G_superflatn=G_superflat(c0)
END FUNCTION
END MODULE gpl_module
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment