* panim.gs * A GrADS script for creating sequence of png files for animation * * Features: * Contour levels and colors remain fixed * Contour/no-contour option * User-specified delay or mouse-controlled animation * * Setup: You may pre-specify contour levels and/or colors using * 'set clevs' and 'set ccols' before running this script. * If contour levels and colors are not pre-specified, * the default values from the first display of the * animation will be used for the remaining displays. * * Set the variable "colorbar" to point to your version of cbar. * i.e., change the line: colorbar = 'cbarn.gs' * * Usage: panim [options] variable title * * Available options are: * -contour Displays a shaded plot with contours overlaid (default) * -output name sets the name of the output files to nameN.png * instead of the default animN.png N = 0 .. * -nocontour Displays only the shaded plot * -grfill Display a shaded pixel plot * -notitle No title will be drawn * -levs use current levs and ccols (i.e., not default contouring * levels and colors) * -skip n Displays every n-th frame (1, n+1, 2n+1, ...) * -maxframe n sets maximum number of frames to n rather than default * -size x y sets size to x y * -script name Executes named script for each display * * Notes: 'variable' can be any GrADS expression as long as * it does not contain blanks. e.g., (tmax-273)*1.8+32 * * If 'title' is omitted, the 'variable' expression is used. * * If the '-script name' option is used, then the 'variable' * and 'title' arguments are ignored. * * Based on xanim 1.0c Wesley Ebisuzaki June 2001 * Comments and cosmetic adjustments added by J.M.Adams * * v0.8 12/2002 * v0.81 2/2003 more javascript friendly function main(args) * Default settings contour = 1 notitle = 0 skip = 1 shade = 'shaded' script = '' colorbar = 'cbarn.gs' colorbar = 'cbarb.gs' output='anim' xsize=640 ysize=480 * change to bigger number for personal machines maxframe=20 * 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 = '-output') i = i + 1 output = subwrd(args,i) endif if (wrd = '-maxframe') i = i + 1 maxframe = subwrd(args,i) endif if (wrd = '-size') i = i + 1 xsize = subwrd(args,i) i = i + 1 ysize = subwrd(args,i) endif if (wrd = '-notitle') notitle = 1 endif if (wrd = '-skip') i = i + 1 skip = 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 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 qshade = 0 frame=0 it = time1 while (it <= time2 & frame <= maxframe) 'set t 'it * Add display commands here 'set gxout ' shade 'set grads off' if (qshade = 1) 'set clevs 'lev 'set ccols 'color endif if (script = '') 'd 'var r1 = subwrd(result,1) if (r1 != 'Cannot') 'run 'colorbar endif else 'run 'script 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 * make png file 'printim ' output frame '.png x'xsize ' y'ysize 'c' frame=frame+1 * Move to next time step it = it+skip endwhile * Clean up 'set t 'time1' 'time2