func check_rect(x1,x2,y1,y2,z1)
 ;checks for legal rectangular subarea
 nx = dimen(z1,0)
 ny = dimen(z1,1)
 if x1 eq 0 and x2 eq 0 and y1 eq 0 and y2 eq 0 then {
   xmmessage,'rectangle is'+#nl+'all zeroes'+#nl+'assuming full image', $f7, 'red'
   return, 0 }
 
 if x1 lt 0 or y1 lt 0 or x2 ge nx or y2 ge ny then {
   xmmessage,'out of range'+#nl+'rectangle'+#nl+'try again', $f7, 'red'
   return, -1 }
 
 if y2 eq 0 then y2 = ny-1
 if x2 eq 0 then x2 = nx-1

 return, 1
 endfunc
 ;===============================================================================
