The i-th patch is denoted by the scalar counter ipatch. Typical patch extraction begins by taking ipatch, a fortran linear index, and converting it to a multidimensional subscript jj each component of which is less than npatch. The patches cover all edges and corners of the given data plane (actually the hypervolume) even where nwall/npatch is not an integer, even for axes whose length is not an integer number of the patch length. Where there are noninteger ratios, the spacing of patches is slightly uneven, but we'll see later that it is easy to reassemble seamlessly the full plane from the patches, so the unevenness does not matter. You might wish to review the utilities line2cart and cart2line which convert between multidimensional array subscripts and the linear memory subscript before looking at the patch extraction-putback code: patchextract patches The cartesian vector jj points to the beginning of a patch, where on the wall the (1,1,..) coordinate of the patch lies. Obviously this begins at the beginning edge of the wall. Then we pick jj so that the last patch on any axis has its last point exactly abutting the end of the axis. The formula for doing this would divide by zero for a wall with only one patch on it. This case arises legitimately where an axis has length one. Thus we handle the case npatch=1 by abutting the patch to the beginning of the wall and forgetting about its end. As in any code mixing integers with floats, to guard against having a floating-point number, say 99.9999, rounding down to 99 instead of up to 100, the rule is to always add .5 to a floating point number the moment before converting it to an integer. Now we are ready to sweep a window to or from the wall. The number of points in a window is size(wind) or equivalently product(nwind). Figure shows an example with five nonoverlapping patches on the 1-axis and many overlapping patches on the 2-axis.
Figure 2 A plane of identical values after patches have been cut and then added back. Results are shown for nwall=(100,30), nwind=(17,6), npatch=(5,11). For these parameters, there is gapping on the horizontal axis and overlap on the depth axis.