Pro spedas_write_config, copy = copy, _extra = _extra
dir = spedas_config_filedir()
ll = strmid(dir, strlen(dir)-1, 1)
If(ll Eq '/' Or ll Eq '\') Then filex = dir+'spedas_config.txt' $
Else filex = dir+PATH_SEP()+'spedas_config.txt'
If(keyword_set(copy)) Then Begin
xt = time_string(systime(/sec))
ttt = strmid(xt, 0, 4)+strmid(xt, 5, 2)+strmid(xt, 8, 2)+$
'_'+strmid(xt, 11, 2)+strmid(xt, 14, 2)+strmid(xt, 17, 2)
filex_out = filex+'_'+ttt
cfg = spedas_read_config(header = hhh)
Endif Else Begin
If(file_search(filex) Ne '') Then spedas_write_config, /copy
filex_out = filex
if ~keyword_set(!spedas) then begin
tmp_struct=file_retrieve(/structure_format)
str_element,tmp_struct,'browser_exe','',/add
str_element,tmp_struct,'temp_dir','',/add
str_element,tmp_struct,'temp_cdf_dir','',/add
str_element,tmp_struct,'linux_fix',0,/add
defsysv,'!spedas',tmp_struct
endif
cfg = !spedas
hhh = [';spedas_config.txt', ';spedas configuration file', $
';Created:'+time_string(systime(/sec))]
Endelse
xdname = file_dirname(filex_out)
If(xdname Ne '') Then file_mkdir, xdname
openw, unit, filex_out, /get_lun
For j = 0, n_elements(hhh)-1 Do printf, unit, hhh[j]
ctags = tag_names(cfg)
nctags = n_elements(ctags)
For j = 0, nctags-1 Do Begin
x0 = strtrim(ctags[j])
x1 = cfg.(j)
If (size(x1, /type) eq 11) then x1 = ''
If(is_string(x1)) Then x1 = strtrim(x1, 2) $
Else Begin
If(size(x1, /type) Eq 1) Then x1 = fix(x1)
x1 = strcompress(/remove_all, string(x1))
Endelse
printf, unit, x0+'='+x1
Endfor
free_lun, unit
Return
End