/*
  tsappend

*!  VERSION 1.1.0  07feb2007

*/

VERSION 8.0

INCLUDE _std_medium
INCLUDE header

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

DIALOG main, label("tsappend - Add observations to a time-series dataset") /*
		*/ tabtitle("Main")
BEGIN
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---*/
  DEFINE _x _xsetbu
  DEFINE _y _top
  INCLUDE _bu_tsset

  RADIO    rb_add            _lft      _ls       _iwd      ., first	/*
  		*/ label("Add specific number of observations")		/*
		*/ onclickon(script add_on)
  EDIT     ed_add            _indent2  _ms       _en7wd    .,           /*
                */ numonly                                              /*
                */ label("Number of observations to add")
  TEXT     tx_add            _en7sep   @         _en7r     .,           /*
                */ label("Number of observations to add")

  RADIO    rb_last           _lft      _ls       _iwd      ., last	/*
  		*/ label("Add observations through a specific date")	/*
		*/ onclickon(script last_on)
  EDIT     ed_last           _indent2  _ms       _buwd     .,		/*
   		*/ label("Date to add observations through")
  DEFINE   _holdx @x
  TEXT     tx_last           _cken7sep @         _en7r     .,		/*
  		*/ label("Date to add observations through")

  COMBOBOX cb_tsfmt          _holdx    _ms       _buwd     .,		/*
   		*/ label("Time-series date function to apply")		/*
   		*/ dropdown						/*
   		*/ contents(tsfmt)					/*
   		*/ values(tsfmt_vals)

  TEXT     tx_tsfmt          _cken7sep @         _en7r     .,		/*
  		*/ label("Time-series date function to apply")

  GROUPBOX gb_options        _lft      _ls       _iwd      _ht3,	/*
  		*/ label("Options")

  EDIT     ed_panel          _indent2  _ms       _en7wd    .,		/*
		*/ numonly						/*
   		*/ label("Time-series date function to apply")		/*
   		*/ option(panel)
  TEXT     tx_panel          _en7sep   @         _cken7rb  .,		/*
  		*/ label("Panel to which observations should be added")
END

/* NB in the next list, daily, weekly, etc changed to lowercase because
   capitalization makes a difference for clock/Clock
*/
LIST tsfmt
BEGIN
clock
Clock
daily
weekly
monthly
quarterly
yearly
half-yearly
END

LIST tsfmt_vals
BEGIN
c
C
d
w
m
q
y
h
END

SCRIPT add_on
BEGIN
	main.tx_add.enable
	main.ed_add.enable
	main.tx_last.disable
	main.ed_last.disable
	main.tx_tsfmt.disable
	main.cb_tsfmt.disable
END

SCRIPT last_on
BEGIN
	main.tx_last.enable
	main.ed_last.enable
	main.tx_tsfmt.enable
	main.cb_tsfmt.enable
	main.tx_add.disable
	main.ed_add.disable
END

PROGRAM command
BEGIN
	if main.rb_add {
		require main.ed_add	
	}
	if main.rb_last {
		require main.ed_last
		require main.cb_tsfmt
	}
	put "tsappend, "
	if !H(main.ed_add) {
		put "add("
		put main.ed_add
		put ")"
	}
	if !H(main.ed_last) {
		put "last("
		put main.ed_last
		put ")"
		put " "
		put "tsfmt("
		put main.cb_tsfmt
		put ")"
	}
	if main.ed_panel {
		put " "
		put "panel("
		put main.ed_panel
		put ")"
	}
END
