]> Pileus Git - aweather/commitdiff
init function, level-2 parseing template
authorAndy Spencer <andy753421@gmail.com>
Mon, 9 Jun 2008 04:38:11 +0000 (04:38 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 9 Jun 2008 04:38:11 +0000 (04:38 +0000)
src/aweather.c
src/cube.c
src/level2.c [new file with mode: 0644]

index c96cf190f7ff1a4c3c2551c17d1c52bf43a2c580..66808500177e671a3f908c3e309310aee575c1cd 100644 (file)
@@ -57,9 +57,9 @@ int main(int argc, char *argv[])
        GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE);
        if (!glconfig) g_assert_not_reached();
        if (!gtk_widget_set_gl_capability(drawing, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE)) g_assert_not_reached();
-       g_signal_connect(drawing, "configure-event", G_CALLBACK(configure), NULL);
-       g_signal_connect(drawing, "expose-event",    G_CALLBACK(expose),    NULL);
-       g_timeout_add(1000/60, rotate, drawing);
+
+       /* Load plugins */
+       cube_init(drawing);
 
        gtk_widget_show_all(window);
        gtk_main();
index 9465938602c6cf1fb05e3f4602fa45925f24b958..1a13e05dab66bb2e911481ae6416791769054eca 100644 (file)
@@ -143,3 +143,10 @@ gboolean rotate (gpointer user_data)
 
        return TRUE;
 }
+
+gboolean cube_init(GtkDrawingArea *drawing)
+{
+       g_signal_connect(drawing, "configure-event", G_CALLBACK(configure), NULL);
+       g_signal_connect(drawing, "expose-event",    G_CALLBACK(expose),    NULL);
+       g_timeout_add(1000/60, rotate, drawing);
+}
diff --git a/src/level2.c b/src/level2.c
new file mode 100644 (file)
index 0000000..9259a14
--- /dev/null
@@ -0,0 +1,90 @@
+/* Prototype stuff for parsing Level-II data */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <error.h>
+#include <arpa/inet.h>
+
+struct packet {
+       short          junk1[6];
+       unsigned short size;
+       unsigned char  id, type;
+       unsigned short seq, gen_date;
+       unsigned int   gen_time;
+       unsigned short num_seg, seg;
+       unsigned int   coll_time;
+       unsigned short coll_date, range, angle, radial, rad_status, elev_angle;
+       unsigned short elev_num;
+       short          first_refl, first_dopp;
+       unsigned short refl_size, dopp_size;
+       unsigned short num_refl_gate, num_dopp_gate, sector;
+       float          gain;
+       unsigned short refl_ptr, vel_ptr, spec_ptr, dopp_res, pattern;
+       short          junk2[4];
+       unsigned short refl_ptr_rda, vel_ptr_rda, spec_ptr_rda, nyquist, atten;
+       short          thresh;
+       short          junk3[17];
+       unsigned char  data[2304];
+       float          dbz[460];
+};
+
+typedef struct {
+       /* 24 bytes */
+       char version[4];
+       char unknown0[16];
+       char station[4];
+} __attribute__ ((packed)) header_t;
+
+int main(int argc, char **argv)
+{
+       if (argc < 2) {
+               printf("usage: %s <level2-data>\n", argv[0]);
+               return 0;
+       }
+
+       /* Read header */
+       FILE *fd = fopen(argv[1], "r");
+       if (fd == NULL)
+               error(1, errno, "Error opening files `%s'", argv[1]);
+       header_t header;
+       if (1 != fread(&header, sizeof(header_t), 1, fd))
+               error(1, errno, "Error reading header");
+
+       /* Cut up the bzips */
+       int file_num = 0;
+       char filename[16];
+       char *buf = NULL;
+       FILE *outfile = NULL;
+       unsigned int size = 0;
+
+       while ((int)size >= 0) {
+               if (1 != fread(&size, 4, 1, fd))
+                       break; //error(1, errno, "Error reading size, pos=%x", (unsigned int)ftell(fd));
+               size = ntohl(size);
+
+               /* Read data */
+               ;
+               if (NULL == (buf = (char *)realloc(buf, size)))
+                       error(1, errno, "cannot allocate `%d' bytes for buffer", size);
+               if (size != fread(buf, 1, size, fd))
+                       error(1, errno, "error reading from input file");
+
+               /* Decmopress data */
+               //char *block = (char *)malloc(8192), *oblock = (char *)malloc(262144);
+               //error = BZ2_bzBuffToBuffDecompress(oblock, &olength, block, length, 0, 0);
+
+               /* Write data */
+               snprintf(filename, 16, "%d.bz2", file_num);
+               outfile = fopen(filename, "w+");
+               fwrite(buf, 1, size, outfile);
+               fclose(outfile);
+
+               //fprintf(stderr, "wrote `%d' bytes to file `%s'\n", size, filename);
+
+               /* iterate */
+               file_num++;
+       }
+
+       return 0;
+}