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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

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