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

Last change on this file since 226 was 226, checked in by pinsard, 17 years ago

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.0 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; This function send back a string which contain the reading command
8; and drawing's parameters.
9;
10; @param BASE {in}{required}
11;
12; @keyword BOXZOOM
13; Vector indicating the geographic zone on which we want to cut the map.
14; If BOXZOOM has :
15;   1 element : The extraction is made on [lon1, lon2, lat1, lat2, 0.,boxzoom[0]]
16;   2 elements: The extraction is made on [lon1, lon2, lat1, lat2, boxzoom[0],boxzoom[1]]
17;   4 elements: The extraction is made on [Boxzoom, 0, max([gdept, gdepw])]
18;   5 elements: The extraction is made on [Boxzoom[0:3], 0, Boxzoom[4]]
19;   6 elements: The extraction is made on Boxzoom
20; Where lon1, lon2,lat1,lat2 are global variables defined at the last domdef!
21;
22; @keyword FORCETYPE
23;
24; @history
25; Sebastien Masson (smasson\@lodyc.jussieu.fr)
26;
27; @version
28; $Id$
29;
30; @todo
31; seb: documenter le param BASE et le keyword FORCETYPE
32;
33;-
34;------------------------------------------------------------
35;------------------------------------------------------------
36;------------------------------------------------------------
37FUNCTION buildcmd, base, BOXZOOM = boxzoom, FORCETYPE = forcetype
38;
39;------------------------------------------------------------
40; we get back the ids of the widget parts
41;------------------------------------------------------------
42;
43  compile_opt idl2, strictarrsubs
44;
45  txtcmdid = widget_info(base, find_by_uname = 'txtcmd')
46  domainid = widget_info(base, find_by_uname = 'domain')
47  actionid = widget_info(base, find_by_uname = 'action')
48;   optionid = widget_info(base, find_by_uname = 'option')
49;------------------------------------------------------------
50  widget_control, base, get_uvalue = top_uvalue
51  smallin = extractatt(top_uvalue, 'smallin')
52  numdessinin = smallin[2]-1
53  smallout = extractatt(top_uvalue, 'smallout')
54  numdessinout = smallout[2]-1
55;
56  options = extractatt(top_uvalue, 'options')
57  optionsflag = extractatt(top_uvalue, 'optionsflag')
58  portrait = (strtrim(optionsflag[where(options EQ 'Portrait/Landscape'), 0], 1))[0]
59;------------------------------------------------------------
60;---------------
61; We determinate which procedure we will call to do the drawing and the type
62;---------------
63  IF keyword_set(forcetype) THEN type = forcetype $
64  ELSE type = widget_info(actionid, /combobox_gettext)
65  case type of
66    'pltz diag up':procedure = 'pltz'
67    'pltz diag dn':procedure = 'pltz'
68    'pltt diag up':procedure = 'pltt'
69    'pltt diag dn':procedure = 'pltt'
70    'xy':procedure = 'plt'
71    'xz':procedure = 'pltz'
72    'yz':procedure = 'pltz'
73    'xt':procedure = 'pltt'
74    'yt':procedure = 'pltt'
75    'zt':procedure = 'pltt'
76    'x':procedure = 'plt1d'
77    'y':procedure = 'plt1d'
78    'z':procedure = 'plt1d'
79    't':procedure = 'pltt'
80    ELSE:procedure = type
81  endcase
82;
83;  Search of 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; What must we read ?
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      tgnm = strlowcase(tag_names(exextra))
187      indtmp = where(tgnm EQ 'box' OR tgnm EQ 'boxzoom', cnt)
188      IF cnt EQ 1 THEN BEGIN
189        boxextra = exextra.(indtmp[0])
190        exextra = extractstru(exextra, ['box', 'boxzoom'])
191      ENDIF
192      extra =  mixstru(exextra, extra)
193      sextra = struct2string(extra)
194      readcmd = [temporary(readcmd), 'extra = '+sextra]
195;
196      *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
197      case 1 of
198        drawvecteur:BEGIN
199; we have to read the vectors
200          *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = !pi
201          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the zonal component of vector')
202          return,  ''
203        END
204        drawover:BEGIN
205; we have to read the field to overlay...
206          *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = 2.*!pi
207          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field to overlay')
208          return,  ''
209        END
210; finished, we draw the plot...
211        ELSE:*top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
212      endcase
213    END
214    'vector':BEGIN
215; for the vectors, there is 2 components. we read u when alreadyvector
216; is a integer and v when alreadyvector is a integer+0.5
217      if floor(alreadyvector)+1 EQ 0 then begin
218        if floor(alreadyvector) EQ alreadyvector then begin
219          readcmd = ['; beginning of reading the zonal component of vector', readcmd]
220          readcmd[i+1] = 'fieldu = ' + prefix + readcmd[i+1]
221        ENDIF ELSE BEGIN
222          readcmd = ['; beginning of reading the meridional component of vector', readcmd]
223          readcmd[i+1] = 'fieldv = ' + prefix + readcmd[i+1]
224        ENDELSE
225        readcmd = [extractatt(top_uvalue, 'currentreadcmd'), temporary(readcmd)]
226      ENDIF ELSE BEGIN
227        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
228        nl = n_elements(oldrdcmd)
229        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
230        readcmd[i] = prefix + readcmd[i]
231        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
232      ENDELSE
233;
234      case alreadyvector+1 of
235        numberofread-1:BEGIN
236; we finalize the reading command
237          IF ending NE '' THEN BEGIN
238            nl = n_elements(readcmd)
239            readcmd[nl-1] = readcmd[nl-1] + ' $'
240            readcmd = [temporary(readcmd), ending]
241          ENDIF
242          readcmd = [temporary(readcmd) $
243                     , 'fieldu = create_struct({arr:temporary(fieldu), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
244                     , '; end of reading the zonal component of vector', ';']
245          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
246; we finished zonal component reading...
247; we know switch to meridional component...
248          *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -.5
249          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the meridional component of vector')
250          return,  ''
251        END
252        numberofread-0.5:BEGIN
253; we finalize the reading command
254          IF ending NE '' THEN BEGIN
255            nl = n_elements(readcmd)
256            readcmd[nl-1] = readcmd[nl-1] + ' $'
257            readcmd = [temporary(readcmd), ending]
258          ENDIF
259          readcmd = [temporary(readcmd)  $
260                     , 'fieldv = create_struct({arr:temporary(fieldv), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
261                     , '; end of reading the meridional component of vector', ';']
262; we finished meridional component reading...
263;
264; we get back _EXTRA of the vector and we complet extra already build
265          extra = extractatt(top_uvalue, 'extra')
266          exextra = cw_specifie_get_value(base)
267          extra =  mixstru(exextra, extra)
268          sextra = struct2string(extra)
269          readcmd = [readcmd, 'vectorextra = '+sextra, 'extra=mixstru(extra,vectorextra)']
270;
271          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
272;
273          if drawover then BEGIN
274; shall we do an overlay???
275            *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = !pi
276            *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field to overlay')
277            return,  ''
278          ENDIF ELSE BEGIN
279; it is done know!
280            *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
281            *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -1
282          ENDELSE
283        END
284        ELSE:BEGIN
285; we still need to read some vector components...
286          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
287          *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = alreadyvector+1
288          if floor(alreadyvector) EQ alreadyvector then text = ' zonal ' $
289          ELSE text = ' meridional '
290          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the '+strtrim(floor(alreadyread)+3, 1)+text+'component of vector')
291          return,  ''
292        END
293      endcase
294    END
295    'over':BEGIN
296      if alreadyover+1 EQ 0 then begin
297; we start the reading...
298        readcmd = ['; beginning of reading the field to overdraw', readcmd]
299        readcmd[i+1] = 'fieldover = '+ prefix +readcmd[i+1]
300        readcmd = [extractatt(top_uvalue, 'currentreadcmd'), temporary(readcmd)]
301      ENDIF ELSE BEGIN
302        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
303        nl = n_elements(oldrdcmd)
304        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
305        readcmd[i] = prefix + readcmd[i]
306        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
307      ENDELSE
308;
309      if alreadyover+1 NE numberofread-1 THEN BEGIN
310; we still need to read some files...
311        *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
312        *top_uvalue[1, findline(top_uvalue, 'alreadyover')] = alreadyover+1
313        *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field number '+strtrim(alreadyover+3, 1)+' to overlay')
314        return,  ''
315      ENDIF
316; we finalize the reading command
317      IF ending NE '' THEN BEGIN
318        nl = n_elements(readcmd)
319        readcmd[nl-1] = readcmd[nl-1] + ' $'
320        readcmd = [temporary(readcmd), ending]
321      ENDIF
322; on finalise la commande de lecture
323      readcmd = [readcmd $
324                 , 'fieldover = create_struct({arr:temporary(fieldover), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
325                 , '; end of reading the field to overdraw', ';']
326; we get back _EXTRA of over and we complet extra already build
327      extra = extractatt(top_uvalue, 'extra')
328      exextra = cw_specifie_get_value(base)
329      extra =  mixstru(exextra, extra)
330      sextra = struct2string(extra)
331      readcmd = [readcmd, 'overextra = '+sextra, 'extra=mixstru(extra,overextra)']
332;
333      *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
334; we reinitialize
335      *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
336      *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -1
337      *top_uvalue[1, findline(top_uvalue, 'alreadyover')] = -1
338    END
339  endcase
340;
341;-----------------------
342;-----------------------
343;-----------------------
344;-----------------------
345;-----------------------
346;-----------------------
347;---------------
348; determination of the boxzoom's name.
349  if NOT keyword_set(boxzoom) then widget_control, domainid, get_value = boxzoom
350  CASE n_elements(boxextra) OF
351    0:
352    1:boxzoom[5] = boxextra
353    2:boxzoom[4:5] = boxextra
354    4:boxzoom[0:3] = boxextra
355    5:boxzoom = [boxextra[0:3], 0, boxextra[4]]
356    6:boxzoom = boxextra
357  ENDCASE
358; Writting of this one as a string
359  box = '['+strtrim(boxzoom[0], 1)
360  for i = 1, (n_elements(boxzoom)-1) < (3+2*(strpos(type, 'z') EQ -1)) do $
361    box = box+', '+strtrim(boxzoom[i], 1)
362; For [plots in z, box must have by default 0,profmax
363  if strpos(type, 'z') NE -1 then BEGIN
364; If more than 1 level is selected:
365    widget_control, widget_info(base, find_by_uname = 'dthlv1'), get_value = niv1
366    niv1 = niv1.combobox_index
367    widget_control, widget_info(base, find_by_uname = 'dthlv2'), get_value = niv2
368    niv2 = niv2.combobox_index
369    if niv1 NE niv2 then begin
370      box = box+','+strtrim(boxzoom[4], 1)+','+strtrim(boxzoom[5], 1)
371    ENDIF ELSE BEGIN
372      if chkstru(exextra, 'profmax') then  pmax = exextra.profmax $
373      ELSE pmax = 200
374      box = box+',0,'+strtrim(boxzoom[5] > pmax, 1)
375    ENDELSE
376  endif
377  box = box+']'
378  IF strpos(type, ' diag up') NE -1 THEN BEGIN
379    sendpoints = '[' + strtrim(boxzoom[0], 1) + ', ' + strtrim(boxzoom[2], 1) + $
380                ', ' + strtrim(boxzoom[1], 1) + ', ' + strtrim(boxzoom[3], 1) + ']'
381  ENDIF
382  IF strpos(type, ' diag dn') NE -1 THEN BEGIN
383    sendpoints = '[' + strtrim(boxzoom[0], 1) + ', ' + strtrim(boxzoom[3], 1) + $
384                ', ' + strtrim(boxzoom[1], 1) + ', ' + strtrim(boxzoom[2], 1) + ']'
385  ENDIF
386;---------------
387; We determinate typein
388;---------------
389    IF strpos(type, ' diag ') NE -1 THEN typein = ''''+strmid(type, 0, 4)+'''' $
390    ELSE typein = ''''+type+''''
391;---------------
392;---------------
393; determination of small
394;---------------
395  ssmall = tostr(smallout)
396;------------------------------------------------------------
397; We will define the string which will contain the command to be executed by widgetdessine.pro
398;------------------------------------------------------------
399  Cmd = [readCmd, procedure+ ', field $' $
400         , '    , boxzoom = '+box+', /findalways, typein='+typein+', small='+ssmall+' $']
401  IF drawvecteur then Cmd = [Cmd, '    , vecteur = {u: fieldu,v: fieldv} $']
402  IF drawover then Cmd = [Cmd, '    , contour = fieldover $']
403  IF n_elements(sendpoints) NE 0 then Cmd = [Cmd, '    , endpoints = ' + sendpoints + ' $']
404  Cmd = [Cmd, '    , _extra= mixstru(ex, extra), portrait = ' + portrait + ', NOERASE=noerase']
405
406;    print, '---------------'
407;    for i = 0, n_elements(Cmd)-1 do print, Cmd[i]
408;    print, '---------------'
409;---------------
410; We complete and/or update the structure top_uvalue...
411;---------------
412  (*top_uvalue[1, findline(top_uvalue, 'nameprocedures')])[numdessinout] = procedure
413  (*top_uvalue[1, findline(top_uvalue, 'types')])[numdessinout] = type
414  (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinout] = boxzoom
415  (*top_uvalue[1, findline(top_uvalue, 'txtcmd')])[numdessinout] = widcmd
416  (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[*, numdessinout] = flags
417  *((*top_uvalue[1, findline(top_uvalue, 'exextra')])[numdessinout]) = extra
418;------------------------------------------------------------
419  return, Cmd
420end
421
422
Note: See TracBrowser for help on using the repository browser.