PRO eis_build_tl_response_db

; Set up some environment variables
home_dir = EXPAND_PATH(GETENV("HOME"))
time_dir = STRJOIN([home_dir,'planning_db','timeline_db'],PATH_SEP(),/SINGLE)

; Check database seed file exists: $HOME/eis_tl_response_db.dbd
test = FILE_TEST(CONCAT_DIR(home_dir,'eis_tl_response_db.dbd'))
IF (test NE 1) THEN BEGIN
   print,'Database seed file not found. Bailing out!'
   RETURN
ENDIF

; Delete existing database files - EXCEPT for definition file .dbd
; In $HOME/planning_db/timeline_db/
dbf = CONCAT_DIR(time_dir , 'eis_tl_response_db.dbf')
dbh = CONCAT_DIR(time_dir , 'eis_tl_response_db.dbh')
dbx = CONCAT_DIR(time_dir , 'eis_tl_response_db.dbx')
dbd = CONCAT_DIR(time_dir , 'eis_tl_response_db.dbd')
FILE_DELETE , dbf , dbh , dbx , dbd , /QUIET
; In $HOME
dbf = CONCAT_DIR(home_dir , 'eis_tl_response_db.dbf')
dbh = CONCAT_DIR(home_dir , 'eis_tl_response_db.dbh')
dbx = CONCAT_DIR(home_dir , 'eis_tl_response_db.dbx')
dbd = CONCAT_DIR(home_dir , 'eis_tl_response_db.dbd')
FILE_DELETE , dbf , dbh , dbx , /QUIET

;replace call to astrolib
defsysv,'!DEBUG', 0
defsysv,'!TEXTUNIT', 0
defsysv,'!PRIV', 3
defsysv,'!TEXTOUT', EXIST = EXIST

dbcreate , 'eis_tl_response_db' , 1 , 1 , 500000 , /EXTERNAL
FILE_COPY , [dbf , dbh , dbx , dbd] , time_dir , /OVERWRITE

;
; Create the first entry, and check!
;
response_struct = {eis_response_props}
response_struct.id                = 1   ; y
response_struct.trig_st_seqid     = 1   ; y
response_struct.eebp_respond      = 1   ; y
response_struct.xrtf_respond      = 0   ; y
response_struct.eisf_respond      = 0   ; y
response_struct.aece_respond      = 0   ; y
response_struct.x_threshold       = 1   ; y
response_struct.y_threshold       = 2   ; y
response_struct.x_min_limit       = 3   ; y
response_struct.y_min_limit       = 4   ; y
response_struct.adjust_x          = 1   ; y
response_struct.adjust_y          = 1   ; y
response_struct.locate_x          = 1   ; y
response_struct.locate_y          = 1   ; y
response_struct.response_st_id    = 1   ; y
response_struct.raster_identifier = 1   ; y
response_struct.line_index        = 1   ; y
response_struct.filler_st_id      = 1   ; y
response_struct.type              = ''  ; y

response_struct.no_hunt_data      = 1   ; n
response_struct.ra1_xcen          = 1.D ; n
response_struct.ra1_ycen          = 1.D ; n
response_struct.ra1_mip           = 1   ; n
response_struct.ra1_yip           = 1   ; n
response_struct.ra1_sc_x          = 5.D ; n
response_struct.ra1_sc_y          = 5.D ; n
response_struct.ra1_pointed       = 1   ; n

response_struct.ra2_use           = 1   ; n
response_struct.ra2_xcen          = 2.D ; n
response_struct.ra2_ycen          = 2.D ; n
response_struct.ra2_mip           = 2   ; n
response_struct.ra2_yip           = 2   ; n
response_struct.ra2_sc_x          = 6.D ; n
response_struct.ra2_sc_y          = 6.D ; n


; Now, save to Response DB
db_save_response_entry_create , response_struct

print," "
print,"All done. I'm out!"
print,"+++++++++++++++++++++++++++++++++++++++++++++"
print,""

END
