pro spd_ui_xyclip,onePtr,twoPtr,zPtr,range,scale,fail=fail,transposez=transposez,yaxis=yaxis,mirrorptr=mirrorptr
compile_opt idl2
fail = 1
out1 = ptrarr(n_elements(onePtr))
out2 = ptrarr(n_elements(twoPtr))
outz = ptrarr(n_elements(zptr))
if keyword_set(mirrorptr) then begin
outmirror = ptrarr(n_elements(mirrorptr))
endif
for i = 0,n_elements(onePtr)-1 do begin
if ~ptr_valid(onePtr[i]) || $
~ptr_valid(twoPtr[i]) then continue
one = *onePtr[i]
two = *twoPtr[i]
if keyword_set(mirrorptr) && $
ptr_valid(mirrorptr[i]) then begin
mirror = *mirrorptr[i]
endif else begin
mirror = 0
endelse
if ptr_valid(zPtr[i]) then z = *zptr[i]
if scale eq 1 || scale eq 2 then begin
if keyword_set(yaxis) && ~ptr_valid(zPtr[i]) then begin
idx = where(one lt 0,c)
if c ne 0 then begin
one[idx] = !VALUES.D_NAN
endif
if keyword_set(mirror) then begin
idx = where(mirror lt 0,c)
if c ne 0 then begin
mirror[idx] = !VALUES.D_NAN
endif
endif
endif else begin
idx = where(one gt 0,c)
if c eq 0 then continue
if ptr_valid(zPtr[i]) then begin
minidx = min(idx)-1
if minidx ge 0 then begin
idx = [minidx,idx]
endif
maxidx = max(idx)+1
if maxidx lt n_elements(one) then begin
idx = [idx,maxidx]
endif
one = one[idx]
if transposez then begin
z = z[*,idx]
endif else begin
z = z[idx,*]
endelse
endif else begin
one = one[idx]
two = two[idx]
if keyword_set(mirror) then mirror=mirror[idx]
endelse
endelse
if scale eq 1 then one = alog10(one)
if scale eq 2 then one = alog(one)
if keyword_set(mirror) && keyword_set(yaxis) then begin
if scale eq 1 then mirror = alog10(mirror)
if scale eq 2 then mirror = alog(mirror)
endif
endif
if keyword_set(yaxis) && ~ptr_valid(zPtr[i]) then begin
idx = where(one lt range[0] or one gt range[1],c)
if c ne 0 then begin
one[idx] = !VALUES.D_NAN
endif
if keyword_set(mirror) then begin
idx = where(mirror lt range[0] or mirror gt range[1],c)
if c ne 0 then begin
mirror[idx] = !VALUES.D_NAN
endif
endif
endif else begin
idx = where(one ge range[0] and one le range[1],c)
if c eq 0 then begin
tmp = min(abs(one - range[0]),idx1)
tmp = min(abs(one - range[1]),idx2)
if idx1 eq idx2 then begin
idx = [idx1]
endif else begin
idx = [idx1,idx2]
endelse
endif
if ptr_valid(zPtr[i]) then begin
minidx = min(idx)-1
if minidx ge 0 then begin
idx = [minidx,idx]
endif
maxidx = max(idx)+1
if maxidx lt n_elements(one) then begin
idx = [idx,maxidx]
endif
one = one[idx]
if transposez then begin
z = z[*,idx]
endif else begin
z = z[idx,*]
endelse
endif else begin
one = one[idx]
two = two[idx]
if keyword_set(mirror) then mirror = mirror[idx]
endelse
endelse
out1[i] = ptr_new(one)
out2[i] = ptr_new(two)
if ptr_valid(zPtr[i]) then outz[i] = ptr_new(z)
if keyword_set(mirror) then outmirror[i] = ptr_new(mirror)
endfor
ptr_free,onePtr
ptr_free,twoPtr
onePtr = out1
twoPtr = out2
zPtr = outz
if keyword_set(outmirror) then mirrorptr = outmirror
fail = 0
return
end