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

Last change on this file since 310 was 310, checked in by smasson, 17 years ago

bugfix in xxx animations

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