;+
;  PRO themis_config
;
;  This procedure serves as the themis configuration file.  It sets global (system)
;  variables and initializes devices
;
;  This procedure will define the location of data files and the data server.
;  This procedure is intended to be called from within the "THM_INIT" procedure.
;
;  This should be the only THEMIS file that requires modification for use in different
;  locations.
;
;  There is no need to modify this file if:
;     - Your computer is an SSL UNIX machine that mounts "/disks/data/"   (i.e. ALL Linux and Solaris machines at SSL)
;     - You use a portable computer that will be caching files on a local hard drive.
;
;
;  Settings  in this file will be overridden by settings in the environment.
;  (see setup_themis or setup_themis_bash for examples of setting environment
;  variables on UNIX-like systems.  The environment can also be set on Windows
;  systems.)
;
;  KEYWORDS
;     no_color_setup   added to prevent cronjob to crash, hfrey, 2007-02-10
;
;  Author:  Davin Larson Nov 2006
;           jmm, 2007-05-17, Altered to read thm_comfig text file,
;           this removes the need for someone to alter this program
;           jmm, 2007-07-02, applies slashes to remote and local
;           directories, if they are not there
;
; $LastChangedBy: davin-win $
; $LastChangedDate: 2007-08-14 03:59:40 -0700 (Tue, 14 Aug 2007) $
; $LastChangedRevision: 1407 $
; $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_3_01/idl/themis/common/thm_config.pro $
;
;-
pro thm_config,caching=caching,colortable=colortable,$
           no_color_setup=no_color_setup


;                        THEMIS SPECIFIC INITIALIZATION
;====================================================================================


; Location of the data Server:

;!themis.use_wget=1   ; uncomment to use experimental wget routine instead of file_http_copy (not recommended)

!themis.remote_data_dir = 'http://sprg.ssl.berkeley.edu/data/themis/'   ; use as backup web server
!themis.remote_data_dir = 'http://themis.ssl.berkeley.edu/data/themis/'

;;;;;;;;;;;
; SECTION 1
;;;;;;;;;;;


; The remainder of this file will determine  defaults based on machine type
; It will not be executed if one of the lines in SECTION 1 has been
; commented out.

;--->  Please edit the following line.
;--->    caching=1 to use local cache.  Preferable for LAPTOP or Non-SSL user.
;--->    caching=0 to use only master copy
;caching = 1

if n_elements(caching) eq 0 then $
   caching = 1 - file_test('/disks/data/themis/.themis_master',/regular)  ; this file should only exist on the master directory at SSL


   if !version.os_family  eq 'Windows' then begin
      sambaserver = '\\justice/data/themis/'
;      if file_test(sambaserver) then !themis.remote_data_dir = sambaserver
      if CACHing then begin
         ;;-->   Location of local cache for WINDOWS
         ;;      Edit the following line to point to a writeable directory.
         if file_test('E:/data/themis/',/direc,/write) then !themis.local_data_dir = 'E:/data/themis/'  else  $
         !themis.local_data_dir = 'C:/data/themis/'
         !themis.no_download = 0
      endif else begin
         ;;-->   Mount point of master data directory for WINDOWS
         ;;      E.g. At SSL, justice runs a read-only Samba server which
         ;;      provides direct access to //sprg.ssl.berkeley.edu/data/themis
         !themis.local_data_dir = sambaserver
         !themis.no_download = 1
      endelse
   endif

   if !version.os_family eq 'unix' then begin

      if caching then begin
         ;;-->  Location of local cache on your laptop for UNIX (or Mac)
         ;;     OR for desktops remote from SSL, this could be edited to
         ;;     point to a shared data area where many users can download
         ;;     data from the master data server.
         !themis.local_data_dir = '~/data/themis/'
         !themis.no_download = 0
      endif else begin
         ;;-->  Location of NFS mount point of master data directory.
         !themis.local_data_dir = '/disks/data/themis/'
         !themis.no_download = 1
      endelse

   endif

; Settings of environment variables can override thm_config
if getenv('THEMIS_DATA_DIR') ne '' then $
   !themis.local_data_dir = getenv('THEMIS_DATA_DIR')

if getenv('THEMIS_REMOTE_DATA_DIR') ne '' then $
   !themis.remote_data_dir = getenv('THEMIS_REMOTE_DATA_DIR')

;settings in your local thm_config.txt file will override the
;defaults, jmm, 17-may-2007

ftest = thm_read_config()
If(size(ftest, /type) Eq 8) Then Begin
  !themis.local_data_dir = ftest.local_data_dir
  !themis.remote_data_dir = ftest.remote_data_dir
  !themis.no_download = ftest.no_download
  !themis.no_update = ftest.no_update
  !themis.downloadonly = ftest.downloadonly
  !themis.verbose = ftest.verbose
Endif

;check for slashes, add if necessary, jmm, 2-jul-2007
temp_string = strtrim(!themis.local_data_dir, 2)
ll = strmid(temp_string, strlen(temp_string)-1, 1)
If(ll Ne '/' And ll Ne '\') Then temp_string = temp_string+'/'
!themis.local_data_dir = temporary(temp_string)
temp_string = strtrim(!themis.remote_data_dir, 2)
ll = strmid(temp_string, strlen(temp_string)-1, 1)
If(ll Ne '/' And ll Ne '\') Then temp_string = temp_string+'/'
!themis.remote_data_dir = temporary(temp_string)


;                        GLOBAL SYSTEM VARIABLES and CONFIGURATIONS  (NON-THEMIS)
;====================================================================================
; Set global system variables:
; Please note: These settings will affect all IDL routines, NOT JUST THEMIS routines!

; ============ install custom color tables.
; Check for color table with additional tables (download if necessary)
; and set it as default for loadct2
; Defines 3 new tables:
; 41 wind3dp
; 42 B-W reversed
; 43 FAST-Special
ctable_relpath = 'idl_ctables/colors1.tbl'
ctable_file = file_retrieve(ctable_relpath, _extra=!themis)
setenv,  'IDL_CT_FILE='+ctable_file

; ============ color setup

; Do not do color setup if taken care for already
if not keyword_set(no_color_setup) then begin

  if n_elements(colortable) eq 0 then colortable = 43     ; default color table

;                        Define POSTSCRIPT color table
  old_dev = !d.name             ;  save current device name
  set_plot,'PS'                 ;  change to PS so we can edit the font mapping
  loadct2,colortable
  device,/symbol,font_index=19  ;set font !19 to Symbol
  set_plot,old_dev              ;  revert to old device

;                        Color table for ordinary windows
  loadct2,colortable

;              Make black on white background
  !p.background = !d.table_size-1                   ; White background   (color table 34)
  !p.color=0                                        ; Black Pen
  !p.font = -1                                      ; Use default fonts


  if !d.name eq 'WIN' then begin
    device,decompose = 0
  endif

  if !d.name eq 'X' then begin
    ; device,pseudo_color=8  ;fixes color table problem for machines with 24-bit color
    device,decompose = 0
    if !version.os_name eq 'linux' then device,retain=2  ; Linux does not provide backing store by default
  endif

endif	; no_color_setup

;===========  debugging options

if !prompt eq 'IDL> ' then !prompt = 'THEMIS> '

; The following calls set persistent flags in dprint that change subsequent output
;dprint,setdebug=3       ; set default debug level to value of 3
;dprint,/print_dlevel    ; uncomment to display dlevel/verbose at each dprint statement
;dprint,/print_dtime     ; uncomment to display time interval between dprint statements.
;dprint,print_trace=1    ; uncomment to display current procedure and line number on each line. (recommended)
;dprint,print_trace=3    ; uncomment to display entire program stack on each line.



;  !quiet=1            ; if !quiet ==1 then  error messages are suppressed


;============= Useful TPLOT options
; Most standard plotting keywords can be included in the global tplot_options routine
; or individually in each tplot variable using the procedure: "options"
; for example:
; tplot_options,'title','Themis Event #1'
; tplot_options,'charsize',1.2   ; set default character size.

; Some other useful options:
tplot_options,window=0            ; Forces tplot to use only window 0 for all time plots
;tplot_options,'wshow',1           ; raises tplot window when tplot is called
;tplot_options,'verbose',1         ; Displays some extra messages
;tplot_options,'psym_lim',100      ; Displays symbols if less than 100 point in panel
tplot_options,'ygap',.5           ; Set gap distance between tplot panels.
tplot_options,'lazy_ytitle',1     ; breaks "_" into carriage returns on ytitles
;tplot_options,'no_interp',1       ; prevents interpolation in spectrograms (recommended)



;!warn.obs_routines = 1
;!warn.OBS_SYSVARS = 1
;!warn.PARENS = 1
;!warn.TRUNCATED_FILENAME = 1



end