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

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

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