I have a very long program I'm trying to stuff express as a single function. (I'll include it at the bottom of my post.) My long-term goal is to trim out the file handling portion of this function, and have another workbook call this function, passing in the table it needs, having the user manipulate the data and then press a continue button, then having it return two or three things to the original notebook.
However, when I use
functionname[x_]:=(
)
to try to encapsulate the program into an object, it generates 7-8 errors.
Any tips on how to functionize this program? (Sample data here: http://www.pastebin.ca/3061136)
Needs["Splines`"]
Needs["ErrorBarPlots`"]
SetOptions[InputNotebook[], PrintPrecision -> 10]
filelocation = SystemDialogInput["FileOpen"];
rawfiledata = Import[filelocation, "Table"];
trimmedfiledata = Drop[rawfiledata, {1}, {2, 4}];
Manipulate[moveamt = movelength, {movelength, 1, 25, 1}]
DynamicWrapper["Select the left and right edges of the data",
mmdata = MovingAverage[trimmedfiledata, moveamt];]
minx = Min[mmdata[[All, 1]]];
minx = minx - 0.02;
maxx = Max[mmdata[[All, 1]]];
maxx = maxx + 0.02;
miny = Min[mmdata[[All, 2]]];
maxy = Max[mmdata[[All, 2]]];
Manipulate[leftEdge = left, {left, minx, maxx, 0.001}]
Manipulate[rightEdge = right, {{right, maxx}, minx, maxx, 0.001}]
Manipulate[c1 = peak, {peak, minx, maxx, 0.001}]
Manipulate[yoff = floor, {floor, miny, maxy, 0.001}]
(*d1 is edges*)
Dynamic[d1 = Select[mmdata, leftEdge < #[[1]] < rightEdge &];]
Dynamic[Show[
ListPlot[mmdata, PlotStyle -> Orange,
GridLines -> {{{c1, Orange}, leftEdge, rightEdge}, {{yoff, Red}}}],
ParametricPlot[bsplinedat = BSplineFunction[mmdata][x], {x, -8, 8}],
ListPlot[d1, PlotStyle -> Purple], ImageSize -> Large]]
Dynamic[f1 =
NonlinearModelFit[d1, a Exp[-(b (x - c1))^2] + yoff, {a, b}, x]]
Dynamic[Show[{ListPlot[d1],
Plot[f1[x], {x, d1[[1, 1]], d1[[-1, 1]]}, PlotRange -> All]}]]
Dynamic[Show[{ListPlot[mmdata],
Plot[f1[x], {x, minx, maxx}, PlotRange -> All, PlotStyle -> Red]}]]
Dynamic[smooth2 = {#[[1]], #[[2]] - f1[#[[1]]]} & /@ mmdata;]
Dynamic[ListPlot[smooth2]]