Skip to content

Commit 4d4fdff

Browse files
authored
Merge pull request #10 from koldunovn/feature/add-grib
Feature/add grib
2 parents dec7039 + a29c584 commit 4d4fdff

File tree

10 files changed

+2199
-70
lines changed

10 files changed

+2199
-70
lines changed

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,39 @@ USHOW_LIBS += $(ZARR_LIBS)
115115
UTERM_LIBS += $(ZARR_LIBS)
116116
endif
117117

118+
# GRIB support (optional) - build with: make WITH_GRIB=1
119+
# Requires: eccodes (brew install eccodes on macOS)
120+
ifdef WITH_GRIB
121+
GRIB_PKG_CFLAGS := $(shell pkg-config --cflags eccodes 2>/dev/null)
122+
GRIB_PKG_LIBS := $(shell pkg-config --libs eccodes 2>/dev/null)
123+
124+
ifneq ($(strip $(GRIB_PKG_CFLAGS)$(GRIB_PKG_LIBS)),)
125+
GRIB_CFLAGS := -DHAVE_GRIB $(GRIB_PKG_CFLAGS)
126+
GRIB_LIBS := $(GRIB_PKG_LIBS)
127+
else
128+
# DKRZ Levante spack path (eccodes uses lib64)
129+
DKRZ_ECCODES := /sw/spack-levante/eccodes-2.44.0-hsksp4
130+
131+
ifneq ($(wildcard $(DKRZ_ECCODES)/include/eccodes.h),)
132+
GRIB_PREFIX ?= $(DKRZ_ECCODES)
133+
GRIB_LIBDIR := $(GRIB_PREFIX)/lib64
134+
GRIB_RPATH := -Wl,-rpath,$(GRIB_LIBDIR)
135+
else
136+
GRIB_PREFIX ?= $(shell brew --prefix eccodes 2>/dev/null || echo "/usr/local")
137+
GRIB_LIBDIR := $(GRIB_PREFIX)/lib
138+
GRIB_RPATH :=
139+
endif
140+
141+
GRIB_CFLAGS := -DHAVE_GRIB -I$(GRIB_PREFIX)/include
142+
GRIB_LIBS := -L$(GRIB_LIBDIR) -leccodes $(GRIB_RPATH)
143+
endif
144+
145+
BASE_CFLAGS += $(GRIB_CFLAGS)
146+
X11_FULL_CFLAGS += $(GRIB_CFLAGS)
147+
USHOW_LIBS += $(GRIB_LIBS)
148+
UTERM_LIBS += $(GRIB_LIBS)
149+
endif
150+
118151
# Directories
119152
SRCDIR = src
120153
OBJDIR = obj
@@ -146,6 +179,11 @@ USHOW_SRCS += $(SRCDIR)/cJSON/cJSON.c
146179
UTERM_SRCS += $(SRCDIR)/cJSON/cJSON.c
147180
endif
148181

182+
# Add grib sources if enabled
183+
ifdef WITH_GRIB
184+
COMMON_SRCS += $(SRCDIR)/file_grib.c
185+
endif
186+
149187
USHOW_OBJS = $(USHOW_SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
150188
UTERM_OBJS = $(UTERM_SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
151189

@@ -231,6 +269,11 @@ $(OBJDIR)/file_zarr.o: $(SRCDIR)/file_zarr.c $(SRCDIR)/file_zarr.h $(SRCDIR)/ush
231269
$(OBJDIR)/cJSON/cJSON.o: $(SRCDIR)/cJSON/cJSON.c $(SRCDIR)/cJSON/cJSON.h
232270
endif
233271

272+
# GRIB dependencies (when WITH_GRIB is set)
273+
ifdef WITH_GRIB
274+
$(OBJDIR)/file_grib.o: $(SRCDIR)/file_grib.c $(SRCDIR)/file_grib.h $(SRCDIR)/ushow.defines.h
275+
endif
276+
234277
# Print configuration
235278
info:
236279
@echo "CC: $(CC)"

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ For optional Zarr support:
3131
brew install c-blosc lz4
3232
```
3333

34+
For optional GRIB support:
35+
```bash
36+
brew install eccodes
37+
```
38+
3439
Install [XQuartz](https://www.xquartz.org/) for X11 support. After installation, the X11 libraries will be in `/opt/X11`.
3540

3641
Build:
3742
```bash
38-
make # Without zarr support
43+
make # Without zarr/grib support
3944
make WITH_ZARR=1 # With zarr support
45+
make WITH_GRIB=1 # With grib support
4046
make uterm # Build terminal viewer only
4147
```
4248

@@ -54,10 +60,16 @@ For optional Zarr support:
5460
sudo apt-get install libblosc-dev liblz4-dev
5561
```
5662

63+
For optional GRIB support:
64+
```bash
65+
sudo apt-get install libeccodes-dev
66+
```
67+
5768
Build:
5869
```bash
59-
make # Without zarr support
70+
make # Without zarr/grib support
6071
make WITH_ZARR=1 # With zarr support
72+
make WITH_GRIB=1 # With grib support
6173
make uterm # Build terminal viewer only
6274
```
6375

@@ -69,8 +81,9 @@ On Levante, the Makefile automatically uses the DKRZ spack-installed libraries:
6981

7082
No modules need to be loaded. Simply run:
7183
```bash
72-
make # Without zarr support
84+
make # Without zarr/grib support
7385
make WITH_ZARR=1 # With zarr support (uses system blosc/lz4)
86+
make WITH_GRIB=1 # With grib support (uses system eccodes)
7487
```
7588

7689
The binary will have the library paths embedded (via rpath), so it runs without setting `LD_LIBRARY_PATH`.
@@ -103,7 +116,7 @@ No libraries should show as "not found".
103116
## Usage
104117

105118
```bash
106-
./ushow [options] <data_file.nc|data.zarr> [file2 ...]
119+
./ushow [options] <data_file.nc|data.zarr|data.grib> [file2 ...]
107120

108121
Options:
109122
-m, --mesh <file> Mesh file with coordinates (for unstructured data)
@@ -115,7 +128,7 @@ Options:
115128

116129
Terminal quick-look mode:
117130
```bash
118-
./uterm [options] <data_file.nc|data.zarr> [file2 ...]
131+
./uterm [options] <data_file.nc|data.zarr|data.grib> [file2 ...]
119132

120133
Options (uterm):
121134
-m, --mesh <file> Mesh file with coordinates
@@ -159,6 +172,12 @@ Zarr store (requires `make WITH_ZARR=1`):
159172
./ushow data.zarr -r 0.25 # Higher resolution display
160173
```
161174

175+
GRIB file (requires `make WITH_GRIB=1`):
176+
```bash
177+
./ushow data.grib # Single GRIB file
178+
./uterm data.grib --color
179+
```
180+
162181
Zarr store with consolidated metadata (faster loading):
163182
```bash
164183
# Zarr stores with .zmetadata file are loaded more efficiently

0 commit comments

Comments
 (0)