
PRO eis_vso_day, date, test=test, no_ingest=no_ingest, force=force


;+
; NAME:
;     EIS_VSO_DAY
;
; PURPOSE:
;     For the specified day this routine retrieves EIS level-0 files
;     from the VSO and puts them in the user's EIS level-0 directory. 
;
; INPUTS:
;     Date:   A date in standard format, e.g., '10-oct-2015'.
;
; OPTIONAL INPUTS:
;     Dir:    Specifies a directory in which to download the
;             files. Otherwise they will be downloaded to the
;             user's level-0 directory.
;
; KEYWORDS PARAMETERS:
;     TEST:   If set, then the routine checks which directory the
;             files would be downloaded to, and prints this to the
;             screen. The files won't actually be downloaded, though.
;     FORCE:  If set, then the routine won't ask if you want to
;             proceed if the request is large.
;
; SIDE EFFECTS:
;     The files are first downloaded to a temporary directory, 
;     and then the routine eis_ingest is applied to move them to the
;     correct EIS directory.
;
; MODIFICATION HISTORY:
;     Ver.1, 22-Nov-2015, Peter Young
;        - I've hard-coded my download directory, so these
;          would have to be more general for other users. Could go in
;          $TMPDIR or /tmp for Mac.
;     Ver.2, 3-Jan-2016, Peter Young
;        - fixed bug if the download directory didn't exist.
;     Ver.3, 11-Apr-2016, Peter Young
;        - I've now switched the temporary directory to $IDL_TMPDIR.
;     Ver.4, 11-May-2017, Peter Young
;        - Added /force keyword.
;     Ver.5, 19-Mar-2020, Peter Young
;        - fixed bug in /test implementation; moved parameter check to
;          after /test code.
;-



IF keyword_set(test) THEN BEGIN 
  eisdata=getenv('EIS_FITS_DATA')
  hindata=getenv('HINODE_DATA')
  IF eisdata EQ '' THEN eisdata=hindata
  l0dir=getenv('EIS_L0_DATA')
 ;
  IF l0dir EQ '' THEN BEGIN
    IF eisdata EQ '' THEN outdir='' ELSE outdir=concat_dir(eisdata,'level0')
  ENDIF ELSE BEGIN
    outdir=l0dir
  ENDELSE
  print,'Files will be downloaded to the directory:'
  print,'   ',outdir
  return
ENDIF 

IF n_params() LT 1 THEN BEGIN
  print,'Use:  IDL> eis_vso_day, date [, /test, /no_ingest, /force]'
  return
ENDIF 

  
t0_tai=anytim2tai(date)
t1_tai=t0_tai+86400.

t0=anytim2utc(/ccsds,t0_tai)
t1=anytim2utc(/ccsds,t1_tai)

list=vso_search(t0,t1,inst='eis',count=count)

IF count NE 0 THEN BEGIN 

  outdir=getenv('IDL_TMPDIR')
  chck=file_info(outdir)
  IF chck.directory EQ 0 THEN file_mkdir,outdir
  
  a=vso_get(list,out_dir=outdir,force=force)

  IF NOT keyword_set(no_ingest) THEN BEGIN 
    list=file_search(outdir,'eis_l0_*.*')
    eis_ingest,list
  ENDIF 

ENDIF

END
