I have a notebook ("notebook 1") which in the beginning sets some parameters, does something depending on their value and saves the result to a file, say:
p=5; result=p^2; result>>"result";
I want to run this for many combinations of parameter values, so I'd like to automate the process. The notebook is large and I don't want to pack it into a single function of the parameters, as that would reduce readability.
So I want to run it from another notebook ("notebook 2"), effectively as if it were a function. I also want each run to be on a fresh kernel.
This is partly done by the following code
runWith[pval_]:=( p=pval; Protect[p]; NotebookEvaluate[notebookaddress]; Unprotect[p]; ClearAll[p])
where notebook 1 uses a parameter named
p and this code runs it with value
pval assigned to it. The protect is necessary because the notebook tries to set it to another value, as in the example above. However this keeps the kernel on successive runs.
Quit to notebook 1 doesn't work, as it is run in the same kernel, so this will quit the kernel of notebook 2 as well.
A solution would be to let notebook 1 evaluate in another kernel, and then quit that kernel, both from notebook 2, but I can't find if this is possible.