;+
; PROJECT
;           SolarB EIS
;
; NAME
;           DB_SAVE_LINELIST_ENTRY_CREATE
;
; PURPOSE
;           Function to save an eis_line_list to the EIS line list database
;
; CATEGORY
;           EIS Technical Planning
;           Database
;
; INPUTS
;           ll - an eis_line_list structure
;
; OPTIONAL INPUTS
;           the top-level-base; useful if calling from a widget tool 
;           (eg; mk_linelist). 
;
; WRITTEN
;           John A Rainnie, RAL, Dec-2005
;
; MODIFICATION HISTORY
;           v0.1 JAR 10-Feb-2007
;               Removed fix_zdbase and now using eis_open_db
;
;-
PRO db_save_linelist_entry_create , ll , tlbID = tlbID

status = eis_open_db(/LINELIST,/UPDATE)

dbbuild, ll.id                    ,                                   $
         ll.write_locked          ,                                   $
         ll.acronym               ,                                   $
         ll.title                 ,                                   $
         ll.author                ,                                   $
         ll.date                  ,                                   $
         ll.nLines                ,                                   $
         ll.lines[*].wavelength   ,                                   $
         ll.lines[*].type         ,                                   $
         ll.lines[*].split

dbclose

;
; OK, now get the line names
;
db_name  = 'eis_linename_db'
dbopen, db_name, unavail = unavail , 1


dbbuild, ll.id                    ,                               $
         ll.lines[0].name         ,                               $
         ll.lines[1].name         ,                               $
         ll.lines[2].name         ,                               $
         ll.lines[3].name         ,                               $
         ll.lines[4].name         ,                               $
         ll.lines[5].name         ,                               $
         ll.lines[6].name         ,                               $
         ll.lines[7].name         ,                               $
         ll.lines[8].name         ,                               $
         ll.lines[9].name         ,                               $
         ll.lines[10].name        ,                               $
         ll.lines[11].name        ,                               $
         ll.lines[12].name        ,                               $
         ll.lines[13].name        ,                               $
         ll.lines[14].name        ,                               $
         ll.lines[15].name        ,                               $
         ll.lines[16].name        ,                               $
         ll.lines[17].name        ,                               $
         ll.lines[18].name        ,                               $
         ll.lines[19].name        ,                               $
         ll.lines[20].name        ,                               $
         ll.lines[21].name        ,                               $
         ll.lines[22].name        ,                               $
         ll.lines[23].name        ,                               $
         ll.lines[24].name


dbclose

; Report successful outcome
; ID needs to be in 000001 format
idValue = STRING(format='(I06)' , ll.id)
messageText = ["Line List has been successfully created" ,                  $
               ""                                       ,                   $
               "ID          = " + idValue               ,                   $
               "Description = " + ll.acronym  ]
; If a tlbID is given, then display a pop-up box
IF (KEYWORD_SET(tlbID) EQ 1) THEN BEGIN
    inform = DIALOG_MESSAGE( messageText ,                                  $
                             				DIALOG_PARENT = tlbID  ,                   $
                             				/INFORMATION )
ENDIF ELSE BEGIN
    print,messageText
ENDELSE


END
