FUNCTION grid_in_cube, grid_info, cube_center, cube_length, cube_size, noresolution=nores ; determine whether the specified grid is at least partially in the ; cube ; ; return for each grid 1 if it is and 0 if it is not in cube ; min left edge and scaling if N_elements(cube_size) le 0 then cube_size=256 if N_elements(cube_length) le 0 then cube_length=1.D if N_elements(cube_center) le 0 then cube_center = fltarr(3)+0.5 min_left = [cube_center(0),cube_center(1),cube_center(2)]-cube_length/2. > 0. max_right = [cube_center(0),cube_center(1),cube_center(2)]+cube_length/2. < 1. scale_up = min(1./(max_right-min_left)) b = 1.D*cube_length/DOUBLE(cube_size) if N_elements(nores) ne 0 then b = 0. print, 'b:',b index_range = grid_info.End_index-grid_info.Start_index+1 delta_distance = (grid_info.Right_edge - grid_info.Left_edge)/(index_range) ; suff_res = delta_distance[0,*] suff_res = where(delta_distance[0,*] ge b) ; print, suff_res print, N_elements(suff_res), ' grids have sufficient resolution for cube' if suff_res[0] lt 0 THEN BEGIN grid_in_cube = grid_info[0] RETURN, grid_in_cube ENDIF new_i = grid_info[suff_res] Left_edge = new_i.Left_edge Right_edge = new_i.Right_edge ; print, LEFT_EDGE help = ROUND(Left_Edge) < 0 help = ((Right_edge[0,*] gt min_left[0] ) and $ (Right_edge[1,*] gt min_left[1] ) and $ (Right_edge[2,*] gt min_left[2] ) and $ (Left_edge[0,*] lt max_right[0]) and $ (Left_edge[1,*] lt max_right[1]) and $ (Left_edge[2,*] lt max_right[2]) ) print, 'there are ', total(help),' grids of sufficient resolution at least partially in cube' if total(help) ge 1 then grid_in = new_i(where(help gt 0)) return, grid_in END