Function energy_converter,data_in,unit_in=unit_in,unit_out=unit_out
;+
;NAME:
; energy_converter
;PURPOSE:
; converter energy between different unit
;CALLING SEQUENCE:
; result=energy_converter(data,unit_in=unit_in,unit_out=unit_out)
;INPUT:
; data_in --- input data, scalar or vector
;OPTIONAL KEYWORD INPUT:
; unit_in --- Unit of input data, string scalar
;OUTPUT:
; data_out --- output data, scalar or vector
;OPTIONAL KEYWORD OUTPUT:
; unit_out --- Unit of output data, string scalar
;
;EXAMPLE:
; IDL> print,energy_converter(1.0,unit_in='keV',unit_out='Hz')
; 2.4179847e+17
;
; IDL> print,energy_converter(1.0,unit_in='keV',unit_out='A')
; 12.398443
;
; IDL> print,energy_converter(1.0,unit_in='keV',unit_out='ergs')
; 1.6021733e-09
;
; IDL> print,energy_converter(1.0,unit_in='keV',unit_out='T')
; 11604508.
;
;REVISION HISTORY:
; Original by DL.Wang,Aug-30-2007
;-
;#################################
;##### Fundmental contstant
light_speed=2.99792458D+18 ; A Hz
plank_const=6.62606868D-27 ;erg / Hz
l_k=1.16045077D+7 ; K / keV
q=1.60217330D-9 ;keV / erg
electron_mass=510.998899D+0 ;keV
proton_mass=938271.991D+0 ;keV
earth_mass=5.9736D+27 ; g
sun_mass=1.989D+33 ; g
;#################################
;##### Unit converter
kev_kev = 1.0D+0
ev_kev = 1.0D-3
hz_kev = plank_const/q
ghz_kev = (plank_const/q)*1.0D+9
A_kev = plank_const*light_speed/q
ergs_kev = 1.0D+0/q
cm_kev = 1.0D+8*A_kev
T_kev = 1.0D+0/l_k
kev_ev = 1.0D+3
kev_hz = q/plank_const
kev_ghz = kev_hz*1.0D-9
kev_A = plank_const*light_speed/q
kev_cm = kev_A*1.0D-8
kev_ergs= q
kev_T = l_k
;########################################
;#### energy_converter ####
;########################################
;
;converter input unit to keV
;
case unit_in of
'keV':data_in=data_in*kev_kev
'eV':data_in=data_in*ev_kev
'Hz':data_in=data_in*hz_kev
'GHz':data_in=data_in*ghz_kev
'A':data_in=(1.0D0/data_in)*A_kev
'cm':data_in=(1.0D0/data_in)*cm_kev
'ergs':data_in=data_in*ergs_kev
'T':data_in=data_in*T_kev
endcase
;
;converter keV to out unit
;
case unit_out of
'keV':data_out=data_in*kev_kev
'eV':data_out=data_in*kev_ev
'Hz':data_out=data_in*kev_hz
'GHz':data_out=data_in*kev_ghz
'A':data_out=(1.0D0/data_in)*kev_A
'cm':data_out=(1.0D0/data_in)*kev_cm
'ergs':data_out=data_in*kev_ergs
'T':data_out=data_in*kev_T
endcase
return,data_out
End
https://blog.sciencenet.cn/blog-456360-658887.html
上一篇:
改正因子计算(IDL程序)下一篇:
距离不同单位表达转化(IDL程序)