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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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