Added write_figure routine