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

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

debug xxx and cie + clean data file + rm perldoc_idl

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