Viewing contents of file '../idllib/user_contrib/creaso/restorearray.pro'
; Copyright(c) 1992, CreaSo Creative Software Systems GmbH. All rights reserved.
;	Unauthorized reproduction prohibited.
;+
; NAME:
;	RESTOREARRAY
;
; PURPOSE:
;    This routine loads the content of an array into a string seperate by the 
;    separator string.
;
; CALLING SEQUENCE:
;	LOADARRAY, STRING_ARRAY, SEPARATOR
;
; INPUTS:
;       STRING, SEPERATOR
;
; KEYWORDS:
;       FULL  - If not set, empty elements will not appear in string
;       SELEM - Starting element
;       EELEM - Ending element
;
; OUTPUT: 
;       string
;
; COMMON BLOCKS:
;	None
;
; SIDE EFFECTS:
;       No known side effects.
;
; RESTRICTIONS:
;	NONE
;
; EXAMPLE:
;      str = loadarray (["ulib","usca","test"], ".")
;      result : str eq ulib.usca.test
;
; MODIFICATION HISTORY:
;	July 1992, AH,	CreaSo		Created.
;-
function restorearray, arr, sep, selem, eelem, full=full

   ;Loop through array

   string = ''

   ;a: Calculate first element

   if selem gt n_elements(arr)-1 then return, string $
   else if selem lt 0 then selem = 0

   ;a: Calculate last element

   if eelem gt n_elements(arr)-1 then eelem = n_elements(arr)-1
   if eelem lt selem then return, string

   ;iy: Full keyword is set

   if keyword_set (full) then begin

      ;a: Append all elements to string

      for i=selem, eelem-1 do begin
         string = string + arr(i) + sep
      endfor

      ;Append last array element to string

      string = string + arr(eelem)
   endif else begin

      ;a: Append only filled elements to string

      for i=selem, eelem-1 do begin
         if arr(i) ne '' then string = string + arr(i)
         if arr(i+1) ne '' then string = string + sep
      endfor

      ;Append last array element to string

      if arr(eelem) ne '' then string = string + arr(eelem)
   endelse

   return, string
END