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

Last change on this file since 493 was 493, checked in by pinsard, 10 years ago

fix some typos in comments

  • 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; <pro>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 $
102                 , EXP=exp, DATE=date $
103                 , LEVEL=level, MASK=mask
104;
105  compile_opt idl2, strictarrsubs
106;
107@common
108;
109  if size(struct, /type) ne 8 then BEGIN ; so contour is not a structure.
110      if keyword_set(grid) then return, ''
111      if keyword_set(name) then return, ''
112      if keyword_set(unit) then return, ''
113      if keyword_set(exp)  then return, ''
114      if keyword_set(date)  then return, ''
115      if keyword_set(level)  then return, -1
116      if keyword_set(mask)  then return, -1
117      return,  struct
118   ENDIF
119;------------------------------------------------------------
120   IF n_tags(struct) EQ 1 then BEGIN ; The structure has only one element.
121      if keyword_set(grid) then return, ''
122      if keyword_set(name) then return, ''
123      if keyword_set(unit) then return, ''
124      if keyword_set(exp)  then return, ''
125      if keyword_set(date)  then return, ''
126      if keyword_set(level)  then return, -1
127      if keyword_set(mask)  then return, -1
128      return,  struct.(0)
129   ENDIF
130;------------------------------------------------------------
131   nomelements = tag_names(struct)
132   for i = 1, n_tags(struct)-1 do begin
133      case strlowcase(strmid(nomelements[i], 0, 1)) of
134         'g':BEGIN
135            if keyword_set(grid) then return, strupcase(struct.(i))
136            vargrid = strupcase(struct.(i))
137         END
138         'n':BEGIN
139            if keyword_set(name) then return, struct.(i)
140            varname = struct.(i)
141         END
142         'u':BEGIN
143            if keyword_set(unit) then return, struct.(i)
144            varunit = struct.(i)
145         END
146         'e':BEGIN
147            if keyword_set(exp) then return, struct.(i)
148            varexp = struct.(i)
149         END
150         'm':BEGIN
151            if keyword_set(mask) then return, struct.(i)
152            valmask = struct.(i)
153         END
154         'd':BEGIN
155            if size(struct.(i),/type) EQ 7 THEN BEGIN
156               vardate = struct.(i)
157            ENDIF ELSE BEGIN
158               time = struct.(i)
159               jpt = n_elements(time)
160               if jpt EQ 1 then vardate =  strtrim(vairdate((struct.(i))[0]), 2)$
161               ELSE vardate =  strtrim(vairdate((struct.(i))[0]), 2)+' - ' $
162                +strtrim(vairdate((struct.(i))[jpt-1]), 2)
163            ENDELSE
164            if keyword_set(date) then return, vardate
165         END
166         'h':BEGIN
167            computehopegrid, (struct.(i)).xaxis, (struct.(i)).yaxis $
168             , (struct.(i)).zaxis, (struct.(i)).linetype $
169             , FIRSTS = (struct.(i)).firsts, LASTS = (struct.(i)).lasts $
170             , FORTHEMASK = struct.(0), pttype = (struct.(i)).pttype
171         END
172         ELSE:BEGIN
173            ras = report('Le nom '+nomelements[i]+' ne correspond a aucun element reconnu de la structure. cf. IDL> xhelp, ''litchamp''')
174         end
175      endcase
176   endfor
177;------------------------------------------------------------
178   if keyword_set(grid) then return, ''
179   if keyword_set(name) then return, ''
180   if keyword_set(unit) then return, ''
181   if keyword_set(exp)  then return, ''
182   if keyword_set(date)  then return, ''
183   if keyword_set(level)  then return, -1
184   if keyword_set(mask)  then return, -1
185
186   return,  struct.(0)
187end
Note: See TracBrowser for help on using the repository browser.