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

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

typo

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