; ;+ ;Function: mvn_spc_met_to_unixtime ;Purpose: Convert MET (mission Elapsed Time) to Unix Time (which is almost equivalent to UTC) ;see also: "mvn_spc_unixtime_to_met" for the reverse conversion ; This routine is in the process of being modified to use SPICE Kernels to correct for clock drift as needed. ; Author: Davin Larson ; $LastChangedBy: davin-mac $ ; $LastChangedDate: 2014-02-02 16:21:26 -0800 (Sun, 02 Feb 2014) $ ; $LastChangedRevision: 14117 $ ; $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/idl_socware/trunk/projects/maven/mvn_spc_met_to_unixtime.pro $ ;- function mvn_spc_met_to_unixtime,input,prelaunch = prelaunch,reverse=reverse,reset=reset common mvn_spc_met_to_unixtime_com , kernel_verified, time_verified, sclk if getenv('USER') ne 'davin' then prelaunch =1 else begin if n_elements(kernel_verified) eq 0 || keyword_set(reset) then begin ; check for cspice first if spice_test() then begin sclk = mvn_spice_kernels(['STD','SCK'],/load) if keyword_set(sclk) then begin kernel_verified = 1 endif else begin kernel_verified = 0 dprint,dlevel=2,'ICY is not installed.' dprint,dlevel=2,'Times are subject to spacecraft clock drift.' prelaunch = 1 endelse endif else begin kernel_verified = 0 prelaunch = 1 endelse reset=0 time_verified = systime(1) endif endelse if keyword_set(reverse) then begin unixtime = input if keyword_set(prelaunch) then begin epoch = 946771200d - 12L*3600 ; long(time_double('2000-1-1/12:00')) ; Normal use ut = time_double(unixtime) ; if unixtime[0] le 1354320000 then unixtime = met + epoch + 3600L*12 ; correction prior to '2012-12-1' delta = (ut le 1354320000) * 3600L*12 met = ut - epoch + delta return,met endif else begin ; dprint,'Using cspice',dlevel=3 et = time_ephemeris(unixtime) cspice_sce2c, -202, et, sclkdp1 met = sclkdp1 / 2d^16 endelse return,met endif met = input if keyword_set(prelaunch) then begin ; epoch = 978307200d ; long(time_double('2001-1-1')) ; valid for files prior to about June, 2012 epoch = 946771200d - 12L*3600 ; long(time_double('2000-1-1/12:00')) ; Normal use unixtime = met + epoch ; if unixtime[0] le 1356998400 then unixtime = met + epoch + 3600L*12 ; correction prior to '2013-1-1' ; if unixtime[0] le 1354320000 then unixtime = met + epoch + 3600L*12 ; correction prior to '2012-12-1' delta = (unixtime le 1354320000) * 3600L*12 unixtime += delta ; if unixtime[0] le 1351728000 then unixtime = met + epoch + 3600L*12 ; correction prior to '2012-11-1' endif else begin eti = double(met) n = n_elements(met) for i=0L,n-1 do begin cspice_sct2e, -202, double(MET[i]*2D^16), ET eti[i] = et endfor unixtime = time_ephemeris(ETI,/et2ut) endelse return,unixtime end