Annotation of OpenXM/src/Macaulay2/m2/curl.m2, Revision 1.2
1.2 ! takayama 1: ID=" $OpenXM: OpenXM/src/Macaulay2/m2/curl.m2,v 1.1 2015/08/19 02:31:25 takayama Exp $ "
1.1 takayama 2:
3: -- curl interface for M2
1.2 ! takayama 4: -- BSD license without advertisements
1.1 takayama 5:
6: curl = method()
7: curl(String,String) := (s,url) -> (
8: try (F := get ("!curl " | s | " " | url))
9: else ( error "Could not start curl " | s | " " | url);
10: F
11: )
12:
13: test1 = method()
14: test1(ZZ) := (ttype) -> (
15: ans1=
16: curl("--data 'oxMessageBody=fd_hessian2(-2,[-3,-2],10,[1/2,1/3])'",
17: "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-asir-r-fd2.sh");
18: print(ans1);
19: ans2=
20: curlPostMessage("oxMessageBody=fd_hessian2(-2,[-3,-2],10,[1/2,1/3])",
21: "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-asir-r-fd2.sh");
22: ans2
23: )
24:
25: -- --data-urlencode should be used for new curl.
26: curlPostMessage = method()
27: curlPostMessage(String,String) := (data,url) -> (
28: curl("--data " | "'" | data | "'", url)
29: )
30:
1.2 ! takayama 31: ----------------------------------------------
! 32: -- Sample interface for cgi-asir.
! 33: ---------------------------------------------
1.1 takayama 34: -- Translate list expressions among asir and M2
35: asir2m2 = method()
36: asir2m2(String):= (s) -> (
37: s2=replace("\\[","{",s);
38: replace("\\]","}",s2)
39: )
40: m22asir = method()
41: m22asir(String):= (s) -> (
42: s2=replace("\\{","[",s);
43: replace("\\}","]",s2)
44: )
45:
46: -- Example: fdHessian2(-2,{-3,-2},10,{1/2,1/3})
47: fdHessian2 = method()
48: fdHessian2(ZZ,List,ZZ,List):= (a,b,c,x) -> (
49: strategy = "asir2-cgi";
50: url = "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-asir-r-fd2.sh";
51: if (strategy == "asir2-cgi") then (
52: s = toString(a) | "," | m22asir(toString(b)) | "," |
53: toString(c) | "," | m22asir(toString(x));
54: s = "oxMessageBody=fd_hessian2(" | s | ")";
55: ans = curlPostMessage(s,url);
56: if (match("error",ans)) then error(ans);
57: h=value(asir2m2(ans));
58: );
1.2 ! takayama 59: {h,ans}
1.1 takayama 60: )
61:
1.2 ! takayama 62: -- s should be in the polynomial ring.
! 63: -- example: QQ[s,x,y,dx,dy,WeylAlgebra=>{x=>dx,y=>dy}]
! 64: -- genericBfct({x*dx+y*dy-3,x*dx-y*dy},{x,y},{dx,dy},{1,1})
! 65: genericBfct = method()
! 66: genericBfct(List,List,List,List):= (ideal,xvar,dvar,w) -> (
! 67: strategy = "asir2-cgi";
! 68: url = "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-generic_bfct2.sh";
! 69: if (strategy == "asir2-cgi") then (
! 70: ss = m22asir(toString(ideal)) | "," | m22asir(toString(xvar)) | "," |
! 71: m22asir(toString(dvar)) | "," | m22asir(toString(w));
! 72: ss = "oxMessageBody=generic_bfct(" | ss | ")";
! 73: ans = curlPostMessage(ss,url);
! 74: if (match("error",ans)) then error(ans);
! 75: h=value(asir2m2(ans));
! 76: );
! 77: {h,ans}
! 78: )
! 79:
! 80: genericBfct(Ideal,List,List,List):= (ideal,xvar,dvar,w) -> (
! 81: genericBfct(flatten(entries(gens(ideal))),xvar,dvar,w)
! 82: )
! 83: -- todo. Extract xvar,dvar. vars ring I
! 84:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>