(*^

::[paletteColors = 128; 
	fontset = title, "New York", 24, L3, center, bold, nohscroll;
	fontset = subtitle, "New York", 18, L2, center, bold, nohscroll;
	fontset = subsubtitle, "New York", 14, L2, center, bold, nohscroll;
	fontset = section, "New York", 14, L2, bold, nohscroll, grayBox;
	fontset = subsection, "New York", 12, L2, bold, nohscroll, blackBox;
	fontset = subsubsection, "New York", 10, L2, bold, nohscroll, whiteBox;
	fontset = text, "New York", 10, L2, nohscroll;
	fontset = smalltext, "New York", 9, L2, nohscroll;
	fontset = input, "Courier", 10, L2, bold, nowordwrap;
	fontset = output, "Courier", 10, L2, nowordwrap;
	fontset = message, "Courier", 10, L2, R65535, nowordwrap;
	fontset = print, "Courier", 10, L2, nowordwrap;
	fontset = info, "Courier", 10, L2, nowordwrap;
	fontset = postscript, "Courier", 12, L2, nowordwrap;
	fontset = name, "Geneva", 10, L2, italic, B65535, nowordwrap, nohscroll;
	fontset = header, "Times", 10, L2;
	fontset = footer, "Times", 12, L2, center;
	fontset = help, "Geneva", 10, L2, nohscroll;
	fontset = clipboard, "New York", 12, L2;
	fontset = completions, "New York", 12, L2, nowordwrap;
	fontset = network, "Courier", 10, L2, nowordwrap;
	fontset = graphlabel, "Courier", 12, L2, nowordwrap;
	fontset = special1, "New York", 12, L2, nowordwrap;
	fontset = special2, "New York", 12, L2, center, nowordwrap;
	fontset = special3, "New York", 12, L2, right, nowordwrap;
	fontset = special4, "New York", 12, L2, nowordwrap;
	fontset = special5, "New York", 12, L2, nowordwrap;]
:[font = input; ]
(* before this we have run the file FortranDef.m *)
:[font = input; startGroup; ]
?FortranDef
:[font = info; inactive; endGroup; ]
FortranDef[fn,expr,parlist,{opts}] takes expr, creates a corresponding Fortran
   program,   compiles it and defines fn[parlist] so that it calls that
   program. Use VariableType ->    "complex" if your function contains complex
   numbers.
:[font = input; startGroup; ]
(* Let's define a complicated function f:*)
f[k0_,x_,y_] = D[ Exp[-I k0 Sqrt[x^2+y^2]],{x,4},{y,4}];

(* Then the same function with Fortran:*)
Clear[Ff];
FortranDef[Ff,f[k0,x,y],{k0_,x_,y_},VariableType->"complex*16"];
:[font = print; inactive; endGroup; ]

:[font = input; startGroup; ]
f[0.23,54.,34.]  (* this is the Mathematica function *)
:[font = output; inactive; output; endGroup; ]
-(1.660300910198964*10^-7) - 3.087544567735867*10^-7*I
;[o]
          -7             -7
-1.6603 10   - 3.08754 10   I
:[font = input; startGroup; ]
Ff[0.23,54.,34.]  (* and this calls the Fortran version *)
:[font = output; inactive; output; endGroup; ]
-(1.6603009101989165*10^-7) - 3.0875445677358941*10^-7*I
;[o]
                      -7                        -7
-1.6603009101989165 10   - 3.0875445677358941 10   I
:[font = input; ]
(* Some test data *)
inps = Table[{k0,23.54,34.},{k0,0.1,0.9,0.01}];
:[font = input; startGroup; ]
(* This calls the Fortran program for each entry:*)
Timing[ Ffres = ((Ff @@ #)& /@ inps); ]
:[font = output; inactive; output; endGroup; ]
{6.97*Second, Null}
;[o]
{6.97 Second, Null}
:[font = input; startGroup; ]
(* And this calls the Fortran code only once for the whole list:*)
Timing[ Fres = MultiEval[Ff,inps]; ]
:[font = output; inactive; output; endGroup; ]
{3.41*Second, Null}
;[o]
{3.41 Second, Null}
:[font = input; startGroup; ]
(* For comparison, we do the same with Mathematica version: *)
Timing[ res = ((f @@ #)& /@ inps); ]
:[font = output; inactive; output; endGroup; ]
{52.18*Second, Null}
;[o]
{52.18 Second, Null}
:[font = input; startGroup; ]
(* Verify MultiEval result and Mathematica result:*)
Max[Table[ Abs[(res[[i]] - Fres[[i]])/res[[i]]], {i,1,Length[inps]}]]
:[font = output; inactive; output; endGroup; ]
1.14355601322054*10^-12
;[o]
          -12
1.14356 10
:[font = input; startGroup; ]
(* Verify Ff result and Mathematica result:*)
Max[Table[ Abs[(res[[i]] - Ffres[[i]])/res[[i]]], {i,1,Length[inps]}]]
:[font = output; inactive; output; endGroup; ]
1.14355601322054*10^-12
;[o]
          -12
1.14356 10
:[font = input; startGroup; ]
Plot[Re[Ff[k0,10.3,40.3]],{k0,0.1,0.9}]
:[font = postscript; inactive; PostScript; output; pictureWidth = 452; pictureHeight = 279; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 0.61803 
MathPictureStart
% Scaling calculations
0.02381 1.0582 0.33615 351.938 [
[(0.2)] 0.23545 0.32365 0 1 Msboxa
[(0.4)] 0.44709 0.32365 0 1 Msboxa
[(0.6)] 0.65873 0.32365 0 1 Msboxa
[(0.8)] 0.87037 0.32365 0 1 Msboxa
[(-0.00075)] 0.01131 0.07219 1 0 Msboxa
[(-0.0005)] 0.01131 0.16018 1 0 Msboxa
[(-0.00025)] 0.01131 0.24816 1 0 Msboxa
[(0.00025)] 0.01131 0.42413 1 0 Msboxa
[(0.0005)] 0.01131 0.51211 1 0 Msboxa
[(0.00075)] 0.01131 0.6001 1 0 Msboxa
[ -0.001 -0.001 0 0 ]
[ 1.001 0.61903 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
0.002 setlinewidth
0 0.33615 moveto
1 0.33615 lineto
stroke
0.23545 0.3299 moveto
0.23545 0.3424 lineto
stroke
0 setgray
[(0.2)] 0.23545 0.32365 0 1 Mshowa
0.44709 0.3299 moveto
0.44709 0.3424 lineto
stroke
0 setgray
[(0.4)] 0.44709 0.32365 0 1 Mshowa
0.65873 0.3299 moveto
0.65873 0.3424 lineto
stroke
0 setgray
[(0.6)] 0.65873 0.32365 0 1 Mshowa
0.87037 0.3299 moveto
0.87037 0.3424 lineto
stroke
0 setgray
[(0.8)] 0.87037 0.32365 0 1 Mshowa
0.02381 0 moveto
0.02381 0.61803 lineto
stroke
0.01756 0.07219 moveto
0.03006 0.07219 lineto
stroke
0 setgray
[(-0.00075)] 0.01131 0.07219 1 0 Mshowa
0.01756 0.16018 moveto
0.03006 0.16018 lineto
stroke
0 setgray
[(-0.0005)] 0.01131 0.16018 1 0 Mshowa
0.01756 0.24816 moveto
0.03006 0.24816 lineto
stroke
0 setgray
[(-0.00025)] 0.01131 0.24816 1 0 Mshowa
0.01756 0.42413 moveto
0.03006 0.42413 lineto
stroke
0 setgray
[(0.00025)] 0.01131 0.42413 1 0 Mshowa
0.01756 0.51211 moveto
0.03006 0.51211 lineto
stroke
0 setgray
[(0.0005)] 0.01131 0.51211 1 0 Mshowa
0.01756 0.6001 moveto
0.03006 0.6001 lineto
stroke
0 setgray
[(0.00075)] 0.01131 0.6001 1 0 Mshowa
grestore
grestore
0 0 moveto
1 0 lineto
1 0.618034 lineto
0 0.618034 lineto
closepath
clip
newpath
0 setgray
gsave
gsave
0.004 setlinewidth
0.12963 0.33615 moveto
0.13845 0.33615 lineto
0.14727 0.33615 lineto
0.14947 0.33614 lineto
0.15168 0.33614 lineto
0.15388 0.33614 lineto
0.15498 0.33614 lineto
0.15608 0.33614 lineto
0.15719 0.33614 lineto
0.15829 0.33614 lineto
0.15939 0.33614 lineto
0.16049 0.33614 lineto
0.1616 0.33614 lineto
0.1627 0.33614 lineto
0.1638 0.33614 lineto
0.1649 0.33614 lineto
0.20018 0.33615 lineto
0.20899 0.33615 lineto
0.2134 0.33615 lineto
0.21781 0.33616 lineto
0.22002 0.33616 lineto
0.22222 0.33616 lineto
0.22332 0.33616 lineto
0.22443 0.33616 lineto
0.22553 0.33616 lineto
0.22663 0.33616 lineto
0.22773 0.33616 lineto
0.22884 0.33616 lineto
0.22994 0.33616 lineto
0.23104 0.33616 lineto
0.23214 0.33616 lineto
0.23325 0.33616 lineto
0.23435 0.33616 lineto
0.23545 0.33616 lineto
0.23765 0.33616 lineto
0.23986 0.33615 lineto
0.24206 0.33615 lineto
0.24427 0.33615 lineto
0.24868 0.33615 lineto
0.25309 0.33614 lineto
0.2575 0.33613 lineto
0.2619 0.33612 lineto
0.27072 0.3361 lineto
0.27954 0.33607 lineto
0.28836 0.33603 lineto
0.29277 0.33602 lineto
0.29497 0.33601 lineto
0.29718 0.33601 lineto
0.29938 0.336 lineto
0.30049 0.336 lineto
Mistroke
0.30159 0.336 lineto
0.30269 0.336 lineto
0.30379 0.336 lineto
0.30489 0.336 lineto
0.306 0.336 lineto
0.3071 0.336 lineto
0.3082 0.336 lineto
0.3093 0.336 lineto
0.31041 0.33601 lineto
0.31261 0.33601 lineto
0.31481 0.33602 lineto
0.31702 0.33603 lineto
0.31922 0.33604 lineto
0.32363 0.33608 lineto
0.32804 0.33612 lineto
0.33245 0.33618 lineto
0.34127 0.33633 lineto
0.35891 0.33673 lineto
0.36772 0.33692 lineto
0.37213 0.337 lineto
0.37434 0.33703 lineto
0.37654 0.33705 lineto
0.37765 0.33706 lineto
0.37875 0.33707 lineto
0.37985 0.33708 lineto
0.38095 0.33708 lineto
0.38205 0.33708 lineto
0.38316 0.33708 lineto
0.38426 0.33708 lineto
0.38536 0.33708 lineto
0.38646 0.33707 lineto
0.38757 0.33706 lineto
0.38977 0.33703 lineto
0.39198 0.33699 lineto
0.39418 0.33694 lineto
0.39859 0.3368 lineto
0.403 0.33661 lineto
0.41182 0.33605 lineto
0.42063 0.3353 lineto
0.42945 0.33441 lineto
0.43827 0.33349 lineto
0.44268 0.33306 lineto
0.44709 0.33268 lineto
0.44929 0.33252 lineto
0.4515 0.33237 lineto
0.4537 0.33226 lineto
0.45481 0.33221 lineto
0.45591 0.33217 lineto
0.45701 0.33213 lineto
0.45811 0.33211 lineto
Mistroke
0.45922 0.33209 lineto
0.46032 0.33208 lineto
0.46142 0.33208 lineto
0.46252 0.33209 lineto
0.46362 0.33211 lineto
0.46473 0.33213 lineto
0.46583 0.33217 lineto
0.46693 0.33222 lineto
0.46914 0.33235 lineto
0.47134 0.33253 lineto
0.47354 0.33275 lineto
0.47795 0.33334 lineto
0.48236 0.33412 lineto
0.49118 0.33625 lineto
0.5 0.33903 lineto
0.50882 0.3422 lineto
0.51764 0.34537 lineto
0.52205 0.3468 lineto
0.52646 0.34803 lineto
0.52866 0.34854 lineto
0.53086 0.34898 lineto
0.53307 0.34934 lineto
0.53417 0.34948 lineto
0.53527 0.3496 lineto
0.53638 0.34969 lineto
0.53748 0.34975 lineto
0.53858 0.34979 lineto
0.53968 0.3498 lineto
0.54078 0.34978 lineto
0.54189 0.34973 lineto
0.54299 0.34965 lineto
0.54409 0.34953 lineto
0.5463 0.34921 lineto
0.5485 0.34874 lineto
0.55071 0.34814 lineto
0.55291 0.3474 lineto
0.55732 0.34547 lineto
0.56173 0.34296 lineto
0.57055 0.33632 lineto
0.58818 0.31861 lineto
0.597 0.30958 lineto
0.60141 0.30561 lineto
0.60582 0.30226 lineto
0.60802 0.30088 lineto
0.61023 0.29973 lineto
0.61133 0.29925 lineto
0.61243 0.29883 lineto
0.61354 0.29848 lineto
0.61464 0.2982 lineto
0.61574 0.29799 lineto
Mistroke
0.61684 0.29785 lineto
0.61795 0.2978 lineto
0.61905 0.29782 lineto
0.62015 0.29793 lineto
0.62125 0.29812 lineto
0.62235 0.29839 lineto
0.62346 0.29875 lineto
0.62566 0.29974 lineto
0.62787 0.3011 lineto
0.63228 0.30493 lineto
0.63668 0.31028 lineto
0.64109 0.31711 lineto
0.64991 0.33482 lineto
0.65873 0.35669 lineto
0.66755 0.38041 lineto
0.67637 0.4029 lineto
0.68078 0.41257 lineto
0.68519 0.42059 lineto
0.68739 0.42384 lineto
0.68959 0.42651 lineto
0.6907 0.42761 lineto
0.6918 0.42855 lineto
0.6929 0.42932 lineto
0.694 0.42991 lineto
0.69511 0.43033 lineto
0.69621 0.43056 lineto
0.69731 0.43059 lineto
0.69841 0.43044 lineto
0.69951 0.43008 lineto
0.70062 0.42952 lineto
0.70172 0.42875 lineto
0.70282 0.42778 lineto
0.70503 0.42519 lineto
0.70723 0.42173 lineto
0.71164 0.41216 lineto
0.71605 0.39907 lineto
0.72046 0.38259 lineto
0.72928 0.34056 lineto
0.74691 0.23544 lineto
0.75573 0.18501 lineto
0.76014 0.16367 lineto
0.76455 0.14625 lineto
0.76675 0.1393 lineto
0.76896 0.13368 lineto
0.77006 0.1314 lineto
0.77116 0.12949 lineto
0.77227 0.12796 lineto
0.77337 0.12682 lineto
0.77447 0.12609 lineto
0.77557 0.12577 lineto
Mistroke
0.77668 0.12587 lineto
0.77778 0.12641 lineto
0.77888 0.12739 lineto
0.77998 0.12881 lineto
0.78108 0.13069 lineto
0.78219 0.13303 lineto
0.78439 0.13909 lineto
0.7866 0.14704 lineto
0.79101 0.16863 lineto
0.79541 0.1977 lineto
0.79982 0.23389 lineto
0.81746 0.43337 lineto
0.82628 0.5472 lineto
0.8351 0.65142 lineto
0.83951 0.69486 lineto
0.84392 0.72988 lineto
0.84612 0.74364 lineto
0.84832 0.75461 lineto
0.84943 0.75899 lineto
0.85053 0.7626 lineto
0.85163 0.76541 lineto
0.85273 0.76741 lineto
0.85384 0.76858 lineto
0.85494 0.76889 lineto
0.85604 0.76834 lineto
0.85714 0.7669 lineto
0.85825 0.76456 lineto
0.85935 0.76132 lineto
0.86155 0.75205 lineto
0.86376 0.73903 lineto
0.86596 0.72224 lineto
0.87037 0.67729 lineto
0.87478 0.61754 lineto
0.87919 0.54388 lineto
0.88801 0.3608 lineto
0.90564 -0.07767 lineto
0.91446 -0.2792 lineto
0.91887 -0.36213 lineto
0.92108 -0.39751 lineto
0.92328 -0.4282 lineto
0.92549 -0.45381 lineto
0.92769 -0.47396 lineto
0.92879 -0.48186 lineto
0.92989 -0.48826 lineto
0.931 -0.49312 lineto
0.9321 -0.49641 lineto
0.9332 -0.49808 lineto
0.9343 -0.49811 lineto
0.93541 -0.49647 lineto
0.93651 -0.49313 lineto
Mistroke
0.93761 -0.48806 lineto
0.93871 -0.48127 lineto
0.94092 -0.46238 lineto
0.94312 -0.43637 lineto
0.94533 -0.40322 lineto
0.94974 -0.31558 lineto
0.95414 -0.20034 lineto
0.95855 -0.0594 lineto
0.97619 0.6906 lineto
Mfstroke
grestore
grestore
% End of Graphics
MathPictureEnd
:[font = output; inactive; output; endGroup; ]
The Unformatted text for this cell was not generated.
Use options in the Actions Settings dialog box to control
when Unformatted text is generated.
;[o]
-Graphics-
:[font = input; startGroup; ]
inps = Table[{k0,10.3,40.3},{k0,0.1,0.9,0.01}];
vals = MultiEval[Ff,inps];
ListPlot[Re[vals], PlotJoined -> True]
:[font = postscript; inactive; PostScript; output; pictureWidth = 452; pictureHeight = 279; preserveAspect; ]
%!
%%Creator: Mathematica
%%AspectRatio: 0.61803 
MathPictureStart
% Scaling calculations
0.02381 0.01176 0.33116 880.804 [
[(20)] 0.25897 0.31866 0 1 Msboxa
[(40)] 0.49412 0.31866 0 1 Msboxa
[(60)] 0.72928 0.31866 0 1 Msboxa
[(80)] 0.96443 0.31866 0 1 Msboxa
[(-0.0003)] 0.01131 0.06692 1 0 Msboxa
[(-0.0002)] 0.01131 0.155 1 0 Msboxa
[(-0.0001)] 0.01131 0.24308 1 0 Msboxa
[(0.0001)] 0.01131 0.41925 1 0 Msboxa
[(0.0002)] 0.01131 0.50733 1 0 Msboxa
[(0.0003)] 0.01131 0.59541 1 0 Msboxa
[ -0.001 -0.001 0 0 ]
[ 1.001 0.61903 0 0 ]
] MathScale
% Start of Graphics
1 setlinecap
1 setlinejoin
newpath
%%Object: Graphics
[ ] 0 setdash
0 setgray
gsave
gsave
0.002 setlinewidth
0 0.33116 moveto
1 0.33116 lineto
stroke
0.25897 0.32491 moveto
0.25897 0.33741 lineto
stroke
0 setgray
[(20)] 0.25897 0.31866 0 1 Mshowa
0.49412 0.32491 moveto
0.49412 0.33741 lineto
stroke
0 setgray
[(40)] 0.49412 0.31866 0 1 Mshowa
0.72928 0.32491 moveto
0.72928 0.33741 lineto
stroke
0 setgray
[(60)] 0.72928 0.31866 0 1 Mshowa
0.96443 0.32491 moveto
0.96443 0.33741 lineto
stroke
0 setgray
[(80)] 0.96443 0.31866 0 1 Mshowa
0.02381 0 moveto
0.02381 0.61803 lineto
stroke
0.01756 0.06692 moveto
0.03006 0.06692 lineto
stroke
0 setgray
[(-0.0003)] 0.01131 0.06692 1 0 Mshowa
0.01756 0.155 moveto
0.03006 0.155 lineto
stroke
0 setgray
[(-0.0002)] 0.01131 0.155 1 0 Mshowa
0.01756 0.24308 moveto
0.03006 0.24308 lineto
stroke
0 setgray
[(-0.0001)] 0.01131 0.24308 1 0 Mshowa
0.01756 0.41925 moveto
0.03006 0.41925 lineto
stroke
0 setgray
[(0.0001)] 0.01131 0.41925 1 0 Mshowa
0.01756 0.50733 moveto
0.03006 0.50733 lineto
stroke
0 setgray
[(0.0002)] 0.01131 0.50733 1 0 Mshowa
0.01756 0.59541 moveto
0.03006 0.59541 lineto
stroke
0 setgray
[(0.0003)] 0.01131 0.59541 1 0 Mshowa
grestore
grestore
0 0 moveto
1 0 lineto
1 0.618034 lineto
0 0.618034 lineto
closepath
clip
newpath
0 setgray
0.004 setlinewidth
0.03557 0.33116 moveto
0.04733 0.33116 lineto
0.05908 0.33116 lineto
0.07084 0.33116 lineto
0.0826 0.33116 lineto
0.09436 0.33117 lineto
0.10611 0.33117 lineto
0.11787 0.33118 lineto
0.12963 0.33119 lineto
0.14139 0.33119 lineto
0.15315 0.33119 lineto
0.1649 0.33117 lineto
0.17666 0.33113 lineto
0.18842 0.33107 lineto
0.20018 0.33098 lineto
0.21193 0.33089 lineto
0.22369 0.33081 lineto
0.23545 0.33081 lineto
0.24721 0.33092 lineto
0.25897 0.33119 lineto
0.27072 0.33163 lineto
0.28248 0.3322 lineto
0.29424 0.33282 lineto
0.306 0.33332 lineto
0.31775 0.33351 lineto
0.32951 0.33316 lineto
0.34127 0.33208 lineto
0.35303 0.33024 lineto
0.36479 0.32775 lineto
0.37654 0.32497 lineto
0.3883 0.32249 lineto
0.40006 0.32108 lineto
0.41182 0.32153 lineto
0.42357 0.32448 lineto
0.43533 0.33021 lineto
0.44709 0.33839 lineto
0.45885 0.34795 lineto
0.47061 0.35715 lineto
0.48236 0.36368 lineto
0.49412 0.36509 lineto
0.50588 0.35932 lineto
0.51764 0.34533 lineto
0.52939 0.32363 lineto
0.54115 0.2967 lineto
0.55291 0.26897 lineto
0.56467 0.24637 lineto
0.57643 0.23544 lineto
0.58818 0.24199 lineto
0.59994 0.26955 lineto
0.6117 0.31801 lineto
Mistroke
0.62346 0.38259 lineto
0.63521 0.45373 lineto
0.64697 0.51789 lineto
0.65873 0.55956 lineto
0.67049 0.56415 lineto
0.68225 0.5214 lineto
0.694 0.42865 lineto
0.70576 0.29325 lineto
0.71752 0.13333 lineto
0.72928 -0.02354 lineto
0.74103 -0.1441 lineto
0.75279 -0.19516 lineto
0.76455 -0.15063 lineto
0.77631 0.00139 lineto
0.78807 0.25313 lineto
0.79982 0.57449 lineto
0.81158 0.91475 lineto
0.82334 1.20872 lineto
0.8351 1.38739 lineto
0.84685 1.39136 lineto
0.85861 1.18496 lineto
0.87037 0.76825 lineto
0.88213 0.18391 lineto
0.89389 -0.48333 lineto
0.90564 -1.11604 lineto
0.9174 -1.58179 lineto
0.92916 -1.75722 lineto
0.94092 -1.5546 lineto
0.95267 -0.94593 lineto
0.96443 0.02088 lineto
0.97619 1.21827 lineto
Mfstroke
% End of Graphics
MathPictureEnd
:[font = output; inactive; output; endGroup; ]
The Unformatted text for this cell was not generated.
Use options in the Actions Settings dialog box to control
when Unformatted text is generated.
;[o]
-Graphics-
^*)