saveLFO = LIKELIHOOD_FUNCTION_OUTPUT;
LIKELIHOOD_FUNCTION_OUTPUT = 6;
likelihoodFnChoice = 0;

if (Rows("LikelihoodFunction")>1)
{
	ChoiceList  (likelihoodFnChoice,"Choose a Likelihood Function",1,NO_SKIP,LikelihoodFunction);
}		

if (likelihoodFnChoice<0)
{
	return;
} 
	
GetString (LF_NAME,LikelihoodFunction,likelihoodFnChoice);

SetDialogPrompt ("Save serialized function to:");
ExecuteCommands ("fprintf(PROMPT_FOR_FILE,CLEAR_FILE,"+LF_NAME+");");
LIKELIHOOD_FUNCTION_OUTPUT = saveLFO;

saveOutFile  = LAST_FILE_PATH;
fprintf(MESSAGE_LOG,"Exported ", LF_NAME, " successfully");
ChoiceList  (doOptimize,"Export LF for optimization",1,NO_SKIP,"Skip optimization","Do not include a command to optimize the likelihood function",
															   "Do optimization","DO include a command to optimize the likelihood function");

if (doOptimize==1)
{
	fscanf (saveOutFile,"Raw",saveLFO);
	fprintf(saveOutFile,CLEAR_FILE,saveLFO[0][Abs(saveLFO)-5],"\nOptimize(res_", LF_NAME, "," , LF_NAME, ");fprintf(stdout,\"\\n\",",LF_NAME,");\nEND;\n");
	saveLFO = 0;
}

