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

Last change on this file since 367 was 327, checked in by pinsard, 16 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

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