atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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 (project * this_proj, int rid, int cid);
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*/
48
49#include <gtk/gtk.h>
50#include <string.h>
51#include <stdlib.h>
52#include <math.h>
53
54#include "global.h"
55#include "interface.h"
56#include "callbacks.h"
57#include "project.h"
58#include "cedit.h"
59#include "curve.h"
60
61extern void adjust_tool_model (int calc, int curve, gchar * string_path);
62
63gint32 etime;
64int resol[2];
65double XDRAW, YDRAW;
66double DXDRAW, DYDRAW;
67double xmax, ymax;
68double x_min, x_max;
69double y_max, y_min;
70double ax, ay;
71double cxy[2];
72double mticks;
76char * sca;
78
79PangoLayout * layout;
80gboolean dogrid;
84
85// Marge sur X et Y dans les graphs
88char * curve_image_file = NULL;
89
90// Number of dash formats
93
94const double dashed0[] = {0.0, 0.0};
95int len0 = sizeof(dashed0) / sizeof(dashed0[0]);
96
97const double dashed1[] = {1.0, 0.0};
98int len1 = sizeof(dashed1) / sizeof(dashed1[0]);
99
100const double dashed2[] = {5.0, 2.5};
101int len2 = sizeof(dashed2) / sizeof(dashed2[0]);
102
103const double dashed3[] = {4.0, 6.0};
104int len3 = sizeof(dashed3) / sizeof(dashed3[0]);
105
106const double dashed4[] = {2.0, 5.0};
107int len4 = sizeof(dashed4) / sizeof(dashed4[0]);
108
109const double dashed5[] = {10.0, 5.0};
110int len5 = sizeof(dashed5) / sizeof(dashed5[0]);;
111
112const double dashed6[] = {10.0, 10.0};
113int len6 = sizeof(dashed6) / sizeof(dashed6[0]);;
114
115const double dashed7[] = {4.0, 1.0, 4.0};
116int len7 = sizeof(dashed7) / sizeof(dashed7[0]);
117
118const double dashed8[] = {10.0, 2.5, 10.0};
119int len8 = sizeof(dashed8) / sizeof(dashed8[0]);;
120
121const double dashed9[] = {10.0, 5.0, 2.0};
122int len9 = sizeof(dashed9) / sizeof(dashed9[0]);;
123
124const double pdashed[] = {1.0};
125int lenp = 1;
126
134curve_dash * selectdash (int iddash)
135{
136 curve_dash * dashtab;
137 dashtab = g_malloc0 (sizeof*dashtab);
138
139 if (iddash == 0)
140 {
141 dashtab -> a = dashed0;
142 dashtab -> b = len0;
143 }
144 if (iddash == 1)
145 {
146 dashtab -> a = dashed1;
147 dashtab -> b = len1;
148 }
149 if (iddash == 2)
150 {
151 dashtab -> a = dashed2;
152 dashtab -> b = len2;
153 }
154 if (iddash == 3)
155 {
156 dashtab -> a = dashed3;
157 dashtab -> b = len3;
158 }
159 if (iddash == 4)
160 {
161 dashtab -> a = dashed4;
162 dashtab -> b = len4;
163 }
164 if (iddash == 5)
165 {
166 dashtab -> a = dashed5;
167 dashtab -> b = len5;
168 }
169 if (iddash == 6)
170 {
171 dashtab -> a = dashed6;
172 dashtab -> b = len6;
173 }
174 if (iddash == 7)
175 {
176 dashtab -> a = dashed7;
177 dashtab -> b = len7;
178 }
179 if (iddash == 8)
180 {
181 dashtab -> a = dashed8;
182 dashtab -> b = len8;
183 }
184 if (iddash == 9)
185 {
186 dashtab -> a = dashed9;
187 dashtab -> b = len9;
188 }
189 if (iddash == 10)
190 {
191 dashtab -> a = pdashed;
192 dashtab -> b = lenp;
193 }
194 return (dashtab);
195}
196
204double scale (double axe)
205{
206 double xs;
207 double axis;
208
209 axis = fabs(axe);
210
211 if (axis < 0.0005)
212 {
213 xs=0.00005;
214 }
215 else if (axis < 0.0025)
216 {
217 xs=0.00025;
218 }
219 else if (axis < 0.005)
220 {
221 xs=0.0005;
222 }
223 else if (axis < 0.025)
224 {
225 xs=0.0025;
226 }
227 else if (axis < 0.05)
228 {
229 xs=0.005;
230 }
231 else if (axis < 0.25)
232 {
233 xs=0.025;
234 }
235 else if (axis < 0.5 )
236 {
237 xs=0.05;
238 }
239 else if (axis < 1.5 )
240 {
241 xs=0.1;
242 }
243 else if (axis < 2.5)
244 {
245 xs=0.25;
246 }
247 else if (axis < 5)
248 {
249 xs=0.5;
250 }
251 else if (axis < 15)
252 {
253 xs = 1.0;
254 }
255 else if (axis < 30)
256 {
257 xs = 2.0;
258 }
259 else if (axis < 50)
260 {
261 xs = 5.0;
262 }
263 else if (axis < 100)
264 {
265 xs = 10.0;
266 }
267 else if (axis < 250)
268 {
269 xs = 25.0;
270 }
271 else if (axis < 500)
272 {
273 xs = 50.0;
274 }
275 else if (axis < 1000)
276 {
277 xs = 100.0;
278 }
279 else if (axis < 5000)
280 {
281 xs = 500.0;
282 }
283 else if (axis < 10000)
284 {
285 xs = 1000.0;
286 }
287 else if (axis < 50000)
288 {
289 xs = 5000.0;
290 }
291 else if (axis < 100000)
292 {
293 xs = 10000.0;
294 }
295 else if (axis < 500000)
296 {
297 xs = 50000.0;
298 }
299 else if (axis < 1000000)
300 {
301 xs = 100000.0;
302 }
303 return xs;
304}
305
315void prep_plot (project * this_proj, int rid, int cid)
316{
317 x_min = resol[0] * this_proj -> curves[rid][cid] -> frame_pos[0][0];
318 x_max = resol[0] * this_proj -> curves[rid][cid] -> frame_pos[0][1];
319 y_max = resol[1] * (1.0 - this_proj -> curves[rid][cid] -> frame_pos[1][1]);
320 y_max = resol[1] - y_max;
321 y_min = resol[1] * (1.0 - this_proj -> curves[rid][cid] -> frame_pos[1][0]);
322 y_min = resol[1] - y_min;
323
324 // The x size of the graph in pixels
325 XDRAW = x_max - x_min;
326// The y size of the graph in pixels
327 YDRAW = y_max - y_min;
328}
329
338void clean_this_curve_window (int cid, int rid)
339{
340 /*if (active_project -> curves[rid][cid] -> window != NULL)
341 {
342 active_project -> curves[rid][cid] -> window = destroy_this_widget (active_project -> curves[rid][cid] -> window);
343 active_project -> curves[rid][cid] -> plot = destroy_this_widget (active_project -> curves[rid][cid] -> plot);
344 }*/
345 if (active_project -> curves[rid][cid] -> ndata > 0)
346 {
347 int i;
348 for (i=0; i<2; i++)
349 {
350 if (active_project -> curves[rid][cid] -> data[i] != NULL)
351 {
352 g_free (active_project -> curves[rid][cid] -> data[i]);
353 active_project -> curves[rid][cid] -> data[i] = NULL;
354 }
355 }
356 }
357 active_project -> curves[rid][cid] -> ndata = 0;
358}
359
369void set_curve_data_zero (int rid, int cid, int interv)
370{
371 active_project -> curves[rid][cid] -> ndata = interv;
372 active_project -> curves[rid][cid] -> data[0] = allocdouble (interv);
373 int i;
374 for (i=0; i<interv; i++)
375 {
376 active_project -> curves[rid][cid] -> data[0][i] = active_project -> min[rid] + i*active_project -> delta[rid];
377 }
378}
379
390void save_curve_ (int * interv, double datacurve[* interv], int * cid, int * rid)
391{
392 int i, j;
393
394#ifdef DEBUG
395 /*g_debug ("SAVE_CURVE:: rid= %d, cid= %d, name= %s, interv= %d", * rid, * cid, active_project -> curves[* rid][* cid] -> name, * interv);
396 for ( i=0 ; i < *interv ; i++ )
397 {
398 g_debug ("SAVECURVE:: i= %d, data[i]= %f", i, datacurve[i]);
399 }*/
400#endif // DEBUG
401
402 clean_this_curve_window (* cid, * rid);
403 if (* interv != 0)
404 {
405 int inter = (* rid == SP) ? * interv/2 + 1: * interv;
406 if (* rid == SK)
407 {
408 active_project -> curves[* rid][* cid] -> ndata = inter;
409 active_project -> curves[* rid][* cid] -> data[0] = duplicate_double (inter, xsk);
410 }
411 else
412 {
413 set_curve_data_zero (* rid, * cid, inter);
414 }
415 if (* rid != SP)
416 {
417 active_project -> curves[* rid][* cid] -> data[1] = duplicate_double (inter, datacurve);
418 }
419 else
420 {
421 active_project -> curves[* rid][* cid] -> data[1] = allocdouble (inter);
422 for (i=0; i<inter; i++)
423 {
424 active_project -> curves[* rid][* cid] -> data[1][i] = datacurve[i*2];
425 }
426 }
427 for (i=0; i<2; i++)
428 {
429 j = active_project -> curves[* rid][* cid] -> extrac -> extras;
430 active_project -> curves[* rid][* cid] -> extrac -> extras = 0;
431 autoscale_axis (active_project, * rid, * cid, i);
432 active_project -> curves[* rid][* cid] -> extrac -> extras = j;
433 active_project -> curves[* rid][* cid] -> majt[i] = scale (active_project -> curves[* rid][* cid] -> axmax[i] - active_project -> curves[* rid][* cid] -> axmin[i]);
434 active_project -> curves[* rid][* cid] -> mint[i] = 2;
435 }
436 }
437 else
438 {
439 active_project -> curves[* rid][* cid] -> ndata = 0;
440 }
441}
442
451void hide_curves (project * this_proj, int c)
452{
453 int i;
454
455 for ( i = 0 ; i < this_proj -> numc[c] ; i ++ )
456 {
457 if (this_proj -> curves[c][i])
458 {
459 if (this_proj -> curves[c][i] -> window)
460 {
461 if (is_the_widget_visible(this_proj -> curves[c][i] -> window))
462 {
463 hide_the_widgets (this_proj -> curves[c][i] -> window);
464 adjust_tool_model (c, i, this_proj -> curves[c][i] -> path);
465 g_free (this_proj -> curves[c][i] -> path);
466 this_proj -> curves[c][i] -> path = NULL;
467 }
468 }
469 }
470 }
471}
472
482void remove_this_curve_from_extras (int a, int b, int c)
483{
484 int i, j, k, l;
485 project * this_proj;
486 CurveExtra * ctmp;
487 for (i=0; i<nprojects; i++)
488 {
489 if (i != a)
490 {
491 this_proj = get_project_by_id (i);
492 for (j=0; j<NGRAPHS; j++)
493 {
494 if (this_proj -> idcc[j] != NULL)
495 {
496 for (k=0; k<this_proj -> numc[j]; k++)
497 {
498 if (this_proj -> curves[j][k] -> extrac > 0)
499 {
500 ctmp = this_proj -> curves[j][k] -> extrac -> first;
501 for (l=0; l<this_proj -> curves[j][k] -> extrac -> extras; l++)
502 {
503 if (ctmp -> id.a == a && ctmp -> id.b == b && ctmp -> id.c == c)
504 {
505 remove_extra (this_proj -> curves[j][k] -> extrac, ctmp);
506 break;
507 }
508 if (ctmp -> next != NULL) ctmp = ctmp -> next;
509 }
510 }
511 }
512 }
513 }
514 }
515 }
516}
517
526void erase_curves (project * this_proj, int c)
527{
528 int i, j;
529
530 for (i=0 ; i<this_proj -> numc[c]; i ++)
531 {
532 if (this_proj -> curves[c][i])
533 {
534 remove_this_curve_from_extras (this_proj -> id, c, i);
535 for (j=0; j<2; j++)
536 {
537 if (this_proj -> curves[c][i] -> data[j])
538 {
539 free (this_proj -> curves[c][i] -> data[j]);
540 this_proj -> curves[c][i] -> data[j] = NULL;
541 }
542 }
543 if (this_proj -> curves[c][i] -> name)
544 {
545 g_free (this_proj -> curves[c][i] -> name);
546 this_proj -> curves[c][i] -> name = NULL;
547 }
548 g_free (this_proj -> curves[c][i]);
549 this_proj -> curves[c][i] = NULL;
550 }
551 }
552}
553
560{
561 int i, j, k;
562 project * this_proj;
563 for (i=0; i<nprojects; i++)
564 {
565 this_proj = get_project_by_id(i);
566 for (j=0; j<NGRAPHS; j++)
567 {
568 for (k=0; k<this_proj -> numc[j]; k++)
569 {
570 if (this_proj -> curves[j][k] -> plot != NULL)
571 {
572 if (is_the_widget_visible(this_proj -> curves[j][k] -> plot))
573 {
574 gtk_widget_queue_draw (this_proj -> curves[j][k] -> plot);
575 }
576 }
577 }
578 }
579 }
580}
581
589void update_curve (gpointer data)
590{
591 tint * cd = (tint *)data;
592 gtk_widget_queue_draw (get_project_by_id(cd -> a) -> curves[cd -> b][cd -> c] -> plot);
593}
Callback declarations for main window.
Variable declarations for the curve layout edition window.
gchar * axis[3]
Definition w_axis.c:65
int tickpos
Definition curve.c:83
int xlog
Definition curve.c:74
void set_curve_data_zero(int rid, int cid, int interv)
initialize curve data
Definition curve.c:369
int len8
Definition curve.c:119
int labpos
Definition curve.c:83
double ay
Definition curve.c:70
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:216
const double dashed9[]
Definition curve.c:121
double cxy[2]
Definition curve.c:71
double DYDRAW
Definition curve.c:66
double xmax
Definition curve.c:67
int ylog
Definition curve.c:74
int dylog
Definition curve.c:75
void save_curve_(int *interv, double datacurve[*interv], int *cid, int *rid)
save calculation results from Fortran90
Definition curve.c:390
void erase_curves(project *this_proj, int c)
free all curve(s) data
Definition curve.c:526
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:204
gint32 etime
Definition curve.c:63
double DXDRAW
Definition curve.c:66
const double dashed3[]
Definition curve.c:103
int resol[2]
Definition curve.c:64
const double dashed0[]
Definition curve.c:94
int len3
Definition curve.c:104
char * sca
Definition curve.c:76
void hide_curves(project *this_proj, int c)
for project hide all curves for a calculation
Definition curve.c:451
void prep_plot(project *this_proj, int rid, int cid)
prepare curve plot (setting up variables for the plot)
Definition curve.c:315
int len4
Definition curve.c:107
int xmarge
Definition curve.c:86
const double dashed1[]
Definition curve.c:97
double YDRAW
Definition curve.c:65
int ymarge
Definition curve.c:87
int len9
Definition curve.c:122
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:134
int len6
Definition curve.c:113
double mticks
Definition curve.c:72
const double pdashed[]
Definition curve.c:124
int ndash
Definition curve.c:91
double XDRAW
Definition curve.c:65
int amajt
Definition curve.c:82
double y_max
Definition curve.c:69
double x_max
Definition curve.c:68
void update_curve(gpointer data)
update curve rendering
Definition curve.c:589
gboolean dogrid
Definition curve.c:80
double ax
Definition curve.c:70
const double dashed4[]
Definition curve.c:106
int lenp
Definition curve.c:125
double y_min
Definition curve.c:69
int nglyph
Definition curve.c:92
const double dashed5[]
Definition curve.c:109
const double dashed6[]
Definition curve.c:112
int len0
Definition curve.c:95
void clean_this_curve_window(int cid, int rid)
free curve window data
Definition curve.c:338
const double dashed2[]
Definition curve.c:100
int len1
Definition curve.c:98
int dxlog
Definition curve.c:75
int nticks
Definition curve.c:73
PangoLayout * layout
Definition curve.c:79
int x_shift
Definition curve.c:81
int len2
Definition curve.c:101
int amint
Definition curve.c:82
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:482
void update_curves()
update all curve(s) rendering for all project(s) in the workspace
Definition curve.c:559
int originp
Definition curve.c:77
double x_min
Definition curve.c:68
const double dashed8[]
Definition curve.c:118
int len5
Definition curve.c:110
char * curve_image_file
Definition curve.c:88
int len7
Definition curve.c:116
double ymax
Definition curve.c:67
const double dashed7[]
Definition curve.c:115
int y_shift
Definition curve.c:81
Variable declarations for the curve widget Functions for interactions with the curve widget.
GtkWidget * majt
Definition tab-4.c:103
#define MARGX
Definition curve.h:54
void autoscale_axis(project *this_proj, int rid, int cid, int aid)
autoscale axis
Definition yaxis.c:55
#define NGLYPHS
Definition curve.h:52
void remove_extra(ExtraSets *sets, CurveExtra *ctmp)
remove data from extra set(s)
Definition m_curve.c:160
#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:608
double * xsk
Definition global.c:176
int nprojects
Definition global.c:158
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:459
Global variable declarations Global convenience function declarations Global data structure defin...
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
Definition gtk-misc.c:714
#define NGRAPHS
#define min(a, b)
Definition global.h:81
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
#define SK
Definition global.h:324
#define SP
Definition global.h:330
project * active_project
Definition project.c:47
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
image * plot
Definition ogl_draw.c:66
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition global.h:104
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95