Skip to content

Commit 78f43bd

Browse files
Merge pull request #518 from NOAA-EMC/wgrib
wgrib src #445
2 parents 446dca7 + 05ad5ff commit 78f43bd

67 files changed

Lines changed: 13828 additions & 13692 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

wgrib/BDS_NValues.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include "bds.h"
3+
#include "grib.h"
4+
5+
/*
6+
* support for complex packing
7+
* determine the number of data points in the BDS
8+
* does not handle matrix values
9+
*/
10+
11+
extern int ec_large_grib, len_ec_bds;
12+
13+
14+
int BDS_NValues(unsigned char *bds) {
15+
16+
/* returns number of grid points as determined from the BDS */
17+
18+
int i = 0;
19+
20+
if (BDS_SimplePacking(bds) && BDS_Grid(bds)) {
21+
i = ((BDS_LEN(bds) - BDS_DataStart(bds))*8 -
22+
BDS_UnusedBits(bds)) / (BDS_NumBits(bds));
23+
}
24+
else if (BDS_ComplexPacking(bds) && BDS_Grid(bds)) {
25+
i = BDS_P2(bds);
26+
}
27+
return i;
28+
}

wgrib/BDSunpk.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stddef.h>
4+
#include <limits.h>
5+
#include "grib.h"
6+
#include "pds4.h"
7+
#include "bms.h"
8+
#include "bds.h"
9+
10+
/* 1996 wesley ebisuzaki
11+
*
12+
* Unpack BDS section
13+
*
14+
* input: *bits, pointer to packed integer data
15+
* *bitmap, pointer to bitmap (undefined data), NULL if none
16+
* n_bits, number of bits per packed integer
17+
* n, number of data points (includes undefined data)
18+
* ref, scale: flt[] = ref + scale*packed_int
19+
* output: *flt, pointer to output array
20+
* undefined values filled with UNDEFINED
21+
*
22+
* note: code assumes an integer > 32 bits
23+
*
24+
* 7/98 v1.2.1 fix bug for bitmaps and nbit >= 25 found by Larry Brasfield
25+
* 2/01 v1.2.2 changed jj from long int to double
26+
* 3/02 v1.2.3 added unpacking extensions for spectral data
27+
* Luis Kornblueh, MPIfM
28+
* 7/06 v.1.2.4 fixed some bug complex packed data was not set to undefined
29+
*/
30+
31+
static unsigned int mask[] = {0,1,3,7,15,31,63,127,255};
32+
static unsigned int map_masks[8] = {128, 64, 32, 16, 8, 4, 2, 1};
33+
static double shift[9] = {1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0};
34+
35+
void BDS_unpack(float *flt, unsigned char *bds, unsigned char *bitmap,
36+
int n_bits, int n, double ref, double scale) {
37+
38+
unsigned char *bits;
39+
40+
int i, mask_idx, t_bits, c_bits, j_bits;
41+
unsigned int j, map_mask, tbits, jmask, bbits;
42+
double jj;
43+
44+
45+
if (BDS_ComplexPacking(bds)) {
46+
fprintf(stderr,"*** Cannot decode complex packed fields n=%d***\n", n);
47+
exit(8);
48+
for (i = 0; i < n; i++) {
49+
*flt++ = UNDEFINED;
50+
}
51+
return;
52+
}
53+
54+
if (BDS_Harmonic(bds)) {
55+
bits = bds + 15;
56+
/* fill in global mean */
57+
*flt++ = BDS_Harmonic_RefValue(bds);
58+
n -= 1;
59+
}
60+
else {
61+
bits = bds + 11;
62+
}
63+
64+
tbits = bbits = 0;
65+
66+
/* assume integer has 32+ bits */
67+
if (n_bits <= 25) {
68+
jmask = (1 << n_bits) - 1;
69+
t_bits = 0;
70+
71+
if (bitmap) {
72+
for (i = 0; i < n; i++) {
73+
/* check bitmap */
74+
mask_idx = i & 7;
75+
if (mask_idx == 0) bbits = *bitmap++;
76+
if ((bbits & map_masks[mask_idx]) == 0) {
77+
*flt++ = UNDEFINED;
78+
continue;
79+
}
80+
81+
while (t_bits < n_bits) {
82+
tbits = (tbits * 256) + *bits++;
83+
t_bits += 8;
84+
}
85+
t_bits -= n_bits;
86+
j = (tbits >> t_bits) & jmask;
87+
*flt++ = ref + scale*j;
88+
}
89+
}
90+
else {
91+
for (i = 0; i < n; i++) {
92+
if (n_bits - t_bits > 8) {
93+
tbits = (tbits << 16) | (bits[0] << 8) | (bits[1]);
94+
bits += 2;
95+
t_bits += 16;
96+
}
97+
while (t_bits < n_bits) {
98+
tbits = (tbits * 256) + *bits++;
99+
t_bits += 8;
100+
}
101+
t_bits -= n_bits;
102+
flt[i] = (tbits >> t_bits) & jmask;
103+
}
104+
/* at least this vectorizes :) */
105+
for (i = 0; i < n; i++) {
106+
flt[i] = ref + scale*flt[i];
107+
}
108+
}
109+
}
110+
else {
111+
/* older unoptimized code, not often used */
112+
c_bits = 8;
113+
map_mask = 128;
114+
while (n-- > 0) {
115+
if (bitmap) {
116+
j = (*bitmap & map_mask);
117+
if ((map_mask >>= 1) == 0) {
118+
map_mask = 128;
119+
bitmap++;
120+
}
121+
if (j == 0) {
122+
*flt++ = UNDEFINED;
123+
continue;
124+
}
125+
}
126+
127+
jj = 0.0;
128+
j_bits = n_bits;
129+
while (c_bits <= j_bits) {
130+
if (c_bits == 8) {
131+
jj = jj * 256.0 + (double) (*bits++);
132+
j_bits -= 8;
133+
}
134+
else {
135+
jj = (jj * shift[c_bits]) + (double) (*bits & mask[c_bits]);
136+
bits++;
137+
j_bits -= c_bits;
138+
c_bits = 8;
139+
}
140+
}
141+
if (j_bits) {
142+
c_bits -= j_bits;
143+
jj = (jj * shift[j_bits]) + (double) ((*bits >> c_bits) & mask[j_bits]);
144+
}
145+
*flt++ = ref + scale*jj;
146+
}
147+
}
148+
return;
149+
}

wgrib/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55

66
add_compile_definitions("DEF_T62_NCEP_TABLE=opn" "FAST_GRIBTAB" "P_TABLE_FIRST")
77

8-
set(c_src wgrib.c)
8+
set(c_src BDS_NValues.c ectable_132.c ectable_210.c nceptab_130.c
9+
BDSunpk.c ectable_133.c ectable_211.c nceptab_131.c
10+
cnames.c ectable_140.c ectable_228.c nceptab_133.c
11+
cptectable_254.c ectable_150.c ensemble.c nceptab_140.c
12+
dwdtable_002.c ectable_151.c flt2ieee.c nceptab_141.c
13+
dwdtable_201.c ectable_160.c gds_grid.c nceptable_opn.c
14+
dwdtable_202.c ectable_162.c gribtable.c nceptable_reanal.c
15+
dwdtable_203.c ectable_170.c ibm2flt.c PDS_date.c
16+
dwdtable_204.c ectable_171.c intpower.c PDStimes.c
17+
dwdtable_205.c ectable_172.c jra55_200.c readgrib.c
18+
ec_ext.c ectable_173.c levels.c seekgrib.c
19+
ectable_128.c ectable_174.c mdl_nceptab.c wgrib_main.c
20+
ectable_129.c ectable_180.c missing.c wrtieee.c
21+
ectable_130.c ectable_190.c nceptab_128.c
22+
ectable_131.c ectable_200.c nceptab_129.c)
923

1024
set(exe_name wgrib)
1125
add_executable(${exe_name} ${c_src})

wgrib/Changes

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
Upgrade from v1.8.0.12g (8/06) to v1.8.0.12o (5/07)
1+
May 2026
22

3-
Changes:
3+
change code from wgrib.c to source code (*.c *.h)
4+
update so that there are no warning with oneapi icx.
5+
Note: this is wgrib v1.8.5
46

5-
updated ncep grib table 129, 130 to on388
6-
updated levels to on388
7-
changed units ncep grib table 128 WTPC(186) K->C
8-
support for updates in the grib table by process owners (compile change)
9-
increased stdin line buffer to 2000 characters
10-
level 210 is now WMO standard for non-NCEP files
7+
History: wgrib was written when Unix was a strange operating system.
8+
The various Unix systems had their own versions of "make", and
9+
other operating systems often lacked a make program. The C
10+
programming language was the new kid on the block, and you learned
11+
from the K&R book.
1112

12-
Reason for upgrade:
13+
To help users who didn't understand make and C compilers, the script
14+
src2all was written to combine all the *.c and *.h files into wgrib.c
15+
so that compiling wgrib would not have to use make. So compiling wgrib
16+
was as simple as: cc -o wgrib wgrib.c
1317

14-
Request from marine branch: need updated ncep tables
15-
16-
Comments:
17-
No major changes since last update except needed table updates.
18-
Compile options change so that table changes can be updated with new JIF.
19-
Little change in the run time is expected.
18+
When wgrib was added to the wgrib2 github repository, "wgrib.c" was
19+
added. This makes modifying the code a PITA.
20+

0 commit comments

Comments
 (0)