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

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

improvements/corrections of some *.pro headers

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