$ show GenericMappingTools/gmt
Generic Mapping Tools (GMT) is a mature, open-source collection of approximately 100 command-line tools for processing geographic and Cartesian data and producing high-quality PostScript illustrations, maps, and animations. The system is architected as a modular C library with a central dispatcher executable (`gmt`) that loads and runs individual modules. It supports both a classic mode (direct module calls) and a modern mode (`gmt begin/end`, `gmt subplot`) that manages sessions, figures, and panels. Key entry points include the `gmt` command, the C API (`GMT_Create_Session`, `GMT_Call_Module`), and shell completion scripts. Data flows involve reading grid, table, image, and color palette table (CPT) data from local files or remote servers (via `@` prefix), processing through modules (e.g., `grdimage`, `psxy`, `grdmath`, `grdfilter`), and outputting PostScript, grids, or other formats. External dependencies include netCDF, GDAL, FFTW, PCRE/POSIX regex, PROJ, GSHHG coastlines, and DCW country polygons. The codebase exhibits high craftsmanship with systematic option parsing, a well-defined API, extensive test coverage, and reusable infrastructure components.
The LLM identified 6 files worth highlighting for reuse:
Provides a reusable pattern for translating long command-line options to short options via a static dictionary array (`GMT_KEYWORD_DICTIONARY`). Each entry maps a long option string to a short option character, with optional directives and modifiers. This pattern is used uniformly across all GMT modules and can be extracted for any CLI tool needing long-option support.
Implements portable math utilities including robust floating-point comparison (`gmt_M_is_finite`, `gmt_M_is_float_equal`), safe trigonometric functions, and statistical helpers. These functions are self-contained and can be reused in any C project requiring reliable numeric operations across platforms.
Provides a cross-platform signal handler for SIGINT, SIGSEGV, etc., with optional backtrace printing on crash. Uses platform-specific APIs (execinfo on Linux/macOS, Windows structured exception handling) and can be extracted as a reusable signal handling module for any C application.
Defines the PostScript Light (PSL) library, a self-contained set of functions for generating PostScript output. Includes macros for page setup, line drawing, text placement, color handling, and transparency. The library is independent of GMT's data structures and can be reused in any project needing programmatic PostScript generation.
Implements a simple static hash table with fixed maximum depth (`GMT_HASH_MAXDEPTH = 16`) for keyword lookups. Provides `gmt_hash_lookup` and `gmt_hash_add` functions. The implementation is minimal, self-contained, and can be reused in any C project needing a lightweight hash table for string-to-integer mapping.
Implements read/write support for the AGC (Atlantic Geoscience Center) binary grid format, a legacy scientific data format. Uses block-based I/O (40x40 tiles), NaN handling (0.0 mapped to NaN), and gridline registration. The code follows a clean pattern of open/read/write/close and can serve as a template for implementing custom binary grid I/O in other projects.