source: trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/xcreateanim.pro @ 150

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

english and nicer header (3a)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1;+
2; @file_comments
3;
4;
5; @categories
6;
7;
8; @param EVENT
9;
10;
11; @returns
12;
13;
14; @uses
15;
16;
17; @restrictions
18;
19;
20; @examples
21;
22;
23; @history
24;
25;
26; @version
27; $Id$
28;
29; @todo
30; seb
31;
32;-
33pro xcreateanim_event, event
34;
35  compile_opt idl2, strictarrsubs
36;
37@common
38; We recuperate arguments contained in the widget
39  if tag_names(event, /structure_name) NE 'WIDGET_BUTTON' then return
40  widget_control, event.id, get_uvalue = uval
41  if n_elements(uval) EQ 0 then return
42  if uval EQ 'cancel' then begin
43    widget_control, event.top, /destroy
44    return
45  ENDIF
46; We will write the animation!
47;
48  widget_control, event.top, get_uvalue = local_uvalue
49  widget_control, local_uvalue.parent, get_uvalue = top_uvalue
50;
51  calendar = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).time_counter
52  key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).caltype
53  fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).fakecal
54;
55  widget_control, widget_info(event.top, find_by_uname = 'Filename') $
56                  , get_value = nomfic & nomfic = nomfic[0]
57;
58  widget_control, widget_info(event.top, find_by_uname = 'directorie') $
59                  , get_value = animdir & animdir = animdir[0]
60;
61  widget_control, widget_info(event.top, find_by_uname = 'debut') $
62                  , get_value = vdate1
63  index1 = where(calendar eq date2jul(vdate1)) & index1 = index1[0]
64  if index1 EQ -1 then return
65;
66  widget_control, widget_info(event.handler, find_by_uname = 'fin') $
67                  , get_value = vdate2
68  index2 = where(calendar eq date2jul(vdate2)) & index2 = index2[0]
69  if index2 EQ -1 OR index2 LE index1 then return
70; We delete the widget before create the file .ps
71  widget_control, event.top, /destroy
72;
73; creation of the routine which will serve us to do the drawing
74;
75; We recuperate the list of instructions
76  globalcommand = extractatt(top_uvalue, 'globalcommand')
77; We complete by first and last lines of the program
78  createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
79             , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, DATE1IN = date1in, DATE2IN = date2in'
80;
81;--------creation of the file---------
82;
83;  we recuperate the number of octets on which we code the palette.
84  device, get_visual_depth = depth
85; Picture's size (in number of pixels):
86  xsize = !d.x_size
87  ysize = !d.y_size
88;
89; We check that the file's name end by .gif
90  if strpos(nomfic, '.gif') EQ -1 then nomfic = nomfic+'.gif'
91
92  current_window = !d.window
93  window, /free, /pixmap, xsize = xsize, ysize = ysize
94
95
96; indication of the number of the picture we are creating
97  base = widget_base()
98  sliderid = widget_slider(base, minimum = 1, maximum = index2-index1+1, value = 1 $
99                           , title = 'image number: ')
100  widget_control, base, /realize
101;
102; Beginning of the gif file. Writting of an empty  picture.
103  IF keyword_set(fakecal) THEN date = index1 ELSE date = jul2date(calendar[index1])
104  xxx2ps, /noerase, date1in = date, date2in = date
105;
106;
107  image = tvrd(true = depth GT 8)
108;- If an 8-bit image was read, reduce the number of colors
109  if depth le 8 then begin
110    tvlct, red, green, blue, /get
111    reduce_colors, image, index
112    red = red[index]
113    green = green[index]
114    blue = blue[index]
115  endif           
116;
117  if depth gt 8 then $
118;- Convert 24-bit image to 8-bit
119  image = color_quan(image, 1, red, green, blue, colors = 256, get_translation = translation, /map_all)
120;
121;
122  write_gif, animdir+nomfic, image, red, green, blue, /multiple
123  wdelete, !d.window
124;
125; Creation and writting loop in the file.
126;
127  IF index2 GT index1 THEN BEGIN
128    FOR ind = index1+1, index2 do BEGIN
129;
130      widget_control, sliderid, set_value = ind-index1+1 ; We move the slider.
131;
132      window, /free, /pixmap, xsize = xsize, ysize = ysize
133      IF keyword_set(fakecal) THEN date = ind ELSE date = jul2date(calendar[ind])
134      xxx2ps, /noerase, date1 = date, date2 = date
135;     
136      image = tvrd(true = depth GT 8)
137;
138      if depth gt 8 then $
139        image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ;
140;
141      write_gif, animdir+nomfic, image, red, green, blue, /multiple
142      wdelete, !d.window
143    ENDFOR
144  ENDIF
145; We put a last white picture
146  window, /free, /pixmap, xsize = xsize, ysize = ysize
147  reinitplt
148  plot,  [0],  [0], /nodata
149  image = tvrd(true = depth GT 8)
150;
151  if depth gt 8 then $
152    image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ;
153;
154  write_gif, animdir+nomfic, image, red, green, blue, /multiple
155  wdelete, !d.window
156; File's closing.
157  write_gif, animdir+nomfic, /close
158  widget_control, base, /destroy
159; Rerock in "normal" mode
160  thisOS = strupcase(strmid(!version.os_family, 0, 3))
161;
162  wset, current_window
163
164; If we are under x, we try to lauch xanim...
165
166  if thisOS NE 'MAC' AND thisOS NE 'WIN' then begin
167    spawn, 'which xanim', result
168    if strpos(result[0], 'xanim') EQ strlen(result[0])-5 then spawn, 'xanim '+animdir+nomfic+' &'
169  endif
170;
171 
172  return
173end
174;----------------------------------------------------------------
175;+
176; @file_comments
177;
178;
179; @categories
180;
181;
182; @param PARENT
183;
184;
185; @returns
186;
187;
188; @uses
189;
190;
191; @restrictions
192;
193;
194; @examples
195;
196;
197; @history
198;
199;
200; @version
201; $Id$
202;
203; @todo
204; seb
205;
206;-
207PRO xcreateanim, parent
208;
209  compile_opt idl2, strictarrsubs
210;
211@common
212;
213   widget_control, parent, get_uvalue = top_uvalue
214;
215; We will make sure that all procedure are not in pltt
216;
217   procedures = extractatt(top_uvalue, 'nameprocedures')
218   if total(procedures EQ 'pltt') NE 0 then begin
219      nothing = report('Certains des plots ont un axe se rapportant au temps. !C Animation impossible!', /error)
220      return
221   ENDIF
222;
223; We will make sure that all figure have the same calendar
224;
225   filelist = extractatt(top_uvalue,  'filelist')
226   filenames = (extractatt(top_uvalue,  'varinfo'))[0, *]
227   filenames = reform(filenames)
228   filenames = filenames[uniq(filenames, sort(filenames))]
229   if strtrim(filenames[0], 1) EQ '' then filenames = filenames[1:n_elements(filenames)-1]
230   indexfile = (where(filelist EQ filenames[0]))[0]
231   calendar = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).time_counter 
232   key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).caltype
233   fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).fakecal
234   if n_elements(filenames) GT 1 then begin
235      for i = 1, n_elements(filenames)-1 do begin
236         indexfilebis = (where(filelist EQ filenames[i]))[0]
237         calendarbis = (*(extractatt(top_uvalue, 'fileparameters'))[indexfilebis]).time_counter
238         if n_elements(calendarbis) NE n_elements(calendar)  then begin
239            nothing = report('Les diffrents plots n''utilisent pas le meme calendrier. !C Animation impossible!', /error)
240            return
241         ENDIF
242         if total(calendar NE calendarbis) NE 0 then begin
243            nothing = report('Les diffrents plots n''utilisent pas le meme calendrier. !C Animation impossible!', /error)
244            return
245         endif
246      endfor
247   endif
248;
249; It is possible to do an animation.
250;
251   base = widget_base(/column, title = 'animation creation', uvalue = {parent:parent, indexfile:indexfile})   
252   rien = widget_label(base, value = 'animation name')
253   rien = widget_text(base,value='anim_idl.gif', uname='Filename', /editable)
254   rien = widget_label(base, value = 'animation directory')
255   if n_elements(animdir) EQ 0 then cd, current = animdir
256   rien = widget_text(base,value=animdir, uname='directorie', /editable)
257   rien = widget_label(base, value = 'starting date')
258   rien = cw_calendar(base, calendar, calendar[0] $
259                      , FAKECAL = fakecal, uname = 'debut', uvalue = {name:'calendar'}, /frame)
260   rien = widget_label(base, value = 'ending date')
261   rien = cw_calendar(base, calendar, calendar[n_elements(calendar)-1] $
262                      , FAKECAL = fakecal, uname = 'fin', uvalue = {name:'calendar'}, /frame)
263   rien = widget_button(base,value='OK', uvalue = 'ok')
264   rien = widget_button(base,value='Cancel', uvalue = 'cancel')
265;
266   widget_control,base,/realize
267   xmanager,'xcreateanim', base, /no_block
268   
269   return
270end
Note: See TracBrowser for help on using the repository browser.