;+ ; NAME: HIMCUT ; PURPOSE: ; Like 'IMCUT', cut out a subregion from an image, and update FITS header. ; ; Very similar to HEXTRACT, but with different arguments ; ; INPUTS: ; KEYWORDS: ; /center use center ; /method2 different coords computation, good for getting out odd-sized ; boxes. See code ; OUTPUTS: ; ; HISTORY: ; Began 2007-04-23 15:06:10 by Marshall Perrin ;- pro himcut,oldim,oldhd, newim,newhd, imsize, xc,yc,$ center=center,method2=method2 ;-------- figure out center of subimage ----------- sz = size(oldim) if n_elements(imsize) eq 0 then begin nx = 256 ny = 256 message, 'imsize not set, using default of 256', /info endif else if n_elements(imsize) eq 1 then begin nx = imsize ny = imsize endif else if n_elements(imsize) eq 2 then begin nx = imsize[0] ny = imsize[1] endif else begin message, 'imsize must contain 1 or 2 elements!', /info stop endelse if keyword_set(center) then begin xc=center[0] yc=center[1] endif ; center on peak pixel if desired if keyword_set(peak) then $ whereismax, image, xc, yc, /silent if n_elements(xc) eq 0 then begin message, 'x-position not set, choosing midpoint', /info xc = sz(1)/2 endif if n_elements(yc) eq 0 then begin message, 'y-position not set, choosing midpoint', /info yc = sz(2)/2 endif ;-------- figure out corners of subimage ----------- dx = fix(nx/2) dy = fix(ny/2) x0 = round(xc) - dx > 0 x1 = round(xc) + dx < (sz(1)-1) y0 = round(yc) - dy > 0 y1 = round(yc) + dy < (sz(2)-1) if not(odd(nx)) then x1 = x1-1 if not(odd(ny)) then y1 = y1 -1 ; revised 2006-04-28 by Marshall ; to better handle getting out odd arrays ; centered on a half pixel ; TODO invoke automatically where appropriate? if keyword_set(method2) then begin dx = (nx/2.) dy = (ny/2.) x0 = round(xc - dx) > 0 x1 = round(xc + dx-1) < (sz(1)-1) y0 = round(yc - dy) > 0 y1 = round(yc + dy-1) < (sz(2)-1) ;stop endif if not(keyword_set(silent)) then $ print, 'cutting = ', printcoo(x0, y0), ' to ', printcoo(x1, y1) ;-------- use HEXTRACT to do the real work ----------- hextract,oldim,oldhd,newim,newhd,x0,x1,y0,y1,silent=silent,errmsg=errmsg end