 
\can mod verify
! portraitNxN.jnl
! 17/06/99 Rodrigo Caballero rca@gfy.ku.dk
 
! Description: Set up an arbitrary number of evenly-spaced viewports
 
! Usage: GO portraitNxN #columns #rows [xmag] [ymag] [aspect]
!  where:
!  #columns: number of viewports accross page
!  #rows: number of viewports down page
!  xmag: horizontal magnification of viewports (as percentage; default=0)
!  ymag: vertical magnification of viewports (as percentage; default=0)
!  aspect: aspect ratio of page (default A4 paper)
 
! Example:
!  GO portraitNxN 5 8 40 50
!  will set up 40 viewports (5 accross, 8 down) magnified by 
!  40% horizontally and 50% vertically. The viewports are named
!  using consecutive numbers starting with "1" for upper-left to
!  "40" for lower-right.

! Notes:
! - The viewports are named using consecutive numbers. This is useful
!   for making a series of consecutive plots; for instance:
!   repeat/l=1:40 (set viewport `l`; shade field) 
!   will plot 40 consecutive snapshots of variable "field", one in each 
!   viewport.
! - The script is set up to fill a European A4 page; American users  should
!   uncoment the relevant line below. 

! check that parameters are OK 
query/ignore $1%<Use: GO portraitNxN #columns #rows [xmag] [ymag] [aspect]%
query/ignore $2%<Use: GO portraitNxN #columns #rows [xmag] [ymag] [aspect]%

let/quiet width=`(1+$3"0"/100)/$1`  
let/quiet height=`(1+$4"0"/100)/$2`

define axis/x=`width/2`:`1-width/2`/npoint=$1 xview
define axis/y=`height/2`:`1-height/2`/npoint=$2 yview
define grid/x=xview/y=yview gview
let/quiet xv=x[g=gview]
let/quiet yv=y[g=gview]
let/quiet x1=xv-width/2  
let/quiet y1=yv-height/2 
let/quiet x2=xv+width/2  
let/quiet y2=yv+height/2 
let/quiet xx1=if x1 ge 0 then x1 else 0
let/quiet yy1=if y1 ge 0 then y1 else 0
let/quiet xx2=if x2 le 1 then x2 else 1
let/quiet yy2=if y2 le 1 then y2 else 1  

ppl/reset
set win/as=$5"`296/210`" ! A4 paper        
!set win/as=$5"`11/8.5`" ! 8 1/2 x 11  paper (uncomment as suitable)

define region/default save
can reg

repeat/j=$2:1:-1 (repeat/i=1:$1 define view/xlim=`xx1`,`xx2`/ylim=`yy1`,`yy2` `i+($2-j)*$1`)

set region save
set mod/last verify
