/*
  stci_9

*! VERSION 1.1.5  03aug2006  (deprecated)

*/

VERSION 9.0

INCLUDE graph_header
INCLUDE header

HELP hlp1, view("help stci")
RESET res1

DIALOG main, tabtitle("Main") ///
	label("stci - Confidence intervals for means and percentiles of survival time")
BEGIN
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_stset

  GROUPBOX gb_opt          _lft      _ss        _iwd      _ht25h,	///
	label("Options")
  CHECKBOX ck_by           _indent   _ms        _cwd3     .,		///
	label("Separate summaries by grouping variable(s):")		///
	onclickon(program by_on) onclickoff(program by_off)
DEFINE holdy @y
  VARLIST  vl_by           @         _ss        @ 	  .,		///
	label("Separate summaries by grouping variable(s)")		///
	option(by)

  TEXT     tx_note1        _lft2     holdy      _cwd3     .,		///
  	label(`"Note: graph tabs active only when "Extended mean" and"')
  TEXT     tx_note2        _lft2     _vss       _cwd3     .,		///
  	label(`""Plot exponentially extended survivor function" are selected."')

  GROUPBOX gb_calc         _ilft     +35        _ibwd     _ht4,		///
	label("Survival-time calculation")
  RADIO    rb_median       _indent   _ss        _cwd4_1   .,		///
	label("Median") first						///
  	onclickon(script median_on) option(median)
  DEFINE xx @x
  RADIO    rb_emean        _lft4_2   @          @         .,		///
	label("Extended mean")						///
	onclickon(program emean_on)					///
	option("emean")
  RADIO    rb_rmean        xx        _ss        @         .,		///
	label("Restricted mean")					///
	onclickon(script rmean_on)					///
	option(rmean)
  RADIO    rb_perc         _lft4_2   @          _rbwd     .,		///
	onclickon(script perc_on)					///
	option(NONE) last
  SPINNER  sp_perc         _rbsep    @          _spwd     .,		///
	min(1) default(50) max(100)					///
	option(p)
  TEXT     tx_sep          _spsep    @          _vnwd     .,		///
	label("Percentile")

  CHECKBOX ck_ccorr        _ilft     +45        _cwd2     .,		///
	option(ccorr)							///
	label("Calculate the standard error using a continuity correction")
  CHECKBOX ck_noshow       _lft2     @          _cwd2     .,		///
	label("Do not show st setting information") option(noshow)

  DEFINE _x _ilft
  DEFINE _y _ms
  DEFINE _cx _spr2b
  INCLUDE _sp_level

  CHECKBOX ck_dd           _lft2     @          _ckwd     .,		///
	onclickon(main.sp_dd.enable)					///
	onclickoff(main.sp_dd.disable)
  SPINNER  sp_dd           _cksep    @          _spwd     .,		///
	min(0) default(3) max(8) option(dd)
  TEXT     tx_dd           _spsep    @          _ckspr2b  .,		///
	label("Maximum number of decimal digits to report")

  CHECKBOX ck_graph        _ilft     +35        _ibwd     _ht2h,	///
	label("Plot exponentially extended survivor function")		///
	option(graph) groupbox						///
	onclickon(program graph_on) onclickoff(program graph_off)
  CHECKBOX ck_tmax         _indent   _ms        _ckwd     .,		///
	onclickon(main.en_tmax.enable)					///
	onclickoff(main.en_tmax.disable)
  EDIT     en_tmax         _cksep    @          _en7wd    .,		///
	numonly	 label("Maximum analysis time to be plotted") option(tmax)
  TEXT     tx_tmax         _en7sep   @          _cken7r2bb .,		///
	label("Maximum analysis time to be plotted")
END

PROGRAM by_on
BEGIN
	call gaction main.vl_by.enable
	call gaction main.ck_graph.disable
	call program graph_off
END

PROGRAM by_off
BEGIN
	call gaction main.vl_by.disable
	if main.rb_emean {
		call gaction main.ck_graph.enable
		if main.ck_graph {
			call program graph_on
		}
	}
END

SCRIPT rmean_on
BEGIN
	main.ck_graph.disable
	program graph_off
	main.ck_ccorr.enable
	main.sp_perc.disable
END

PROGRAM emean_on
BEGIN
	if ! main.ck_by {
		call gaction main.ck_graph.enable
		if main.ck_graph {
			call program graph_on
		}
	}
	call gaction main.ck_ccorr.disable
	call gaction main.sp_perc.disable
END

SCRIPT median_on
BEGIN
	main.ck_graph.disable
	program graph_off
	main.ck_ccorr.disable
	main.sp_perc.disable
END

SCRIPT perc_on
BEGIN
	main.ck_graph.disable
	program graph_off
	main.ck_ccorr.disable
	main.sp_perc.enable
END

PROGRAM graph_on
BEGIN
	call gaction main.ck_tmax.enable
	call gaction main.tx_tmax.enable

	call script p1_opts_enable
	call script addplot_enable
	call script gr_twoway_enable
END

PROGRAM graph_off
BEGIN
	call gaction main.ck_tmax.disable
	call gaction main.en_tmax.disable
	call gaction main.tx_tmax.disable

	call script p1_opts_disable
	call script addplot_disable
	call script gr_twoway_disable
END

INCLUDE ifin
INCLUDE p1_opts
INCLUDE addplot
INCLUDE gr_twoway

SCRIPT PREINIT
BEGIN
	script p1_opts_createAsNoRange
	script p1_opts_setDefaultLine
END

PROGRAM command
BEGIN
	put "stci "
	INCLUDE _ifin_pr
	beginoptions
		if main.ck_by {
			require main.vl_by
			optionarg main.vl_by
		}
		option radio(main rb_median rb_emean rb_rmean rb_perc)
		if main.rb_perc{
			optionarg main.sp_perc
		}
		if main.rb_rmean{
			option main.ck_ccorr
		}
		if main.ck_dd{
			optionarg main.sp_dd
		}
		INCLUDE _level_main_pr
		option main.ck_graph
		if main.ck_graph {
			if main.ck_tmax {
				require main.en_tmax
				optionarg main.en_tmax
			}
		}
		option main.ck_noshow

		put " " /program p1_opts_output
		put " " /program addplot_output
		put " " /program gr_twoway_output
	endoptions
END
