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

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

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

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