atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
global.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
23/*
24* This file: 'global.c'
25*
26* Contains:
27*
28
29 - global variables declarations
30 - global convenience functions implementation
31
32*
33* List of functions:
34
35 int * allocint (int val);
36 int ** allocdint (int xal, int yal);
37 int *** alloctint (int xal, int yal, int zal);
38 int **** allocqint (int wal, int xal, int yal, int zal);
39 int * duplicate_int (int num, int * old_val);
40
41 float * allocfloat (int val);
42 float ** allocdfloat (int xal, int yal);
43 float *** alloctfloat (int xal, int yal, int zal);
44 float * duplicate_float (int num, float * old_val);
45
46 double * allocdouble (int val);
47 double ** allocddouble (int xal, int yal);
48 double *** alloctdouble (int xal, int yal, int zal);
49 double **** allocqdouble (int wal, int xal, int yal, int zal);
50 double * duplicate_double (int num, double * old_val);
51 double get_calc_time (struct timespec start, struct timespec stop);
52
53 gboolean * allocbool (int val);
54 gboolean ** allocdbool (int xal, int yal);
55 gboolean *** alloctbool (int xal, int yal, int zal);
56 gboolean * duplicate_bool (int num, gboolean * old_val);
57
58 gchar ** duplicate_strings (int num, gchar ** old_val);
59 gchar * calculation_time (gboolean modelv, double ctime);
60
61*/
62
63#include <stdio.h>
64#include <stdlib.h>
65#include <sys/types.h>
66#include <sys/stat.h>
67
68#include <gtk/gtk.h>
69#include <gdk/gdk.h>
70
71#define BILLION 1000000000L;
72
73#ifdef G_OS_WIN32
74gchar * PACKAGE_PREFIX = NULL;
75gchar * PACKAGE_LIB_DIR = NULL;
76gchar * PACKAGE_DATA_DIR = NULL;
77gchar * PACKAGE_LOCALE_DIR = NULL;
78gchar * PACKAGE_IMP = NULL;
79gchar * PACKAGE_CON = NULL;
80gchar * PACKAGE_IMG = NULL;
81gchar * PACKAGE_PDF = NULL;
82gchar * PACKAGE_SVG = NULL;
83gchar * PACKAGE_EPS = NULL;
84gchar * PACKAGE_PNG = NULL;
85gchar * PACKAGE_JPG = NULL;
86gchar * PACKAGE_BMP = NULL;
87gchar * PACKAGE_TIFF = NULL;
88gchar * PACKAGE_VOID = NULL;
89gchar * PACKAGE_GR = NULL;
90gchar * PACKAGE_SQ = NULL;
91gchar * PACKAGE_BD = NULL;
92gchar * PACKAGE_AN = NULL;
93gchar * PACKAGE_RI = NULL;
94gchar * PACKAGE_CH = NULL;
95gchar * PACKAGE_SP = NULL;
96gchar * PACKAGE_MS = NULL;
97gchar * PACKAGE_TD = NULL;
98gchar * PACKAGE_MOL = NULL;
99gchar * PACKAGE_OGL = NULL;
100gchar * PACKAGE_OGLM = NULL;
101gchar * PACKAGE_OGLC = NULL;
102gchar * PACKAGE_PRO = NULL;
103gchar * PACKAGE_SET = NULL;
104gchar * PACKAGE_LOGO = NULL;
105gchar * PACKAGE_LAGPL = NULL;
106gchar * PACKAGE_LABOUT = NULL;
107gchar * PACKAGE_DOTA = NULL;
108gchar * PACKAGE_DOTB = NULL;
109gchar * PACKAGE_DOTC = NULL;
110gchar * PACKAGE_DOTD = NULL;
111gchar * PACKAGE_DOTE = NULL;
112gchar * PACKAGE_DOTF = NULL;
113gchar * PACKAGE_DOTG = NULL;
114gchar * PACKAGE_DOTH = NULL;
115gchar * PACKAGE_DFBD = NULL;
116gchar * PACKAGE_DFAN = NULL;
117gchar * PACKAGE_DFDI = NULL;
118gchar * PACKAGE_DFTD = NULL;
119gchar * PACKAGE_DFIN = NULL;
120gchar * PACKAGE_SGCP = NULL;
121gchar * PACKAGE_SGCI = NULL;
122gchar * PACKAGE_SGCF = NULL;
123gchar * PACKAGE_SGHP = NULL;
124gchar * PACKAGE_SGTR = NULL;
125gchar * PACKAGE_SGTI = NULL;
126gchar * PACKAGE_SGTP = NULL;
127gchar * PACKAGE_SGOP = NULL;
128gchar * PACKAGE_SGOI = NULL;
129gchar * PACKAGE_SGOC = NULL;
130gchar * PACKAGE_SGOF = NULL;
131gchar * PACKAGE_SGMP = NULL;
132gchar * PACKAGE_SGMI = NULL;
133gchar * PACKAGE_SGTC = NULL;
134#endif
135gchar * ATOMES_CONFIG = NULL;
136gchar * ATOMES_URL = "https://atomes.ipcms.fr";
137gchar * mode_name[2]={"Analysis", "Edition"};
138gchar * bravais_img[14];
139gchar * ifield[8];
140gchar * projfile = NULL;
141char * ifbug="\nIf this is a bug please report it to:";
142
143char * rings_type[5] = {"All (No rules)",
144 "King's",
145 "Guttman's",
146 "Primitive",
147 "Strong"};
148
149char * untime[6] = {"fs",
150 "ps",
151 "ns",
152 "µs",
153 "ms",
154 " "};
155
156gchar * workspacefile = NULL;
157
158int nprojects = 0;
159int activep = 0;
160int activev = 0;
161int activef = 0;
162int inactep = 0;
163int activew = 0;
165int atomes_visual = 1; // OpenGL visual: 1 = GTK default, 0 = X11 default (GTK3 + GtkGLArea only), -1 = no OpenGL
166// Loop Id for the dialogs
167int dialog_id = -1;
168
172
174int * pasted_todo = NULL;
175
176double * xsk = NULL;
177
178GMainLoop * Event_loop[5];
179
180gboolean in_movie_encoding = FALSE;
181gboolean newspace = TRUE;
183gboolean tmp_adv_bonding[2];
184gboolean column_label = FALSE;
185gboolean check_label = TRUE;
186gboolean object_motion = FALSE;
187gboolean selected_status = FALSE;
188gboolean silent_input = FALSE;
190
191struct timespec start_time;
192struct timespec stop_time;
193
194double opac = 0.75;
195double pi = 3.141592653589793238462643383279502884197;
196
197gchar * edition_action_names[3] = {"edit.chemistry",
198 "edit.periodicity",
199 "edit.cutoffs"};
200
201gchar * analyze_action_names[9] = {"analyze.gr",
202 "analyze.sq",
203 "analyze.sk",
204 "analyze.gk",
205 "analyze.bonds",
206 "analyze.rings",
207 "analyze.chains",
208 "analyze.sp",
209 "analyze.msd"};
210GSimpleAction * edition_actions[3];
211GSimpleAction * analyze_actions[9];
212
213GtkApplication * AtomesApp = NULL;
214GtkWidget * MainWindow = NULL;
215GtkWidget * MainView = NULL;
216GtkWidget * MainFrame[2];
217GtkWidget * pop = NULL;
218GtkWidget * curvetoolbox = NULL;
219GtkWidget * progressbar = NULL;
220GtkWidget * MainScrol[2];
221GtkWidget * atomes_logo = NULL;
222GtkWidget * calc_dialog = NULL;
223GtkWidget * register_button = NULL;
224
225GtkTextTag * tag = NULL;
226GtkStatusbar * statusbar;
227
228GdkPixbuf * THETD = NULL;
229GdkPixbuf * THEMO = NULL;
230GdkPixbuf * THEBD = NULL;
231GdkPixbuf * SETTING = NULL;
232GdkPixbuf * SETTINGS = NULL;
233GdkPixbuf * OGL = NULL;
234GdkPixbuf * OGLM = NULL;
235GdkPixbuf * OGLC = NULL;
236GdkPixbuf * RUN = NULL;
237
238// Basic utility functions
239
266gboolean * allocbool (int val)
267{
268 gboolean * var = NULL;
269
270 var = g_malloc0 (val*sizeof*var);
271 return var;
272}
273
282gboolean ** allocdbool (int xal, int yal)
283{
284 gboolean ** var = NULL;
285 int i;
286
287 var = g_malloc (xal*sizeof*var);
288 for ( i = 0 ; i < xal ; i ++ )
289 {
290 /* allocation d'un tableau de tableau */
291 var[i] = allocbool(yal);
292 }
293 return var;
294}
295
305gboolean *** alloctbool (int xal, int yal, int zal)
306{
307 gboolean *** var = NULL;
308 int i;
309
310 var = g_malloc (xal*sizeof*var);
311 for ( i = 0 ; i < xal ; i ++ )
312 {
313 /* allocation d'un tableau de tableau */
314 var[i] = allocdbool(yal, zal);
315 }
316 return var;
317}
318
326int * allocint (int val)
327{
328 int * var = NULL;
329
330 var = g_malloc0 (val*sizeof*var);
331 return var;
332}
333
342int ** allocdint (int xal, int yal)
343{
344 int ** var = NULL;
345 int i;
346
347 var = g_malloc (xal*sizeof*var);
348 for ( i = 0 ; i < xal ; i ++ )
349 {
350 /* allocation d'un tableau de tableau */
351 var[i] = allocint(yal);
352 }
353 return var;
354}
355
365int *** alloctint (int xal, int yal, int zal)
366{
367 int *** var = NULL;
368 int i;
369
370 var = g_malloc (xal*sizeof*var);
371 for ( i = 0 ; i < xal ; i ++ )
372 {
373 /* allocation d'un tableau de tableau */
374 var[i] = allocdint(yal, zal);
375 }
376 return var;
377}
378
389int **** allocqint (int wal, int xal, int yal, int zal)
390{
391 int **** var = NULL;
392 int i;
393
394 var = g_malloc (wal*sizeof*var);
395 for ( i = 0 ; i < wal ; i ++ )
396 {
397 /* allocation d'un tableau de tableau */
398 var[i] = alloctint(xal, yal, zal);
399 }
400 return var;
401}
402
410float * allocfloat (int val)
411{
412 float * var = NULL;
413
414 var = g_malloc0 (val*sizeof*var);
415 return var;
416}
417
426float ** allocdfloat (int xal, int yal)
427{
428 float ** var = NULL;
429 int i;
430
431 var = g_malloc (xal*sizeof*var);
432 for ( i = 0 ; i < xal ; i ++ )
433 {
434 /* allocation d'un tableau de tableau */
435 var[i] = allocfloat(yal);
436 }
437 return var;
438}
439
449float *** alloctfloat (int xal, int yal, int zal)
450{
451 float *** var = NULL;
452 int i;
453
454 var = g_malloc (xal*sizeof*var);
455 for ( i = 0 ; i < xal ; i ++ )
456 {
457 /* allocation d'un tableau de tableau */
458 var[i] = allocdfloat (yal, zal);
459 }
460 return var;
461}
462
463
471double * allocdouble (int val)
472{
473 double * var = NULL;
474
475 var = g_malloc0 (val*sizeof*var);
476 return var;
477}
478
487double ** allocddouble (int xal, int yal)
488{
489 double ** var = NULL;
490 int i;
491
492 var = g_malloc (xal*sizeof*var);
493 for ( i = 0 ; i < xal ; i ++ )
494 {
495 /* allocation d'un tableau de tableau */
496 var[i] = allocdouble (yal);
497 }
498 return var;
499}
500
510double *** alloctdouble (int xal, int yal, int zal)
511{
512 double *** var = NULL;
513 int i;
514
515 var = g_malloc (xal*sizeof*var);
516 for ( i = 0 ; i < xal ; i ++ )
517 {
518 /* allocation d'un tableau de tableau */
519 var[i] = allocddouble (yal, zal);
520 }
521 return var;
522}
523
534double **** allocqdouble (int wal, int xal, int yal, int zal)
535{
536 double **** var = NULL;
537 int i;
538
539 var = g_malloc (wal*sizeof*var);
540 for ( i = 0 ; i < wal ; i ++ )
541 {
542 /* allocation d'un tableau de tableau */
543 var[i] = alloctdouble (xal, yal, zal);
544 }
545 return var;
546}
547
556gchar ** duplicate_strings (int num, gchar ** old_val)
557{
558 gchar ** new_val = g_malloc0 (num*sizeof*new_val);
559 int i;
560 for (i=0; i<num; i++) new_val[i] = g_strdup_printf ("%s", old_val[i]);
561 return new_val;
562}
563
572int * duplicate_int (int num, int * old_val)
573{
574 int * new_val = allocint (num);
575 int i;
576 for (i=0; i<num; i++) new_val[i] = old_val[i];
577 return new_val;
578}
579
588gboolean * duplicate_bool (int num, gboolean * old_val)
589{
590 gboolean * new_val = allocbool (num);
591 int i;
592 for (i=0; i<num; i++) new_val[i] = old_val[i];
593 return new_val;
594}
595
604float * duplicate_float (int num, float * old_val)
605{
606 float * new_val = allocfloat (num);
607 int i;
608 for (i=0; i<num; i++) new_val[i] = old_val[i];
609 return new_val;
610}
611
620double * duplicate_double (int num, double * old_val)
621{
622 double * new_val = allocdouble (num);
623 int i;
624 for (i=0; i<num; i++) new_val[i] = old_val[i];
625 return new_val;
626}
627
636double get_calc_time (struct timespec start, struct timespec stop)
637{
638 return (double)(stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec)/BILLION;
639}
640
649gchar * calculation_time (gboolean modelv, double ctime)
650{
651 int i, j, k;
652 gchar * t_string = (modelv) ? "\n \tAnalysis was performed in: ": "";
653 if (ctime < 60.0)
654 {
655 return g_strdup_printf ("%s%f s", t_string, ctime);
656 }
657 else if (ctime < 3600.0)
658 {
659 i = ctime/60.0;
660 return g_strdup_printf ("%s%d m %f s", t_string, i, ctime-i*60.0);
661 }
662 else if (ctime < 86400.0)
663 {
664 // Really ?!
665 i = ctime/3600.0;
666 j = (ctime - i*3600.0)/60.0;
667 return g_strdup_printf ("%s%d h %d m %f s", t_string, i, j, ctime-i*3600.0-j*60.0);
668 }
669 else
670 {
671 // Seriously ?!
672 i = ctime/86400.0;
673 j = (ctime - i*86400.0)/3600.0;
674 k = (ctime - i*86400.0 - j*3600.0)/60.0;
675 return g_strdup_printf ("%s%d d %d h %d m %f s", t_string, i, j, k, ctime-i*86400.0-j*3600.0-k*60.0);
676 }
677}
float val
Definition dlp_init.c:117
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:342
gboolean reading_input
Definition global.c:182
double **** allocqdouble(int wal, int xal, int yal, int zal)
allocate a double **** pointer
Definition global.c:534
gchar * ATOMES_CONFIG
Definition global.c:135
char * untime[6]
Definition global.c:149
float ** allocdfloat(int xal, int yal)
allocate a float ** pointer
Definition global.c:426
GtkStatusbar * statusbar
Definition global.c:226
GtkWidget * register_button
Definition global.c:223
int mol_update
Definition global.c:171
gchar * workspacefile
Definition global.c:156
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:620
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:572
int *** alloctint(int xal, int yal, int zal)
allocate an int *** pointer
Definition global.c:365
char * ifbug
Definition global.c:141
gchar * edition_action_names[3]
Definition global.c:197
gchar * analyze_action_names[9]
Definition global.c:201
double pi
Definition global.c:195
#define BILLION
Definition global.c:71
gboolean newspace
Definition global.c:181
int dialog_id
Definition global.c:167
char * rings_type[5]
Definition global.c:143
GtkTextTag * tag
Definition global.c:225
GtkWidget * MainScrol[2]
Definition global.c:220
struct timespec start_time
Definition global.c:191
int activep
Definition global.c:159
GSimpleAction * edition_actions[3]
Definition global.c:210
int * pasted_todo
Definition global.c:174
int inactep
Definition global.c:162
gboolean in_movie_encoding
Definition global.c:180
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:266
double * xsk
Definition global.c:176
int activef
Definition global.c:161
gboolean tmp_adv_bonding[2]
Definition global.c:183
GdkPixbuf * OGLC
Definition global.c:235
GMainLoop * Event_loop[5]
Definition global.c:178
gboolean silent_input
Definition global.c:188
double ** allocddouble(int xal, int yal)
allocate a double ** pointer
Definition global.c:487
int activew
Definition global.c:163
GtkApplication * AtomesApp
Definition global.c:213
int nprojects
Definition global.c:158
GtkWidget * MainFrame[2]
Definition global.c:216
int activev
Definition global.c:160
gboolean selected_status
Definition global.c:187
int frag_update
Definition global.c:170
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:471
GtkWidget * MainWindow
Definition global.c:214
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:649
GdkPixbuf * OGLM
Definition global.c:234
gboolean column_label
Definition global.c:184
gchar * projfile
Definition global.c:140
gchar ** duplicate_strings(int num, gchar **old_val)
copy a list of strings
Definition global.c:556
gchar * ATOMES_URL
Definition global.c:136
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:604
int bonds_update
Definition global.c:169
gboolean * duplicate_bool(int num, gboolean *old_val)
copy a list of gboolean
Definition global.c:588
GdkPixbuf * SETTINGS
Definition global.c:232
gboolean check_label
Definition global.c:185
double *** alloctdouble(int xal, int yal, int zal)
allocate a double *** pointer
Definition global.c:510
double opac
Definition global.c:194
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
gchar * mode_name[2]
Definition global.c:137
GdkPixbuf * THEBD
Definition global.c:230
gboolean object_motion
Definition global.c:186
GdkPixbuf * OGL
Definition global.c:233
gboolean *** alloctbool(int xal, int yal, int zal)
allocate a gboolean *** pointer
Definition global.c:305
GdkPixbuf * RUN
Definition global.c:236
GdkPixbuf * THETD
Definition global.c:228
gboolean ** allocdbool(int xal, int yal)
allocate a gboolean ** pointer
Definition global.c:282
GtkWidget * atomes_logo
Definition global.c:221
GtkWidget * progressbar
Definition global.c:219
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:636
GdkPixbuf * SETTING
Definition global.c:231
int atomes_visual
Definition global.c:165
int **** allocqint(int wal, int xal, int yal, int zal)
allocate an int **** pointer
Definition global.c:389
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:410
struct timespec stop_time
Definition global.c:192
gchar * bravais_img[14]
Definition global.c:138
int statusval
Definition global.c:164
gboolean cif_use_symmetry_positions
Definition global.c:189
GSimpleAction * analyze_actions[9]
Definition global.c:211
GtkWidget * curvetoolbox
Definition global.c:218
GdkPixbuf * THEMO
Definition global.c:229
GtkWidget * pop
Definition global.c:217
gchar * ifield[8]
Definition global.c:139
float *** alloctfloat(int xal, int yal, int zal)
allocate a float *** pointer
Definition global.c:449
GtkWidget * calc_dialog
Definition global.c:222
int tmp_pixels[2]
Definition global.c:173
GtkWidget * MainView
Definition global.c:215