source: trunk/SRC/ToBeReviewed/STRUCTURE/mixstru.pro @ 163

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Concatenate 2 structures together. The difference with CREATE_STRUCT
8; is  that if the 2 structure have same elements's name, then mixstru
9; do not break down but choose for the common element the value
10; specified by the first structure.
11;
12; @categories
13; Structure
14;
15; @param STRU1 {in}{required}
16; Structure which can have same elements's name than
17; STRU2 but with a different value.
18;
19; @param STRU2 {in}{required}
20; Structure which can have same elements's name than
21; STRU1 but with a different value.
22;
23; @returns
24; A structure
25;
26; @restrictions
27; If STRU1 or  STRU2 is not a structure, mixstru send back -1
28;
29; @examples
30;     
31;     IDL> a=get_extra(/toto,ok=123)
32;     IDL> b=get_extra(ok=111, year=1999, age_capitaine=35)
33;     IDL> help, a,b,/struct
34;     ** Structure <8334424>, 2 tags, length=4, refs=1:
35;        OK              INT            123
36;        TOTO            INT              1
37;     ** Structure <8373da4>, 3 tags, length=6, refs=1:
38;        AGE_CAPITAINE   INT             35
39;        OK              INT            111
40;        YEAR            INT           1999
41;     IDL> help, mixstru(a,b),/struct
42;     ** Structure <82f25ac>, 4 tags, length=8, refs=1:
43;        AGE_CAPITAINE   INT             35
44;        YEAR            INT           1999
45;        OK              INT            123
46;        TOTO            INT              1
47;     IDL> help, mixstru(b,a),/struct
48;     ** Structure <834604c>, 4 tags, length=8, refs=1:
49;        TOTO            INT              1
50;        AGE_CAPITAINE   INT             35
51;        OK              INT            111
52;        YEAR            INT           1999
53;
54; @history
55; Sebastien Masson (smasson\@lodyc.jussieu.fr)
56;                      7/10/1999
57;
58; @version
59; $Id$
60;
61;-
62;------------------------------------------------------------
63;------------------------------------------------------------
64;------------------------------------------------------------
65FUNCTION mixstru, stru1, stru2
66;
67  compile_opt idl2, strictarrsubs
68;
69@cm_general
70
71   IF size(stru1, /type) EQ 0 AND size(stru2, /type) EQ 8 THEN return, stru2
72   IF size(stru2, /type) EQ 0 AND size(stru1, /type) EQ 8 THEN return, stru1
73   if size(stru1, /type) NE 8 then return,  -1
74   if size(stru2, /type) NE 8 then return,  -1
75   tname = tag_names(stru2)
76   
77   str = ''
78   FOR i = 0, n_tags(stru2)-1 DO str = str + tname[i]+' = stru2.(' + strtrim(i, 2)+ '), '
79
80   res = createfunc('get_extra('+str+'_extra = stru1)' $
81              , kwdlist = 'stru1 = stru1, stru2 = stru2' $
82              , stru1 = stru1, stru2 = stru2 $
83              , filename = myuniquetmpdir +'for_createfunc.pro')
84
85   return, res
86
87end
Note: See TracBrowser for help on using the repository browser.