;
; Copyright (c) 1998, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made.  This
; routine is provided as is without any express or implied warranties
; whatsoever.
;+
; NAME:
;	build_structure
;
; PURPOSE:
;	This routine accumulates values into a structure or concatinates two structures
;
; CATEGORY:
;   PROG_TOOLS
;
; CALLING SEQUENCE:
;   build_structure,structure,declaration,value,[name=name],[/random_structure_name],[/counted_structure_name]
;
; INPUTS:
;   structure : if it's present the structure which will be accumulated to
;   declaration: the tag which will be added to the structure
;   value  : the value which will be added to the structure
;
;
; OUTPUTS:
;	structure: A structure holding value
;
; EXAMPLE:
;   build_structure,def,'test',5
;   help,test,/str
;** Structure <117e2f8>, 1 tags, length=2, refs=1:
;   TEST            INT              5
;   build_structure,def,'AN',5
;   help,def,/str
;** Structure <117ec88>, 2 tags, length=4, refs=1:
;   TEST            INT              5
;   AN              INT              5
;
;
; MODIFICATION HISTORY:
; 	Written by:	R.Bauer (ICG-1), 1998-Jun-27
;   1999-02-23 Problem if tag is alread defined in structure by is_tag resolved
;   1999-03-16 random_structure_name added
;   1999-03-20 counted_structure_name added
;-

PRO build_structure,structure,declaration,value

   errvar=0
   CATCH,errvar

   IF errvar NE 0 THEN BEGIN
       RETURN
   ENDIF


   IF N_PARAMS() EQ 3 THEN BEGIN
      IF N_ELEMENTS(structure) EQ 0 THEN structure=CREATE_STRUCT(declaration,value) ELSE BEGIN
         IF NOT is_tag(structure,declaration) THEN structure=CREATE_STRUCT(structure[0],declaration,value) ELSE MESSAGE,declaration+' already in structure',/cont
      ENDELSE
      ENDIF ELSE BEGIN
      IF size(declaration,/type) eq 8 THEN structure=CREATE_STRUCT(structure,declaration)

   ENDELSE
END







