#!/usr/bin/python
"""Add a configuration entry to the parameters"""
import sys
import array
import struct
import math
import numarray
from tables import *

from local_modules import hdf5


def create_config(file_id):
    try:
        table = file_id.root.Configuration
    except Exception:
        table = file_id.createTable(file_id.root, 'Configuration',
                                    hdf5.Configuration, "Simulation Parameters")
    c1 = table.row

    c1["idnumber"]   = 1
    c1["num_phots"]  = 1000
    c1["descr"]      = "Background Illumination"
    c1["bin_size"]   = 2e-4
    c1["out_file"]   = "outtest.h5"
    c1["src_type"]   = "gaussian"
    c1["src_dir"]    = (0, 0, 1)
    c1["src_pos"]    = (0, 0,-2.1e-3 )
    c1["sim_type"]   = hdf5.sim_types["Incoherent"]
    c1["extra_params"] = 0

    c1.append()
    table.flush()
    
def create_extra(file_id):    
    try:
        table = file_id.root.EXTRAParams
    except Exception:
        table = file_id.createTable(file_id.root, 'EXTRAParams',
                                    hdf5.EXTRAParam, "EXTRA Parameters")
    p1 = table.row
    p1["idnumber"]   = 0
    p1["mode"]       = hdf5.extra_modes["Limited"]
    p1["Li_limit"]   = 5
    p1.append()
    table.flush()

def main():
    if len(sys.argv) <> 2:
        print( "Usage: " + sys.argv[0] + "H5file.h5")
        sys.exit(1)
        
    file_id = openFile(sys.argv[1],mode = "r+")


    create_config(file_id)
    create_extra(file_id)

if __name__ == "__main__":
    main()
