
''' Ensure variable is defined '''
try:
    DR_GROUP_ID
except NameError:
    def initialize_globals():
        global DR_GROUP_ID  # Create global variable when not defined
        global drg          # Create a data recording group variable
        DR_GROUP_ID = 0
        drg = []            # Initialize variable as an empty array
    initialize_globals()


def add_dr_group():
    global DR_GROUP_ID
    global drg
    group_name = "auto"
    drg.append( trick.sim_services.DRAscii(group_name) )
    drg[DR_GROUP_ID].set_freq(trick.sim_services.DR_Always)
    drg[DR_GROUP_ID].enable()
    drg[DR_GROUP_ID].set_cycle(10.0)

    drg[DR_GROUP_ID].add_variable("parent.sched.amf_error")
    drg[DR_GROUP_ID].add_variable("parent.sched.mass")
    drg[DR_GROUP_ID].add_variable("parent.sched.pos")
    drg[DR_GROUP_ID].add_variable("parent.sched.vel")
    drg[DR_GROUP_ID].add_variable("parent.sched.acc")

    trick_data_record.drd.add_group( drg[DR_GROUP_ID], trick.DR_Buffer )
add_dr_group()


"""
add 1 to DR_GROUP_ID, THIS SETS DR_GROUP_ID UP
FOR THE NEXT DATA RECORDING FILE
"""
def increment_group_id():
    global DR_GROUP_ID
    DR_GROUP_ID += 1
increment_group_id()
