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

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

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:litchamp
6;
7; PURPOSE:permet de lire un simple tableau ou une structure
8; correspondant a un champ.
9; Si en entree on a :
10;   -un simple tableau, litchamp renvoie le tableau
11;   -une stucture, litchamp renvoie le premier element de la structure
12;   qui doit obligatoirement etre le champ sous forme d''un tableau.
13;   Au passage litchamp regarde les autres elements de la structure et
14;   met a jour si besoin les variables globales qui se rapportent au
15;   champ: vargrid, varname, varunit, vardate, varexp , valmask et time
16;
17; CATEGORY:permet d''appeler plt, pltz, pltt ... avec un tableau ou une
18; structure et de mettre a jour les variables globales liees au champ.
19;
20; CALLING SEQUENCE:res=litchamp(struct)
21;
22; INPUTS:
23;        struct: c''est soit un tableau soit une structure.
24;    Si struct est une structure, elle doit suivre les regles
25;    suivantes:
26;        -le premier element est le tableau contenant le champ.
27;        -les autres elements sont des strings qui contiennent des
28;        informations sur le champ SAUF pour l''element relatif a
29;        date. Ce dernier peut etre soit un string pour designer une date
30;        particuliere (ex: 'August 1999') ou bien un vecteur de jours
31;        juliens (d''IDL) correspondant au calendrier a associer au
32;        champ si c'est une serie temporelle.
33;        -l''ordre des elements (autre que le premier) n''a pas
34;        d''importance.
35;        -les autres elements (autre que le premier) sont tous
36;        optionnels.
37;        -ils sont reconnus par la premiere lettre de leur nom:
38;             g  pour actualiser vargrid
39;             u  pour actualiser varunit
40;             e  pour actualiser varexp
41;             d  pour actualiser vardate
42;             n  pour actualiser varname
43;             m  pour actualiser valmask
44;
45; KEYWORD PARAMETERS:
46;
47;        /GRID: activer ce mot cle si on veut que litchamp renvoie la
48;        variable associee a l''element de la structure commencant
49;        par 'g' si il existe et '' dans le cas contraire.
50;
51;        /UNIT: activer ce mot cle si on veut que litchamp renvoie la
52;        variable associee a l''element de la structure commencant
53;        par 'u' si il existe et '' dans le cas contraire.
54;
55;        /EXP: activer ce mot cle si on veut que litchamp renvoie la
56;        variable associee a l''element de la structure commencant
57;        par 'e' si il existe et '' dans le cas contraire.
58;
59;        /DATE: activer ce mot cle si on veut que litchamp renvoie la
60;        variable associee a l''element de la structure commencant
61;        par 'd' si il existe et '' dans le cas contraire.
62;
63;        /NAME: activer ce mot cle si on veut que litchamp renvoie la
64;        variable associee a l''element de la structure commencant
65;        par 'n' si il existe et '' dans le cas contraire.
66;
67;        /LEVEL: activer ce mot cle si on veut que litchamp renvoie la
68;        variable associee a l''element de la structure commencant
69;        par 'l' si il existe et -1 dans le cas contraire.
70;
71;        /MASK: activer ce mot cle si on veut que litchamp renvoie la
72;        variable associee a l''element de la structure commencant
73;        par 'm' si il existe et -1 dans le cas contraire.
74;
75; OUTPUTS:c''est le tableau qui continent le champ.
76;
77; COMMON BLOCKS:
78;       common.pro
79;
80; SIDE EFFECTS: actualise au besion les variables globales vargrid,
81; varname, varunit, vardate, varexp, valmask et time.
82;
83; RESTRICTIONS:
84;
85; EXAMPLE:
86;     
87;    IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp     
88;    T,  ,  , 0, 
89;    IDL> help, litchamp({a:indgen(5), u:'C', name:'toto'})   
90;    <Expression>    INT       = Array[5]
91;    IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp     
92;    T, toto, C, 0, 
93;    IDL> help, litchamp({a:indgen(5), da:'1999'})   
94;    <Expression>    INT       = Array[5]
95;    IDL> print, vargrid,', ', varname,', ', varunit,', ', vardate,', ', varexp     
96;    T, toto, C, 1999, 
97;
98;
99; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr)
100;                       28/5/1999
101;-
102;------------------------------------------------------------
103;------------------------------------------------------------
104;------------------------------------------------------------
105FUNCTION litchamp, struct, GRID = grid, NAME = name, UNIT = unit, EXP = exp, DATE = date $
106                   , LEVEL = level, MASK = mask
107;
108  compile_opt idl2, strictarrsubs
109;
110@common
111;------------------------------------------------------------
112   if size(struct, /type) ne 8 then BEGIN ; alors contour n''est pas une structure
113      if keyword_set(grid) then return, ''
114      if keyword_set(name) then return, ''
115      if keyword_set(unit) then return, ''
116      if keyword_set(exp)  then return, ''
117      if keyword_set(date)  then return, ''
118      if keyword_set(level)  then return, -1
119      if keyword_set(mask)  then return, -1
120      return,  struct           
121   ENDIF 
122;------------------------------------------------------------
123   IF n_tags(struct) EQ 1 then BEGIN ; la structure n'a qu''un element
124      if keyword_set(grid) then return, ''
125      if keyword_set(name) then return, ''
126      if keyword_set(unit) then return, ''
127      if keyword_set(exp)  then return, ''
128      if keyword_set(date)  then return, ''
129      if keyword_set(level)  then return, -1
130      if keyword_set(mask)  then return, -1
131      return,  struct.(0)
132   ENDIF 
133;------------------------------------------------------------
134   nomelements = tag_names(struct)
135   for i = 1, n_tags(struct)-1 do begin
136      case strlowcase(strmid(nomelements[i], 0, 1)) of
137         'g':BEGIN
138            if keyword_set(grid) then return, strupcase(struct.(i))
139            vargrid = strupcase(struct.(i))
140         END
141         'n':BEGIN
142            if keyword_set(name) then return, struct.(i)
143            varname = struct.(i)
144         END
145         'u':BEGIN
146            if keyword_set(unit) then return, struct.(i)
147            varunit = struct.(i)
148         END
149         'e':BEGIN
150            if keyword_set(exp) then return, struct.(i)
151            varexp = struct.(i)
152         END
153         'm':BEGIN
154            if keyword_set(mask) then return, struct.(i)
155            valmask = struct.(i)
156         END
157         'd':BEGIN
158            if size(struct.(i),/type) EQ 7 THEN BEGIN
159               vardate = struct.(i)
160            ENDIF ELSE BEGIN
161               time = struct.(i)
162               jpt = n_elements(time)
163               if jpt EQ 1 then vardate =  strtrim(vairdate((struct.(i))[0]), 2)$
164               ELSE vardate =  strtrim(vairdate((struct.(i))[0]), 2)+' - ' $
165                +strtrim(vairdate((struct.(i))[jpt-1]), 2)
166            ENDELSE
167            if keyword_set(date) then return, vardate
168         END
169         'h':BEGIN
170            computehopegrid, (struct.(i)).xaxis, (struct.(i)).yaxis $
171             , (struct.(i)).zaxis, (struct.(i)).linetype $
172             , FIRSTS = (struct.(i)).firsts, LASTS = (struct.(i)).lasts $
173             , FORTHEMASK = struct.(0), pttype = (struct.(i)).pttype
174         END
175         ELSE:BEGIN
176            ras = report('Le nom '+nomelements[i]+' ne correspont a aucun element reconnu de la structure. cf. IDL> xhelp, ''litchamp''')
177         end
178      endcase
179   endfor
180;------------------------------------------------------------
181   if keyword_set(grid) then return, ''
182   if keyword_set(name) then return, ''
183   if keyword_set(unit) then return, ''
184   if keyword_set(exp)  then return, ''
185   if keyword_set(date)  then return, ''
186   if keyword_set(level)  then return, -1
187   if keyword_set(mask)  then return, -1
188
189   return,  struct.(0)
190end
Note: See TracBrowser for help on using the repository browser.