X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fradar.c;h=d6bcd7bd4ba76101590840e1664a377f400ec49f;hb=8c3400c6b10e27dbdf757b6f46c5bbef8619a478;hp=1f34fb34ba276330a317341769076dccde8bbb16;hpb=0710ad564f97bf0e8aa3460fcb79110623d46544;p=aweather diff --git a/src/plugins/radar.c b/src/plugins/radar.c index 1f34fb3..d6bcd7b 100644 --- a/src/plugins/radar.c +++ b/src/plugins/radar.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -302,6 +301,11 @@ RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig, site->city = city; site->pconfig = pconfig; + /* Set initial location */ + gdouble lat, lon, elev; + grits_viewer_get_location(viewer, &lat, &lon, &elev); + _site_on_location_changed(viewer, lat, lon, elev, site); + /* Add marker */ g_idle_add_full(G_PRIORITY_LOW, _site_add_marker, site, NULL); @@ -441,7 +445,7 @@ gboolean _conus_update_end(gpointer _conus) GError *error = NULL; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(conus->path, &error); if (!pixbuf || error) { - g_warning("Conus: update_end - error loading pixbuf"); + g_warning("Conus: update_end - error loading pixbuf: %s", conus->path); _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new("Error loading pixbuf")); g_remove(conus->path); goto out; @@ -485,21 +489,34 @@ gpointer _conus_update_thread(gpointer _conus) g_debug("Conus: update_thread - nearest"); gboolean offline = grits_viewer_get_offline(conus->viewer); gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/"; - GList *files = grits_http_available(conus->http, - "^Conus_[^\"]*_N0Ronly.gif$", "", - NULL, (offline ? NULL : conus_url)); - gchar *nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M"); - g_list_foreach(files, (GFunc)g_free, NULL); - g_list_free(files); - if (!nearest) { - conus->message = "No suitable files"; - goto out; + gchar *nearest; + if (time(NULL) - conus->time < 60*60*5 && !offline) { + /* radar.weather.gov is full of lies. + * the index pages get cached and out of date */ + struct tm tm; + gmtime_r(&conus->time, &tm); + time_t onthe8 = conus->time - 60*((tm.tm_min+1)%10+1); + gmtime_r(&onthe8, &tm); + nearest = g_strdup_printf("Conus_%04d%02d%02d_%02d%02d_N0Ronly.gif", + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_hour, tm.tm_min); + } else { + GList *files = grits_http_available(conus->http, + "^Conus_[^\"]*_N0Ronly.gif$", "", NULL, NULL); + nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M"); + g_list_foreach(files, (GFunc)g_free, NULL); + g_list_free(files); + if (!nearest) { + conus->message = "No suitable files"; + goto out; + } } /* Fetch the image */ g_debug("Conus: update_thread - fetch"); gchar *uri = g_strconcat(conus_url, nearest, NULL); - conus->path = grits_http_fetch(conus->http, uri, nearest, GRITS_ONCE, + conus->path = grits_http_fetch(conus->http, uri, nearest, + offline ? GRITS_LOCAL : GRITS_ONCE, _conus_update_loading, conus); g_free(nearest); g_free(uri); @@ -624,14 +641,14 @@ static void _draw_hud(GritsCallback *callback, GritsOpenGL *opengl, gpointer _se static void _load_colormap(gchar *filename, AWeatherColormap *cm) { g_debug("GritsPluginRadar: _load_colormap - %s", filename); - FILE *file = g_fopen(filename, "r"); + FILE *file = fopen(filename, "r"); if (!file) g_error("GritsPluginRadar: open failed"); guint8 color[4]; GArray *array = g_array_sized_new(FALSE, TRUE, sizeof(color), 256); - fgets(cm->name, sizeof(cm->name), file); - fscanf(file, "%f\n", &cm->scale); - fscanf(file, "%f\n", &cm->shift); + if (!fgets(cm->name, sizeof(cm->name), file)) goto out; + if (!fscanf(file, "%f\n", &cm->scale)) goto out; + if (!fscanf(file, "%f\n", &cm->shift)) goto out; int r, g, b, a; while (fscanf(file, "%d %d %d %d\n", &r, &g, &b, &a) == 4) { color[0] = r; @@ -642,7 +659,9 @@ static void _load_colormap(gchar *filename, AWeatherColormap *cm) } cm->len = (gint )array->len; cm->data = (void*)array->data; +out: g_array_free(array, FALSE); + fclose(file); } static void _update_hidden(GtkNotebook *notebook,