Skip to content
Snippets Groups Projects
Commit 8164dda1 authored by Alan De Smet's avatar Alan De Smet
Browse files

Import of ../wgrib2.tgz.v1.7.7.b

parent 472b1280
No related branches found
No related tags found
No related merge requests found
......@@ -122,8 +122,7 @@ int f_ijbox(ARG4) {
self->iptr = (int *) malloc(ni*nj * sizeof(int));
if (self->iptr == NULL) fatal_error("memory allocation in ijbox","");
self->out = ffopen(arg3,open_mode);
if (self->out == NULL)
if ((self->out = ffopen(arg3,open_mode)) == NULL)
fatal_error("ijbox could not open output file %s", arg3);
}
......
......@@ -192,10 +192,25 @@ v0.1.7.2b 3/2008 ----------------------------------------
various set_ routines
Manfred Schwarb: big cleanup signed/unsigned, remove extern from wgrib2.h
print statements, signed/unsigned conversions in lola/geo fixed
v0.1.7.4 4/2008 ----------------------------------------
v0.1.7.4 4/2008 ---------------------------------------- (internal release)
wgrib.c: up to 8 parameters for mysql
csv.c: added Niklas Sondell, Storm Weather Center
mysql.c: added Niklas Sondell, Storm Weather Center
ijsmall_domain, small_domain added
wgrib2/makefile: mysql support
v0.1.7.5 5/2008 ----------------------------------------
added: set_flag_table_3_3 in order to fix some polar stereographic files
fixed Wrt_grib.c (tail not written)
fixed small_domain
v0.1.7.6 5/2008 ----------------------------------------
fixed small_domain
fixed problem with makefile_all_libs
v0.1.7.7 5/2008 ----------------------------------------
fixed netcdf=0 mysql=1 problem in makefile
grib_ieee -- keep original scan order
fixed f_set_date
v0.1.7.7a 6/2008 ----------------------------------------
fixed typo in small_domain
ij_undefined now uses ix=1..nx iy=1..ny
-stats now has cos-weighted means
v0.1.7.7b 6/2008 ----------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "grb2.h"
#include "wgrib2.h"
#include "fnlist.h"
......@@ -15,46 +16,54 @@
*
*/
extern int decode, latlon;
double *lat, *lon;
extern int decode;
//extern int file_append;
//extern float *lat, *lon;
#define CONV (3.14159265/180.0)
/*
* HEADER:100:stats:inv:0:statistical summary of data values
*/
int f_stats(ARG0) {
double sum, min, max;
int first, n;
double sum, sum_wt, wt, min, max, t;
int first, n, do_wt;
unsigned int i;
if (mode == -1) {
decode = 1;
latlon = decode = 1;
}
else if (mode >= 0) {
first = 1;
n = 0;
sum =UNDEFINED;
min = max = UNDEFINED;
do_wt = lat != NULL;
sum_wt = wt = 0.0;
for (i = 0; i < ndata; i++) {
if (!UNDEFINED_VAL(data[i])) {
n++;
if (first) {
max = min = data[i];
max = min = data[i];
first = 0;
sum = data[i];
if (do_wt) { wt = cos(CONV*lat[i]); sum_wt = data[i]*wt; }
}
else {
max = max < data[i]? data[i] : max;
min = min > data[i]? data[i] : min;
sum += data[i];
if (do_wt) { t = cos(CONV*lat[i]); wt += t; sum_wt += data[i]*t; }
}
}
}
if (n) sum /= n;
sprintf(inv_out,"ndata=%u:undef=%u:mean=%lg:min=%lg:max=%lg", ndata, ndata-n, sum, min, max);
if (wt > 0) {
sum_wt = sum_wt/wt;
inv_out += strlen(inv_out);
sprintf(inv_out,":cos_wt_mean=%lg", sum_wt);
}
}
return 0;
}
......
......@@ -31,7 +31,21 @@ int f_flag_table_3_3(ARG0) {
return 0;
}
int flag_table_3_3(unsigned char **sec) {
int res, grid_template;
unsigned char *p;
p = flag_table_3_3_location(sec);
if (p == NULL) return -1;
return (int) *p;
}
int set_flag_table_3_3(unsigned char **sec, unsigned int flag) {
unsigned char *p;
p = flag_table_3_3_location(sec);
if (p == NULL) return -1;
*p = flag;
return 0;
}
unsigned char *flag_table_3_3_location(unsigned char **sec) {
int grid_template;
unsigned char *gds;
grid_template = code_table_3_1(sec);
......@@ -46,21 +60,22 @@ int flag_table_3_3(unsigned char **sec) {
case 42:
case 43:
case 204:
res = (int) gds[54]; break;
return gds+54; break;
case 10:
case 20:
case 30:
case 31:
case 90:
case 110:
res = (int) gds[46]; break;
return gds+46; break;
default: res = -1; break;
default: return NULL; break;
}
return res;
return NULL;
}
/*
* HEADER:1:vector_dir:inv:0:grid or earth relative winds
*/
......
......@@ -73,8 +73,8 @@ int f_lola(ARG4) {
save->dlat = dy;
save->iptr = (int *) malloc(nx*ny * sizeof(int));
save->out = ffopen(arg3,open_mode);
if (save->out == NULL) fatal_error("lola could not open file %s", arg3);
if ((save->out = ffopen(arg3,open_mode)) == NULL)
fatal_error("lola could not open file %s", arg3);
return 0;
}
......
......@@ -91,11 +91,11 @@ int f_set_date(ARG1) {
p += 4;
if (sscanf(p,"%2d",&month) == 0) fatal_error("set_date: month %s", arg1);
p += 2;
if (sscanf(p,"%2d",&day) == 0) {
if (sscanf(p,"%2d",&day) == 1) {
p += 2;
if (sscanf(p,"%2d",&hour) == 0) {
if (sscanf(p,"%2d",&hour) == 1) {
p += 2;
if (sscanf(p,"%2d",&minute) == 0) {
if (sscanf(p,"%2d",&minute) == 1) {
p += 2;
sscanf(p,"%2d",&second);
}
......@@ -314,3 +314,23 @@ int f_set_metadata(ARG1) {
}
return 0;
}
/*
* HEADER:100:set_flag_table_3.3:misc:1:flag table 3.3 = X
*/
int f_set_flag_table_3_3(ARG1) {
if (mode >= 0) return set_flag_table_3_3(sec, atoi(arg1));
return 0;
}
/*
* HEADER:100:set_flag_table_3.4:misc:1:flag table 3.4 = X
*/
int f_set_flag_table_3_4(ARG1) {
if (mode >= 0) return set_flag_table_3_4(sec, atoi(arg1));
return 0;
}
......@@ -7,6 +7,7 @@
#include "wgrib2.h"
#include "fnlist.h"
// #define DEBUG
/*
* small_grib
*
......@@ -250,9 +251,13 @@ int small_domain(unsigned char **sec, double lonW, double lonE, double latS, dou
int *ix0, int *ix1, int *iy0, int *iy1) {
int i, j, k, flag, x0, x1, y0, y1;
int X0, X1, Y0, Y1, flag0;
double e,w,n,s;
double tmp;
#ifdef DEBUG
printf("\n>> small_domain: lon lat %f:%f %f:%f\n", lonW, lonE, latS, latN);
#endif
if (lat == NULL || lon == NULL) {
*ix0 = 1;
*ix1 = nx;
......@@ -261,19 +266,30 @@ int small_domain(unsigned char **sec, double lonW, double lonE, double latS, dou
return 1;
}
if (lonE < lonW) lonE += 360.0;
if (lonE-lonW > 360.0) fatal_error("small_domain: longitude range is greater than 360 degrees","");
if (lonW < 0.0) { lonW += 360.0; lonE += 360.0; }
flag = 0;
k = 0;
#ifdef DEBUG
printf("\n>> small_domain: new lon lat %f:%f %f:%f\n", lonW, lonE, latS, latN);
printf(">> small_domain: nx %d ny %d\n", nx, ny);
#endif
flag0 = 0;
k = -1;
x0 = x1 = y0 = y1 = -1;
for (j = 1; j <= ny; j++) {
flag = 0;
for (i = 1; i <= nx; i++) {
k++;
tmp = lon[k];
if (tmp < lonW) tmp += 360.0;
if (tmp < lonW) tmp += 360.0;
if ( (tmp <= lonE) && (lat[k] >= latS) && (lat[k] <= latN)) {
if (flag == 0) {
// printf(">> small_domain: i %d j %d lon=%f lat=%f\n",i,j,tmp,lat[k]);
if (flag == 0) {
x0 = x1 = i;
y0 = y1 = j;
w = e = tmp;
......@@ -297,22 +313,42 @@ int small_domain(unsigned char **sec, double lonW, double lonE, double latS, dou
x0 = i;
}
}
k++;
}
if (flag) {
#ifdef DEBUG
printf(">> small_domain: x0 %d x1 %d y0 %d y1 %d\n",x0,x1,y0,y1);
#endif
if (x1 < x0 && cyclic(sec)) x1 += nx;
if (flag0 == 0) {
X0 = x0;
X1 = x1;
Y0 = y0;
Y1 = y1;
flag0 = 1;
}
if (x0 < X0) X0 = x0;
if (x1 > X1) X1 = x1;
if (y0 < Y0) Y0 = y0;
if (y1 > Y1) Y1 = y1;
}
}
if (x1 < x0 && cyclic(sec)) x1 += nx;
if (x1 < x0) flag = 0;
if (flag == 0) {
#ifdef DEBUG
printf(">> small domain: flag0 %d flag %d\n", flag0, flag);
#endif
if (flag0 && X1 < X0) flag0 = 0;
if (flag0 == 0) {
*ix0 = 1;
*ix1 = nx;
*iy0 = 1;
*iy1 = ny;
return 1;
}
*ix0 = x0;
*ix1 = x1;
*iy0 = y0;
*iy1 = y1;
#ifdef DEBUG
printf(">> small domain: ix %d:%d iy %d:%d\n", X0, X1, Y0, Y1);
#endif
*ix0 = X0;
*ix1 = X1;
*iy0 = Y0;
*iy1 = Y1;
return 0;
}
......@@ -101,13 +101,13 @@ int f_undefine(ARG3) {
}
/*
* HEADER:100:ijundefine:misc:3:sets grid point values to undefined X=(in-box|out-box) Y=ix0:ix1 Z=iy0:iy1
* HEADER:100:ijundefine:misc:3:sets grid point values to undefined X=(in-box|out-box) Y=ix0:ix1 Z=iy0:iy1 ix=(1..nx) iy=(1..ny)
*/
/* this routine sets the data grid points to UNDEFINED
* use: select certain regions for further processing
* example: -stats (min/max/ave) value of defined grid points
* spreadsheet output uses i,j coordinates, i = 0..nx-1 j = 0..iy-1;
* spreadsheet output uses i,j coordinates, i = 1..nx j = 1..iy;
*/
int f_ijundefine(ARG3) {
......@@ -134,14 +134,14 @@ int f_ijundefine(ARG3) {
fatal_error("undef: bad ix0:ix1 %s", arg2);
}
save->ix0 = x;
save->ix1 = y;
save->ix0 = x-1;
save->ix1 = y-1;
if (sscanf(arg3,"%d:%d", &x, &y) != 2) {
fatal_error("undef: bad iy0:iy0 %s", arg3);
}
save->iy0 = x;
save->iy1 = y;
save->iy0 = x-1;
save->iy1 = y-1;
*local = save;
}
if (mode < 0) return 0;
......
......@@ -10,6 +10,9 @@
* ieee-Grib: hooks for making own grib files
*
* 12/2007 Public Domain by Wesley Ebisuzaki
* 5/2008: more symbols
* 5/2008: fix "tail"
* 5/2008: keep original scan order
*
*/
......@@ -22,7 +25,7 @@ extern int flush_mode;
extern enum output_order_type output_order;
/*
* HEADER:100:grib_ieee:output:1:writes X.grb, X.head, X.tail, and X.h
* HEADER:100:grib_ieee:output:1:writes data[] to X.grb, X.head, X.tail, and X.h
*/
int f_grib_ieee(ARG1) {
......@@ -77,7 +80,8 @@ int f_grib_ieee(ARG1) {
int grib_ieee(unsigned char **sec, float *data, unsigned int ndata, FILE *out, FILE *head, FILE *tail, FILE *c) {
int n_defined, j;
int i, flag;
int i;
// int flag;
unsigned long int size;
unsigned char *p, *sec0, *sec1, *sec2, *sec3, *sec4, *sec5, *sec6, *sec7;
unsigned char s[8];
......@@ -90,8 +94,8 @@ int grib_ieee(unsigned char **sec, float *data, unsigned int ndata, FILE *out, F
sec4 = sec[4];
/* change scan mode */
flag = flag_table_3_4(sec);
set_order(sec, output_order);
// flag = flag_table_3_4(sec);
// set_order(sec, output_order);
/* make a new section 6 */
......@@ -177,7 +181,8 @@ int grib_ieee(unsigned char **sec, float *data, unsigned int ndata, FILE *out, F
s[0] = s[1] = s[2] = s[3] = 55; /* s = "7777" */
fprintf(c,"unsigned char tail[4] = {55, 55, 55, 55};\n\n");
fwrite((void *) s, sizeof(char), 4, out);
fwrite((void *) s, sizeof(char), 4, tail);
fprintf(c,"#define NDATA %u\n", ndata);
......@@ -237,8 +242,8 @@ int grib_ieee(unsigned char **sec, float *data, unsigned int ndata, FILE *out, F
free(sec6);
free(sec7);
/* set scan mode to original order */
set_flag_table_3_4(sec, flag);
// /* set scan mode to original order */
// set_flag_table_3_4(sec, flag);
return 0;
}
......
......@@ -115,6 +115,8 @@ struct function functions[] = {
{"set_center",f_set_center, misc, 1, "changes center X = C or C:S C and S are center/subcenter numbers", 100},
{"set_data_bin",f_set_data_bin, misc, 1, "read binary data from X", 100},
{"set_date",f_set_date, misc, 1, "changes date code .. not complete .. only analysis/fcst", 100},
{"set_flag_table_3.3",f_set_flag_table_3_3, misc, 1, "flag table 3.3 = X", 100},
{"set_flag_table_3.4",f_set_flag_table_3_4, misc, 1, "flag table 3.4 = X", 100},
{"set_ftime",f_set_ftime, misc, 1, "set ftime .. only on pdt=4.0 only anl/fcst", 100},
{"set_grib_type",f_set_grib_type, misc, 1, "set grib type = jpeg, simple, ieee", 100},
{"set_lev",f_set_lev, misc, 1, "changes level code .. not complete", 100},
......@@ -135,7 +137,7 @@ struct function functions[] = {
{"csv",f_csv, output, 1, "make comma separated file, X=file", 100},
{"grib",f_grib, output, 1, "writes GRIB record (one submessage) to X", 100},
{"GRIB",f_GRIB, output, 1, "writes entire GRIB record (all submessages)", 100},
{"grib_ieee",f_grib_ieee, output, 1, "writes X.grb, X.head, X.tail, and X.h", 100},
{"grib_ieee",f_grib_ieee, output, 1, "writes data[] to X.grb, X.head, X.tail, and X.h", 100},
{"grib_out",f_grib_out, output, 1, "writes decoded/modified data in grib-2 format to file X", 100},
{"ieee",f_ieee, output, 1, "write big-endian IEEE data to X", 100},
{"ijbox",f_ijbox, output, 4, "grid values in bounding box X=i1:i2[:di] Y=j1:j2[:dj] Z=file A=[bin|text|spread]", 100},
......
......@@ -120,6 +120,8 @@ int f_set_bin_prec(int mode, unsigned char **sec, float *data, unsigned int ndat
int f_set_center(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_data_bin(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_date(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_flag_table_3_3(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_flag_table_3_4(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_ftime(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_grib_type(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
int f_set_lev(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv, void **local, char *arg1);
......
......@@ -26,7 +26,7 @@ USE_MYSQL=0
DEFS=
ifeq ($(USE_NETCDF),1)
DEFS+=-DUSE_NETCDF
netcdf_lib=-L../netcdf-3.6.2/libsrc/.libs
netcdf_lib=-L../netcdf-3.6.2/libsrc/.libs -lnetcdf
netcdf_inc=-I../netcdf-3.6.2/libsrc
endif
ifeq ($(USE_REGEX),1)
......@@ -40,13 +40,13 @@ ifeq ($(USE_MYSQL),1)
# mysql_inc=-I/export/wesley/wd51we/download/mysql-5.0.51a-linux-i686-glibc23/include
# mysql_lib=-L/export/wesley/wd51we/download/mysql-5.0.51a-linux-i686-glibc23/lib -lmysqlclient
# mysql_lib=/export/wesley/wd51we/download/mysql-5.0.51a-linux-i686-glibc23/lib/libmysqlclient.a
mysql_inc=`mysql_config --ccflags`
mysql_inc=`mysql_config --cflags`
mysql_lib=`mysql_config --libs`
endif
g2=../g2clib-1.0.5
jasper_lib=-L../jasper-1.900.1/src/libjasper/.libs
jasper_lib=-L../jasper-1.900.1/src/libjasper/.libs -ljasper
jasper_inc=-I../jasper-1.900.1/src/libjasper/include
......@@ -65,7 +65,7 @@ ifeq ($(CC),gcc)
CFLAGS+=-Wall -ffast-math -funroll-loops
endif
LDFLAGS=-L${g2} -lgrib2c ${jasper_lib} -ljasper ${netcdf_lib} -lnetcdf ${mysql_lib} -L/usr/lib -lpng -lz -lm
LDFLAGS=-L${g2} -lgrib2c ${jasper_lib} ${netcdf_lib} ${mysql_lib} -L/usr/lib -lpng -lz -lm
#CC=gcc
wgrib2: $h ${all}
......
# REQUIRES GMAKE!!!!
#
# this makefile is for gnu-make on a linux box
# wgrib2 rerequires grib2c (NCEP C grib2), jasper (jpeg), z and png libraries
# makefile for wgrib2
#
# compiles every #@?! library needed by wgrib2
# then tries to compile wgrib2
#
# REQUIRES GNU make
# mod 1/07 M. Schwarb
# mod 2/07 W. Ebisuzaki changes for *.dat files
# mod 8/07 W. Ebisuzaki cleanup
# mod 1/07 M. Schwarb (libgrib2c name change)
#
# this version uses netcdf libraries -- compile C only version
# get from UCAR if compile doesn't work
#
#
# on NCEP AIX
# export CC=/usr/vacpp/bin/xlC_r
# export CPP=/usr/bin/cpp
j=jasper-1.900.1
jlib=$j/src/libjasper/.libs/libjasper.a
g=g2clib-1.0.5
glib=$g/libgrib2c.a
w=wgrib2
prog=$w/wgrib2
n=netcdf-3.6.2
nlib=$n/libsrc/.libs/libnetcdf.a
sh=/bin/sh
p=libpng-1.2.23
plib=$p/.libs/libpng.a
# optional packages
# USE_NETCDF .. netcdf package
# USE_REGEX .. use regular expression matching
# USE_TIGGE .. optional TIGGE-like grib table
z=zlib-1.2.3
zlib=$z/libz.a
# DEFS=-DUSE_NETCDF -DUSE_REGEX
DEFS=-DUSE_REGEX -DUSE_NETCDF -DUSE_TIGGE
MAKE=gmake
all:=$(patsubst %.c,%.o,$(wildcard *.c))
code:=$(filter-out fnlist.o,$(all))
o=$(wildcard *.o)
h:=grb2.h wgrib2.h fnlist.h
options=$(wildcard [A-Z]*.c)
CODE_TABLE_DAT=$(wildcard CodeTable_[0-9].[0-9]*.dat)
FLAGS=${DEFS} ${CPPFLAGS} ${CFLAGS}
wCPPFLAGS=-I../$z -I../$p -I../$j/src/libjasper/include -I../$n/libsrc -I../$g -I/usr/include ${CPPFLAGS} -O2
wgrib2: $h ${all}
${CC} -o wgrib2 ${FLAGS} ${all} ${LDFLAGS}
wLDFLAGS=-L../$g -lgrib2c -L../$z -lz -L../$p/.libs -lpng -L../$j/src/libjasper/.libs -ljasper -L../$n/libsrc/.libs -lnetcdf
fnlist.c: ${options}
./function.sh
fnlist.h: ${options}
./function.sh
all: ${jlib} ${plib} ${zlib} ${glib} ${nlib} ${prog}
fast: ${code}
touch fnlist.o fnlist.c fnlist.h
${CC} -o wgrib2 ${FLAGS} ${all} ${LDFLAGS}
${jlib}:
cp $j.tar.gz tmpj.tar.gz
gunzip -n tmpj.tar.gz
tar -xvf tmpj.tar
rm tmpj.tar
cd $j && ./configure --disable-libjpeg --disable-opengl && ${MAKE}
Help.o: Help.c wgrib2.h
${CC} -c ${FLAGS} Help.c
${plib}: ${zlib}
cp $p.tar.gz tmpp.tar.gz
gunzip -n tmpp.tar.gz
tar -xvf tmpp.tar
rm tmpp.tar
cd $p && export CPPFLAGS="${wCPPFLAGS}" && ./configure && ${MAKE}
CodeTable.o: CodeTable.c ${CODE_TABLE_DAT}
${CC} -c ${FLAGS} CodeTable.c
${zlib}:
cp $z.tar.gz tmpz.tar.gz
gunzip -n tmpz.tar.gz
tar -xvf tmpz.tar
rm tmpz.tar
cd $z && ./configure && ${MAKE}
cname.o: cname.c gribtab.dat
${CC} -c ${FLAGS} cname.c
Sec1.o: Sec1.c code_table0.dat ncep_tableC.dat
${CC} -c ${FLAGS} Sec1.c
${glib}: ${jlib} ${plib} ${zlib}
cd $g && export CPPFLAGS="${wCPPFLAGS}" && ${MAKE} -f makefile_all_libs
gribtab.o: gribtab.c gribtab.dat misc_gribtab.dat
${CC} -c ${FLAGS} gribtab.c
${nlib}:
cp netcdf.tar.gz tmpn.tar.gz
gunzip -n tmpn.tar.gz
tar -xvf tmpn.tar
rm tmpn.tar
cd $n && ./configure --enable-c-only && ${MAKE} check
.c.o: $(*).c
$(CC) -c ${FLAGS} $*.c
${prog}: $w/wgrib2.c $w/*.c $w/*.h ${glib} ${jlib} ${nlib} ${zlib} ${plib}
cd $w && export LDFLAGS="${wLDFLAGS}" && export CPPFLAGS="${wCPPFLAGS}" && ${MAKE} -f makefile_all_libs
clean:
touch wgrib2
rm ${o} wgrib2
cd $w && ${MAKE} clean
cd $g && touch junk.a junk.o && rm *.o *.a
rm -rf $n
rm -rf $j
rm -rf $p
rm -rf $z
......@@ -6,7 +6,7 @@
#include <stdio.h>
#ifndef VERSION
#define VERSION "v0.1.7.5 5/2008 Wesley Ebisuzaki, Jaakko Hyvätti, Kristian Nilssen, Karl Pfeiffer, \
#define VERSION "v0.1.7.7b 6/2008 Wesley Ebisuzaki, Jaakko Hyvätti, Kristian Nilssen, Karl Pfeiffer, \
Manfred Schwarb, Arlindo da Silva, Niklas Sondell, Sergey Varlamov"
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment