/*
  ac

*! VERSION 2.0.2  23may2007

*/

VERSION 10.0

INCLUDE _std_large
INCLUDE header
HELP hlp1, view("help ac")
RESET res1

SCRIPT POSTINIT
BEGIN
	script gr_plots_setDefaultDropline
	script gr_ciplots_setDefaultArea
END

DIALOG main, tabtitle("Main")					///
	label("ac - Graph autocorrelations with confidence intervals")
BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset
  TEXT     tx_var	_lft	_top	_cwd2	.,		///
	label("Variable:")
  VARNAME  vn_var	@	_ss	_vnwd	.,		///
	label("Variable")

  GROUPBOX gb_opt	_lft	+35	_iwd	_ht19,		///
	label("Options")

  GROUPBOX gb_lags	_indent	_ss	_ibwd	_ht4h,		///
	label("Number of autocorrelations to compute")
  RADIO    rb_lags1	_indent	_ss	_inwd	.,		///
	label("Default -- min([n/2] - 2, 40)")			///
	onclickon(gaction main.sp_lags2.disable)		///
	first
  RADIO    rb_lags2	@	_ms	_rbwd	.,		///
	onclickon(gaction main.sp_lags2.enable)			///
	last
  SPINNER  sp_lags2	_rbsep	@	_spwd	.,		///
	label("Autocorrelations")				///
	min(1) max(100) default(1)				///
	option(lags)
  TEXT     tx_lags2	_spsep	@	_rbspr2bb .,		///
	label("Autocorrelations")

  CHECKBOX ck_gen	_ilft	_xls	_ibwd	.,		///
	onclickon(script graph_off)				///
	onclickoff(script graph_on)				///
	label("Generate a variable to hold the autocorrelations: (suppresses the graph)")
  EDIT     ed_gen	_indent2 _ss	_vnwd	.,		///
	max(32) 						///
	option(nograph generate)				///
	error("Generate a variable containing the autocorrelations")

  DEFINE _x _ilft
  DEFINE _y +35
  DEFINE _cx _sprb
  INCLUDE _sp_level

  CHECKBOX ck_fft	_x	_ls	_ibwd	.,		///
	option(fft)						///
	label("Calculate autocorrelation using Fourier transforms")
END

SCRIPT graph_off
BEGIN
	main.ed_gen.enable
	script gr_plots_disable
	script gr_ciplots_disable
	script gr_addplots_disable
	script gr_yaxis_disable
	script gr_xaxis_disable
	script gr_titles_disable
	script gr_legend_disable
	script gr_overall_disable
END

SCRIPT graph_on
BEGIN
	main.ed_gen.disable
	script gr_plots_enable
	script gr_ciplots_enable
	script gr_addplots_enable
	script gr_yaxis_enable
	script gr_xaxis_enable
	script gr_titles_enable
	script gr_legend_enable
	script gr_overall_enable
END

INCLUDE ifin
INCLUDE gr_plots
INCLUDE gr_ciplots
INCLUDE gr_addplots_2
INCLUDE gr_yaxis
INCLUDE gr_xaxis
INCLUDE gr_titles
INCLUDE gr_legend
INCLUDE gr_overall

PROGRAM command
BEGIN
	put "ac "
	varlist main.vn_var
	INCLUDE _ifin_pr
	beginoptions
		if main.rb_lags2 {
			optionarg main.sp_lags2
		}
		if main.ck_gen {
			require main.ed_gen
			optionarg main.ed_gen
		}
		INCLUDE _level_main_pr
		option main.ck_fft

		put " " /program gr_plots_output
		put " " /program gr_ciplots_output
		put " " /program gr_addplots_output
		put " " /program gr_yaxis_output
		put " " /program gr_xaxis_output
		put " " /program gr_titles_output
		put " " /program gr_legend_output
		put " " /program gr_overall_output
	endoptions
END
