function xanim(args) if (args='') say "* xanim.gs" say "* A GrADS script for Xwindows animation" say "*" say "* Features:" say "* Uses double buffering for smooth animations " say "* Contour levels and colors remain fixed" say "* Contour/no-contour option" say "* User-specified delay or mouse-controlled animation" say "*" say "* Setup: You may pre-specify contour levels and/or colors using " say "* 'set clevs' and 'set ccols' before running this script. " say "* If contour levels and colors are not pre-specified, " say "* the default values from the first display of the " say "* animation will be used for the remaining displays." say "*" say "* Set the variable "colorbar" to point to your version of cbar." say "* i.e., change the line: colorbar = 'cbarn.gs'" say "*" say "* Usage: xanim [options] variable title" say "*" say "* Available options are:" say "* -contour Displays a shaded plot with contours overlaid (default)" say "* -grfill Display a shaded pixel plot" say "* -jpg printim jpg figure" say "* -levs use current levs and ccols (i.e., not default contouring" say "* levels and colors)" say "* -nocontour Displays only the shaded plot" say "* -notitle No title will be drawn" say "* -pause Allows mouse button control of animation:" say "* left=forward, right=backwards, middle=quit" say "* -repeat n Loops through images n+1 times " say "* -sec n Pauses n seconds after each frame" say "* -skip n Displays every n-th frame (1, n+1, 2n+1, ...)" say "* -script name Executes named script for each display (no title, no variable)" say "* -script2 name Executes named script for each display (with title and variable)" say "* -yflip Flips the order of the vertical axis." say "* -ylab word Draw ylab word." say "*" say "* Notes: 'variable' can be any GrADS expression as long as" say "* it does not contain blanks. e.g., (tmax-273)*1.8+32" say "*" say "* If 'title' is omitted, the 'variable' expression is used." say "*" say "* If the '-script name' option is used, then the 'variable' " say "* and 'title' arguments are ignored. " say "* " say "* Written by Wesley Ebisuzaki June 2001" say "* Comments and cosmetic adjustments added by J.M.Adams " say "* v1.0c" say "*" say "* v1.0c 2/2002 added grfill option (wne)" say "* v1.1 6/2009 added help page, jpg, scripts, yflip and ylab options (bjt)" return endif * Default settings contour = 1 jpg = 0 notitle = 0 pause = 0 sec = 0 repeat = 0 skip = 1 dbuff = 0 shade = 'shaded' script = '' script2 = '' yflip_on = 0 ylab_on = 0 colorbar = 'cbarn.gs' #colorbar = 'cbarb.gs' * Parse all the options i = 1 wrd = subwrd(args,i) while (substr(wrd,1,1) = '-') if (wrd = '-contour') contour = 1 endif if (wrd = '-nocontour') contour = 0 endif if (wrd = '-grfill') contour = 0 shade = 'grfill' endif if (wrd = '-jpg') jpg = 1 dbuff = 1 '!mkdir -p jpg' endif if (wrd = '-notitle') notitle = 1 endif if (wrd = '-levs') dbuff = 1 endif if (wrd = '-pause') pause = 1 sec = 0 endif if (wrd = '-repeat') i = i + 1 repeat = subwrd(args,i) endif if (wrd = '-sec') i = i + 1 sec = subwrd(args,i) endif if (wrd = '-skip') i = i + 1 skip = subwrd(args,i) endif if (wrd = '-script') i = i + 1 script = subwrd(args,i) notitle = 1 contour = 0 endif if (wrd = '-script2') * say I am in script2 i = i + 1 script2 = subwrd(args,i) endif if (wrd = '-yflip') yflip_on = 1 endif if (wrd = '-ylab') i = i + 1 ylab = subwrd(args,i) ylab_on = 1 endif i = i + 1 wrd = subwrd(args,i) endwhile * If scripts are not used, get the variable expression if (script = '') var = subwrd(args,i) i = i + 1 endif * Get the title which may contain more than one word * If no title is specified, it will be the variable expression title = '' while (subwrd(args,i) != '') title = title%' '%subwrd(args,i) i = i+1 endwhile if (title = '' & notitle = 0) title = var endif * Get the dimension environment 'q dim' diminfo = result line5 = sublin(diminfo,5) time1 = subwrd(line5,11) time2 = subwrd(line5,13) if (time2 = '') say 'The time dimension must be varying' exit 8 endif * Start plotting if (dbuff = 0) 'set dbuff on' endif qshade = 0 while (repeat >= 0) it = time1 while (it <= time2) 'set t 'it * Add display commands here 'set gxout ' shade 'set grads off' if (qshade = 1) 'set clevs 'lev 'set ccols 'color endif if (yflip_on = 1) 'set yflip on' endif if (script = '') 'd 'var r1 = subwrd(result,1) if (r1 != 'Cannot') 'run 'colorbar endif else 'run 'script endif if (script2 != '') * say script2 'run 'script2 endif if (ylab_on = 1) 'draw ylab 'ylab endif * Get the shaded contour levels and colors if not pre-specified if (qshade = 0) 'query shades' shdinfo = result r1 = subwrd(shdinfo,1) if (r1 != 'None') nlevs = subwrd(shdinfo,5) rec = sublin(shdinfo,2) color = subwrd(rec,1) lev = '' n = 2 while (n <= nlevs) rec = sublin(shdinfo,n+1) color = color%' '%subwrd(rec,1) lev = lev%' '%subwrd(rec,2) n = n + 1 endwhile qshade = 1 endif endif * Settings for contour overlay if (contour = 1 & qshade = 1) 'set gxout contour' 'set clevs 'lev 'set ccolor 15' 'set ccols 15' 'd 'var endif * Time stamp is added to the title 'q dim' rec = sublin(result,5) time = subwrd(rec,6) if (notitle = 0) 'draw title 'title' 'time endif if (jpg != 0) 'printim jpg/'var'.'it'.jpg x1024 y768' endif * Swap buffers and then pause or sleep if (dbuff = 0) 'swap' endif if (pause != 0) 'q pos' mousekey = subwrd(result,5) if (mousekey = 2) it = time2 repeat = 0 endif if (mousekey = 3) if (it < time1) it = time2+skip endif it = it-skip-skip endif else if (sec != 0) '!sleep ' sec endif endif * Swap buffers and then pause or sleep if (dbuff != 0) 'clear' endif * Move to next time step it = it+skip endwhile repeat = repeat - 1 if (repeat >= 0 & sec != 0) '!sleep ' sec '!sleep ' sec endif endwhile * Clean up 'set t 'time1' 'time2 if (dbuff = 0) 'set dbuff off' endif