1 | pro xcreateanim_event, event |
---|
2 | @common |
---|
3 | ; on recupere les aguments contenus ds le widget |
---|
4 | if tag_names(event, /structure_name) NE 'WIDGET_BUTTON' then return |
---|
5 | widget_control, event.id, get_uvalue = uval |
---|
6 | if n_elements(uval) EQ 0 then return |
---|
7 | if uval EQ 'cancel' then begin |
---|
8 | widget_control, event.top, /destroy |
---|
9 | return |
---|
10 | ENDIF |
---|
11 | ; on va ecrire l''animation! |
---|
12 | ; |
---|
13 | widget_control, event.top, get_uvalue = local_uvalue |
---|
14 | widget_control, local_uvalue.parent, get_uvalue = top_uvalue |
---|
15 | ; |
---|
16 | calendar = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).time_counter |
---|
17 | key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).caltype |
---|
18 | ; |
---|
19 | widget_control, widget_info(event.top, find_by_uname = 'Filename') $ |
---|
20 | , get_value = nomfic & nomfic = nomfic[0] |
---|
21 | ; |
---|
22 | widget_control, widget_info(event.top, find_by_uname = 'directorie') $ |
---|
23 | , get_value = animdir & animdir = animdir[0] |
---|
24 | ; |
---|
25 | widget_control, widget_info(event.top, find_by_uname = 'debut') $ |
---|
26 | , get_value = vdate1 |
---|
27 | index1 = where(calendar eq date2jul(vdate1)) & index1 = index1[0] |
---|
28 | if index1 EQ -1 then return |
---|
29 | ; |
---|
30 | widget_control, widget_info(event.handler, find_by_uname = 'fin') $ |
---|
31 | , get_value = vdate2 |
---|
32 | index2 = where(calendar eq date2jul(vdate2)) & index2 = index2[0] |
---|
33 | if index2 EQ -1 OR index2 LE index1 then return |
---|
34 | ; on detruit le widget avant de creer le fichier .ps |
---|
35 | widget_control, event.top, /destroy |
---|
36 | ; test pour savoir quel type des calendrier on a |
---|
37 | caldat, calendar, m, d |
---|
38 | if total(d EQ 15) EQ n_elements(d) then mensuel = 1 ELSE mensuel = 0 |
---|
39 | if total(d EQ 1) EQ n_elements(d) AND total(m EQ 6) EQ n_elements(m) $ |
---|
40 | then annuel = 1 ELSE annuel = 0 |
---|
41 | ; |
---|
42 | ; creation de la routine qui nous serviera pour faire le dessin |
---|
43 | ; |
---|
44 | ; on recupere la liste des instructions |
---|
45 | globalcommand = extractatt(top_uvalue, 'globalcommand') |
---|
46 | ; on complete par le premiere et les dernieres lignes du programme |
---|
47 | createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $ |
---|
48 | , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, DATE1IN = date1in, DATE2IN = date2in' |
---|
49 | ; |
---|
50 | ;--------creation du fichier---------- |
---|
51 | ; |
---|
52 | ; recupere le nombre d'octets surlequel on code la palette |
---|
53 | device, get_visual_depth = depth |
---|
54 | ; taille de l''image (en nombre de pixel: |
---|
55 | xsize = !d.x_size |
---|
56 | ysize = !d.y_size |
---|
57 | ; |
---|
58 | ; on verifie que le nom du fichier termine bien par .gif |
---|
59 | if strpos(nomfic, '.gif') EQ -1 then nomfic = nomfic+'.gif' |
---|
60 | |
---|
61 | current_window = !d.window |
---|
62 | window, /free, /pixmap, xsize=xsize, ysize=ysize |
---|
63 | |
---|
64 | |
---|
65 | ; indication du numero de l''image que l''on est en train de creer |
---|
66 | base = widget_base() |
---|
67 | sliderid = widget_slider(base, minimum = 1, maximum = index2-index1+1, value = 1 $ |
---|
68 | , title = 'image number: ') |
---|
69 | widget_control,base,/realize |
---|
70 | ; |
---|
71 | ; commencement du fichier gif. ecriture d''une image vide |
---|
72 | date = jul2date(calendar[index1]) |
---|
73 | xxx2ps, /noerase, date1in = date, date2in = date |
---|
74 | ; |
---|
75 | ; |
---|
76 | image = tvrd(true = depth GT 8) |
---|
77 | ;- If an 8-bit image was read, reduce the number of colors |
---|
78 | if depth le 8 then begin |
---|
79 | tvlct, red, green, blue, /get |
---|
80 | reduce_colors, image, index |
---|
81 | red = red[index] |
---|
82 | green = green[index] |
---|
83 | blue = blue[index] |
---|
84 | endif |
---|
85 | ; |
---|
86 | if depth gt 8 then $ |
---|
87 | ;- Convert 24-bit image to 8-bit |
---|
88 | image = color_quan(image, 1, red, green, blue, colors=256, get_translation = translation, /map_all) |
---|
89 | ; |
---|
90 | ; |
---|
91 | write_gif,animdir+nomfic, image, red, green, blue, /multiple |
---|
92 | wdelete, !d.window |
---|
93 | ; |
---|
94 | ; boucle de creation et d''ecriture ds le fichier. |
---|
95 | ; |
---|
96 | for ind = index1+1, index2 do BEGIN |
---|
97 | ; |
---|
98 | widget_control, sliderid, set_value = ind-index1+1 ; on bouge le slider |
---|
99 | ; |
---|
100 | window, /free, /pixmap, xsize=xsize, ysize=ysize |
---|
101 | date = jul2date(calendar[ind]) |
---|
102 | xxx2ps, /noerase, date1 = date, date2 = date |
---|
103 | ; |
---|
104 | image = tvrd(true = depth GT 8) |
---|
105 | ; |
---|
106 | if depth gt 8 then $ |
---|
107 | image = color_quan(image, 1, aaa, bbb, ccc, colors=256, translation = translation) ; |
---|
108 | ; |
---|
109 | write_gif,animdir+nomfic,image,red, green, blue, /multiple |
---|
110 | wdelete, !d.window |
---|
111 | ENDFOR |
---|
112 | ; on met une derniere image blanche |
---|
113 | window, /free, /pixmap, xsize=xsize, ysize=ysize |
---|
114 | reinitplt |
---|
115 | plot, [0], [0], /nodata |
---|
116 | image = tvrd(true = depth GT 8) |
---|
117 | ; |
---|
118 | if depth gt 8 then $ |
---|
119 | image = color_quan(image, 1, aaa, bbb, ccc, colors=256, translation = translation) ; |
---|
120 | ; |
---|
121 | write_gif,animdir+nomfic,image,red, green, blue, /multiple |
---|
122 | wdelete, !d.window |
---|
123 | ; fermeture du fichier |
---|
124 | write_gif,animdir+nomfic,/close |
---|
125 | widget_control, base, /destroy |
---|
126 | ; rebascule en mode "normal" |
---|
127 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
128 | ; |
---|
129 | wset, current_window |
---|
130 | |
---|
131 | ; si on est sous x on essaie de lancer xanim... |
---|
132 | |
---|
133 | if thisOS NE 'MAC' AND thisOS NE 'WIN' then begin |
---|
134 | spawn, 'which xanim',result |
---|
135 | if strpos(result[0],'xanim') EQ strlen(result[0])-5 then spawn, 'xanim '+animdir+nomfic+' &' |
---|
136 | endif |
---|
137 | ; |
---|
138 | |
---|
139 | return |
---|
140 | end |
---|
141 | ;---------------------------------------------------------------- |
---|
142 | PRO xcreateanim, parent |
---|
143 | @common |
---|
144 | ; |
---|
145 | widget_control, parent, get_uvalue = top_uvalue |
---|
146 | ; |
---|
147 | ; on va s''assurer que toutes les procedures de sont pas pltt |
---|
148 | ; |
---|
149 | procedures = extractatt(top_uvalue, 'nameprocedures') |
---|
150 | if total(procedures EQ 'pltt') NE 0 then begin |
---|
151 | nothing = report('Certains des plots ont un axe se rapportant au temps. !C Animation impossible!', /error) |
---|
152 | return |
---|
153 | ENDIF |
---|
154 | ; |
---|
155 | ; on va s''assurer que toutes les figures ont le meme calendrier |
---|
156 | ; |
---|
157 | filelist = extractatt(top_uvalue, 'filelist') |
---|
158 | filenames = (extractatt(top_uvalue, 'varinfo'))[0, *] |
---|
159 | filenames = reform(filenames) |
---|
160 | filenames = filenames[uniq(filenames, sort(filenames))] |
---|
161 | if strtrim(filenames[0], 1) EQ '' then filenames = filenames[1:n_elements(filenames)-1] |
---|
162 | indexfile = (where(filelist EQ filenames[0]))[0] |
---|
163 | calendar = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).time_counter |
---|
164 | if n_elements(filenames) GT 1 then begin |
---|
165 | for i = 1, n_elements(filenames)-1 do begin |
---|
166 | indexfilebis = (where(filelist EQ filenames[i]))[0] |
---|
167 | calendarbis = (*(extractatt(top_uvalue, 'fileparameters'))[indexfilebis]).time_counter |
---|
168 | if n_elements(calendarbis) NE n_elements(calendar) then begin |
---|
169 | nothing = report('Les diffrents plots n''utilisent pas le meme calendrier. !C Animation impossible!', /error) |
---|
170 | return |
---|
171 | ENDIF |
---|
172 | if total(calendar NE calendarbis) NE 0 then begin |
---|
173 | nothing = report('Les diffrents plots n''utilisent pas le meme calendrier. !C Animation impossible!', /error) |
---|
174 | return |
---|
175 | endif |
---|
176 | endfor |
---|
177 | endif |
---|
178 | ; |
---|
179 | ; c''est possible de faire une animation |
---|
180 | ; |
---|
181 | base = widget_base(/column, title = 'animation creation', uvalue = {parent:parent, indexfile:indexfile}) |
---|
182 | rien = widget_label(base, value = 'animation name') |
---|
183 | rien = widget_text(base,value='anim_idl.gif', uname='Filename', /editable) |
---|
184 | rien = widget_label(base, value = 'animation directory') |
---|
185 | if n_elements(animdir) EQ 0 then cd, current = animdir |
---|
186 | rien = widget_text(base,value=animdir, uname='directorie', /editable) |
---|
187 | rien = widget_label(base, value = 'starting date') |
---|
188 | rien = cw_calendar(base, calendar, uname = 'debut', uvalue = {name:'calendar'}, /frame) |
---|
189 | rien = widget_label(base, value = 'ending date') |
---|
190 | rien = cw_calendar(base, calendar, calendar[n_elements(calendar)-1] $ |
---|
191 | , uname = 'fin', uvalue = {name:'calendar'}, /frame) |
---|
192 | rien = widget_button(base,value='OK', uvalue = 'ok') |
---|
193 | rien = widget_button(base,value='Cancel', uvalue = 'cancel') |
---|
194 | ; |
---|
195 | widget_control,base,/realize |
---|
196 | xmanager,'xcreateanim', base, /no_block |
---|
197 | |
---|
198 | return |
---|
199 | end |
---|