source: trunk/SRC/ToBeReviewed/STRUCTURE/extractstru.pro @ 226

Last change on this file since 226 was 226, checked in by pinsard, 17 years ago

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
[150]5; @file_comments
6; extract elements of a structure to constitute a new structure.
[2]7;
[150]8; @categories
[157]9; Utilities
[2]10;
[150]11; @param STRU {in}{required}
12; A structure
[2]13;
[163]14; @param LISTE {in}{required}{type=vector}
[226]15; A vector of string including names of STRU to be deleted
[150]16; (by default) or to be kept (if KEEP is activated).
[2]17;
[150]18; @keyword KEEP
19; Specify that the given liste concern elements of STRU to be kept.
[2]20;
[163]21; @keyword DELETE
[150]22; Specify  that the given liste concern elements of STRU to be deleted.
23; This keyword is activated by default.
[2]24;
[150]25; @returns
26; A structure or -1 in case of problem
[2]27;
[150]28; @examples
[2]29;
30;    IDL> extra=get_extra(/ok, year=1999, age_capitaine=35 )
31;    IDL> help, extra,/struct
32;    ** Structure <83e66bc>, 3 tags, length=6, refs=1:
33;       AGE_CAPITAINE   INT             35
34;       OK              INT              1
35;       YEAR            INT           1999
36;    IDL> help, extractstru(extra,['ok','hhuihi','YEAR']),/stru
37;    ** Structure <831afac>, 1 tags, length=2, refs=1:
38;       AGE_CAPITAINE   INT             35
[150]39;    IDL> help, extractstru(extra,['ok','hhuihi','YEAR'],/keep),/stru
[2]40;    ** Structure <834bbc4>, 2 tags, length=4, refs=1:
41;       OK              INT              1
42;       YEAR            INT           1999
43;
[150]44; @history
[157]45; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]46;                      8/10/1999
[150]47;
48; @version
49; $Id$
[226]50;
[2]51;-
52;------------------------------------------------------------
53;------------------------------------------------------------
54;------------------------------------------------------------
[150]55FUNCTION extractstru, stru, liste, KEEP = keep, DELETE = delete
[114]56;
57  compile_opt idl2, strictarrsubs
58;
[2]59   if size(stru, /type) NE 8 then return,  -1
60   if size(liste, /type) NE 7 then return,  -1
[226]61; checking for keep and vire keywords
[150]62   keep = keyword_set(keep)*(1-keyword_set(delete))
63   delete = keyword_set(delete)*(1-keyword_set(keep)) +(keyword_set(delete) EQ keep)
[2]64;
65   tname = tag_names(stru)
66   index = make_selection(tname, strupcase(liste), /only_valid, /quiet)
67;
[150]68   if keep then BEGIN ; We just keep the list
[2]69      if index[0] EQ -1 then return,  -1
70      if n_elements(index) EQ n_elements(tname) then return, stru
71      res = create_struct(tname[index[0]], stru.(index[0]))
72      if n_elements(index) GT 1 then for i = 1, n_elements(index)-1 do $
73            res = create_struct(res, tname[index[i]], stru.(index[i]))
[150]74   ENDIF ELSE BEGIN ; We delete the list
[2]75      if n_elements(index) EQ n_elements(tname) then return,  -1
76      if index[0] EQ -1 then return, stru
[150]77; We take the complementary one of index to obtain indexes we keep.
[2]78      index = different(indgen(n_elements(tname)), index)
79      res = create_struct(tname[index[0]], stru.(index[0]))
80      if n_elements(index) GT 1 then for i = 1, n_elements(index)-1 do $
81            res = create_struct(res, tname[index[i]], stru.(index[i]))
[226]82   ENDELSE
[2]83
84   return, res
85end
Note: See TracBrowser for help on using the repository browser.