! err67_regridding_dyn.jnl 
!  6/2011
! See ticket 1862
! Create three variables. Regrid one to the grid
! of the other two which share an X axis and
! have different Y axes; one coarser than the other.
! The regridding and modulo operatinons incorrectly
! re-use intermediate results.

! Create test datasets to use
use coads_climatology
let filled = MISSING(sst[L=1], 0)
save/file=cc.nc/clobber filled[x=-179:179]

! Define an x axis over a different x range from above,
! and two y axes, same y range but different resoloutions.

define axis/x=0:356.25:3.75/units=deg lon
define axis/y=-90:90/npoints=72/units=deg lat1
define axis/y=-90:90/npoints=92/units=deg lat2

save/clobber/file=c1.nc filled[gx=lon,gy=lat1]
can mem
save/clobber/file=c2.nc filled[gx=lon,gy=lat2]

can dat/all; can mem; can var/all;

! Now regrid the data coming in on x=-179:179 to the other grids
use c1
use c2
use cc

set view upper
shade filled[d=3,gxy=filled[d=1]]
list/x=330/y=40:90 filled[d=3,gxy=filled[d=1]]

! The bug has data wrapped around incorrectly
set view lower
shade  filled[d=3,gxy=filled[d=2]]
list/x=330/y=40:90 filled[d=3,gxy=filled[d=2]]
