// globals



function printout () {
	doPrintout (true);
}

function preview () {
	preprocess ();
	calculate ();
	doPrintout (false);	
}


function doPrintout (final) {
	densityscaled = getValue ("densityscaled");
	bw =  getValue ("bw");
	adjust = getValue ("adjust");
	narm = getValue ("narm");
	n = getValue ("n"); 
	x = getValue ("x");
	plot_adds = getValue ("plotoptions.code.calculate");


	if (final) { 
echo ('rk.header ("Histogram", list ("Variable", rk.get.description (' + x + ') '); if ((densityscaled) && getValue ("density")) { echo (', "Density bandwidth", "' + bw + '", "Density adjust", ' + adjust + ', "Density resolution", ' + n + ', "Density Remove missing values", ' + narm + ' '); } echo (' ' + getValue ("histogram_opt.code.preprocess") + '))\n');
echo ('\n');
echo ('rk.graph.on ()\n');
	}

echo ('try ({\n');
echo ('	hist (' + x + getValue ("histogram_opt.code.calculate") + getValue ("histogram_opt.code.printout") + getValue ("plotoptions.code.printout") + ')\n');
	if ((densityscaled) && getValue ("density")) { 
echo ('	lines(density(' + x + ', bw="' + bw + '", adjust = ' + adjust + ', ' + narm + ', n = ' + getValue ("n") + ')' + getValue ("col_density.code.printout") + ')\n');
	} 
	if (!empty (plot_adds)) { 
echo ('\n');
		
		printIndented ("\t", plot_adds);
	}

echo ('})\n');
	if (final) { 
echo ('rk.graph.off ()\n');
	}
}


