source: trunk/STRUCTURE/extractstru.pro @ 11

Last change on this file since 11 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:extractstru
6;
7; PURPOSE:extrait des elements d''une structure pour constituer une
8;         nouvelle structure
9;
10; CATEGORY: dibouille sur les structures
11;
12; CALLING SEQUENCE: res = extractstru(stru, liste)
13;
14; INPUTS:
15;
16;    stru: une structure
17;
18;    liste: un vecteur de string comportant les noms des elements de
19;    stru a virer (par DEFAUT) ou a garder (si GARDE est active)
20;
21; KEYWORD PARAMETERS:
22;
23;    /GARDE: specifie que la liste donnee concerne les elements de
24;    stru a garder
25;
26;    /VIRE: specifie que la liste donnee concerne les elements de
27;    stru a virer. Ce mot cle est active par defaut
28;
29; OUTPUTS:une stucture ou -1 en cas de pb
30;
31; COMMON BLOCKS:
32;
33; SIDE EFFECTS:
34;
35; RESTRICTIONS: none !!!
36;    liste peut contenir des noms d''elements qui ne sont pas ds stru,
37;    le programme se debrouille avec
38;
39; EXAMPLE:
40;
41;    IDL> extra=get_extra(/ok, year=1999, age_capitaine=35 )
42;    IDL> help, extra,/struct
43;    ** Structure <83e66bc>, 3 tags, length=6, refs=1:
44;       AGE_CAPITAINE   INT             35
45;       OK              INT              1
46;       YEAR            INT           1999
47;    IDL> help, extractstru(extra,['ok','hhuihi','YEAR']),/stru
48;    ** Structure <831afac>, 1 tags, length=2, refs=1:
49;       AGE_CAPITAINE   INT             35
50;    IDL> help, extractstru(extra,['ok','hhuihi','YEAR'],/garde),/stru
51;    ** Structure <834bbc4>, 2 tags, length=4, refs=1:
52;       OK              INT              1
53;       YEAR            INT           1999
54;
55; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
56;                      8/10/1999
57;-
58;------------------------------------------------------------
59;------------------------------------------------------------
60;------------------------------------------------------------
61FUNCTION extractstru, stru, liste, GARDE = garde, VIRE = vire
62   if size(stru, /type) NE 8 then return,  -1
63   if size(liste, /type) NE 7 then return,  -1
64; cheking for garde and vire keywords
65   garde = keyword_set(garde)*(1-keyword_set(vire))
66   vire = keyword_set(vire)*(1-keyword_set(garde)) +(keyword_set(vire) EQ garde)
67;
68   tname = tag_names(stru)
69   index = make_selection(tname, strupcase(liste), /only_valid, /quiet)
70;
71   if garde then BEGIN ; on garde que la liste
72      if index[0] EQ -1 then return,  -1
73      if n_elements(index) EQ n_elements(tname) then return, stru
74      res = create_struct(tname[index[0]], stru.(index[0]))
75      if n_elements(index) GT 1 then for i = 1, n_elements(index)-1 do $
76            res = create_struct(res, tname[index[i]], stru.(index[i]))
77   ENDIF ELSE BEGIN ; on vire la liste
78      if n_elements(index) EQ n_elements(tname) then return,  -1
79      if index[0] EQ -1 then return, stru
80; on prend le complementaire de index pour obtenir les indices que
81; l''on garde
82      index = different(indgen(n_elements(tname)), index)
83      res = create_struct(tname[index[0]], stru.(index[0]))
84      if n_elements(index) GT 1 then for i = 1, n_elements(index)-1 do $
85            res = create_struct(res, tname[index[i]], stru.(index[i]))
86   ENDELSE
87
88   return, res
89end
Note: See TracBrowser for help on using the repository browser.