j_dtm β Weighted Digital Terrain Model (DTM) Bundle & Header Management Library
Overview & Purpose in the OMG Architecture
j_dtm (code/subr/j_dtm.c, code/subr/j_dtm.h), authored by John E. Hughes Clarke (September 1989 / September 1998), manages the multi-file OMG Weighted Digital Terrain Model (jDTMbundle) format used during incremental multibeam bathymetric gridding (weigh_grid).
When gridding multibeam soundings into a floating-point Digital Terrain Model (.r4), OMGβs weighted gridding engine maintains three parallel raster files:
<prefix>.r4: The normalized depth grid (z).<prefix>.r4_weights: The accumulated sum of spatial/beam weights (sum_w) at each grid node.<prefix>.r4_weight_depth: The accumulated sum of weighted depths (sum_wd = sum(w * z)) at each grid node.
To ensure that subsequent gridding runs appending additional survey lines to an existing DTM use identical gridding parameters, j_dtm packs all gridding metadata, filter parameters, and per-beam weight/mask tables into the unused 768-byte rgb_cmap color-table blocks across the three JHC_header headers (768 * 3 = 2304 bytes total).
Key Data Structures, Constants & Macros
Input Format & Weighting Model Constants (code/subr/j_dtm.h)
- Input Data Formats:
URI_SEABEAM(1),LOLADE_ASCII(2),OMG_EM12(3),OMG_HDCS(4),OMG_MR1(5),OMG_AR(6). - Gridding Methods (
method):SHOALBIAS_METHOD(0): Shoal-biased binning.PURE_WT_FILTER_METHOD(1): Pure distance-weighted interpolation.PERC_WT_FILTER_METHOD(2): Depth-percentage scaled distance weighting.BEAM_WT_FILTER_METHOD(3): True 3D acoustic beam footprint weighting.
- Weighting Models (
wtmodel):UNSPEC(0),LINEAR(1),BUTTER(2β Butterworth filter),RECIP(3β reciprocal distance),BEAMWIDTH(4). - Footprint Asymmetry (
along_across_asym):FT_ALONG(1),FT_ACROSS(2),FT_ASYM(3).
Core Struct: jDTMbundle
Encapsulates the file handles, memory pointers, raster headers, and serialized gridding configuration of a weighted DTM:
- File Pointers & Data Buffers:
FILE *r4d_fp,*r4w_fp,*r4wd_fp,*r4ww_fp: File streams for.r4,.r4_weights,.r4_weight_depth, and future variance.r4_ww.float *z,*sum_w,*sum_wd,*sum_ww: In-memory 2D float arrays.int opened,usenmap: File open state andmmapusage flag.JHC_header r4head,r4whead,r4wdhead,r4wwhead: Individual 1024-byte OMG raster headers.
- Gridding & Filter Parameters:
unsigned char usetide,toolType,input_dataformat,method,wtmodel,along_across_asym.float beamwidth: Transducer beamwidth in degrees.float power,lambda,cutoff: Absolute spatial filter decay power, wavelength, and cutoff radius.float perc_lambda,perc_cutoff: Depth-percentage scaled filter wavelength and cutoff radius.float zmin,zmax,zshift,pixshift_X,pixshift_Y: Depth clipping bounds and datum/pixel shifts.
- Per-Beam Weighting & Mask Tables:
unsigned char beam_mask[256]: Per-beam accept/reject mask stored in the 3rd headerβsrgb_cmap.unsigned char cbeam_weight[256]: Compact 8-bit beam weights (in units of0.005, representing0.0to1.0across 200 levels) stored in the 2nd headerβsrgb_cmap.float beam_weight[256]: Expanded floating-point beam weights (cbeam_weight[i] / 200.0).
Public Functions & Signatures
-
int jDTM_open_and_loadhead(char *prefix, jDTMbundle *jdtm)Opens<prefix>.r4,<prefix>.r4_weights, and<prefix>.r4_weight_depthin read-update ("r+") mode, reads their threeJHC_headerstructures viaread_JHC_header(), concatenates their three 768-bytergb_cmaparrays into a 2304-bytecomboheadbuffer, and unpacks all gridding parameters,cbeam_weight(expanding tobeam_weight), andbeam_maskusing endian-safeget_swapped_char()andget_swapped_float(). Returns1on success,-1if.r4cannot be opened,0if weight files are missing, or-2on header read error. -
int jDTM_dumphead(jDTMbundle *jdtm)Serializes all gridding parameters, quantizesbeam_weight[] * 200.0intocbeam_weight[], packsbeam_mask[]into the 2304-bytecomboheadbuffer usingput_swapped_char()andput_swapped_float(), distributes the three 768-byte segments back intor4head.rgb_cmap,r4whead.rgb_cmap, andr4wdhead.rgb_cmap, and writes all three headers back to disk viawrite_JHC_header(). -
int jDTM_closefiles(jDTMbundle *jdtm)Closesr4d_fp,r4w_fp, andr4wd_fp, and resetsjdtm->opened = 0.
How It Fits Into the OMG Architecture
j_dtm is the persistence layer for weigh_grid and related DTM manipulation utilities in code/omg/ and code/JV/. By embedding gridding provenance directly inside the JHC_header colormap space of the .r4, .r4_weights, and .r4_weight_depth files, it guarantees consistent multi-pass gridding without requiring an external sidecar parameter file.