From: Matei C. <cm...@us...> - 2011-10-08 06:33:19
|
Update of /cvsroot/gcx/gcx/src In directory vz-cvs-4.sog:/tmp/cvs-serv21683 Modified Files: Makefile.am psf.c Added Files: skyview.c Log Message: Fix bounds check in radial_profile and add missing file --- NEW FILE: skyview.c --- /******************************************************************************* Copyright(c) 2011 Matei Conovici. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The full GNU General Public License is included in this distribution in the file called LICENSE. Contact Information: mco...@gm... *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <sys/time.h> #include <string.h> #include <errno.h> #include "gcx.h" #include "params.h" #include "obsdata.h" #include "catalogs.h" #include "sourcesdraw.h" #include "gui.h" #include "wcs.h" #include "demosaic.h" #include "interface.h" static char *skyview_xml = "<interface>" " <requires lib=\"gtk+\" version=\"2.16\"/>" " <!-- interface-naming-policy project-wide -->" " <object class=\"GtkWindow\" id=\"skyview\">" " <property name=\"title\" translatable=\"yes\">Download SkyView Image</property>" " <child>" " <object class=\"GtkVBox\" id=\"vbox1\">" " <property name=\"width_request\">350</property>" " <property name=\"height_request\">230</property>" " <property name=\"visible\">True</property>" " <property name=\"orientation\">vertical</property>" " <child>" " <object class=\"GtkFrame\" id=\"frame1\">" " <property name=\"visible\">True</property>" " <property name=\"border_width\">5</property>" " <property name=\"label_xalign\">0</property>" " <child>" " <object class=\"GtkAlignment\" id=\"alignment1\">" " <property name=\"visible\">True</property>" " <property name=\"top_padding\">5</property>" " <property name=\"bottom_padding\">5</property>" " <property name=\"left_padding\">5</property>" " <property name=\"right_padding\">5</property>" " <child>" " <object class=\"GtkVBox\" id=\"vbox2\">" " <property name=\"visible\">True</property>" " <property name=\"orientation\">vertical</property>" " <property name=\"spacing\">2</property>" " <child>" " <object class=\"GtkLabel\" id=\"label2\">" " <property name=\"visible\">True</property>" " <property name=\"xalign\">0</property>" " <property name=\"xpad\">6</property>" " <property name=\"label\" translatable=\"yes\">Position</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">0</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkEntry\" id=\"skyview_position\">" " <property name=\"visible\">True</property>" " <property name=\"can_focus\">True</property>" " <property name=\"tooltip_text\" translatable=\"yes\">Coordinates or object name (resolved by SIMBAD)</property>" " <property name=\"invisible_char\">●</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">1</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkLabel\" id=\"label3\">" " <property name=\"visible\">True</property>" " <property name=\"xalign\">0</property>" " <property name=\"xpad\">6</property>" " <property name=\"label\" translatable=\"yes\">Survey</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">2</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkComboBox\" id=\"skyview_survey\">" " <property name=\"visible\">True</property>" " <property name=\"model\">skyview_survey_store</property>" " <property name=\"active\">0</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">3</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkLabel\" id=\"label4\">" " <property name=\"visible\">True</property>" " <property name=\"xalign\">0</property>" " <property name=\"xpad\">6</property>" " <property name=\"label\" translatable=\"yes\">Field Size</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">4</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkEntry\" id=\"skyview_fieldsize\">" " <property name=\"width_request\">30</property>" " <property name=\"visible\">True</property>" " <property name=\"can_focus\">True</property>" " <property name=\"tooltip_text\" translatable=\"yes\">Field size in degrees of arc</property>" " <property name=\"invisible_char\">●</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">5</property>" " </packing>" " </child>" " </object>" " </child>" " </object>" " </child>" " <child type=\"label\">" " <object class=\"GtkLabel\" id=\"label1\">" " <property name=\"visible\">True</property>" " <property name=\"xpad\">5</property>" " <property name=\"label\" translatable=\"yes\">Download image from NASA <i>SkyView</i></property>" " <property name=\"use_markup\">True</property>" " </object>" " </child>" " </object>" " <packing>" " <property name=\"padding\">4</property>" " <property name=\"position\">0</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkHButtonBox\" id=\"hbuttonbox1\">" " <property name=\"visible\">True</property>" " <property name=\"border_width\">4</property>" " <property name=\"layout_style\">spread</property>" " <child>" " <object class=\"GtkButton\" id=\"skyview_fetch\">" " <property name=\"label\" translatable=\"yes\">_Fetch</property>" " <property name=\"visible\">True</property>" " <property name=\"can_focus\">True</property>" " <property name=\"receives_default\">True</property>" " <property name=\"use_underline\">True</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">0</property>" " </packing>" " </child>" " <child>" " <object class=\"GtkButton\" id=\"skyview_cancel\">" " <property name=\"label\" translatable=\"yes\">_Cancel</property>" " <property name=\"visible\">True</property>" " <property name=\"can_focus\">True</property>" " <property name=\"receives_default\">True</property>" " <property name=\"use_underline\">True</property>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">1</property>" " </packing>" " </child>" " </object>" " <packing>" " <property name=\"expand\">False</property>" " <property name=\"fill\">False</property>" " <property name=\"position\">1</property>" " </packing>" " </child>" " </object>" " </child>" " </object>" " <object class=\"GtkListStore\" id=\"skyview_survey_store\">" " <columns>" " <!-- column-name survey_label -->" " <column type=\"gchararray\"/>" " <!-- column-name survey_value -->" " <column type=\"gchararray\"/>" " </columns>" " <data>" " <row>" " <col id=\"0\" translatable=\"yes\">DSS</col>" " <col id=\"1\" translatable=\"yes\">dss</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">DSS1 Blue</col>" " <col id=\"1\" translatable=\"yes\">dss1b</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">DSS1 Red</col>" " <col id=\"1\" translatable=\"yes\">dss1r</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">DSS2 Blue</col>" " <col id=\"1\" translatable=\"yes\">dss2b</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">DSS2 Red</col>" " <col id=\"1\" translatable=\"yes\">dss2r</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">DSS2 IR</col>" " <col id=\"1\" translatable=\"yes\">dss2ir</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">SDSS G</col>" " <col id=\"1\" translatable=\"yes\">sdssg</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">SDSS I</col>" " <col id=\"1\" translatable=\"yes\">sdssi</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">SDSS R</col>" " <col id=\"1\" translatable=\"yes\">sdssr</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">SDSS U</col>" " <col id=\"1\" translatable=\"yes\">sdssu</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">SDSS Z</col>" " <col id=\"1\" translatable=\"yes\">sdssz</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">GALEX Far UV</col>" " <col id=\"1\" translatable=\"yes\">galexfar</col>" " </row>" " <row>" " <col id=\"0\" translatable=\"yes\">GALEX Near UV</col>" " <col id=\"1\" translatable=\"yes\">galexnear</col>" " </row>" " </data>" " </object>" "</interface>"; static void delete_download(GtkWidget *widget, GdkEvent *event, gpointer data) { g_return_if_fail(data != NULL); g_object_set_data(G_OBJECT(data), "download", NULL); } static int logw_print(char *msg, void *data) { GtkWidget *logw = data; GtkWidget *text; GtkToggleButton *stopb; text = g_object_get_data(G_OBJECT(logw), "query_log_text"); g_return_val_if_fail(text != NULL, 0); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (text), GTK_WRAP_CHAR); gtk_text_buffer_insert_at_cursor(gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)), msg, -1); while (gtk_events_pending()) gtk_main_iteration(); stopb = g_object_get_data(G_OBJECT(logw), "query_stop_toggle"); if (gtk_toggle_button_get_active(stopb)) { gtk_toggle_button_set_active(stopb, 0); return 1; } return 0; } static int fetch_skyview_image(GtkWidget *window, const char *position, const char *survey, const char *field) { GtkWidget *logw, *im_window; char *epos, *esurvey, *efield; char cmd[1024]; char *fn = NULL; FILE *vq; fd_set fds; struct timeval tv; int ret; char *p, *line; size_t ll; struct ccd_frame *fr; ll = 256; line = malloc(ll); line[0] = 0; epos = g_uri_escape_string(position, NULL, FALSE); esurvey = g_uri_escape_string(survey, NULL, FALSE); efield = g_uri_escape_string(field, NULL, FALSE); snprintf(cmd, 1024, "%s -q -O - \"%s?Position='%s'" "&survey=%s&Size=%s&Pixels=%d&coordinates=J2000" "&projection=Tan&float=on&scaling=Linear" "&resolver=SIMBAD-NED&Sampler=LI" "&return=filename\"", P_STR(QUERY_WGET), P_STR(QUERY_SKYVIEW_RUNQUERY_URL), epos, esurvey, efield, P_INT(QUERY_SKYVIEW_PIXELS)); g_free(epos); g_free(esurvey); g_free(efield); vq = popen(cmd, "r"); if (vq == NULL) { err_printf("cannot run wget (%s)\n", strerror(errno)); return -1; } /* FIXME: should probably use g_spawn_async here, and refactor query.c to use the same mechanism */ logw = create_query_log_window(); g_object_set_data_full(G_OBJECT(window), "download", logw, (GDestroyNotify)(gtk_widget_destroy)); g_signal_connect (G_OBJECT (logw), "delete_event", G_CALLBACK (delete_download), window); gtk_widget_show(logw); logw_print("Running SkyView query ", logw); do { FD_ZERO(&fds); FD_SET(fileno(vq), &fds); tv.tv_sec = 0; tv.tv_usec = 500000; errno = 0; ret = select(fileno(vq) + 1, &fds, NULL, NULL, &tv); if (ret == 0 || errno || !FD_ISSET(fileno(vq), &fds)) { if (logw_print(".", logw)) break; continue; } ret = getline(&line, &ll, vq); if (ret <= 0) continue; } while (ret >= 0); pclose(vq); logw_print("\n", logw); if ((p = strchr(line, '\n')) != NULL) *p = 0; if (strncasecmp(line, "skv", 3) || strlen(line) > 16) goto err_out; /* destination filename */ snprintf(cmd, 1024, "%s/%s.fits", P_STR(QUERY_SKYVIEW_DIR), line); fn = strdup(cmd); snprintf(cmd, 1024, "Fetching to %s.fits ", line); logw_print(cmd, logw); snprintf(cmd, 1024, "%s -q -O %s %s/%s.fits", P_STR(QUERY_WGET), fn, P_STR(QUERY_SKYVIEW_TEMPSPACE_URL), line); vq = popen(cmd, "r"); if (vq == NULL) { err_printf("cannot run wget (%s)\n", strerror(errno)); goto err_out; } ll = 256; line[0] = 0; do { FD_ZERO(&fds); FD_SET(fileno(vq), &fds); tv.tv_sec = 0; tv.tv_usec = 200000; errno = 0; ret = select(fileno(vq) + 1, &fds, NULL, NULL, &tv); if (ret == 0 || errno || !FD_ISSET(fileno(vq), &fds)) { if (logw_print(".", logw)) break; continue; } /* consume the event, if any */ ret = getline(&line, &ll, vq); if (ret <= 0) continue; } while (ret >= 0); pclose(vq); /* load it in the im_window */ im_window = g_object_get_data (G_OBJECT(window), "im_window"); fr = read_image_file(fn, P_STR(FILE_UNCOMPRESS), P_INT(FILE_UNSIGNED_FITS), default_cfa[P_INT(FILE_DEFAULT_CFA)]); if (fr == NULL) { err_printf_sb2(im_window, "Error opening %s", fn); goto err_out; } rescan_fits_wcs(fr, &fr->fim); rescan_fits_exp(fr, &fr->exp); frame_to_channel(fr, im_window, "i_channel"); release_frame(fr); extern void set_last_open(gpointer object, char *file_class, char *path); set_last_open(im_window, "last_open_fits", strdup(fn)); /* possibly remove the file */ if (!P_INT(QUERY_SKYVIEW_KEEPFILES)) unlink(fn); /* meh */ ret = 0; goto out; err_out: ret = -1; out: g_object_set_data(G_OBJECT(window), "download", NULL); free(line); free(fn); return ret; } static gboolean skyview_close_window (GtkWidget *widget, GdkEvent *event, gpointer im_window) { g_object_set_data (G_OBJECT(im_window), "skyview", NULL); return FALSE; } static void skyview_cancel(GtkWidget *button, gpointer window) { GtkWidget *im_window = g_object_get_data (G_OBJECT(window), "im_window"); if (im_window) g_object_set_data (G_OBJECT(im_window), "skyview", NULL); gtk_widget_destroy (window); } static void skyview_fetch(GtkWidget *button, gpointer window) { GtkWidget *wpos = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "skyview_position")), *wcombo = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "skyview_survey")), *wfield = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "skyview_fieldsize")); GtkTreeModel *model; GtkTreeIter iter; const char *pos, *field, *survey; GValue val = { 0 }; pos = gtk_entry_get_text (GTK_ENTRY(wpos)); field = gtk_entry_get_text (GTK_ENTRY(wfield)); model = gtk_combo_box_get_model (GTK_COMBO_BOX(wcombo)); if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(wcombo), &iter)) return; gtk_tree_model_get_value(model, &iter, 1, &val); survey = g_value_get_string(&val); if (!fetch_skyview_image(window, pos, survey, field)) { skyview_cancel(button, window); } g_value_unset (&val); } static GtkWidget *create_skyview(gpointer window) { GtkBuilder *builder; GtkWidget *skyview; static char *widgets[] = { "skyview_position", "skyview_fieldsize", "skyview_survey", "skyview_survey_store", "skyview_fetch", "skyview_cancel", NULL }; int i; GError *err = NULL; builder = gtk_builder_new (); gtk_builder_add_from_string (builder, skyview_xml, strlen(skyview_xml), &err); skyview = GTK_WIDGET (gtk_builder_get_object (builder, "skyview")); for (i = 0; widgets[i]; i++) { GObject *o = gtk_builder_get_object (builder, widgets[i]); g_object_set_data (G_OBJECT(skyview), widgets[i], o); } GtkComboBox *combo = GTK_COMBO_BOX (g_object_get_data (G_OBJECT(skyview), "skyview_survey")); GtkCellRenderer * cell = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), cell, TRUE ); gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combo ), cell, "text", 0, NULL ); g_object_unref (builder); g_object_set_data (G_OBJECT(window), "skyview", skyview); g_object_set_data (G_OBJECT(skyview), "im_window", window); g_signal_connect(G_OBJECT(skyview), "delete-event", G_CALLBACK(skyview_close_window), window); g_signal_connect(G_OBJECT(g_object_get_data(G_OBJECT(skyview), "skyview_fetch")), "clicked", G_CALLBACK(skyview_fetch), skyview); g_signal_connect(G_OBJECT(g_object_get_data(G_OBJECT(skyview), "skyview_cancel")), "clicked", G_CALLBACK(skyview_cancel), skyview); /* fill in defaults */ struct wcs *wcs = g_object_get_data(G_OBJECT(window), "wcs_of_window"); if (wcs) { static char buf[64]; snprintf(buf, 64, "%.5f, %.5f", wcs->xref, wcs->yref); gtk_entry_set_text (GTK_ENTRY(g_object_get_data(G_OBJECT(skyview), "skyview_position")), buf); } gtk_entry_set_text (GTK_ENTRY(g_object_get_data(G_OBJECT(skyview), "skyview_fieldsize")), "1.5"); return skyview; } void act_download_skyview(GtkAction *action, gpointer window) { GtkWidget *dialog; dialog = g_object_get_data (G_OBJECT(window), "skyview"); if (dialog == NULL) { dialog = create_skyview(window); gtk_widget_show_all (dialog); } else { gtk_widget_show (dialog); gdk_window_raise (dialog->window); } } Index: Makefile.am =================================================================== RCS file: /cvsroot/gcx/gcx/src/Makefile.am,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Makefile.am 28 Sep 2011 06:05:47 -0000 1.27 --- Makefile.am 8 Oct 2011 06:33:17 -0000 1.28 *************** *** 22,26 **** mbandrep.c starfile.c getline.h synth.c psf.c psf.h dsimplex.c dsimplex.h \ basename.c dirname.c libgen.h query.c query.h plate.c \ ! demosaic.c demosaic.h skyview.c skyview.h \ tele_indi.c tele_indi.h camera_indi.c camera_indi.h \ fwheel_indi.c fwheel_indi.h common_indi.c common_indi.h \ --- 22,26 ---- mbandrep.c starfile.c getline.h synth.c psf.c psf.h dsimplex.c dsimplex.h \ basename.c dirname.c libgen.h query.c query.h plate.c \ ! demosaic.c demosaic.h skyview.c \ tele_indi.c tele_indi.h camera_indi.c camera_indi.h \ fwheel_indi.c fwheel_indi.h common_indi.c common_indi.h \ Index: psf.c =================================================================== RCS file: /cvsroot/gcx/gcx/src/psf.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** psf.c 28 Sep 2011 06:05:47 -0000 1.17 --- psf.c 8 Oct 2011 06:33:17 -0000 1.18 *************** *** 515,520 **** // ye = ys + ri; g_return_val_if_fail(ri < fr->w, 0); ! for (iy = 0; iy < ri && ys + iy < fr->w; iy++) { ! for (ix = 0; ix < ri && xs + ix < fr->h; ix++) { double dist; dist = sqrt(sqr(ix + xs - x) + sqr(iy + ys - y)); --- 515,520 ---- // ye = ys + ri; g_return_val_if_fail(ri < fr->w, 0); ! for (iy = 0; iy < ri && ys + iy < fr->h; iy++) { ! for (ix = 0; ix < ri && xs + ix < fr->w; ix++) { double dist; dist = sqrt(sqr(ix + xs - x) + sqr(iy + ys - y)); |