Changeset 150 for trunk/SRC/ToBeReviewed/STRUCTURE
- Timestamp:
- 08/09/06 12:12:54 (18 years ago)
- Location:
- trunk/SRC/ToBeReviewed/STRUCTURE
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/STRUCTURE/chkstru.pro
r134 r150 1 ; $Id$2 1 ;------------------------------------------------------------- 3 2 ;+ 4 ; NAME: 5 ; CHKSTRU (function) 3 ; @file_comments 4 ; check validity of a structure and test if necessary 5 ; fields are contained 6 6 ; 7 ; PURPOSE: 8 ; check validity of a structure and test if necessary 9 ; fields are contained 7 ; @categories 8 ; tools 10 9 ; 11 ; CATEGORY: 12 ; tools 10 ; @param STRUCTURE {in}{required} 11 ; The structure to be tested. If STRUCTURE is 12 ; not of type structure, the function will return 0 13 13 ; 14 ; CALLING SEQUENCE: 15 ; res=CHKSTRU(STRUCTURE,FIELDS [,/VERBOSE]) 14 ; @param FIELDS {in}{required} 15 ; A string or string array with field names to 16 ; be contained in STRUCTURE. CHKSTRU returns 1 (true) 17 ; only if all field names are contained in STRUCTURE. 18 ; The entries of FIELDS may be upper or lowercase. 16 19 ; 17 ; INPUTS: 18 ; STRUCTURE --> the structure to be tested. If STRUCTURE is 19 ; not of type structure, the function will return 0 20 ; @keyword INDEX 21 ; A named variable that will contain the indices of 22 ; the required field names in the structure. They can then 23 ; be assessed through structure.(index[i]) . Index will 24 ; contain -1 for all fields entries that are not in the 25 ; structure. 20 26 ; 21 ; FIELDS --> a string or string array with field names to 22 ; be contained in STRUCTURE. CHKSTRU returns 1 (true) 23 ; only if all field names are contained in STRUCTURE. 24 ; The entries of FIELDS may be upper or lowercase. 27 ; @keyword VERBOSE 28 ; set this keyword to return an error message 29 ; in case of an error. 25 30 ; 26 ; KEYWORD PARAMETERS: 27 ; INDEX --> a named variable that will contain the indices of 28 ; the required field names in the structure. They can then 29 ; be assessed through structure.(index[i]) . Index will 30 ; contain -1 for all fields entries that are not in the 31 ; structure. 31 ; @keyword EXTRACT 32 ; set this keyword to extract a fields from the 33 ; structure. -1 is return is fields or structure. are 34 ; incorrect. 32 35 ; 33 ; /VERBOSE --> set this keyword to return an error message34 ; in case of an error.36 ; @returns 37 ; CHKSTRU returns 1 if successful, otherwise 0. 35 38 ; 36 ; /EXTRACT --> set this keyword to extract a fields from the 37 ; structure. -1 is return is fields or structure. are 38 ; incorrect. 39 ; 40 ; OUTPUTS: 41 ; CHKSTRU returns 1 if successful, otherwise 0. 42 ; 43 ; SUBROUTINES: 44 ; 45 ; REQUIREMENTS: 46 ; 47 ; NOTES: 48 ; 49 ; EXAMPLE: 39 ; @examples 50 40 ; test = { a:1, b:2, c:3 } 51 41 ; required = ['a','c'] … … 56 46 ; 2 57 47 ; 58 ; MODIFICATION HISTORY:48 ; @history 59 49 ; mgs, 02 Mar 1998: VERSION 1.00 60 50 ; mgs, 07 Apr 1998: - second parameter (FIELDS) now optional 61 51 ; 12 Jan 2001: EXTRACT keyword by S. Masson (smasson@lodyc.jussieu.fr) 52 ; 53 ; @version 54 ; $Id$ 62 55 ; 63 56 ;- -
trunk/SRC/ToBeReviewed/STRUCTURE/extractstru.pro
r134 r150 3 3 ;------------------------------------------------------------ 4 4 ;+ 5 ; NAME:extractstru 5 ; @file_comments 6 ; extract elements of a structure to constitute a new structure. 6 7 ; 7 ; PURPOSE:extrait des elements d''une structure pour constituer une8 ; nouvelle structure8 ; @categories 9 ; utilities 9 10 ; 10 ; CATEGORY: dibouille sur les structures 11 ; @param STRU {in}{required} 12 ; A structure 11 13 ; 12 ; CALLING SEQUENCE: res = extractstru(stru, liste)13 ; 14 ; INPUTS:14 ; @param LISTE {in}{required} 15 ; A vector of string including names of STRU to be deleted 16 ; (by default) or to be kept (if KEEP is activated). 15 17 ; 16 ; stru: une structure 18 ; @keyword KEEP 19 ; Specify that the given liste concern elements of STRU to be kept. 17 20 ; 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) 21 ; @keyword DELETE: 22 ; Specify that the given liste concern elements of STRU to be deleted. 23 ; This keyword is activated by default. 20 24 ; 21 ; KEYWORD PARAMETERS: 25 ; @returns 26 ; A structure or -1 in case of problem 22 27 ; 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: 28 ; @examples 40 29 ; 41 30 ; IDL> extra=get_extra(/ok, year=1999, age_capitaine=35 ) … … 48 37 ; ** Structure <831afac>, 1 tags, length=2, refs=1: 49 38 ; AGE_CAPITAINE INT 35 50 ; IDL> help, extractstru(extra,['ok','hhuihi','YEAR'],/ garde),/stru39 ; IDL> help, extractstru(extra,['ok','hhuihi','YEAR'],/keep),/stru 51 40 ; ** Structure <834bbc4>, 2 tags, length=4, refs=1: 52 41 ; OK INT 1 53 42 ; YEAR INT 1999 54 43 ; 55 ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) 44 ; @history 45 ; Sebastien Masson (smasson@lodyc.jussieu.fr) 56 46 ; 8/10/1999 47 ; 48 ; @version 49 ; $Id$ 50 ; 57 51 ;- 58 52 ;------------------------------------------------------------ 59 53 ;------------------------------------------------------------ 60 54 ;------------------------------------------------------------ 61 FUNCTION extractstru, stru, liste, GARDE = garde, VIRE = vire55 FUNCTION extractstru, stru, liste, KEEP = keep, DELETE = delete 62 56 ; 63 57 compile_opt idl2, strictarrsubs … … 65 59 if size(stru, /type) NE 8 then return, -1 66 60 if size(liste, /type) NE 7 then return, -1 67 ; cheking for gardeand vire keywords68 garde = keyword_set(garde)*(1-keyword_set(vire))69 vire = keyword_set(vire)*(1-keyword_set(garde)) +(keyword_set(vire) EQ garde)61 ; cheking for keep and vire keywords 62 keep = keyword_set(keep)*(1-keyword_set(delete)) 63 delete = keyword_set(delete)*(1-keyword_set(keep)) +(keyword_set(delete) EQ keep) 70 64 ; 71 65 tname = tag_names(stru) 72 66 index = make_selection(tname, strupcase(liste), /only_valid, /quiet) 73 67 ; 74 if garde then BEGIN ; on garde que la liste68 if keep then BEGIN ; We just keep the list 75 69 if index[0] EQ -1 then return, -1 76 70 if n_elements(index) EQ n_elements(tname) then return, stru … … 78 72 if n_elements(index) GT 1 then for i = 1, n_elements(index)-1 do $ 79 73 res = create_struct(res, tname[index[i]], stru.(index[i])) 80 ENDIF ELSE BEGIN ; on vire la liste74 ENDIF ELSE BEGIN ; We delete the list 81 75 if n_elements(index) EQ n_elements(tname) then return, -1 82 76 if index[0] EQ -1 then return, stru 83 ; on prend le complementaire de index pour obtenir les indices que 84 ; l''on garde 77 ; We take the complementary one of index to obtain indexes we keep. 85 78 index = different(indgen(n_elements(tname)), index) 86 79 res = create_struct(tname[index[0]], stru.(index[0])) -
trunk/SRC/ToBeReviewed/STRUCTURE/mixstru.pro
r134 r150 3 3 ;------------------------------------------------------------ 4 4 ;+ 5 ; NAME: mixstru6 5 ; 7 ; PURPOSE: concatene 2 structures ensemble. La difference avec 8 ; CREATE_STRUCT etant que si les 2 stuctures ont les memes noms 9 ; d''elements alors mixstru ne plante pas mais choisit pour valeur de 10 ; l''element commun celle specifiee par la premiere structure. 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 11 ; 12 ; CATEGORY: structure 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. 13 18 ; 14 ; CALLING SEQUENCE: rs=mixstru(stru1,stru2) 15 ; 16 ; INPUTS: stru1 et stu2 sont 2 structures qui peuvent avoir des 17 ; elements portant le meme nom mais avec une valeur differente. 19 ; @param STRU2 {in}{required} 20 ; Structure which can have same elements's name than 21 ; STRU1 but with a different value. 18 22 ; 19 ; KEYWORD PARAMETERS: none 23 ; @returns 24 ; A stucture 20 25 ; 21 ; OUTPUTS: une stucture 26 ; @restrictions 27 ; If STRU1 or STRU2 is not a structure, mixstru send back -1 22 28 ; 23 ; COMMON BLOCKS: 24 ; 25 ; SIDE EFFECTS: si stru1 ou stru2 ne sont pas des structures mixstru 26 ; renvoie -1 27 ; 28 ; RESTRICTIONS: 29 ; 30 ; EXAMPLE: 29 ; @examples 31 30 ; 32 31 ; IDL> a=get_extra(/toto,ok=123) … … 53 52 ; YEAR INT 1999 54 53 ; 55 ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) 54 ; @history 55 ; Sebastien Masson (smasson@lodyc.jussieu.fr) 56 56 ; 7/10/1999 57 ; 58 ; @version 59 ; $Id$ 60 ; 57 61 ;- 58 62 ;------------------------------------------------------------ -
trunk/SRC/ToBeReviewed/STRUCTURE/struct2string.pro
r134 r150 3 3 ;------------------------------------------------------------ 4 4 ;+ 5 ; NAME:struct2string 5 ; 6 ; @file_comments 7 ; Convert a structure to an "executable string" 6 8 ; 7 ; PURPOSE:convert a structure to an "executable string" 9 ; @categories 10 ; utilities 11 ; 12 ; @param STRUCT {in}{required} 13 ; A structure 8 14 ; 9 ; CATEGORY:bidouille 15 ; @keyword MAX_STRUCT_LENGTH 16 ; The maximum length of the structure 17 ; permetted to convert the structure to string. Default is 18 ; 10000l. 10 19 ; 11 ; CALLING SEQUENCE:sting=struct2string(struct) 12 ; 13 ; INPUTS:struct: a structure 20 ; @keyword DIRECT2STRING 21 ; To get a string instead an "executable string" 14 22 ; 15 ; KEYWORD PARAMETERS: 23 ; @keyword CUT_IN_STRING 24 ; Try it 16 25 ; 17 ; MAX_STRUCT_LENGTH : the maximum length of the structure 18 ; permetted to convert the structure to string. Default is 19 ; 10000l. 26 ; @restrictions 27 ; Use tostr.pro, cf this function header! 20 28 ; 21 ; /DIRECT2STRING: to get a string instead an "executable string" 22 ; 23 ; /CUT_IN_STRING: try it 24 ; 25 ; OUTPUTS: 26 ; 27 ; SIDE EFFECTS:use tostr.pro, cf this function header! 28 ; 29 ; RESTRICTIONS:use tostr.pro, cf this function header! 30 ; 31 ; EXAMPLE: 29 ; @examples 32 30 ; 33 31 ; IDL> print, struct2string(!d) … … 38 36 ; ,[0,0],'ZOOM',[1,1]) 39 37 ; 40 ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) 38 ; @history 39 ; Sebastien Masson (smasson@lodyc.jussieu.fr) 41 40 ; 2000 07 03 41 ; 42 ; @version 43 ; $Id$ 44 ; 42 45 ;- 43 46 ;------------------------------------------------------------ -
trunk/SRC/ToBeReviewed/STRUCTURE/where_tag.pro
r134 r150 1 1 ;+ 2 ; NAME: 3 ; WHERE_TAG 4 ; PURPOSE: 5 ; Like WHERE but works on structure tag names 6 ; EXPLANATION: 7 ; Obtain subscripts of elements in structure array for which 8 ; a particular Tag has values in a range or matching specified values. 9 ; Like the WHERE function but for use with structures 10 ; CATEGORY: 11 ; Structures 12 ; CALLING SEQUENCE: 13 ; w = where_tag( struct, [ Nfound, TAG_NAME=, TAG_NUMBER = , RANGE =, 14 ; VALUES =, RANGE =, ISELECT =, /NOPRINT ] 2 ; @file_comments 3 ; Like WHERE but works on structure tag names 4 ; Obtain subscripts of elements in structure array for which 5 ; a particular Tag has values in a range or matching specified values. 6 ; Like the WHERE function but for use with structures 7 ; 8 ; @categories 9 ; Structures 15 10 ; 16 ; INPUTS:17 ; Struct =structure array to search.11 ; @param STRUCT {in}{required} 12 ; structure array to search. 18 13 ; 19 ; INPUT KEYWORDS: 20 ; User *must* specify (1) TAG_NAME or TAG_NUMBER to search, and (2) 21 ; the VALUES or RANGE to search on 14 ; @keyword TAG_NAME 15 ; Scalar string specifying Tag Name 16 ; 17 ; @keyword TAG_NUMBER 18 ; Otherwise give the Tag Number, 19 ; 20 ; @keyword RANGE 21 ; [min,max] range to search for in Struct 22 ; 23 ; @keyword VALUES 24 ; One or array of numbers to match for in Struct, 25 ; 26 ; @keyword ISELECT 27 ; Specifies indices to select only part of structure array, 28 ; (use it to recycle subscripts from previous searches). 29 ; 30 ; @keyword NOPRINT 31 ; Suppress informational messages about nothing found. 22 32 ; 23 ; TAG_NAME = Scalar string specifying Tag Name24 ; TAG_NUMBER = otherwise give the Tag Number,25 ; RANGE = [min,max] range to search for in Struct,26 ; VALUES = one or array of numbers to match for in Struct,27 ; ISELECT= specifies indices to select only part of structure array,28 ; (use it to recycle subscripts from previous searches).29 ; /NOPRINT = suppress informational messages about nothing found.33 ; @returns 34 ; Nfound {out} 35 ; # of occurences found. 36 ; 37 ; @restrictions 38 ; User *must* specify (1) TAG_NAME or TAG_NUMBER to search, and (2) 39 ; the VALUES or RANGE to search on; 30 40 ; 31 ; OUTPUTS: 32 ; Nfound = # of occurences found. 33 ; 34 ; RESULT: 35 ; Function returns subscripts (indices) to desired elements. 36 ; 37 ; EXAMPLES: 41 ; @examples 38 42 ; Suppose STR is a structure with tags CAT_NO:indgen(10), and 39 43 ; NAME:strarr(10). Find the indices where STR.CAT_NO is … … 43 47 ; IDL> print, WHERE_TAG( str, TAG_NUM = 0, RANGE = [3,5]) 44 48 ; 45 ; PROCEDURE: 46 ; Get tag number and apply the WHERE function appropriately. 47 ; 48 ; MODIFICATION HISTORY: 49 ; @history 49 50 ; written 1990 Frank Varosi STX @ NASA/GSFC 50 51 ; Stop printing "Tag <xxx> not found" with /NOPRINT, CD Pike 8-Jun-93 52 ; 53 ; @version 54 ; $Id$ 55 ; 51 56 ;- 52 57 function where_Tag, Struct, Nfound, TAG_NAME=Tag_Name, $
Note: See TracChangeset
for help on using the changeset viewer.