;+ ; NAME: ; Distance2Sun ; PURPOSE: ; Calulates Electron-Sun distance and angle Sun-Electron-Observer ; CALLING SEQUENCE: FUNCTION Distance2Sun, Elo, S, SinChi, degrees=Degrees, grid=grid ; INPUTS: ; Elo array; type: float ; elongations of lines of sight ; S array; type: float ; Distance along line of sight (i.e. Observer-Electron ; distance) in units of the Observer-Sun distance. ; If /grid NOT set then S should have the same structure ; as 'Elo'. If /grid is set then any array is allowed. ; OPTIONAL INPUT PARAMETERS: ; /degree if set all angles are in degrees (default: radians) ; /grid if set then every element in S is combined with ; every element in Elo ; OUTPUTS: ; Result array; type: float ; Sun-Electron distance (same units as S) ; SinChi array; type: float ; Sine of angle Sun-Electron-Observer ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; ToRadians, SuperArray ; PROCEDURE: ;> The elongation is the angle between observer-Sun and observer-electron ; direction (Elo = 0 is the direction observer-Sun) ;> Cosine and sine rule in triangle with Sun, Observer and Electron on the corners. ; MODIFICATION HISTORY: ; SEP-1996, Paul Hick (UCSD) ; JUN-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Replacement for old ElSunDistance function ; Added /grid keyword ;- InitVar, grid, /key rpm = ToRadians(degrees=Degrees) Sun = 1 CASE grid OF 0: BEGIN Elo_ = Elo*rpm RSun = ( Sun*Sun+S*S-2.0d0*Sun*S*cos(Elo_) ) > 0.0d0 END 1: BEGIN szL = size(Elo) szS = size(S ) nL = szL[szL[0]+2] nS = szS[szS[0]+2] Elo_ = SuperArray(Elo*rpm, nS, /lead ) S_ = SuperArray(S , nL, /trail) RSun = ( Sun*Sun+S_*S_-2.0d0*Sun*S_*cos(Elo_) ) > 0.0d0 sz = 0 IF nS GT 1 THEN sz = [sz, szS[1:szS[0]]] IF nL GT 1 THEN sz = [sz, szL[1:szL[0]]] CASE n_elements(sz) OF 1 : RSun = reform(RSun, /overwrite) ELSE: RSun = reform(RSun, /overwrite, sz[1:*]) ENDCASE END ENDCASE RSun = sqrt(RSun) SinChi = Sun/RSun*sin(Elo_) RETURN, RSun & END