Monday, August 25, 2008

subplot for GrADS

function subplot(args)
*******************************************************
** Usage: run Subplot.gs mx my nw opt
** Creating an axes in the nw-th pane
** of a figure divided into an mx-by-my
** matrix of rectangular panes
** http://scriptdemo.blogspot.com
*******************************************************
mx=subwrd(args,1)
my=subwrd(args,2)
nw=subwrd(args,3)
opt=subwrd(args,4)
if (opt='')
opt=0
endif
* Portrait x=8.5, y=11 & LandScape x=11,y=8.5

if (opt=1)
say 'This function will create 'mx' by 'my' subplots with a layout of Portrait'
Xpage=8.5
Ypage=11.0
else
say 'This function will create 'mx' by 'my' subplots with a layout of Landscape'
Xpage=11.0
Ypage=8.5
endif

ML=0.25
MT=0.25
SX=(Xpage-2*ML)/mx
SY=(Ypage-2*MT)/my

nx=math_fmod(nw,mx)
ny=math_int(nw/mx)+1
if (nx=0)
nx=mx
ny=ny-1
endif

xmin=ML+(nx-1)*SX+0.02*SX
xmax=ML+(nx-1)*SX+0.98*SX
ymin=SY*my+MT-(ny-1)*SY-0.98*SY
ymax=SY*my+MT-(ny-1)*SY-0.02*SY
'set vpage 'xmin' 'xmax' 'ymin' 'ymax

No comments:

ShowCalendar