source: trunk/SRC/ToBeReviewed/LECTURE/litchamp.pro @ 199

Last change on this file since 199 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Allows to read an array or a structure corresponding to a field.
8; If we have in input:
9;   -an array, litchamp send back the array.
10;   -a structure, litchamp send back the first element of the structure
11;   which must be the field in an array.
12;   Litchamp profit of this to look other elements of the structure et
13;   update if needed global variables which refer to the field:
14;   vargrid, varname, varunit, vardate, varexp , valmask et time
15;
16; @categories
17; Graphics
18;
19; @param STRUCT {in}{required}{type=array or struct}{type=array or structure}
20;  If STRUCT is a structure, it must follow following rules:
21;        -the first element is the array containing the field.
22;        -other elements are strings containing informations on the field except
23;        for the one about the date. This one can be either a string to designate
24;        a particular date (ex: 'August 1999') or a vector of julian days (of IDL)
25;        corresponding  to the calendar to be associated with the field if it is a
26;        temporal series.
27;        -the order of elements (except the first) has not any importance.
28;        -the other elements (except the first) are optional.
29;        -they are recognize by the first letter of their names:
30;             g  to update vargrid
31;             u  to update varunit
32;             e  to update varexp
33;             d  to update vardate
34;             n  to update varname
35;             m  to update valmask
36;
37; @keyword GRID
38; We activate this keyword if we want litchamp to send back the variable
39; associated with the element of the structure starting by 'g' if it exist
40; and '' if it does not.
41;
42; @keyword UNIT
43; We activate this keyword if we want litchamp to send back the variable
44; associated with the element of the structure starting by 'u' if it exist
45; and '' if it does not.
46;
47; @keyword EXP
48; We activate this keyword if we want litchamp to send back the variable
49; associated with the element of the structure starting by 'u' if it exist
50; and '' if it does not.
51;
52; @keyword DATE
53; We activate this keyword if we want litchamp to send back the variable
54; associated with the element of the structure starting by 'd' if it exist
55; and '' if it does not.
56;
57; @keyword NAME
58; We activate this keyword if we want litchamp to send back the variable
59; associated with the element of the structure starting by 'n' if it exist
60; and '' if it does not.
61;
62; @keyword LEVEL
63; We activate this keyword if we want litchamp to send back the variable
64; associated with the element of the structure starting by 'l' if it exist
65; and -1 if it does not.
66;
67; @keyword MASK
68; We activate this keyword if we want litchamp to send back the variable
69; associated with the element of the structure starting by 'm' if it exist
70; and -1 if it does not.
71;
72; @returns
73; It is the array containing the field.
74;
75; @uses
76; common.pro
77;
78; @restrictions
79; Update if needed global variables vargrid,
80; varname, varunit, vardate, varexp, valmask and time.
81;
82; @examples
83;     
84;    IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp     
85;    T,  ,  , 0, 
86;    IDL> help, litchamp({a:indgen(5), u:'C', name:'toto'})   
87;    <Expression>    INT       = Array[5]
88;    IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp     
89;    T, toto, C, 0, 
90;    IDL> help, litchamp({a:indgen(5), da:'1999'})   
91;    <Expression>    INT       = Array[5]
92;    IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp     
93;    T, toto, C, 1999, 
94;
95;
96; @history
97; Sebastien Masson (smasson\@lodyc.jussieu.fr)
98;                       28/5/1999
99;
100; @version
101; $Id$
102;
103;-
104;------------------------------------------------------------
105;------------------------------------------------------------
106;------------------------------------------------------------
107FUNCTION litchamp, struct, GRID = grid, NAME = name, UNIT = unit, EXP = exp, DATE = date $
108                   , LEVEL = level, MASK = mask
109;
110  compile_opt idl2, strictarrsubs
111;
112@common
113;------------------------------------------------------------
114  if size(struct, /type) ne 8 then BEGIN ; so contour is not a structure.
115      if keyword_set(grid) then return, ''
116      if keyword_set(name) then return, ''
117      if keyword_set(unit) then return, ''
118      if keyword_set(exp)  then return, ''
119      if keyword_set(date)  then return, ''
120      if keyword_set(level)  then return, -1
121      if keyword_set(mask)  then return, -1
122      return,  struct           
123   ENDIF 
124;------------------------------------------------------------
125   IF n_tags(struct) EQ 1 then BEGIN ; The structure has only one element.
126      if keyword_set(grid) then return, ''
127      if keyword_set(name) then return, ''
128      if keyword_set(unit) then return, ''
129      if keyword_set(exp)  then return, ''
130      if keyword_set(date)  then return, ''
131      if keyword_set(level)  then return, -1
132      if keyword_set(mask)  then return, -1
133      return,  struct.(0)
134   ENDIF 
135;------------------------------------------------------------
136   nomelements = tag_names(struct)
137   for i = 1, n_tags(struct)-1 do begin
138      case strlowcase(strmid(nomelements[i], 0, 1)) of
139         'g':BEGIN
140            if keyword_set(grid) then return, strupcase(struct.(i))
141            vargrid = strupcase(struct.(i))
142         END
143         'n':BEGIN
144            if keyword_set(name) then return, struct.(i)
145            varname = struct.(i)
146         END
147         'u':BEGIN
148            if keyword_set(unit) then return, struct.(i)
149            varunit = struct.(i)
150         END
151         'e':BEGIN
152            if keyword_set(exp) then return, struct.(i)
153            varexp = struct.(i)
154         END
155         'm':BEGIN
156            if keyword_set(mask) then return, struct.(i)
157            valmask = struct.(i)
158         END
159         'd':BEGIN
160            if size(struct.(i),/type) EQ 7 THEN BEGIN
161               vardate = struct.(i)
162            ENDIF ELSE BEGIN
163               time = struct.(i)
164               jpt = n_elements(time)
165               if jpt EQ 1 then vardate =  strtrim(vairdate((struct.(i))[0]), 2)$
166               ELSE vardate =  strtrim(vairdate((struct.(i))[0]), 2)+' - ' $
167                +strtrim(vairdate((struct.(i))[jpt-1]), 2)
168            ENDELSE
169            if keyword_set(date) then return, vardate
170         END
171         'h':BEGIN
172            computehopegrid, (struct.(i)).xaxis, (struct.(i)).yaxis $
173             , (struct.(i)).zaxis, (struct.(i)).linetype $
174             , FIRSTS = (struct.(i)).firsts, LASTS = (struct.(i)).lasts $
175             , FORTHEMASK = struct.(0), pttype = (struct.(i)).pttype
176         END
177         ELSE:BEGIN
178            ras = report('Le nom '+nomelements[i]+' ne correspont a aucun element reconnu de la structure. cf. IDL> xhelp, ''litchamp''')
179         end
180      endcase
181   endfor
182;------------------------------------------------------------
183   if keyword_set(grid) then return, ''
184   if keyword_set(name) then return, ''
185   if keyword_set(unit) then return, ''
186   if keyword_set(exp)  then return, ''
187   if keyword_set(date)  then return, ''
188   if keyword_set(level)  then return, -1
189   if keyword_set(mask)  then return, -1
190
191   return,  struct.(0)
192end
Note: See TracBrowser for help on using the repository browser.