;------------------------------------------------------------------------------;
;+
; NAME
;		         EIS_CHECK_DATABASE
; PURPOSE
;           This function checks that the OFFICIAL and USER databases
;           are visible.
; NOTES
;           This function is called by eis_mk_raster, eis_mk_study and
;           eis_mk_plan - if it returns zero (it has failed) - then these
;           GUIs are not invoked!
; INPUTS
;           None
; HISTORY
;           Written - 25 July 2006 John Rainnie @ RAL
;-
;------------------------------------------------------------------------------;
FUNCTION eis_check_database

; Are we pointing to OFFICIAL or USER database
zdbase = eis_get_zdbase()

s = fix_zdbase(/eis)
; Check whether we can see the databases
db_name   = 'eis_linelist_db'
dbhname   = find_with_def(db_name+'.dbh', 'ZDBASE')
validFile = FILE_TEST( dbhname , /READ)
IF (validFile EQ 0) THEN BEGIN
    BEEP
    print,'************************************************'
    print,''
    print,' Cannot see the OFFICIAL databases.....aborting!'
    print,''
    print,'************************************************'
    RETURN , 0
ENDIF

s = fix_zdbase(/user)
; Check whether we can see the databases
db_name   = 'eis_linelist_db'
dbhname   = find_with_def(db_name+'.dbh', 'ZDBASE')
validFile = FILE_TEST( dbhname , /READ)
IF (validFile EQ 0) THEN BEGIN
    BEEP
    print,'********************************************'
    print,''
    print,' Cannot see the USER databases.....aborting!'
    print,''
    print,'********************************************'
    RETURN , 0
ENDIF

CASE zdbase OF
    0    : db = 'OFFICIAL'
    1    : db = 'USER'
    ELSE : stop
ENDCASE

print,'****************************************'
print,''
print,' Paths to databases are valid!
print,''
print,STRJOIN([' Currently set to', db,'database!'],' ',/SINGLE)
print,''
print,'****************************************'

; Restore ZDBASE
CASE zdbase OF
    0     : s = fix_zdbase(/eis)
    1     : s = fix_zdbase(/user)
    ELSE  : stop
ENDCASE

RETURN , 1

END
