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

Last change on this file since 171 was 157, checked in by navarro, 18 years ago

header improvements + xxx doc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.6 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      extra =  mixstru(exextra, extra)
187      sextra = struct2string(extra)
188      readcmd = [temporary(readcmd), 'extra = '+sextra]
189;
190      *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
191      case 1 of
192        drawvecteur:BEGIN
193; we have to read the vectors
194          *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = !pi
195          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the zonal component of vector')
196          return,  ''
197        END
198        drawover:BEGIN
199; we have to read the field to overlay...
200          *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = 2.*!pi
201          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field to overlay')
202          return,  ''
203        END
204; finished, we draw the plot...
205        ELSE:*top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
206      endcase
207    END
208    'vector':BEGIN
209; for the vectors, there is 2 components. we read u when alreadyvector
210; is a interger and v when alreadyvector is a interger+0.5
211      if floor(alreadyvector)+1 EQ 0 then begin
212        if floor(alreadyvector) EQ alreadyvector then begin
213          readcmd = ['; beginning of reading the zonal component of vector', readcmd]
214          readcmd[i+1] = 'fieldu = ' + prefix + readcmd[i+1]
215        ENDIF ELSE BEGIN
216          readcmd = ['; beginning of reading the meridional component of vector', readcmd]
217          readcmd[i+1] = 'fieldv = ' + prefix + readcmd[i+1]
218        ENDELSE
219        readcmd = [extractatt(top_uvalue, 'currentreadcmd'), temporary(readcmd)]
220      ENDIF ELSE BEGIN
221        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
222        nl = n_elements(oldrdcmd)
223        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
224        readcmd[i] = prefix + readcmd[i]
225        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
226      ENDELSE
227;
228      case alreadyvector+1 of
229        numberofread-1:BEGIN
230; we finalize the reading command
231          IF ending NE '' THEN BEGIN
232            nl = n_elements(readcmd)
233            readcmd[nl-1] = readcmd[nl-1] + ' $'
234            readcmd = [temporary(readcmd), ending]
235          ENDIF
236          readcmd = [temporary(readcmd) $
237                     , 'fieldu = create_struct({arr:temporary(fieldu), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
238                     , '; end of reading the zonal component of vector', ';']
239          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
240; we finished zonal component reading...
241; we know switch to meridional component...
242          *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -.5
243          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the meridional component of vector')
244          return,  ''
245        END
246        numberofread-0.5:BEGIN
247; we finalize the reading command
248          IF ending NE '' THEN BEGIN
249            nl = n_elements(readcmd)
250            readcmd[nl-1] = readcmd[nl-1] + ' $'
251            readcmd = [temporary(readcmd), ending]
252          ENDIF
253          readcmd = [temporary(readcmd)  $
254                     , 'fieldv = create_struct({arr:temporary(fieldv), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
255                     , '; end of reading the meridional component of vector', ';']
256; we finished meridional component reading...
257;
258; we get back _EXTRA of the vector and we complet extra already build
259          extra = extractatt(top_uvalue, 'extra')
260          exextra = cw_specifie_get_value(base)
261          extra =  mixstru(exextra, extra)
262          sextra = struct2string(extra)
263          readcmd = [readcmd, 'vectorextra = '+sextra, 'extra=mixstru(extra,vectorextra)']
264;
265          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
266;
267          if drawover then BEGIN
268; shall we do an overlay???
269            *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = !pi
270            *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field to overlay')
271            return,  ''
272          ENDIF ELSE BEGIN
273; it is done know!
274            *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
275            *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -1
276          ENDELSE
277        END
278        ELSE:BEGIN
279; we still need to read some vector components...
280          *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
281          *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = alreadyvector+1
282          if floor(alreadyvector) EQ alreadyvector then text = ' zonal ' $
283          ELSE text = ' meridional '
284          *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the '+strtrim(floor(alreadyread)+3, 1)+text+'component of vector')
285          return,  ''
286        END
287      endcase
288    END
289    'over':BEGIN
290      if alreadyover+1 EQ 0 then begin
291; we start the reading...
292        readcmd = ['; beginning of reading the field to overdraw', readcmd]
293        readcmd[i+1] = 'fieldover = '+ prefix +readcmd[i+1]
294        readcmd = [extractatt(top_uvalue, 'currentreadcmd'), temporary(readcmd)]
295      ENDIF ELSE BEGIN
296        oldrdcmd = extractatt(top_uvalue, 'currentreadcmd')
297        nl = n_elements(oldrdcmd)
298        oldrdcmd[nl-1] = oldrdcmd[nl-1] + ' $'
299        readcmd[i] = prefix + readcmd[i]
300        readcmd = [temporary(oldrdcmd), temporary(readcmd)]
301      ENDELSE
302;
303      if alreadyover+1 NE numberofread-1 THEN BEGIN
304; we still need to read some files...
305        *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
306        *top_uvalue[1, findline(top_uvalue, 'alreadyover')] = alreadyover+1
307        *top_uvalue[1, findline(top_uvalue, 'noticebase')] = xnotice('Select the field number '+strtrim(alreadyover+3, 1)+' to overlay')
308        return,  ''
309      ENDIF
310; we finalize the reading command
311      IF ending NE '' THEN BEGIN
312        nl = n_elements(readcmd)
313        readcmd[nl-1] = readcmd[nl-1] + ' $'
314        readcmd = [temporary(readcmd), ending]
315      ENDIF
316; on finalise la commande de lecture
317      readcmd = [readcmd $
318                 , 'fieldover = create_struct({arr:temporary(fieldover), grid:vargrid, unit:varunit, experiment:varexp, name:varname})' $
319                 , '; end of reading the field to overdraw', ';']
320; we get back _EXTRA of over and we complet extra already build
321      extra = extractatt(top_uvalue, 'extra')
322      exextra = cw_specifie_get_value(base)
323      extra =  mixstru(exextra, extra)
324      sextra = struct2string(extra)
325      readcmd = [readcmd, 'overextra = '+sextra, 'extra=mixstru(extra,overextra)']
326;
327      *top_uvalue[1, findline(top_uvalue, 'currentreadcmd')] = readcmd
328; we reinitialize
329      *top_uvalue[1, findline(top_uvalue, 'alreadyread')] = -1
330      *top_uvalue[1, findline(top_uvalue, 'alreadyvector')] = -1
331      *top_uvalue[1, findline(top_uvalue, 'alreadyover')] = -1
332    END
333  endcase
334;
335;-----------------------
336;-----------------------
337;-----------------------
338;-----------------------
339;-----------------------
340;-----------------------
341;---------------
342; determination of the boxzoom's name.
343  if NOT keyword_set(boxzoom) then widget_control, domainid, get_value = boxzoom
344; Writting of this one as a string
345  box = '['+strtrim(boxzoom[0], 1)
346  for i = 1, (n_elements(boxzoom)-1) < (3+2*(strpos(type, 'z') EQ -1)) do $
347    box = box+', '+strtrim(boxzoom[i], 1)
348; For [plots in z, box must have by default 0,profmax
349  if strpos(type, 'z') NE -1 then BEGIN
350; If more than 1 level is selected:
351    widget_control, widget_info(base, find_by_uname = 'dthlv1'), get_value = niv1
352    niv1 = niv1.combobox_index
353    widget_control, widget_info(base, find_by_uname = 'dthlv2'), get_value = niv2
354    niv2 = niv2.combobox_index
355    if niv1 NE niv2 then begin
356      box = box+','+strtrim(boxzoom[4], 1)+','+strtrim(boxzoom[5], 1)
357    ENDIF ELSE BEGIN
358      if chkstru(exextra, 'profmax') then  pmax = exextra.profmax $
359      ELSE pmax = 200
360      box = box+',0,'+strtrim(pmax, 1)
361    ENDELSE
362  endif
363  box = box+']'
364  IF strpos(type, ' diag up') NE -1 THEN BEGIN
365    sendpoints = '[' + strtrim(boxzoom[0], 1) + ', ' + strtrim(boxzoom[2], 1) + $
366                ', ' + strtrim(boxzoom[1], 1) + ', ' + strtrim(boxzoom[3], 1) + ']'
367  ENDIF
368  IF strpos(type, ' diag dn') NE -1 THEN BEGIN
369    sendpoints = '[' + strtrim(boxzoom[0], 1) + ', ' + strtrim(boxzoom[3], 1) + $
370                ', ' + strtrim(boxzoom[1], 1) + ', ' + strtrim(boxzoom[2], 1) + ']'
371  ENDIF
372;---------------
373; We determinate typein
374;---------------
375    IF strpos(type, ' diag ') NE -1 THEN typein = ''''+strmid(type, 0, 4)+'''' $
376    ELSE typein = ''''+type+''''
377;---------------
378;---------------
379; determination of small
380;---------------
381  ssmall = tostr(smallout)
382;------------------------------------------------------------
383; We will define the string which will contain the command to be executed by widgetdessine.pro
384;------------------------------------------------------------
385  Cmd = [readCmd, procedure+ ', field $' $
386         , '    , boxzoom = '+box+', /findalways, typein='+typein+', small='+ssmall+' $']
387  IF drawvecteur then Cmd = [Cmd, '    , vecteur = {u: fieldu,v: fieldv} $']
388  IF drawover then Cmd = [Cmd, '    , contour = fieldover $']
389  IF n_elements(sendpoints) NE 0 then Cmd = [Cmd, '    , endpoints = ' + sendpoints + ' $']
390  Cmd = [Cmd, '    , _extra= mixstru(ex, extra), portrait = ' + portrait + ', NOERASE=noerase']
391
392;    print, '---------------'
393;    for i = 0, n_elements(Cmd)-1 do print, Cmd[i]
394;    print, '---------------'
395;---------------
396; We complete and/or update the structure top_uvalue...
397;---------------
398  (*top_uvalue[1, findline(top_uvalue, 'nameprocedures')])[numdessinout] = procedure
399  (*top_uvalue[1, findline(top_uvalue, 'types')])[numdessinout] = type
400  (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinout] = boxzoom
401  (*top_uvalue[1, findline(top_uvalue, 'txtcmd')])[numdessinout] = widcmd
402  (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[*, numdessinout] = flags
403  *((*top_uvalue[1, findline(top_uvalue, 'exextra')])[numdessinout]) = extra
404;------------------------------------------------------------
405  return, Cmd
406end
407
408
Note: See TracBrowser for help on using the repository browser.