atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
curve.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'curve.c'
24*
25* Contains:
26*
27
28 - Functions to manage curves
29
30*
31* List of functions:
32
33 double scale (double axe);
34
35 void prep_plot (Curve * this_curve);
36 void clean_this_curve_window (int cid, int rid);
37 void set_curve_data_zero (int rid, int cid, int interv);
38 void save_curve_ (int * interv, double datacurve[* interv], int * cid, int * rid);
39 void hide_curves (project * this_proj, int c);
40 void remove_this_curve_from_extras (int a, int b, int c);
41 void erase_curves (project * this_proj, int c);
42 void update_curves ();
43 void update_curve (gpointer data);
44
45 curve_dash * selectdash (int iddash);
46
47 Curve * get_curve_from_pointer (gpointer data);
48*/
49
50#include <gtk/gtk.h>
51#include <string.h>
52#include <stdlib.h>
53#include <math.h>
54
55#include "global.h"
56#include "interface.h"
57#include "callbacks.h"
58#include "project.h"
59#include "cedit.h"
60#include "curve.h"
61
62extern void adjust_tool_model (int calc, int curve, gchar * string_path);
63
64gint32 etime;
65int resol[2];
66double XDRAW, YDRAW;
67double DXDRAW, DYDRAW;
68double xmax, ymax;
69double x_min, x_max;
70double y_max, y_min;
71double ax, ay;
72double cxy[2];
73double mticks;
77char * sca;
79
80PangoLayout * layout;
81gboolean dogrid;
85
86// Marge sur X et Y dans les graphs
89char * curve_image_file = NULL;
90
91// Number of dash formats
94
95const double dashed0[] = {0.0, 0.0};
96int len0 = sizeof(dashed0) / sizeof(dashed0[0]);
97
98const double dashed1[] = {1.0, 0.0};
99int len1 = sizeof(dashed1) / sizeof(dashed1[0]);
100
101const double dashed2[] = {5.0, 2.5};
102int len2 = sizeof(dashed2) / sizeof(dashed2[0]);
103
104const double dashed3[] = {4.0, 6.0};
105int len3 = sizeof(dashed3) / sizeof(dashed3[0]);
106
107const double dashed4[] = {2.0, 5.0};
108int len4 = sizeof(dashed4) / sizeof(dashed4[0]);
109
110const double dashed5[] = {10.0, 5.0};
111int len5 = sizeof(dashed5) / sizeof(dashed5[0]);;
112
113const double dashed6[] = {10.0, 10.0};
114int len6 = sizeof(dashed6) / sizeof(dashed6[0]);;
115
116const double dashed7[] = {4.0, 1.0, 4.0};
117int len7 = sizeof(dashed7) / sizeof(dashed7[0]);
118
119const double dashed8[] = {10.0, 2.5, 10.0};
120int len8 = sizeof(dashed8) / sizeof(dashed8[0]);;
121
122const double dashed9[] = {10.0, 5.0, 2.0};
123int len9 = sizeof(dashed9) / sizeof(dashed9[0]);;
124
125const double pdashed[] = {1.0};
126int lenp = 1;
127
135curve_dash * selectdash (int iddash)
136{
137 curve_dash * dashtab;
138 dashtab = g_malloc0(sizeof*dashtab);
139
140 if (iddash == 0)
141 {
142 dashtab -> a = dashed0;
143 dashtab -> b = len0;
144 }
145 if (iddash == 1)
146 {
147 dashtab -> a = dashed1;
148 dashtab -> b = len1;
149 }
150 if (iddash == 2)
151 {
152 dashtab -> a = dashed2;
153 dashtab -> b = len2;
154 }
155 if (iddash == 3)
156 {
157 dashtab -> a = dashed3;
158 dashtab -> b = len3;
159 }
160 if (iddash == 4)
161 {
162 dashtab -> a = dashed4;
163 dashtab -> b = len4;
164 }
165 if (iddash == 5)
166 {
167 dashtab -> a = dashed5;
168 dashtab -> b = len5;
169 }
170 if (iddash == 6)
171 {
172 dashtab -> a = dashed6;
173 dashtab -> b = len6;
174 }
175 if (iddash == 7)
176 {
177 dashtab -> a = dashed7;
178 dashtab -> b = len7;
179 }
180 if (iddash == 8)
181 {
182 dashtab -> a = dashed8;
183 dashtab -> b = len8;
184 }
185 if (iddash == 9)
186 {
187 dashtab -> a = dashed9;
188 dashtab -> b = len9;
189 }
190 if (iddash == 10)
191 {
192 dashtab -> a = pdashed;
193 dashtab -> b = lenp;
194 }
195 return dashtab;
196}
197
205double scale (double axe)
206{
207 double xs;
208 double axis;
209
210 axis = fabs(axe);
211
212 if (axis < 0.0005)
213 {
214 xs=0.00005;
215 }
216 else if (axis < 0.0025)
217 {
218 xs=0.00025;
219 }
220 else if (axis < 0.005)
221 {
222 xs=0.0005;
223 }
224 else if (axis < 0.025)
225 {
226 xs=0.0025;
227 }
228 else if (axis < 0.05)
229 {
230 xs=0.005;
231 }
232 else if (axis < 0.25)
233 {
234 xs=0.025;
235 }
236 else if (axis < 0.5 )
237 {
238 xs=0.05;
239 }
240 else if (axis < 1.5 )
241 {
242 xs=0.1;
243 }
244 else if (axis < 2.5)
245 {
246 xs=0.25;
247 }
248 else if (axis < 5)
249 {
250 xs=0.5;
251 }
252 else if (axis < 15)
253 {
254 xs = 1.0;
255 }
256 else if (axis < 30)
257 {
258 xs = 2.0;
259 }
260 else if (axis < 50)
261 {
262 xs = 5.0;
263 }
264 else if (axis < 100)
265 {
266 xs = 10.0;
267 }
268 else if (axis < 250)
269 {
270 xs = 25.0;
271 }
272 else if (axis < 500)
273 {
274 xs = 50.0;
275 }
276 else if (axis < 1000)
277 {
278 xs = 100.0;
279 }
280 else if (axis < 5000)
281 {
282 xs = 500.0;
283 }
284 else if (axis < 10000)
285 {
286 xs = 1000.0;
287 }
288 else if (axis < 50000)
289 {
290 xs = 5000.0;
291 }
292 else if (axis < 100000)
293 {
294 xs = 10000.0;
295 }
296 else if (axis < 500000)
297 {
298 xs = 50000.0;
299 }
300 else if (axis < 1000000)
301 {
302 xs = 100000.0;
303 }
304 return xs;
305}
306
314{
315 tint * ad = (tint *)data;
316 return get_project_by_id(ad -> a) -> analysis[ad -> b] -> curves[ad -> c];
317}
318
326void prep_plot (Curve * this_curve)
327{
328 x_min = resol[0] * this_curve -> frame_pos[0][0];
329 x_max = resol[0] * this_curve -> frame_pos[0][1];
330 y_max = resol[1] * (1.0 - this_curve -> frame_pos[1][1]);
331 y_max = resol[1] - y_max;
332 y_min = resol[1] * (1.0 - this_curve -> frame_pos[1][0]);
333 y_min = resol[1] - y_min;
334 // The x size of the graph in pixels
335 XDRAW = x_max - x_min;
336// The y size of the graph in pixels
337 YDRAW = y_max - y_min;
338}
339
348void clean_this_curve_window (int cid, int rid)
349{
350 /*if (active_project -> analysis[rid] -> curves[cid] -> window != NULL)
351 {
352 active_project -> analysis[rid] -> curves[cid] -> window = destroy_this_widget (active_project -> analysis[rid] -> curves[cid] -> window);
353 active_project -> analysis[rid] -> curves[cid] -> plot = destroy_this_widget (active_project -> analysis[rid] -> curves[cid] -> plot);
354 }*/
355 if (active_project -> analysis[rid] -> curves[cid] -> ndata > 0)
356 {
357 int i;
358 for (i=0; i<2; i++)
359 {
360 if (active_project -> analysis[rid] -> curves[cid] -> data[i] != NULL)
361 {
362 g_free (active_project -> analysis[rid] -> curves[cid] -> data[i]);
363 active_project -> analysis[rid] -> curves[cid] -> data[i] = NULL;
364 }
365 }
366 }
367 active_project -> analysis[rid] -> curves[cid] -> ndata = 0;
368}
369
379void set_curve_data_zero (int rid, int cid, int interv)
380{
381 active_project -> analysis[rid] -> curves[cid] -> ndata = interv;
382 active_project -> analysis[rid] -> curves[cid] -> data[0] = allocdouble (interv);
383 int i;
384 if (rid != SKT)
385 {
386 for (i=0; i<interv; i++)
387 {
388 active_project -> analysis[rid] -> curves[cid] -> data[0][i] = active_project -> analysis[rid] -> min + i*active_project -> analysis[rid] -> delta;
389 }
390 }
391 else
392 {
393 double delta_omega = (pi/(active_project -> analysis[MSD] -> delta*active_project -> analysis[MSD] -> num_delta)) / active_project -> sqw_freq;
394 for (i=0; i<interv; i++)
395 {
396 active_project -> analysis[rid] -> curves[cid] -> data[0][i] = i*delta_omega;
397 }
398 }
399}
400
411void save_curve_ (int * interv, double datacurve[* interv], int * cid, int * rid)
412{
413 int i, j;
414 Curve * this_curve = active_project -> analysis[* rid] -> curves[* cid];
415#ifdef DEBUG
416 // g_debug ("SAVE_CURVE:: rid= %d, cid= %d, name= %s, interv= %d", * rid, * cid, this_curve -> name, * interv);
417 /*for ( i=0 ; i < *interv ; i++ )
418 {
419 g_debug ("SAVECURVE:: i= %d, data[i]= %f", i, datacurve[i]);
420 }*/
421#endif // DEBUG
422
423 clean_this_curve_window (* cid, * rid);
424 if (* interv != 0)
425 {
426 int inter = (* rid == SPH) ? * interv/2 + 1: * interv;
427 if (* rid == SKD || (* rid == SKT && * cid < active_project -> skt_sets))
428 {
429 this_curve -> ndata = inter;
430 this_curve -> data[0] = duplicate_double (inter, xsk);
431 }
432 else
433 {
434 set_curve_data_zero (* rid, * cid, inter);
435 }
436 if (* rid != SPH)
437 {
438 this_curve -> data[1] = duplicate_double (inter, datacurve);
439 }
440 else
441 {
442 this_curve -> data[1] = allocdouble (inter);
443 for (i=0; i<inter; i++)
444 {
445 this_curve -> data[1][i] = datacurve[i*2];
446 }
447 }
448 for (i=0; i<2; i++)
449 {
450 j = (this_curve -> extrac) ? this_curve -> extrac -> extras : 0;
451 if (this_curve -> extrac) this_curve -> extrac -> extras = 0;
452 autoscale_axis (active_project, this_curve, * rid, * cid, i);
453 if (this_curve -> extrac) this_curve -> extrac -> extras = j;
454 this_curve -> majt[i] = scale (this_curve -> axmax[i] - this_curve -> axmin[i]);
455 this_curve -> mint[i] = 2;
456 }
457 }
458 else
459 {
460 this_curve -> ndata = 0;
461 }
462}
463
472void hide_curves (project * this_proj, int c)
473{
474 int i;
475 for ( i = 0 ; i < this_proj -> analysis[c] -> numc ; i ++ )
476 {
477 if (this_proj -> analysis[c] -> curves[i])
478 {
479 if (this_proj -> analysis[c] -> curves[i] -> window)
480 {
481 if (is_the_widget_visible(this_proj -> analysis[c] -> curves[i] -> window))
482 {
483 hide_the_widgets (this_proj -> analysis[c] -> curves[i] -> window);
484 adjust_tool_model (c, i, this_proj -> analysis[c] -> curves[i] -> path);
485 g_free (this_proj -> analysis[c] -> curves[i] -> path);
486 this_proj -> analysis[c] -> curves[i] -> path = NULL;
487 }
488 }
489 }
490 }
491}
492
502void remove_this_curve_from_extras (int a, int b, int c)
503{
504 int i, j, k, l;
505 project * this_proj;
506 CurveExtra * ctmp;
507 for (i=0; i<nprojects; i++)
508 {
509 if (i != a)
510 {
511 this_proj = get_project_by_id (i);
512 if (this_proj -> analysis)
513 {
514 for (j=0; j<NCALCS; j++)
515 {
516 if (this_proj -> analysis[j])
517 {
518 if (this_proj -> analysis[j] -> idcc != NULL)
519 {
520 for (k=0; k<this_proj -> analysis[j] -> numc; k++)
521 {
522 if (this_proj -> analysis[j] -> curves[k] -> extrac > 0)
523 {
524 ctmp = this_proj -> analysis[j] -> curves[k] -> extrac -> first;
525 for (l=0; l<this_proj -> analysis[j] -> curves[k] -> extrac -> extras; l++)
526 {
527 if (ctmp -> id.a == a && ctmp -> id.b == b && ctmp -> id.c == c)
528 {
529 remove_extra (this_proj -> analysis[j] -> curves[k] -> extrac, ctmp);
530 break;
531 }
532 if (ctmp -> next != NULL) ctmp = ctmp -> next;
533 }
534 }
535 }
536 }
537 }
538 }
539 }
540 }
541 }
542}
543
552void erase_curves (project * this_proj, int c)
553{
554 int i, j;
555 for (i=0 ; i<this_proj -> analysis[c] -> numc; i ++)
556 {
557 if (this_proj -> analysis[c] -> curves[i])
558 {
559 remove_this_curve_from_extras (this_proj -> id, c, i);
560 for (j=0; j<2; j++)
561 {
562 if (this_proj -> analysis[c] -> curves[i] -> data[j])
563 {
564 g_free (this_proj -> analysis[c] -> curves[i] -> data[j]);
565 this_proj -> analysis[c] -> curves[i] -> data[j] = NULL;
566 }
567 if (this_proj -> analysis[c] -> curves[i] -> axis_title[j])
568 {
569 g_free (this_proj -> analysis[c] -> curves[i] -> axis_title[j]);
570 }
571 g_free (this_proj -> analysis[c] -> curves[i] -> labels_font[j]);
572 this_proj -> analysis[c] -> curves[i] -> labels_font[j] = NULL;
573 g_free (this_proj -> analysis[c] -> curves[i] -> axis_title_font[j]);
574 this_proj -> analysis[c] -> curves[i] -> axis_title_font[j] = NULL;
575 }
576 if (this_proj -> analysis[c] -> curves[i] -> name)
577 {
578 g_free (this_proj -> analysis[c] -> curves[i] -> name);
579 this_proj -> analysis[c] -> curves[i] -> name = NULL;
580 }
581 if (this_proj -> analysis[c] -> curves[i] -> title)
582 {
583 g_free (this_proj -> analysis[c] -> curves[i] -> title);
584 this_proj -> analysis[c] -> curves[i] -> title = NULL;
585 }
586 if (this_proj -> analysis[c] -> curves[i] -> title_font)
587 {
588 g_free (this_proj -> analysis[c] -> curves[i] -> title_font);
589 this_proj -> analysis[c] -> curves[i] -> title_font = NULL;
590 }
591 g_free (this_proj -> analysis[c] -> curves[i] -> legend_font);
592 g_free (this_proj -> analysis[c] -> curves[i] -> layout);
593 g_free (this_proj -> analysis[c] -> curves[i] -> extrac);
594 g_free (this_proj -> analysis[c] -> curves[i]);
595 this_proj -> analysis[c] -> curves[i] = NULL;
596 }
597 }
598}
599
606{
607 int i, j, k;
608 project * this_proj;
609 for (i=0; i<nprojects; i++)
610 {
611 this_proj = get_project_by_id(i);
612 for (j=0; j<NCALCS; j++)
613 {
614 for (k=0; k<this_proj -> analysis[j] -> numc; k++)
615 {
616 if (this_proj -> analysis[j] -> curves[k] -> plot != NULL)
617 {
618 if (is_the_widget_visible(this_proj -> analysis[j] -> curves[k] -> plot))
619 {
620 gtk_widget_queue_draw (this_proj -> analysis[j] -> curves[k] -> plot);
621 }
622 }
623 }
624 }
625 }
626}
627
635void update_curve (gpointer data)
636{
637 gtk_widget_queue_draw (get_curve_from_pointer(data) -> plot);
638}
Callback declarations for main window.
Variable declarations for the curve layout edition window.
int tickpos
Definition curve.c:84
int xlog
Definition curve.c:75
void set_curve_data_zero(int rid, int cid, int interv)
initialize curve data
Definition curve.c:379
int len8
Definition curve.c:120
int labpos
Definition curve.c:84
double ay
Definition curve.c:71
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:233
const double dashed9[]
Definition curve.c:122
double cxy[2]
Definition curve.c:72
double DYDRAW
Definition curve.c:67
double xmax
Definition curve.c:68
int ylog
Definition curve.c:75
int dylog
Definition curve.c:76
void save_curve_(int *interv, double datacurve[*interv], int *cid, int *rid)
save calculation results from Fortran90
Definition curve.c:411
void erase_curves(project *this_proj, int c)
free all curve(s) data
Definition curve.c:552
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:205
gint32 etime
Definition curve.c:64
double DXDRAW
Definition curve.c:67
const double dashed3[]
Definition curve.c:104
int resol[2]
Definition curve.c:65
const double dashed0[]
Definition curve.c:95
int len3
Definition curve.c:105
void prep_plot(Curve *this_curve)
prepare curve plot (setting up variables for the plot)
Definition curve.c:326
char * sca
Definition curve.c:77
void hide_curves(project *this_proj, int c)
for project hide all curves for a calculation
Definition curve.c:472
int len4
Definition curve.c:108
int xmarge
Definition curve.c:87
const double dashed1[]
Definition curve.c:98
double YDRAW
Definition curve.c:66
int ymarge
Definition curve.c:88
int len9
Definition curve.c:123
Curve * get_curve_from_pointer(gpointer data)
get Curve pointer from pointer
Definition curve.c:313
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:135
int len6
Definition curve.c:114
double mticks
Definition curve.c:73
const double pdashed[]
Definition curve.c:125
int ndash
Definition curve.c:92
double XDRAW
Definition curve.c:66
int amajt
Definition curve.c:83
double y_max
Definition curve.c:70
double x_max
Definition curve.c:69
void update_curve(gpointer data)
update curve rendering
Definition curve.c:635
gboolean dogrid
Definition curve.c:81
double ax
Definition curve.c:71
const double dashed4[]
Definition curve.c:107
int lenp
Definition curve.c:126
double y_min
Definition curve.c:70
int nglyph
Definition curve.c:93
const double dashed5[]
Definition curve.c:110
const double dashed6[]
Definition curve.c:113
int len0
Definition curve.c:96
void clean_this_curve_window(int cid, int rid)
free curve window data
Definition curve.c:348
const double dashed2[]
Definition curve.c:101
int len1
Definition curve.c:99
int dxlog
Definition curve.c:76
int nticks
Definition curve.c:74
PangoLayout * layout
Definition curve.c:80
int x_shift
Definition curve.c:82
int len2
Definition curve.c:102
int amint
Definition curve.c:83
void remove_this_curve_from_extras(int a, int b, int c)
free all target (a,b,c) curve from other curve(s) extra(s)
Definition curve.c:502
void update_curves()
update all curve(s) rendering for all project(s) in the workspace
Definition curve.c:605
int originp
Definition curve.c:78
double x_min
Definition curve.c:69
const double dashed8[]
Definition curve.c:119
int len5
Definition curve.c:111
char * curve_image_file
Definition curve.c:89
int len7
Definition curve.c:117
double ymax
Definition curve.c:68
const double dashed7[]
Definition curve.c:116
int y_shift
Definition curve.c:82
Variable declarations for the curve widget Functions for interactions with the curve widget.
GtkWidget * majt
#define MARGX
Definition curve.h:54
#define NGLYPHS
Definition curve.h:52
void remove_extra(ExtraSets *sets, CurveExtra *ctmp)
remove data from extra set(s)
Definition m_curve.c:159
void autoscale_axis(project *this_proj, Curve *this_curve, int rid, int cid, int aid)
autoscale axis
Definition yaxis.c:56
#define MARGY
Definition curve.h:55
#define NDASHS
Definition curve.h:50
GtkTreePath * path
Definition datab.c:103
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:595
double pi
Definition global.c:202
double * xsk
Definition global.c:180
int nprojects
Definition global.c:161
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:446
Global variable declarations Global convenience function declarations Global data structure defin...
#define SKT
Definition global.h:347
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
Definition gtk-misc.c:183
#define SPH
Definition global.h:345
#define SKD
Definition global.h:339
#define min(a, b)
Definition global.h:93
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:224
project * active_project
Definition project.c:47
#define NCALCS
#define MSD
Definition global.h:346
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
image * plot
Definition ogl_draw.c:72
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:332
Definition global.h:118