;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           eis_get_rp_array
;
; PURPOSE
;           Return array of ORe pointings
;
; INPUTS
;           rpev - 
;
; KEYWORDS
;           None
; NOTES
;           This
;
; CATEGORY
;           EIS timeline planning
;
; WRITTEN
;           John Rainne, 19-Apr-2011
;
; VERSION
;           V0.0 JAR Feb-2006
;
;-
;______________________________________________________________________________
FUNCTION eis_get_rp_array , rpev

; OK, check we have some re-point events to plot
valid_rpev = 1
IF (N_ELEMENTS(*rpev)  EQ 1)  AND                               $
   (N_TAGS((*rpev)[0]) EQ 0)  THEN RETURN , 0

; Before we can plot, we need to concatenate from an array of pointers
IF (valid_rpev EQ 1) THEN BEGIN

    ; JAR 6-Feb-2007
    ; There are occasions on which the J-Side re-point file doesn't
    ; actually contain any ORe lines. In which case I now check which
    ; members of the *rpev array are structures (ie N_TAGS > 0).

    rpev_tags = BYTARR(N_ELEMENTS(*rpev))
    FOR j = 0 , N_ELEMENTS(*rpev) - 1 DO rpev_tags[j] = N_TAGS(*(*rpev)[j])
    rpev_real = WHERE(rpev_tags GT 0 , real_count)


;    FOR i = 0 , N_ELEMENTS(*rpev) -1 DO BEGIN
    FOR i = 0 , real_count -1 DO BEGIN

          CASE i OF
               0    : rp_array = (*(*rpev)[rpev_real[0]]).rp_ore_array
               ELSE : BEGIN
                         ; v1.5 JAR 17-Sep-2008
                         ; Need to check new and existing (old) arrays.
                         ; Check each is a structure (using N_TAGS).
                         ; If (1) both are NOT or (2) the new one isn't -
                         ;     do nothing.
                         old_n_tags = N_TAGS(rp_array[0])
                         new_n_tags = N_TAGS((*(*rpev)[rpev_real[i]]).rp_ore_array)

                         ; Concatenate if both are valid structures!
                         IF (old_n_tags GT 0) AND (new_n_tags GT 0) THEN   $
                             rp_array = [ rp_array                   ,     $
                                   (*(*rpev)[rpev_real[i]]).rp_ore_array ]

                         ; Set old as new if the latter is valid.
                         IF (old_n_tags EQ 0) AND (new_n_tags GT 0) THEN   $
                             rp_array = (*(*rpev)[rpev_real[i]]).rp_ore_array
                             ; Changed 0 to i to trap no-upload re-point
                             ; file being the first re-point file
                             ; 18-Nov-2009 JAR/DHB

                      END
          ENDCASE

    ENDFOR
ENDIF

RETURN , rp_array

END