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

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

debug + new xxx

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