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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • 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; indication of the number of the picture we are creating
90  base = widget_base()
91  sliderid = widget_slider(base, minimum = 1, maximum = index2-index1+1, value = 1 $
92                           , title = 'image number: ')
93  widget_control, base, /realize
94;
95; Beginning of the gif file. Writing of an empty picture.
96  IF keyword_set(fakecal) THEN date = index1 ELSE date = jul2date(calendar[index1])
97  xxx2ps, /noerase, date1in = date, date2in = date
98;
99  image = tvrd(true = depth GT 8)
100;- If an 8-bit image was read, reduce the number of colors
101  if depth le 8 then begin
102    tvlct, red, green, blue, /get
103    reduce_colors, image, index
104    red = red[index]
105    green = green[index]
106    blue = blue[index]
107  endif
108;
109  if depth gt 8 then $
110;- Convert 24-bit image to 8-bit
111  image = color_quan(image, 1, red, green, blue, colors = 256, get_translation = translation, /map_all)
112;
113  write_gif, animdir+nomfic, image, red, green, blue, /multiple
114  wdelete, !d.window
115;
116; Creation and writing loop in the file.
117;
118  IF index2 GT index1 THEN BEGIN
119    FOR ind = index1+1, index2 do BEGIN
120;
121      widget_control, sliderid, set_value = ind-index1+1 ; We move the slider.
122;
123      window, /free, /pixmap, xsize = xsize, ysize = ysize
124      IF keyword_set(fakecal) THEN date = ind ELSE date = jul2date(calendar[ind])
125      xxx2ps, /noerase, date1 = date, date2 = date
126;
127      image = tvrd(true = depth GT 8)
128;
129      if depth gt 8 then $
130        image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ;
131;
132      write_gif, animdir+nomfic, image, red, green, blue, /multiple
133      wdelete, !d.window
134    ENDFOR
135  ENDIF
136; We put a last white picture
137  window, /free, /pixmap, xsize = xsize, ysize = ysize
138  reinitplt
139  plot,  [0],  [0], /nodata
140  image = tvrd(true = depth GT 8)
141;
142  if depth gt 8 then $
143    image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ;
144;
145  write_gif, animdir+nomfic, image, red, green, blue, /multiple
146  wdelete, !d.window
147; File's closing.
148  write_gif, animdir+nomfic, /close
149  widget_control, base, /destroy
150; Rerock in "normal" mode
151  thisOS = strupcase(strmid(!version.os_family, 0, 3))
152;
153  wset, current_window
154
155; If we are under X, we try to launch xanim...
156
157  if thisOS NE 'MAC' AND thisOS NE 'WIN' then begin
158    spawn, 'which xanim', result
159    if strpos(result[0], 'xanim') EQ strlen(result[0])-5 then spawn, 'xanim '+animdir+nomfic+' &'
160  endif
161;
162
163  return
164end
165;
166;+
167; @file_comments
168;
169; @categories
170;
171; @param PARENT
172;
173; @returns
174;
175; @uses
176;
177; @restrictions
178;
179; @examples
180;
181; @history
182;
183; @version
184; $Id$
185;
186; @todo
187; seb
188;
189;-
190PRO xcreateanim, parent
191;
192  compile_opt idl2, strictarrsubs
193;
194@common
195;
196   widget_control, parent, get_uvalue = top_uvalue
197;
198; We will make sure that all procedure are not in pltt
199;
200   procedures = extractatt(top_uvalue, 'nameprocedures')
201   if total(procedures EQ 'pltt') NE 0 then begin
202      nothing = report('Certains des plots ont un axe se rapportant au temps. !C Animation impossible!', /error)
203      return
204   ENDIF
205;
206; We will make sure that all figure have the same calendar
207;
208   filelist = extractatt(top_uvalue,  'filelist')
209   filenames = (extractatt(top_uvalue,  'varinfo'))[0, *]
210   filenames = reform(filenames)
211   filenames = filenames[uniq(filenames, sort(filenames))]
212   if strtrim(filenames[0], 1) EQ '' then filenames = filenames[1:n_elements(filenames)-1]
213   indexfile = (where(filelist EQ filenames[0]))[0]
214   calendar = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).time_counter
215   key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).caltype
216   fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).fakecal
217   if n_elements(filenames) GT 1 then begin
218      for i = 1, n_elements(filenames)-1 do begin
219         indexfilebis = (where(filelist EQ filenames[i]))[0]
220         calendarbis = (*(extractatt(top_uvalue, 'fileparameters'))[indexfilebis]).time_counter
221         if n_elements(calendarbis) NE n_elements(calendar)  then begin
222            nothing = report('plots do not use the same calendar. !C Animation impossible!', /error)
223            return
224         ENDIF
225         if total(calendar NE calendarbis) NE 0 then begin
226            nothing = report('plots do not use the same calendar. !C Animation impossible!', /error)
227            return
228         endif
229      endfor
230   endif
231;
232; It is possible to do an animation.
233;
234   base = widget_base(/column, title = 'animation creation', uvalue = {parent:parent, indexfile:indexfile})
235   rien = widget_label(base, value = 'animation name')
236   rien = widget_text(base,value='anim_idl.gif', uname='Filename', /editable)
237   rien = widget_label(base, value = 'animation directory')
238   if n_elements(animdir) EQ 0 then cd, current = animdir
239   rien = widget_text(base,value=animdir, uname='directorie', /editable)
240   rien = widget_label(base, value = 'starting date')
241   rien = cw_calendar(base, calendar, calendar[0] $
242                      , FAKECAL = fakecal, uname = 'debut', uvalue = {name:'calendar'}, /frame)
243   rien = widget_label(base, value = 'ending date')
244   rien = cw_calendar(base, calendar, calendar[n_elements(calendar)-1] $
245                      , FAKECAL = fakecal, uname = 'fin', uvalue = {name:'calendar'}, /frame)
246   rien = widget_button(base,value='OK', uvalue = 'ok')
247   rien = widget_button(base,value='Cancel', uvalue = 'cancel')
248;
249   widget_control,base,/realize
250   xmanager,'xcreateanim', base, /no_block
251
252   return
253end
Note: See TracBrowser for help on using the repository browser.