;+
;Project
;          Hinode/EIS
;
; Name
;          eis_solarb_science_update
;
; Purpose
;          To create/update solarb_science tag in TL entry
;
; Category
;          Timeline planning
;          Response Studies
;
; Written
;          John Rainnie 26-Jan-2010
;
; Version
;          v0.0 JAR 01-01-2010
;               Blah
;
;-
;______________________________________________________________________________
FUNCTION eis_solarb_science_update , new , old

new = STRCOMPRESS(STRTRIM(new,2),/REMOVE_ALL)
old = STRCOMPRESS(STRTRIM(old,2),/REMOVE_ALL)
print,new
print,old

; Is the existing (old) tag blank? In which case, simply return the
; new tag
IF (is_blank(old) EQ 1) THEN RETURN , new

; OK, so it already has a string value
; Let's split up the existing value, using the ',' as a delimiter
split = STRSPLIT(old,',' , count = count , /EXTRACT)

; If it has only one value, then check it is a match
IF (count EQ 1) THEN BEGIN
   match = STRMATCH(new,old,/FOLD_CASE)
   ; IF match is +ve, then return old or new (don't matter)
   IF (match EQ 1) THEN BEGIN
       RETURN , new
   ENDIF ELSE BEGIN
       ; However, if there is NO match, just concatenate the 2
       RETURN , STRJOIN([old,new],',',/SINGLE)
   ENDELSE
ENDIF

; OK, if we got here then we have more than 1 value
index = WHERE(STRMATCH(split , new , /FOLD_CASE) EQ 1 , count)
IF (count EQ 1) THEN BEGIN
   ; Then there's no change. This is merely an update. Right?
   ; So just set it back to what it was.
   RETURN , old
ENDIF ELSE BEGIN
   ; So this must be a new item. Concatenate it.
   RETURN , STRJOIN([old,new],',',/SINGLE)
ENDELSE


RETURN , ''

END
