* Compiles but segfaults.
[scdataviz] / scdataviz.c
1 /*
2 ** scdataviz.c
3 ** 
4 ** Made by (Johnny Q. Hacker)
5 ** Login   <solarion@johnathan>
6 ** 
7 ** Holds the SC graphing widget.
8
9
10
11     Copyright (C) 2008 Joseph Pingenot
12
13     This program is free software: you can redistribute it and/or modify
14     it under the terms of the GNU Affero General Public License as published by
15     the Free Software Foundation, either version 3 of the License, or
16     (at your option) any later version.
17
18     This program is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21     GNU Affero General Public License for more details.
22
23     You should have received a copy of the GNU Affero General Public License
24     along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26 ** Started on  Thu Jul 17 11:03:27 2008 Johnny Q. Hacker
27 ** Last update Sun May 12 01:17:25 2002 Speed Blue
28 */
29
30 #include <gtk/gtk.h>
31 #include <graphwidget.h>
32 #include <matdb-dotcode.h>
33
34 #undef DEBUG
35
36 struct xy_properties {
37   GString *xprop;
38   GString *yprop;
39   Graph *graph;
40 };
41
42
43 static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
44   struct xy_properties *propmap = user_data;
45   struct matdb_material *mat = value;
46   if(!strcasecmp(mat->name->str, "vacuum")) return;
47   if(!strcasecmp(mat->name->str, "pvb")) return;
48   double *x, *y;
49   #ifdef DEBUG
50   fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str);
51   #endif
52   if(((x=g_hash_table_lookup(mat->properties, propmap->xprop->str)) != NULL)
53      && ((y=g_hash_table_lookup(mat->properties, propmap->yprop->str)) != NULL)) {
54     graph_add_point(propmap->graph, *x, *y, mat->name);
55   #ifdef DEBUG
56     fprintf(stderr, "added (x->%s=%g, y->%s=%g)\n", propmap->xprop->str, *x, propmap->yprop->str, *y);
57   }else{
58     fprintf(stderr, "no such properties (x->%s, y->%s)\n", propmap->xprop->str, propmap->yprop->str);
59   #endif
60   }
61 }
62
63 int main(int   argc, char *argv[]) 
64 {
65     GtkWidget *window;
66     GtkWidget *graph;
67     GString *file = g_string_new("../matdb");
68     int err=0;
69     struct matdb *mdb = read_matdb_dotcode(file, &err);
70     //fprintf(stderr, "read_matdb_dotcode(%s, %d)=%x", file->str, err,
71     //(int)mdb);
72     fprintf(stderr, "err=%d\n", err);
73     //print_matdb(mdb);
74     
75     gtk_init (&argc, &argv);
76     
77     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
78     graph = graph_widget_new();
79
80     struct xy_properties propmap;
81     propmap.xprop = g_string_new("a_lc");
82     propmap.yprop = g_string_new("E_g_Gamma");
83     propmap.graph = graph_widget_get_graph(GRAPH_WIDGET(graph));
84     g_hash_table_foreach(mdb->materials, &put_mat_in_graph, &propmap);
85     graph_add_linear_connectors(propmap.graph);
86
87
88     //Connect signals
89     g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
90
91     gtk_container_add(GTK_CONTAINER(window), graph);
92     /*
93     graph_add_point(graph_widget_get_graph(graph), 5, 3);
94     graph_add_point(graph_widget_get_graph(graph), 8, 12);
95     graph_add_point(graph_widget_get_graph(graph), 11, 48);
96     */
97     
98     gtk_widget_show_all  (window);
99     
100     gtk_main ();
101     
102     return 0;
103 }