;+
; Contains the iso_fc_intersect procedure
;
; :Author:
; Baptiste Cecconi
;
; :History:
; 2009/02/20: Created
;
; 2009/02/20: Last Edit
;-
;
;+
; iso_fc_intersect is a procedure that <behavior desc here>
;
; :Uses:
; magnetic_field, xyz_to_rtp
;
; :Params:
; v_SC: in, required, type=sometype
; position de Cassini
; v_SP: in, required, type=sometype
; position du maximum de fc sur la ligne de visee
; ff: in, required, type=sometype
; A parameter named ff
; beam_fc: in, required, type=sometype
; A parameter named beam_fc
; dist_fc: in, required, type=sometype
; A parameter named dist_fc
; xyz_fc: in, required, type=sometype
; A parameter named xyz_fc
; ndic: in, required, type=sometype
; A parameter named ndic
;
; :Keywords:
; use_fx: in, optional, type=sometype
; A keyword named use_fx
; verbose: in, optional, type=sometype
; A keyword named verbose
; in: in, optional, type=sometype
; determination de l'intersection avec l'iso-fc lorsque le point
; initial est a l'interieur de l'iso-fc. Les deux points initiaux
; pour l'algorithme de dichotomie sont : V_SP et v_SC.
; out: in, optional, type=sometype
; determination de l'intersection avec l'iso-fc lorsque le point
; initial est au dehors de l'iso-fc. Les deux points initiaux pour
; l'algorithme de dichotomie sont : V_SP et le centre de Saturne.
; mfl_model: in, optional, type=sometype
; A keyword named mfl_model
; nocrt: in, optional, type=sometype
; A keyword named nocrt
;-
PRO iso_fc_intersect,v_SC,v_SP,ff,beam_fc,dist_fc,xyz_fc,ndic,$
use_fx=use_fx,verbose=verbose,in=in,out=out,mfl_model=mfl_model,$
nocrt=nocrt
;V20
if ~keyword_set(mfl_model) then mfl_model='SPV'
if ~keyword_set(in) and ~keyword_set(out) then message,'Keyword /in or /out must selected.'
ndata = n_elements(ff)
fsb=2.79924835996d0 ; converts Gauss to MHz
fsb=fsb*1.d3 ; converts Gauss to kHz
v_SP0 = v_SP
if keyword_set(in) then v_SP1 = v_SC
if keyword_set(out) then v_SP1 = fltarr(3,ndata); avant: 0.1*v_SP/rebin(reform(total(v_SP^2.,1),1,ndata),3,ndata)
; v_SP_trace = fltarr(3,ndata,2,ndic+1)
; v_SP_trace(*,*,0,0) = v_SP0
; v_SP_trace(*,*,1,0) = v_SP1
; fc2_trace = fltarr(ndata,ndic)
xyz_fc = fltarr(3,ndata)
for idic=0L,ndic-1L do begin
v_SP2 = (v_SP0-v_SP1)/2 + v_SP1
rtp2 = xyz_to_rtp(v_SP2)
magnetic_field,rtp2(0,*),rtp2(1,*),rtp2(2,*),bvec2,btot2,mfl_model=mfl_model,nocrt=nocrt
fc2 = btot2*fsb
; fc2_trace(*,idic) = fc2
ww_in = where(fc2 ge ff, cnt_ww_in, compl=ww_out, ncompl=cnt_ww_out)
if cnt_ww_in ne 0 then begin
if keyword_set(in) then v_SP0(*,ww_in) = v_SP2(*,ww_in)
if keyword_set(out) then v_SP1(*,ww_in) = v_SP2(*,ww_in)
endif
if cnt_ww_out ne 0 then begin
if keyword_set(in) then v_SP1(*,ww_out) = v_SP2(*,ww_out)
if keyword_set(out) then v_SP0(*,ww_out) = v_SP2(*,ww_out)
endif
; v_SP_trace(*,*,0,idic+1) = v_SP0
; v_SP_trace(*,*,1,idic+1) = v_SP1
endfor
xyz_fc = v_SP0
rtp_fc = xyz_to_rtp(xyz_fc)
th = atan(bvec2(1,*),bvec2(0,*))
bxyz = make_vect_sph(1.,reform(rtp_fc(1,*)+th),reform(rtp_fc(2,*)))
beam_fc = angular_distance(v_SC-v_SP,bxyz)
if keyword_set(in) then dist_fc=0.
if keyword_set(out) then dist_fc = sqrt(total((xyz_fc-v_SP)^2.,1))
end