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

Last change on this file since 367 was 325, checked in by pinsard, 16 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • 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;-
26PRO xcreateanim_event, event
27;
28  compile_opt idl2, strictarrsubs
29;
30@common
31
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(abs(calendar - date2jul(vdate1)) LT 1./86400.))[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(abs(calendar - date2jul(vdate2)) LT 1./86400.))[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;-
193PRO xcreateanim, parent
194;
195  compile_opt idl2, strictarrsubs
196;
197@common
198;
199   widget_control, parent, get_uvalue = top_uvalue
200;
201; We will make sure that all procedure are not in pltt
202;
203   procedures = extractatt(top_uvalue, 'nameprocedures')
204   if total(procedures EQ 'pltt') NE 0 then begin
205      nothing = report('Certains des plots ont un axe se rapportant au temps. !C Animation impossible!', /error)
206      return
207   ENDIF
208;
209; We will make sure that all figure have the same calendar
210;
211   filelist = extractatt(top_uvalue,  'filelist')
212   filenames = (extractatt(top_uvalue,  'varinfo'))[0, *]
213   filenames = reform(filenames)
214   filenames = filenames[uniq(filenames, sort(filenames))]
215   if strtrim(filenames[0], 1) EQ '' then filenames = filenames[1:n_elements(filenames)-1]
216   indexfile = (where(filelist EQ filenames[0]))[0]
217   calendar = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).time_counter
218   key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).caltype
219   fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).fakecal
220   if n_elements(filenames) GT 1 then begin
221      for i = 1, n_elements(filenames)-1 do begin
222         indexfilebis = (where(filelist EQ filenames[i]))[0]
223         calendarbis = (*(extractatt(top_uvalue, 'fileparameters'))[indexfilebis]).time_counter
224         if n_elements(calendarbis) NE n_elements(calendar)  then begin
225            nothing = report('plots do not use the same calendar. !C Animation impossible!', /error)
226            return
227         ENDIF
228         if total(calendar NE calendarbis) NE 0 then begin
229            nothing = report('plots do not use the same calendar. !C Animation impossible!', /error)
230            return
231         endif
232      endfor
233   endif
234;
235; It is possible to do an animation.
236;
237   base = widget_base(/column, title = 'animation creation', uvalue = {parent:parent, indexfile:indexfile})
238   rien = widget_label(base, value = 'animation name')
239   rien = widget_text(base,value='anim_idl.gif', uname='Filename', /editable)
240   rien = widget_label(base, value = 'animation directory')
241   if n_elements(animdir) EQ 0 then cd, current = animdir
242   rien = widget_text(base,value=animdir, uname='directorie', /editable)
243   rien = widget_label(base, value = 'starting date')
244   rien = cw_calendar(base, calendar, calendar[0] $
245                      , FAKECAL = fakecal, uname = 'debut', uvalue = {name:'calendar'}, /frame)
246   rien = widget_label(base, value = 'ending date')
247   rien = cw_calendar(base, calendar, calendar[n_elements(calendar)-1] $
248                      , FAKECAL = fakecal, uname = 'fin', uvalue = {name:'calendar'}, /frame)
249   rien = widget_button(base,value='OK', uvalue = 'ok')
250   rien = widget_button(base,value='Cancel', uvalue = 'cancel')
251;
252   widget_control,base,/realize
253   xmanager,'xcreateanim', base, /no_block
254
255   return
256end
Note: See TracBrowser for help on using the repository browser.