source: trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/buildcmd.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:buildcmd
6;
7; PURPOSE:cette fonction reourne un string qui contient la commande de
8; lecture et les parametres du trace.
9;
10; CATEGORY:
11;
12; CALLING SEQUENCE:
13;
14; INPUTS:
15;
16; KEYWORD PARAMETERS:
17;
18; OUTPUTS:
19;
20; COMMON BLOCKS:
21;
22; SIDE EFFECTS:
23;
24; RESTRICTIONS:
25;
26; EXAMPLE:
27;
28; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
29;
30;-
31;------------------------------------------------------------
32;------------------------------------------------------------
33;------------------------------------------------------------
34FUNCTION buildcmd, base, BOXZOOM = boxzoom, FORCETYPE = forcetype
35;
36;------------------------------------------------------------
37; we get back the ids of the widget parts
38;------------------------------------------------------------
39;
40  compile_opt idl2, strictarrsubs
41;
42  txtcmdid = widget_info(base, find_by_uname = 'txtcmd')
43  domainid = widget_info(base, find_by_uname = 'domain')
44  actionid = widget_info(base, find_by_uname = 'action')
45;   optionid = widget_info(base, find_by_uname = 'option')
46;------------------------------------------------------------
47  widget_control, base, get_uvalue = top_uvalue
48  smallin = extractatt(top_uvalue, 'smallin')
49  numdessinin = smallin[2]-1
50  smallout = extractatt(top_uvalue, 'smallout')
51  numdessinout = smallout[2]-1
52;
53  options = extractatt(top_uvalue, 'options')   
54  optionsflag = extractatt(top_uvalue, 'optionsflag')
55  portrait = (strtrim(optionsflag[where(options EQ 'Portrait/Landscape'), 0], 1))[0]
56;------------------------------------------------------------
57;---------------
58; on determine quelle procedure on va etre appele pour faire le dessin
59; et le type
60;---------------
61  IF keyword_set(forcetype) THEN type = forcetype $
62  ELSE type = widget_info(actionid, /combobox_gettext)
63  case type of
64    'plt':procedure = 'plt'
65    'pltz':procedure = 'pltz'
66    'pltz diag up':procedure = 'pltz'
67    'pltz diag dn':procedure = 'pltz'
68    'pltt':procedure = 'pltt'
69    'pltt diag up':procedure = 'pltt'
70    'pltt diag dn':procedure = 'pltt'
71    'xy':procedure = 'plt'
72    'xz':procedure = 'pltz'
73    'yz':procedure = 'pltz'
74    'xt':procedure = 'pltt'
75    'yt':procedure = 'pltt'
76    'zt':procedure = 'pltt'
77    'x':procedure = 'plt1d'
78    'y':procedure = 'plt1d'
79    'z':procedure = 'plt1d'
80    't':procedure = 'pltt'
81  endcase
82;
83;  recherche des options
84;
85  options = extractatt(top_uvalue, 'options')   
86  optionsflag = extractatt(top_uvalue, 'optionsflag')
87  flags = optionsflag[*, numdessinin]
88  xindex = (flags[where(options EQ 'Longitude / x index')])[0]
89  yindex = (flags[where(options EQ 'Latitude / y index')])[0]
90  drawvecteur = (flags[where(options EQ 'Vecteur')])[0]*(procedure eq 'plt')
91  drawover = (flags[where(options EQ 'Overlay')])[0]
92;
93  alreadyread = extractatt(top_uvalue, 'alreadyread')
94  alreadyvector = extractatt(top_uvalue, 'alreadyvector')
95  alreadyover = extractatt(top_uvalue, 'alreadyoer')
96; que devons-nous lire ?
97  case 1 of
98    alreadyover NE -1:BEGIN
99      toread = alreadyover+1
100      readswitch = 'over'
101    END
102    alreadyvector NE -1 AND alreadyvector NE !pi:BEGIN
103      toread = alreadyvector+1
104      readswitch = 'vector'
105    END
106    alreadyread NE -1 AND alreadyread NE !pi AND alreadyread NE 2.*!pi:BEGIN
107      toread = alreadyread+1
108      readswitch = 'classic'
109    END
110    else:BEGIN
111      case 1 of
112        alreadyvector eq !pi:BEGIN
113          toread = alreadyover+1
114          readswitch = 'over'
115        END
116        alreadyread EQ !pi:BEGIN
117          toread = alreadyvector+1
118          readswitch = 'vector'
119        END
120        alreadyread EQ 2.*!pi:BEGIN
121          toread = alreadyover+1
122          readswitch = 'over'
123        END
124        ELSE:BEGIN
125          toread = alreadyread+1
126          readswitch = 'classic'
127        END
128      endcase
129    END
130  ENDCASE
131;
132  widget_control, txtcmdid, get_value = widcmd
133  widcmd =  strtrim(widcmd, 2)
134  IF widcmd[0] EQ '' THEN widcmd = 'zzz'
135 
136  cutcmd, widcmd[0], toread, numberofread, prefix, nameexp, ending
137;
138  readcmd = buildreadcmd(base, ''''+nameexp+'''', procedure, type $
139                         , BOXZOOM = boxzoom, complete = readswitch EQ 'classic' AND alreadyread EQ -1)
140; we look for the line containing funclec_name
141  currentfile = extractatt(top_uvalue, 'currentfile')
142  readparameters = *(extractatt(top_uvalue, 'readparameters'))[currentfile]
143  i = 0
144  while strpos(readcmd[i], readparameters.funclec_name + '(') EQ -1 do i = i+1
145
146;-----------------------
147;-----------------------
148;-----------------------
149;-----------------------
150;-----------------------
151  case readswitch of
152    'classic':BEGIN
153      if alreadyread+1 EQ 0 then BEGIN
154; we start the reading command
155        readcmd = ['; beginning of reading the field to draw', readcmd]
156        readcmd[i+1] = 'field = ' + prefix + readcmd[i+1]
157      ENDIF ELSE BEGIN
158; we complet the reading command
159        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
160        nl = n_elements(oldrdcmd)
161        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
162        readcmd[i] = prefix + readcmd[i]
163        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
164      ENDELSE
165; exit if we have to read other fields...
166      if alreadyread+1 NE numberofread-1 THEN BEGIN
167        *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
168        *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = alreadyread+1
169        *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field number '+strtrim(alreadyread+3, 1))
170        return,  ''
171      ENDIF
172; we finalize the reading command
173      IF ending NE '' THEN BEGIN
174        nl = n_elements(readcmd)
175        readcmd[nl-1] = readcmd[nl-1] + ' $'
176        readcmd = [temporary(readcmd), ending]
177      ENDIF
178      readcmd = [temporary(readcmd) $
179                 , 'field = create_struct({arr:temporary(field), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
180                 , '; end of reading the field to draw', ';']
181; we get back _EXTRA:
182      extra = extractatt(top_uvalue, 'extra')
183      if xindex NE 0 then extra = create_struct(extra, 'xindex', xindex)
184      if yindex NE 0 then extra = create_struct(extra, 'yindex', yindex)
185      exextra = cw_specifie_get_value(base)
186      extra =  mixstru(exextra, extra)
187      sextra = struct2string(extra)
188      readcmd = [temporary(readcmd), 'extra = '+sextra]
189;
190      *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
191      case 1 of
192        drawvecteur:BEGIN
193; we have to read the vectors
194          *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = !pi
195          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the zonal component of vector')
196          return,  ''
197        END
198        drawover:BEGIN
199; we have to read the field to overlay...
200          *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = 2.*!pi
201          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field to overlay')
202          return,  ''
203        END
204; finished, we draw the plot...
205        ELSE:*top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
206      endcase
207    END
208    'vector':BEGIN
209; for the vectors, there is 2 components. we read u when alreadyvector
210; is a interger and v when alreadyvector is a interger+0.5
211      if floor(alreadyvector)+1 EQ 0 then begin
212        if floor(alreadyvector) EQ alreadyvector then begin
213          readcmd = ['; beginning of reading the zonal component of vector', readcmd]
214          readcmd[i+1] = 'fieldu = ' + prefix + readcmd[i+1]
215        ENDIF ELSE BEGIN
216          readcmd = ['; beginning of reading the meridional component of vector', readcmd]
217          readcmd[i+1] = 'fieldv = ' + prefix + readcmd[i+1]
218        ENDELSE
219        readcmd = [extractatt(top_uvalue, 'currentreadcmd'), temporary(readcmd)]
220      ENDIF ELSE BEGIN
221        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
222        nl = n_elements(oldrdcmd)
223        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
224        readcmd[i] = prefix + readcmd[i]
225        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
226      ENDELSE
227;
228      case alreadyvector+1 of
229        numberofread-1:BEGIN
230; we finalize the reading command
231          IF ending NE '' THEN BEGIN
232            nl = n_elements(readcmd)
233            readcmd[nl-1] = readcmd[nl-1] + ' $'
234            readcmd = [temporary(readcmd), ending]
235          ENDIF
236          readcmd = [temporary(readcmd) $
237                     , 'fieldu = create_struct({arr:temporary(fieldu), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
238                     , '; end of reading the zonal component of vector', ';']
239          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
240; we finished zonal component reading...
241; we know switch to meridional component...
242          *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -.5
243          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the meridional component of vector')
244          return,  ''
245        END
246        numberofread-0.5:BEGIN
247; we finalize the reading command
248          IF ending NE '' THEN BEGIN
249            nl = n_elements(readcmd)
250            readcmd[nl-1] = readcmd[nl-1] + ' $'
251            readcmd = [temporary(readcmd), ending]
252          ENDIF
253          readcmd = [temporary(readcmd)  $
254                     , 'fieldv = create_struct({arr:temporary(fieldv), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
255                     , '; end of reading the meridional component of vector', ';']
256; we finished meridional component reading...
257;
258; we get back _EXTRA of the vector and we complet extra already build
259          extra = extractatt(top_uvalue, 'extra')
260          exextra = cw_specifie_get_value(base)
261          extra =  mixstru(exextra, extra)
262          sextra = struct2string(extra)
263          readcmd = [readcmd, 'vectorextra = '+sextra, 'extra=mixstru(extra,vectorextra)']
264;
265          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
266;
267          if drawover then BEGIN
268; shall we do an overlay???
269            *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = !pi
270            *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field to overlay')
271            return,  ''
272          ENDIF ELSE BEGIN
273; it is done know!
274            *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
275            *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -1
276          ENDELSE
277        END
278        ELSE:BEGIN
279; we still need to read some vector components...
280          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
281          *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = alreadyvector+1
282          if floor(alreadyvector) EQ alreadyvector then text = ' zonal ' $
283          ELSE text = ' meridional '
284          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the '+strtrim(floor(alreadyread)+3, 1)+text+'component of vector')
285          return,  ''
286        END
287      endcase
288    END
289    'over':BEGIN
290      if alreadyover+1 EQ 0 then begin
291; we start the reading...
292        readcmd = ['; beginning of reading the field to overdraw', readcmd]
293        readcmd[i+1] = 'fieldover = '+ prefix +readcmd[i+1]
294        readcmd = [extractatt(top_uvalue, 'currentreadcmd'), temporary(readcmd)]
295      ENDIF ELSE BEGIN
296        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
297        nl = n_elements(oldrdcmd)
298        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
299        readcmd[i] = prefix + readcmd[i]
300        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
301      ENDELSE
302;
303      if alreadyover+1 NE numberofread-1 THEN BEGIN
304; we still need to read some files...
305        *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
306        *top_uvalue[1, findline(top_uvalue, 'alreadyover')] = alreadyover+1
307        *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field number '+strtrim(alreadyover+3, 1)+' to overlay')
308        return,  ''
309      ENDIF
310; we finalize the reading command
311      IF ending NE '' THEN BEGIN
312        nl = n_elements(readcmd)
313        readcmd[nl-1] = readcmd[nl-1] + ' $'
314        readcmd = [temporary(readcmd), ending]
315      ENDIF
316; on finalise la commande de lecture
317      readcmd = [readcmd $
318                 , 'fieldover = create_struct({arr:temporary(fieldover), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
319                 , '; end of reading the field to overdraw', ';']
320; we get back _EXTRA of over and we complet extra already build
321      extra = extractatt(top_uvalue, 'extra')
322      exextra = cw_specifie_get_value(base)
323      extra =  mixstru(exextra, extra)
324      sextra = struct2string(extra)
325      readcmd = [readcmd, 'overextra = '+sextra, 'extra=mixstru(extra,overextra)']
326;
327      *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
328; we reinitialize
329      *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
330      *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -1
331      *top_uvalue[1, findline(top_uvalue, 'alreadyover')] = -1
332    END
333  endcase
334;
335;-----------------------
336;-----------------------
337;-----------------------
338;-----------------------
339;-----------------------
340;-----------------------
341;---------------
342; determination du nom de la boxzoom
343;---------------
344  if NOT keyword_set(boxzoom) then widget_control, domainid, get_value = boxzoom
345; ecriture de celle-ci sous forme d''un string
346  box = '['+strtrim(boxzoom[0], 1)
347  for i = 1, (n_elements(boxzoom)-1) < (3+2*(strpos(type, 'z') EQ -1)) do $
348    box = box+', '+strtrim(boxzoom[i], 1)
349; pour les [plots en z, box doit avoir par defaut 0,profmax
350  if strpos(type, 'z') NE -1 then BEGIN
351; si + de 1 niveau est selectionne:
352    widget_control, widget_info(base, find_by_uname = 'dthlv1'), get_value = niv1
353    niv1 = niv1.combobox_index
354    widget_control, widget_info(base, find_by_uname = 'dthlv2'), get_value = niv2
355    niv2 = niv2.combobox_index
356    if niv1 NE niv2 then begin
357      box = box+','+strtrim(boxzoom[4], 1)+','+strtrim(boxzoom[5], 1)
358    ENDIF ELSE BEGIN
359      if chkstru(exextra, 'profmax') then  pmax = exextra.profmax $
360      ELSE pmax = 200
361      box = box+',0,'+strtrim(pmax, 1)
362    ENDELSE
363  endif
364  box = box+']'
365  IF strpos(type, ' diag up') NE -1 THEN BEGIN
366    sendpoints = '[' + strtrim(boxzoom[0], 1) + ', ' + strtrim(boxzoom[2], 1) + $
367                ', ' + strtrim(boxzoom[1], 1) + ', ' + strtrim(boxzoom[3], 1) + ']'
368  ENDIF
369  IF strpos(type, ' diag dn') NE -1 THEN BEGIN
370    sendpoints = '[' + strtrim(boxzoom[0], 1) + ', ' + strtrim(boxzoom[3], 1) + $
371                ', ' + strtrim(boxzoom[1], 1) + ', ' + strtrim(boxzoom[2], 1) + ']'
372  ENDIF
373;---------------
374; on determine typein
375;---------------
376    IF strpos(type, ' diag ') NE -1 THEN typein = ''''+strmid(type, 0, 4)+'''' $
377    ELSE typein = ''''+type+''''
378;---------------
379;---------------
380; determination de small
381;---------------
382  ssmall = tostr(smallout)
383;------------------------------------------------------------
384; on va definir le string qui contiendra la commande a executer par widgetdessine.pro
385;------------------------------------------------------------
386  Cmd = [readCmd, procedure+ ', field $' $
387         , '    , boxzoom = '+box+', /findalways, typein='+typein+', small='+ssmall+' $']
388  IF drawvecteur then Cmd = [Cmd, '    , vecteur = {u: fieldu,v: fieldv} $']
389  IF drawover then Cmd = [Cmd, '    , contour = fieldover $']
390  IF n_elements(sendpoints) NE 0 then Cmd = [Cmd, '    , endpoints = ' + sendpoints + ' $']
391  Cmd = [Cmd, '    , _extra= mixstru(ex, extra), portrait = ' + portrait + ', NOERASE=noerase']
392
393;    print, '---------------'
394;    for i = 0, n_elements(Cmd)-1 do print, Cmd[i]
395;    print, '---------------'
396;---------------
397; on complete et/ou actualise la structure top_uvalue...
398;---------------
399  (*top_uvalue[1, findline(top_uvalue, 'nameprocedures')])[numdessinout] = procedure
400  (*top_uvalue[1, findline(top_uvalue, 'types')])[numdessinout] = type
401  (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinout] = boxzoom
402  (*top_uvalue[1, findline(top_uvalue, 'txtcmd')])[numdessinout] = widcmd
403  (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[*, numdessinout] = flags
404  *((*top_uvalue[1, findline(top_uvalue, 'exextra')])[numdessinout]) = extra
405;------------------------------------------------------------
406  return, Cmd
407end
408
409
Note: See TracBrowser for help on using the repository browser.