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

Last change on this file since 150 was 142, checked in by navarro, 18 years ago

english and nicer header (2a)

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