Pro mvn_sta_cmn_l2file_save, otp_struct, fullfile0, temp_dir = temp_dir, $
no_compression = no_compression, _extra = _extra
If(~is_struct(otp_struct)) Then Begin
dprint, 'Bad structure input '
Return
Endif
If(~is_string(fullfile0)) Then Begin
dprint, 'Bad filename input '
Return
Endif
mvn_sta_l2_filerevision, fullfile0, fullfile, delfiles
If(~is_string(fullfile)) Then Begin
dprint, 'No filename for file: '+fullfile0
Return
Endif
file = file_basename(fullfile)
file_id = file_basename(file, '.cdf')
otp_struct.filename = file
ppp = strsplit(file_id, '_', /extract)
app_id = strmid(ppp[3], 0, 2)
otp_struct.g_attributes.logical_source = strjoin(ppp[0:3], '_')
otp_struct.g_attributes.logical_file_id = strjoin(ppp[0:5], '_')
If(keyword_set(temp_dir)) Then tdir = temp_dir Else tdir = '/mydisks/home/maven/'
If(n_elements(ppp) Eq 7 && strlen(ppp[4]) Eq 8) Then tdir_out = tdir+ppp[4] $
Else tdir_out = tdir+'YYYYMMDD'
file_mkdir, tdir_out
fullfilex = tdir_out+'/'+file
dummy = cdf_save_vars2(otp_struct, fullfilex, /no_file_id_update)
spawn, '/usr/local/pkg/cdf-3.5.0_CentOS-6.5/bin/cdfconvert '+fullfilex+' '+fullfilex+' -compression cdf:none -delete'
md5file = ssw_str_replace(fullfile, '.cdf', '.md5')
md5filex = ssw_str_replace(fullfilex, '.cdf', '.md5')
If(is_string(file_search(md5filex))) Then file_delete, md5filex
spawn, 'md5sum '+fullfilex+' > '+md5filex
md5str = strarr(1)
openr, unit, md5filex, /get_lun
readf, unit, md5str
free_lun, unit
ppp = strsplit(md5str[0], /extract)
openw, unit, md5filex, /get_lun
printf, unit, ppp[0], ' ', file
free_lun, unit
If(~keyword_set(no_compression)) Then Begin
spawn, '/usr/local/pkg/cdf-3.5.0_CentOS-6.5/bin/cdfconvert '+fullfilex+' '+fullfilex+' -compression cdf:gzip.5 -delete'
Endif
dir = file_dirname(fullfile)
file_move, fullfilex, fullfile, /overwrite
file_move, md5filex, md5file, /overwrite
If(is_string(file_search(fullfile0))) Then file_delete, fullfile0
If(is_string(delfiles)) Then Begin
ndel = n_elements(delfiles)
For j = 0, ndel-1 Do Begin
file_delete, delfiles[j]
del_md5filej = ssw_str_replace(delfiles[j], '.cdf', '.md5')
If(is_string(file_search(del_md5filej))) Then file_delete, del_md5filej
Endfor
Endif
file_delete, tdir_out, /recursive
spawn, 'ln '+fullfile+' '+fullfile0
spawn, 'chmod g+w '+fullfile
spawn, 'chmod g+w '+fullfile0
spawn, 'chmod g+w '+md5file
Return
End