1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME: mixstru |
---|
6 | ; |
---|
7 | ; PURPOSE: concatene 2 structures ensemble. La difference avec |
---|
8 | ; CREATE_STRUCT etant que si les 2 stuctures ont les memes noms |
---|
9 | ; d''elements alors mixstru ne plante pas mais choisit pour valeur de |
---|
10 | ; l''element commun celle specifiee par la premiere structure. |
---|
11 | ; |
---|
12 | ; CATEGORY: structure |
---|
13 | ; |
---|
14 | ; CALLING SEQUENCE: rs=mixstru(stru1,stru2) |
---|
15 | ; |
---|
16 | ; INPUTS: stru1 et stu2 sont 2 structures qui peuvent avoir des |
---|
17 | ; elements portant le meme nom mais avec une valeur differente. |
---|
18 | ; |
---|
19 | ; KEYWORD PARAMETERS: none |
---|
20 | ; |
---|
21 | ; OUTPUTS: une stucture |
---|
22 | ; |
---|
23 | ; COMMON BLOCKS: |
---|
24 | ; |
---|
25 | ; SIDE EFFECTS: si stru1 ou stru2 ne sont pas des structures mixstru |
---|
26 | ; renvoie -1 |
---|
27 | ; |
---|
28 | ; RESTRICTIONS: |
---|
29 | ; |
---|
30 | ; EXAMPLE: |
---|
31 | ; |
---|
32 | ; IDL> a=get_extra(/toto,ok=123) |
---|
33 | ; IDL> b=get_extra(ok=111, year=1999, age_capitaine=35) |
---|
34 | ; IDL> help, a,b,/struct |
---|
35 | ; ** Structure <8334424>, 2 tags, length=4, refs=1: |
---|
36 | ; OK INT 123 |
---|
37 | ; TOTO INT 1 |
---|
38 | ; ** Structure <8373da4>, 3 tags, length=6, refs=1: |
---|
39 | ; AGE_CAPITAINE INT 35 |
---|
40 | ; OK INT 111 |
---|
41 | ; YEAR INT 1999 |
---|
42 | ; IDL> help, mixstru(a,b),/struct |
---|
43 | ; ** Structure <82f25ac>, 4 tags, length=8, refs=1: |
---|
44 | ; AGE_CAPITAINE INT 35 |
---|
45 | ; YEAR INT 1999 |
---|
46 | ; OK INT 123 |
---|
47 | ; TOTO INT 1 |
---|
48 | ; IDL> help, mixstru(b,a),/struct |
---|
49 | ; ** Structure <834604c>, 4 tags, length=8, refs=1: |
---|
50 | ; TOTO INT 1 |
---|
51 | ; AGE_CAPITAINE INT 35 |
---|
52 | ; OK INT 111 |
---|
53 | ; YEAR INT 1999 |
---|
54 | ; |
---|
55 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
56 | ; 7/10/1999 |
---|
57 | ;- |
---|
58 | ;------------------------------------------------------------ |
---|
59 | ;------------------------------------------------------------ |
---|
60 | ;------------------------------------------------------------ |
---|
61 | FUNCTION mixstru, stru1, stru2 |
---|
62 | IF size(stru1, /type) EQ 0 AND size(stru2, /type) EQ 8 THEN return, stru2 |
---|
63 | IF size(stru2, /type) EQ 0 AND size(stru1, /type) EQ 8 THEN return, stru1 |
---|
64 | if size(stru1, /type) NE 8 then return, -1 |
---|
65 | if size(stru2, /type) NE 8 then return, -1 |
---|
66 | tname = tag_names(stru2) |
---|
67 | res = '' |
---|
68 | rien = execute('res = get_extra('+tname[0]+'=stru2.(0), _extra = stru1)') |
---|
69 | if rien EQ 0 then stop |
---|
70 | if n_tags(stru2) GT 1 then begin |
---|
71 | FOR i = 1, n_tags(stru2)-1 DO BEGIN |
---|
72 | rien = execute('res = get_extra('+tname[i]+'=stru2.(i), _extra = res)') |
---|
73 | if rien EQ 0 then stop |
---|
74 | endfor |
---|
75 | endif |
---|
76 | return, res |
---|
77 | end |
---|