pro ssl2dsl,name_input=name_input,name_thx_spinper=name_thx_spinper,$
name_thx_spinphase=name_thx_spinphase,name_output=name_output,$
DSL2SSL=DSL2SSL,ignore_dlimits=ignore_dlimits,$
INTERPOLATE_STATE=INTERPOLATE_STATE,spinmodel_ptr=spinmodel_ptr,$
use_spinphase_correction=use_spinphase_correction
if n_elements(name_input) EQ 0 then begin
message,'Missing required argument name_input'
end
if n_elements(name_output) EQ 0 then begin
message,'Missing required argument name_output'
end
if keyword_set(interpolate_state) then begin
if n_elements(name_thx_spinphase) EQ 0 then begin
message,'/INTERPOLATE_STATE specified, but name_thx_spinphase not specified'
end
if n_elements(name_thx_spinper) EQ 0 then begin
message,'/INTERPOLATE_STATE specified, but name_thx_spinper not specified'
end
end else begin
if n_elements(spinmodel_ptr) EQ 0 then begin
message,'/INTERPOLATE_STATE not specified; missing required argument spinmodel_ptr'
end
endelse
get_data,name_input,data=thx_xxx_in, limit=l_in, dl=dl_in
data_in_coord = cotrans_get_coord(dl_in)
thx_xxx_out=thx_xxx_in
if keyword_set(DSL2SSL) then begin
DPRINT, 'DSL-->SSL'
if keyword_set(ignore_dlimits) then begin
data_in_coord='dsl'
endif
if ~ strmatch(data_in_coord, 'unknown') && ~ strmatch(data_in_coord, $
'dsl') then begin
dprint, 'coord of input '+name_input+': '+data_in_coord+ $
' must be DSL'
return
end
out_coord = 'ssl'
isDSL2SSL=1
endif else begin
DPRINT, 'SSL-->DSL'
if keyword_set(ignore_dlimits) then begin
data_in_coord='ssl'
endif
if ~ strmatch(data_in_coord, 'unknown') && ~ strmatch(data_in_coord, $
'ssl') then begin
dprint, 'coord of input '+name_input+': '+data_in_coord+ $
' must be SSL'
return
end
out_coord = 'dsl'
isDSL2SSL=0
endelse
count=SIZE(thx_xxx_in.X,/N_ELEMENTS)
DPRINT, 'number of DATA records: ',count
thx_xxx_in=thx_xxx_out
if keyword_set(interpolate_state) then begin
get_data,name_thx_spinper,data=thx_spinper
get_data,name_thx_spinphase,data=thx_spinphase
if size(thx_spinper, /type) ne 8 || size(thx_spinphase, /type) ne 8 then begin
message, 'aborted: must load spin data from state file'
endif
if min(thx_spinper.x,/nan)-min(thx_xxx_in.x,/nan) gt 60*60 || max(thx_xxx_in.x,/nan) - max(thx_spinper.x,/nan) gt 60*60 then begin
dprint,'NON-FATAL-ERROR: ' + name_thx_spinper + ' and ' + name_input + ' fail to overlap for time greater than 1 hour. Data may have significant interpolation errors.'
endif
if min(thx_spinphase.x,/nan)-min(thx_xxx_in.x,/nan) gt 60*60 || max(thx_xxx_in.x,/nan) - max(thx_spinphase.x,/nan) gt 60*60 then begin
dprint,'NON-FATAL-ERROR: ' + name_thx_spinphase + ' and ' + name_input + ' fail to overlap for time greater than 1 hour. Data may have significant interpolation errors.'
endif
countPhase=SIZE(thx_spinphase.X,/N_ELEMENTS)
DPRINT, 'number of Phase records: ',countPhase
thx_spinphase_highres=thm_interpolate_state(thx_xxx_in=thx_xxx_in,$
thx_spinper=thx_spinper,$
thx_spinphase=thx_spinphase)
phase=thx_spinphase_highres.Y*!dpi/180.d0
endif else begin
dprint, 'Using spin model to calculate phase versus time...'
spinmodel_interp_t,model=spinmodel_ptr,time=thx_xxx_in.X,spinphase=phase_deg,use_spinphase_correction=use_spinphase_correction
spinmodel_phase=phase_deg*!dpi/180.0D
phase=spinmodel_phase
endelse
if isDSL2SSL eq 0 then begin
thx_xxx_out.Y[*,0]=thx_xxx_in.Y[*,0]* cos(phase) -thx_xxx_in.Y[*,1]* sin(phase)
thx_xxx_out.Y[*,1]=thx_xxx_in.Y[*,0]* sin(phase) +thx_xxx_in.Y[*,1]* cos(phase)
endif else begin
thx_xxx_out.Y[*,0]= thx_xxx_in.Y[*,0]* cos(phase) +thx_xxx_in.Y[*,1]* sin(phase)
thx_xxx_out.Y[*,1]=-thx_xxx_in.Y[*,0]* sin(phase) +thx_xxx_in.Y[*,1]* cos(phase)
endelse
dl_out=dl_in
cotrans_set_coord, dl_out, out_coord
str_element, dl_out, 'ytitle', /delete
l_out=l_in
str_element, l_out, 'ytitle', /delete
store_data,name_output,data=thx_xxx_out, limit=l_out, dl=dl_out
DPRINT, 'done'
end