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
RevLine 
[150]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;-
[2]33pro xcreateanim_event, event
[114]34;
35  compile_opt idl2, strictarrsubs
36;
[2]37@common
[150]38; We recuperate arguments contained in the widget
[74]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
[150]46; We will write the animation!
[2]47;
[74]48  widget_control, event.top, get_uvalue = local_uvalue
49  widget_control, local_uvalue.parent, get_uvalue = top_uvalue
[2]50;
[74]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
[2]54;
[74]55  widget_control, widget_info(event.top, find_by_uname = 'Filename') $
56                  , get_value = nomfic & nomfic = nomfic[0]
[2]57;
[74]58  widget_control, widget_info(event.top, find_by_uname = 'directorie') $
59                  , get_value = animdir & animdir = animdir[0]
[2]60;
[74]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
[2]65;
[74]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
[150]70; We delete the widget before create the file .ps
[74]71  widget_control, event.top, /destroy
[2]72;
[150]73; creation of the routine which will serve us to do the drawing
[2]74;
[150]75; We recuperate the list of instructions
[74]76  globalcommand = extractatt(top_uvalue, 'globalcommand')
[150]77; We complete by first and last lines of the program
[74]78  createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
79             , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, DATE1IN = date1in, DATE2IN = date2in'
[2]80;
[150]81;--------creation of the file---------
[2]82;
[150]83;  we recuperate the number of octets on which we code the palette.
[74]84  device, get_visual_depth = depth
[150]85; Picture's size (in number of pixels):
[74]86  xsize = !d.x_size
87  ysize = !d.y_size
[2]88;
[150]89; We check that the file's name end by .gif
[74]90  if strpos(nomfic, '.gif') EQ -1 then nomfic = nomfic+'.gif'
[2]91
[74]92  current_window = !d.window
93  window, /free, /pixmap, xsize = xsize, ysize = ysize
[2]94
95
[150]96; indication of the number of the picture we are creating
[74]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
[2]101;
[150]102; Beginning of the gif file. Writting of an empty  picture.
[74]103  IF keyword_set(fakecal) THEN date = index1 ELSE date = jul2date(calendar[index1])
104  xxx2ps, /noerase, date1in = date, date2in = date
[2]105;
106;
[74]107  image = tvrd(true = depth GT 8)
[2]108;- If an 8-bit image was read, reduce the number of colors
[74]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           
[2]116;
[74]117  if depth gt 8 then $
[2]118;- Convert 24-bit image to 8-bit
[74]119  image = color_quan(image, 1, red, green, blue, colors = 256, get_translation = translation, /map_all)
[2]120;
121;
[74]122  write_gif, animdir+nomfic, image, red, green, blue, /multiple
123  wdelete, !d.window
[2]124;
[150]125; Creation and writting loop in the file.
[2]126;
[74]127  IF index2 GT index1 THEN BEGIN
128    FOR ind = index1+1, index2 do BEGIN
[2]129;
[150]130      widget_control, sliderid, set_value = ind-index1+1 ; We move the slider.
[2]131;
[74]132      window, /free, /pixmap, xsize = xsize, ysize = ysize
133      IF keyword_set(fakecal) THEN date = ind ELSE date = jul2date(calendar[ind])
[2]134      xxx2ps, /noerase, date1 = date, date2 = date
135;     
136      image = tvrd(true = depth GT 8)
137;
138      if depth gt 8 then $
[74]139        image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ;
[2]140;
[74]141      write_gif, animdir+nomfic, image, red, green, blue, /multiple
[2]142      wdelete, !d.window
[74]143    ENDFOR
144  ENDIF
[150]145; We put a last white picture
[74]146  window, /free, /pixmap, xsize = xsize, ysize = ysize
147  reinitplt
148  plot,  [0],  [0], /nodata
149  image = tvrd(true = depth GT 8)
[2]150;
[74]151  if depth gt 8 then $
152    image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ;
[2]153;
[74]154  write_gif, animdir+nomfic, image, red, green, blue, /multiple
155  wdelete, !d.window
[150]156; File's closing.
[74]157  write_gif, animdir+nomfic, /close
158  widget_control, base, /destroy
[150]159; Rerock in "normal" mode
[74]160  thisOS = strupcase(strmid(!version.os_family, 0, 3))
[2]161;
[74]162  wset, current_window
[2]163
[150]164; If we are under x, we try to lauch xanim...
[2]165
[74]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
[2]170;
[74]171 
172  return
[2]173end
174;----------------------------------------------------------------
[150]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;-
[2]207PRO xcreateanim, parent
[114]208;
209  compile_opt idl2, strictarrsubs
210;
[2]211@common
212;
213   widget_control, parent, get_uvalue = top_uvalue
214;
[150]215; We will make sure that all procedure are not in pltt
[2]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;
[150]223; We will make sure that all figure have the same calendar
[2]224;
225   filelist = extractatt(top_uvalue,  'filelist')
[69]226   filenames = (extractatt(top_uvalue,  'varinfo'))[0, *]
[2]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 
[74]232   key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).caltype
233   fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).fakecal
[2]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;
[150]249; It is possible to do an animation.
[2]250;
[69]251   base = widget_base(/column, title = 'animation creation', uvalue = {parent:parent, indexfile:indexfile})   
252   rien = widget_label(base, value = 'animation name')
[2]253   rien = widget_text(base,value='anim_idl.gif', uname='Filename', /editable)
[69]254   rien = widget_label(base, value = 'animation directory')
[2]255   if n_elements(animdir) EQ 0 then cd, current = animdir
256   rien = widget_text(base,value=animdir, uname='directorie', /editable)
[69]257   rien = widget_label(base, value = 'starting date')
[74]258   rien = cw_calendar(base, calendar, calendar[0] $
259                      , FAKECAL = fakecal, uname = 'debut', uvalue = {name:'calendar'}, /frame)
[69]260   rien = widget_label(base, value = 'ending date')
[2]261   rien = cw_calendar(base, calendar, calendar[n_elements(calendar)-1] $
[74]262                      , FAKECAL = fakecal, uname = 'fin', uvalue = {name:'calendar'}, /frame)
[2]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.