j_farray â 2D Floating-Point Grid Container & Bilinear Interpolation Library
Overview & Purpose in the OMG Architecture
j_farray (code/subr/j_farray.c, code/subr/j_farray.h), written by John E. Hughes Clarke in August 1998, provides a lightweight, self-contained C data structure (farray) and accessor API for allocating, indexing, and bilinearly interpolating 2D floating-point grids in memory.
Throughout the OMG water-column raytracing (j_watercolumn, jb_watercolumn), acoustic modeling, and gridding subsystems, algorithms frequently need temporary 2D lookup tables parameterized by real-world physical coordinates (such as depth vs. depression angle, or range vs. two-way travel time) without the full disk-header overhead of a 1024-byte JHC_header. j_farray encapsulates the grid dimensions, physical origin (xmin, ymin), step sizes (xstep, ystep), and heap buffer pointer into a single struct with bounds-checked integer and continuous real-coordinate accessors.
Key Data Structures (code/subr/j_farray.h)
farray
typedef struct {
int x, y; /* Number of columns (x) and rows (y) */
int alloced; /* 1 if data buffer is allocated, 0 otherwise */
float xmin, ymin; /* Physical coordinate origin at index (0, 0) */
float xstep, ystep; /* Physical step size per grid cell in X and Y */
float *data; /* Pointer to row-major float array (x * y elements) */
} farray;
Public Functions & Signatures
Lifecycle Management
int jFA_init(farray *fa, int x, int y, float xmin, float ymin, float xstep, float ystep)Initializes thefarraymetadata fields (x,y,xmin,ymin,xstep,ystep) and allocatesx * y * sizeof(float)bytes on the heap. Setsfa->alloced = 1and returns1on success, or setsfa->alloced = 0and returns0ifmallocfails.void jFA_free(farray *fa)Freesfa->dataand resetsfa->alloced = 0.
Coordinate Conversion
int jFA_ixy_to_rxy(farray *fa, int ix, int iy, float *rx, float *ry)Converts discrete integer grid indices(ix, iy)into continuous physical coordinates: \(\text{rx} = \text{xmin} + \text{ix} \cdot \text{xstep}, \quad \text{ry} = \text{ymin} + \text{iy} \cdot \text{ystep}\) Returns1if(ix, iy)lies within[0..x-1, 0..y-1], or0if out of bounds.int jFA_rxy_to_ixy(farray *fa, int *ix, int *iy, float rx, float ry)Converts continuous physical coordinates(rx, ry)into truncated integer cell indices(*ix, *iy)and returns1if within the array bounds, or0if outside.
Cell Access & Interpolation
float jFA_get_ivalue(farray *fa, int x, int y)Returns the floating-point value stored at integer grid cell(x, y)(*(fa->data + y * fa->x + x)). Returns-1.0iffais unallocated, or0.0if(x, y)is outside the valid grid dimensions.int jFA_set_ivalue(farray *fa, int x, int y, float value)Writesvalueinto grid cell(x, y). Returns1on success,-1if unallocated, or0if out of bounds.float jFA_get_rvalue(farray *fa, float rx, float ry)Retrieves an interpolated value at continuous physical coordinates(rx, ry):- Locates the top-left cell index
(xoffset, yoffset)viajFA_rxy_to_ixy(). - Fetches the four surrounding cell values (
tl,tr,bl,br) viajFA_get_ivalue(). - If all four corner values are non-zero, performs 2D bilinear interpolation; otherwise returns
0.0.
- Locates the top-left cell index
How It Fits Into the OMG Architecture
j_farray is included directly by j_watercolumn.h and jb_watercolumn.c, making it available to every tool in the OMG suite that performs sound velocity profile (SVP) processing, raytracing, or water-column uncertainty analysis.