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