4 #include <gdk/gdkkeysyms.h>
12 static GtkWidget *rotate_button;
15 static int nred, ngreen, nblue;
16 static unsigned char red[256], green[256], blue[256];
18 static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
20 GdkGLContext *glcontext = gtk_widget_get_gl_context (da);
21 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (da);
26 glRotatef(0, 0, 0, 0);
28 glShadeModel(GL_FLAT);
33 for (rayi = 0; rayi < sweep->h.nrays; rayi++) {
34 Ray *ray = sweep->ray[rayi];
36 /* right and left with respect to north */
37 double right = ((ray->h.azimuth + ray->h.beam_width)*M_PI)/180.0;
38 double left = ((ray->h.azimuth - ray->h.beam_width)*M_PI)/180.0;
40 double rx = sin(right), ry = cos(right);
41 double lx = sin(left), ly = cos(left);
43 int nbins = ray->h.nbins;
45 int max_dist = nbins * ray->h.gate_size + ray->h.range_bin1;
46 int bini, dist = ray->h.range_bin1;
47 for (bini = 0; bini < nbins; bini++, dist += ray->h.gate_size) {
48 if (ray->range[bini] == BADVAL) continue;
50 /* (find middle of bin) / scale for opengl */
51 double nd = ((double)dist - ((double)ray->h.gate_size)/2.) / (double)max_dist;
52 double fd = ((double)dist + ((double)ray->h.gate_size)/2.) / (double)max_dist;
55 red[(unsigned char)ray->h.f(ray->range[bini])],
56 green[(unsigned char)ray->h.f(ray->range[bini])],
57 blue[(unsigned char)ray->h.f(ray->range[bini])]
60 glVertex3f(lx*nd, ly*nd, 0.); // near left
61 glVertex3f(lx*fd, ly*fd, 0.); // far left
62 glVertex3f(rx*fd, ry*fd, 0.); // far right
63 glVertex3f(rx*nd, ry*nd, 0.); // near right
72 /* Print the color table */
75 for (i = 0; i < nred; i++) {
76 glColor3ub(red[i], green[i], blue[i]);
77 glVertex3f(-1., (float)((i ) - nred/2)/(nred/2), 0.); // bot left
78 glVertex3f(-1., (float)((i+1) - nred/2)/(nred/2), 0.); // top left
79 glVertex3f(-.9, (float)((i+1) - nred/2)/(nred/2), 0.); // top right
80 glVertex3f(-.9, (float)((i ) - nred/2)/(nred/2), 0.); // bot right
89 gboolean radar_init(GtkDrawingArea *drawing, GtkNotebook *config)
91 /* Add configuration tab */
92 GtkWidget *label = gtk_label_new("Radar");
93 rotate_button = gtk_toggle_button_new_with_label("Rotate");
94 gtk_notebook_append_page(GTK_NOTEBOOK(config), rotate_button, label);
96 /* Set up OpenGL Stuff */
97 g_signal_connect(drawing, "expose-event", G_CALLBACK(expose), NULL);
99 /* Parse hard coded file.. */
100 RSL_read_these_sweeps("0", NULL);
101 radar = RSL_wsr88d_to_radar("/scratch/aweather/src/KABR_20080609_0224", "KABR");
102 RSL_load_refl_color_table();
103 RSL_get_color_table(RSL_RED_TABLE, red, &nred);
104 RSL_get_color_table(RSL_GREEN_TABLE, green, &ngreen);
105 RSL_get_color_table(RSL_BLUE_TABLE, blue, &nblue);
106 if (radar->h.nvolumes < 1 || radar->v[0]->h.nsweeps < 1)
107 g_print("No sweeps found\n");
108 sweep = radar->v[0]->sweep[0];
109 RSL_volume_to_gif(radar->v[DZ_INDEX], "dz_sweep", 1024, 1024, 200.0);