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

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

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.8 KB
RevLine 
[2]1;+
2;
[142]3; @file_comments
[163]4; Allows to read an array or a structure corresponding to a field.
[231]5; If we have in input:
[296]6;   - an array, litchamp send back the array.
7;   - a structure, litchamp send back the first element of the structure
[142]8;   which must be the field in an array.
[495]9; litchamp profit of this to look other elements of the structure and
[296]10; update if needed global variables which refer to the field:
11; vargrid, varname, varunit, vardate, varexp , valmask et time
[2]12;
[142]13; @categories
[157]14; Graphics
[2]15;
[163]16; @param STRUCT {in}{required}{type=array or struct}{type=array or structure}
[142]17;  If STRUCT is a structure, it must follow following rules:
18;        -the first element is the array containing the field.
[163]19;        -other elements are strings containing informations on the field except
[142]20;        for the one about the date. This one can be either a string to designate
[493]21;        a particular date (ex: 'August 1999') or a vector of Julian days (of IDL)
[142]22;        corresponding  to the calendar to be associated with the field if it is a
23;        temporal series.
[231]24;        -the order of elements (except the first) has not any importance.
[163]25;        -the other elements (except the first) are optional.
[295]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,
[142]32;             m  to update valmask
[2]33;
[142]34; @keyword GRID
[231]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
[142]37; and '' if it does not.
[2]38;
[142]39; @keyword UNIT
[231]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
[142]42; and '' if it does not.
[2]43;
[142]44; @keyword EXP
[231]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
[142]47; and '' if it does not.
[2]48;
[142]49; @keyword DATE
[231]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
[142]52; and '' if it does not.
[2]53;
[142]54; @keyword NAME
[231]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
[142]57; and '' if it does not.
[2]58;
[142]59; @keyword LEVEL
[231]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
[142]62; and -1 if it does not.
[231]63;
[142]64; @keyword MASK
[231]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
[142]67; and -1 if it does not.
[2]68;
[142]69; @returns
70; It is the array containing the field.
[2]71;
[142]72; @uses
[370]73; <pro>common</pro>
[2]74;
[142]75; @restrictions
76; Update if needed global variables vargrid,
77; varname, varunit, vardate, varexp, valmask and time.
[2]78;
[142]79; @examples
[231]80;
[371]81;   IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp
[231]82;    T,  ,  , 0,
[371]83;   IDL> help, litchamp({a:indgen(5), u:'C', name:'toto'})
[2]84;    <Expression>    INT       = Array[5]
[371]85;   IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp
[231]86;    T, toto, C, 0,
[371]87;   IDL> help, litchamp({a:indgen(5), da:'1999'})
[2]88;    <Expression>    INT       = Array[5]
[371]89;   IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp
[231]90;    T, toto, C, 1999,
[2]91;
[142]92; @history
[157]93; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]94;                       28/5/1999
[142]95;
96; @version
97; $Id$
98;
[2]99;-
[327]100FUNCTION litchamp, struct, GRID=grid, NAME=name, UNIT=unit $
101                 , EXP=exp, DATE=date $
102                 , LEVEL=level, MASK=mask
[114]103;
104  compile_opt idl2, strictarrsubs
105;
[2]106@common
[231]107;
[142]108  if size(struct, /type) ne 8 then BEGIN ; so contour is not a structure.
[2]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
[231]116      return,  struct
117   ENDIF
[2]118;------------------------------------------------------------
[142]119   IF n_tags(struct) EQ 1 then BEGIN ; The structure has only one element.
[2]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)
[231]128   ENDIF
[2]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
[231]153         'd':BEGIN
154            if size(struct.(i),/type) EQ 7 THEN BEGIN
[2]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)+' - ' $
[231]161                +strtrim(vairdate((struct.(i))[jpt-1]), 2)
[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
[231]171         ELSE:BEGIN
[493]172            ras = report('Le nom '+nomelements[i]+' ne correspond a aucun element reconnu de la structure. cf. IDL> xhelp, ''litchamp''')
[2]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.