From 1398794a7901ac38c29856d6d08b5f9fac15ff1a Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 3 May 2009 11:04:16 +0000 Subject: [PATCH] Finally getting stuff to work again, NEXRAD Level II data needs to be decompressed first using the opt/dec program. --- Makefile.am | 1 + opt/dec.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ opt/mkfile | 8 +++++ src/.vimrc | 1 + src/Makefile.am | 8 +++-- src/aweather.c | 2 +- src/opengl.c | 2 +- src/radar.c | 26 +++++++------- 8 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 opt/dec.c create mode 100644 opt/mkfile create mode 100644 src/.vimrc diff --git a/Makefile.am b/Makefile.am index 4e92a6d..bc1d29c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS = src test: all + LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \ ./src/aweather maintainer-clean-local: diff --git a/opt/dec.c b/opt/dec.c new file mode 100644 index 0000000..6126249 --- /dev/null +++ b/opt/dec.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include + +#define debug(...) fprintf(stderr, __VA_ARGS__); + +char *bunzip2(char *input, int input_len, int *output_len) +{ + bz_stream *stream = calloc(1, sizeof(bz_stream)); + + switch (BZ2_bzDecompressInit(stream, 0, 0)) { + case BZ_CONFIG_ERROR: err(1, "the library has been mis-compiled"); + case BZ_PARAM_ERROR: err(1, "Parameter error"); + case BZ_MEM_ERROR: err(1, "insufficient memory is available"); + //case BZ_OK: debug("success\n"); break; + //default: debug("unknown\n"); break; + } + + int status; + int output_size = 512; + char *output = NULL; + + do { + stream->next_in = input + stream->total_in_lo32; + stream->avail_in = input_len - stream->total_in_lo32; + output_size *= 2; + output = realloc(output, output_size); + //debug("alloc %d\n", output_size); + stream->next_out = output + stream->total_out_lo32; + stream->avail_out = output_size - stream->total_out_lo32; + //debug("decompressing..\n" + // " next_in = %p\n" + // " avail_in = %u\n" + // " next_out = %p\n" + // " avail_out = %u\n", + // stream->next_in, + // stream->avail_in, + // stream->next_out, + // stream->avail_out); + } while ((status = BZ2_bzDecompress(stream)) == BZ_OK && output_size < 1024*1024); + + // debug("done with status %d = %d\n", status, BZ_STREAM_END); + + *output_len = stream->total_out_lo32; + BZ2_bzDecompressEnd(stream); + return output; +} + +int main(int argc, char **argv) +{ + if (argc != 3) { + printf("usage: ./dec \n"); + return 0; + } + + FILE *input = fopen(argv[1], "r"); + FILE *output = fopen(argv[2], "w+"); + if (!input) err(1, "error opening input"); + if (!output) err(1, "error opening output"); + + int st; + int size = 0; + char *buf = malloc(24); + + /* Clear header */ + //debug("reading header\n"); + fread (buf, 1, 24, input); + fwrite(buf, 1, 24, output); + + //debug("reading body\n"); + while ((st = fread(&size, 1, 4, input))) { + //debug("read %u bytes\n", st); + //fwrite(&size, 1, 4, output); // DEBUG + size = abs(ntohl(size)); + if (size < 0) + return 0; + //debug("size = %x\n", size); + if (size > 10*1024*1024) + err(1, "sanity check failed, buf is to big: %d", size); + buf = realloc(buf, size); + fread (buf, 1, size, input); + //fwrite(buf, 1, size, output); // DEBUG + + int dec_len; + char *dec = bunzip2(buf, size, &dec_len); + // debug("decompressed %u bytes\n", dec_len); + fwrite(dec, 1, dec_len, output); + free(dec); + } + + return 0; +} diff --git a/opt/mkfile b/opt/mkfile new file mode 100644 index 0000000..d3410f8 --- /dev/null +++ b/opt/mkfile @@ -0,0 +1,8 @@ +PROGS=level2 dec +level2_cflags=`{pkg-config --cflags glib-2.0} +level2_libs=`{pkg-config --libs glib-2.0} -lbz2 +dec_libs=`{pkg-config --libs glib-2.0} -lbz2 +default: dec + ./dec ../data/KNQA_20090501_1925 KNQA_20090501_1925.raw + cmp ../data/KNQA_20090501_1925 KNQA_20090501_1925.raw +<$HOME/lib/mkcommon diff --git a/src/.vimrc b/src/.vimrc new file mode 100644 index 0000000..1e1d189 --- /dev/null +++ b/src/.vimrc @@ -0,0 +1 @@ +set makeprg=make\ test diff --git a/src/Makefile.am b/src/Makefile.am index c6b6055..4bbe43a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,11 @@ -AM_CPPFLAGS = $(GTK_CFLAGS) +AM_CPPFLAGS = $(GTK_CFLAGS) -I/usr/local/trmm/GVBOX/include/ AM_CFLAGS = -Wall -Werror --std=gnu99 bin_PROGRAMS = aweather aweather_SOURCES = aweather.c opengl.c cube.c radar.c -aweather_LDADD = $(GTK_LIBS) -lrsl +aweather_LDADD = $(GTK_LIBS) -L/usr/local/trmm/GVBOX/lib/ -lrsl + +test: all + LD_LIBRARY_PATH=/usr/local/trmm/GVBOX/lib/ \ + ./aweather diff --git a/src/aweather.c b/src/aweather.c index e2000fb..35eede0 100644 --- a/src/aweather.c +++ b/src/aweather.c @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) /* Load plugins */ opengl_init(GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); - //radar_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); + radar_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); cube_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area)); gtk_widget_show_all(window); diff --git a/src/opengl.c b/src/opengl.c index 8ab075a..f348d71 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -14,7 +14,7 @@ static gboolean expose_start(GtkWidget *da, GdkEventExpose *event, gpointer user /* draw in here */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - return TRUE; + return FALSE; } /* Plugins run stuff here */ static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, gpointer user_data) diff --git a/src/radar.c b/src/radar.c index 78b9b4e..2fdf7d3 100644 --- a/src/radar.c +++ b/src/radar.c @@ -44,17 +44,17 @@ static void bscan_sweep(Sweep *sweep, guint8 **data, int *width, int *height) *data = buf; /* debug */ - static int fi = 0; - char fname[128]; - sprintf(fname, "image-%d.ppm", fi); - FILE *fp = fopen(fname, "w+"); - fprintf(fp, "P6\n"); - fprintf(fp, "# Foo\n"); - fprintf(fp, "%d %d\n", *width, *height); - fprintf(fp, "255\n"); - fwrite(buf, 3, *width * *height, fp); - fclose(fp); - fi++; + //static int fi = 0; + //char fname[128]; + //sprintf(fname, "image-%d.ppm", fi); + //FILE *fp = fopen(fname, "w+"); + //fprintf(fp, "P6\n"); + //fprintf(fp, "# Foo\n"); + //fprintf(fp, "%d %d\n", *width, *height); + //fprintf(fp, "255\n"); + //fwrite(buf, 3, *width * *height, fp); + //fclose(fp); + //fi++; } /* Load a sweep as the active texture */ @@ -126,7 +126,7 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data) glTexCoord2d(0.0, ((double)ri)/sweep->h.nrays); glVertex3f(lx*near_dist, ly*near_dist, 0.); // near left glTexCoord2d(0.7, ((double)ri)/sweep->h.nrays); glVertex3f(lx*far_dist, ly*far_dist, 0.); // far left } - g_print("ri=%d, nr=%d, bw=%f\n", _ri, sweep->h.nrays, sweep->h.beam_width); + //g_print("ri=%d, nr=%d, bw=%f\n", _ri, sweep->h.nrays, sweep->h.beam_width); glEnd(); /* Texture debug */ //glBegin(GL_QUADS); @@ -164,7 +164,7 @@ gboolean radar_init(GtkDrawingArea *_drawing, GtkNotebook *config) /* Parse hard coded file.. */ RSL_read_these_sweeps("all", NULL); //RSL_read_these_sweeps("all", NULL); - Radar *radar = RSL_wsr88d_to_radar("/scratch/aweather/data/KNQA_20090501_1925", "KNQA"); + Radar *radar = RSL_wsr88d_to_radar("/scratch/aweather/data/KNQA_20090501_1925.raw", "KNQA"); RSL_load_refl_color_table(); RSL_get_color_table(RSL_RED_TABLE, red, &nred); RSL_get_color_table(RSL_GREEN_TABLE, green, &ngreen); -- 2.43.2