atomes 1.3.1
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-2026 by CNRS and University of Strasbourg */
15
22
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 string_to_double (gpointer string);
52 double get_calc_time (struct timespec start, struct timespec stop);
53
54 gboolean * allocbool (int val);
55 gboolean ** allocdbool (int xal, int yal);
56 gboolean *** alloctbool (int xal, int yal, int zal);
57 gboolean * duplicate_bool (int num, gboolean * old_val);
58
59 gchar ** duplicate_strings (int num, gchar ** old_val);
60 gchar * calculation_time (gboolean modelv, double ctime);
61
62*/
63
64#include <libintl.h>
65#include <locale.h>
66#ifdef OSX
67#include <xlocale.h>
68#endif
69#include <glib.h>
70#include <glib/gi18n.h>
71
72#include <stdio.h>
73#include <stdlib.h>
74#include <sys/types.h>
75#include <sys/stat.h>
76
77#include <gtk/gtk.h>
78#include <gdk/gdk.h>
79
80#define i18n(String) String
81
82#define BILLION 1000000000L;
83
84#ifdef G_OS_WIN32
85gchar * PACKAGE_PREFIX = NULL;
86gchar * PACKAGE_LIBEXEC = NULL;
87gchar * PACKAGE_LOCALE = NULL;
88#endif
89gchar * PACKAGE_LIB_DIR = NULL;
90gchar * PACKAGE_IMP = NULL;
91gchar * PACKAGE_CON = NULL;
92gchar * PACKAGE_IMG = NULL;
93gchar * PACKAGE_PDF = NULL;
94gchar * PACKAGE_SVG = NULL;
95gchar * PACKAGE_EPS = NULL;
96gchar * PACKAGE_PNG = NULL;
97gchar * PACKAGE_JPG = NULL;
98gchar * PACKAGE_BMP = NULL;
99gchar * PACKAGE_TIFF = NULL;
100gchar * PACKAGE_VOID = NULL;
101gchar * PACKAGE_TD = NULL;
102gchar * PACKAGE_MOL = NULL;
103gchar * PACKAGE_OGL = NULL;
104gchar * PACKAGE_OGLM = NULL;
105gchar * PACKAGE_OGLC = NULL;
106gchar * PACKAGE_PRO = NULL;
107gchar * PACKAGE_SET = NULL;
108gchar * PACKAGE_LOGO = NULL;
109gchar * PACKAGE_LAGPL = NULL;
110gchar * PACKAGE_LABOUT = NULL;
111gchar * PACKAGE_DOTA = NULL;
112gchar * PACKAGE_DOTB = NULL;
113gchar * PACKAGE_DOTC = NULL;
114gchar * PACKAGE_DOTD = NULL;
115gchar * PACKAGE_DOTE = NULL;
116gchar * PACKAGE_DOTF = NULL;
117gchar * PACKAGE_DOTG = NULL;
118gchar * PACKAGE_DOTH = NULL;
119gchar * PACKAGE_DFBD = NULL;
120gchar * PACKAGE_DFAN = NULL;
121gchar * PACKAGE_DFDI = NULL;
122gchar * PACKAGE_DFTD = NULL;
123gchar * PACKAGE_DFIN = NULL;
124gchar * PACKAGE_SGCP = NULL;
125gchar * PACKAGE_SGCI = NULL;
126gchar * PACKAGE_SGCF = NULL;
127gchar * PACKAGE_SGHP = NULL;
128gchar * PACKAGE_SGTR = NULL;
129gchar * PACKAGE_SGTI = NULL;
130gchar * PACKAGE_SGTP = NULL;
131gchar * PACKAGE_SGOP = NULL;
132gchar * PACKAGE_SGOI = NULL;
133gchar * PACKAGE_SGOC = NULL;
134gchar * PACKAGE_SGOF = NULL;
135gchar * PACKAGE_SGMP = NULL;
136gchar * PACKAGE_SGMI = NULL;
137gchar * PACKAGE_SGTC = NULL;
138gchar * ATOMES_CONFIG_DIR = NULL;
139gchar * ATOMES_CONFIG = NULL;
140gchar * ATOMES_URL = "https://atomes.ipcms.fr";
141gchar * mode_name[2] = {i18n("Analysis"), i18n("Edition")};
142gchar * bravais_img[14];
143gchar * ifield[8];
144gchar * projfile = NULL;
145char * ifbug = i18n("\nIf this is a bug please report it to:");
146
147char * rings_type[5] = {i18n("All (No Rule)"),
148 i18n("King's"),
149 i18n("Guttman's"),
150 i18n("Primitive"),
151 i18n("Strong")};
152
153char * untime[5] = {"fs",
154 "ps",
155 "ns",
156 "µs",
157 "ms"};
158
159gchar * workspacefile = NULL;
160
161int nprojects = 0;
162int activep = 0;
163int activev = 0;
164int activef = 0;
165int inactep = 0;
166int activew = 0;
168int atomes_visual = 1; // OpenGL visual: 1 = GTK default, 0 = X11 default (GTK3 + GtkGLArea only), Else = no OpenGL
169// Loop Id for the dialogs
170int dialog_id = -1;
171
176
178int * pasted_todo = NULL;
179
180double * xsk = NULL;
181
182GMainLoop * Event_loop[5];
183
184gboolean in_movie_encoding = FALSE;
185gboolean newspace = TRUE;
187gboolean tmp_adv_bonding[2];
188gboolean column_label = FALSE;
189gboolean check_label = TRUE;
190gboolean object_motion = FALSE;
191gboolean selected_status = FALSE;
192gboolean silent_input = FALSE;
194
195gboolean atomes_from_libreoffice = FALSE;
196gboolean atomes_render_image = FALSE;
197
198struct timespec start_time;
199struct timespec stop_time;
200
201double opac = 0.75;
202double pi = 3.141592653589793238462643383279502884197;
203
204GSimpleAction * edition_actions[3];
205
206GtkApplication * AtomesApp = NULL;
207GtkWidget * MainWindow = NULL;
208GtkWidget * MainView = NULL;
209GtkWidget * MainFrame[2];
210GtkWidget * pop = NULL;
211GtkWidget * curvetoolbox = NULL;
212GtkWidget * progressbar = NULL;
213GtkWidget * MainScrol[2];
214GtkWidget * atomes_logo = NULL;
215GtkWidget * atomes_shortcuts = NULL;
216GtkWidget * calc_dialog = NULL;
217GtkWidget * register_button = NULL;
218
219GtkTextTag * tag = NULL;
220GtkStatusbar * statusbar;
221
222GdkPixbuf * THETD = NULL;
223GdkPixbuf * THEMO = NULL;
224GdkPixbuf * THEBD = NULL;
225GdkPixbuf * SETTING = NULL;
226GdkPixbuf * SETTINGS = NULL;
227GdkPixbuf * OGL = NULL;
228GdkPixbuf * OGLM = NULL;
229GdkPixbuf * OGLC = NULL;
230GdkPixbuf * RUN = NULL;
231
232// Basic utility functions
233
241gboolean * allocbool (int val)
242{
243 gboolean * var = NULL;
244
245 var = g_malloc0(val*sizeof*var);
246 return var;
247}
248
257gboolean ** allocdbool (int xal, int yal)
258{
259 gboolean ** var = NULL;
260 int i;
261
262 var = g_malloc0(xal*sizeof*var);
263 for ( i = 0 ; i < xal ; i ++ )
264 {
265 /* allocation d'un tableau de tableau */
266 var[i] = allocbool(yal);
267 }
268 return var;
269}
270
280gboolean *** alloctbool (int xal, int yal, int zal)
281{
282 gboolean *** var = NULL;
283 int i;
284
285 var = g_malloc0(xal*sizeof*var);
286 for ( i = 0 ; i < xal ; i ++ )
287 {
288 /* allocation d'un tableau de tableau */
289 var[i] = allocdbool(yal, zal);
290 }
291 return var;
292}
293
301int * allocint (int val)
302{
303 int * var = NULL;
304
305 var = g_malloc0(val*sizeof*var);
306 return var;
307}
308
317int ** allocdint (int xal, int yal)
318{
319 int ** var = NULL;
320 int i;
321
322 var = g_malloc0(xal*sizeof*var);
323 for ( i = 0 ; i < xal ; i ++ )
324 {
325 /* allocation d'un tableau de tableau */
326 var[i] = allocint (yal);
327 }
328 return var;
329}
330
340int *** alloctint (int xal, int yal, int zal)
341{
342 int *** var = NULL;
343 int i;
344
345 var = g_malloc0(xal*sizeof*var);
346 for ( i = 0 ; i < xal ; i ++ )
347 {
348 /* allocation d'un tableau de tableau */
349 var[i] = allocdint (yal, zal);
350 }
351 return var;
352}
353
364int **** allocqint (int wal, int xal, int yal, int zal)
365{
366 int **** var = NULL;
367 int i;
368
369 var = g_malloc0(wal*sizeof*var);
370 for ( i = 0 ; i < wal ; i ++ )
371 {
372 /* allocation d'un tableau de tableau */
373 var[i] = alloctint (xal, yal, zal);
374 }
375 return var;
376}
377
385float * allocfloat (int val)
386{
387 float * var = NULL;
388
389 var = g_malloc0(val*sizeof*var);
390 return var;
391}
392
401float ** allocdfloat (int xal, int yal)
402{
403 float ** var = NULL;
404 int i;
405
406 var = g_malloc0(xal*sizeof*var);
407 for ( i = 0 ; i < xal ; i ++ )
408 {
409 /* allocation d'un tableau de tableau */
410 var[i] = allocfloat (yal);
411 }
412 return var;
413}
414
424float *** alloctfloat (int xal, int yal, int zal)
425{
426 float *** var = NULL;
427 int i;
428
429 var = g_malloc0(xal*sizeof*var);
430 for ( i = 0 ; i < xal ; i ++ )
431 {
432 /* allocation d'un tableau de tableau */
433 var[i] = allocdfloat (yal, zal);
434 }
435 return var;
436}
437
438
446double * allocdouble (int val)
447{
448 double * var = NULL;
449
450 var = g_malloc0(val*sizeof*var);
451 return var;
452}
453
462double ** allocddouble (int xal, int yal)
463{
464 double ** var = NULL;
465 int i;
466
467 var = g_malloc0(xal*sizeof*var);
468 for ( i = 0 ; i < xal ; i ++ )
469 {
470 /* allocation d'un tableau de tableau */
471 var[i] = allocdouble (yal);
472 }
473 return var;
474}
475
485double *** alloctdouble (int xal, int yal, int zal)
486{
487 double *** var = NULL;
488 int i;
489
490 var = g_malloc0(xal*sizeof*var);
491 for ( i = 0 ; i < xal ; i ++ )
492 {
493 /* allocation d'un tableau de tableau */
494 var[i] = allocddouble (yal, zal);
495 }
496 return var;
497}
498
509double **** allocqdouble (int wal, int xal, int yal, int zal)
510{
511 double **** var = NULL;
512 int i;
513
514 var = g_malloc0(wal*sizeof*var);
515 for ( i = 0 ; i < wal ; i ++ )
516 {
517 /* allocation d'un tableau de tableau */
518 var[i] = alloctdouble (xal, yal, zal);
519 }
520 return var;
521}
522
531gchar ** duplicate_strings (int num, gchar ** old_val)
532{
533 gchar ** new_val = g_malloc0(num*sizeof*new_val);
534 int i;
535 for (i=0; i<num; i++) new_val[i] = g_strdup_printf ("%s", old_val[i]);
536 return new_val;
537}
538
547int * duplicate_int (int num, int * old_val)
548{
549 int * new_val = allocint (num);
550 int i;
551 for (i=0; i<num; i++) new_val[i] = old_val[i];
552 return new_val;
553}
554
563gboolean * duplicate_bool (int num, gboolean * old_val)
564{
565 gboolean * new_val = allocbool (num);
566 int i;
567 for (i=0; i<num; i++) new_val[i] = old_val[i];
568 return new_val;
569}
570
579float * duplicate_float (int num, float * old_val)
580{
581 float * new_val = allocfloat (num);
582 int i;
583 for (i=0; i<num; i++) new_val[i] = old_val[i];
584 return new_val;
585}
586
595double * duplicate_double (int num, double * old_val)
596{
597 double * new_val = allocdouble (num);
598 int i;
599 for (i=0; i<num; i++) new_val[i] = old_val[i];
600 return new_val;
601}
602
603
611double string_to_double (gpointer string)
612{
613 char * endPtr = NULL;
614 double value = g_ascii_strtod ((char *)string, & endPtr);
615 if (endPtr == (char *)string)
616 {
617 g_warning (_("Error in string format: string = \"%s\" - value == %lf\n"), endPtr, value);
618 }
619 return value;
620}
621
630double get_calc_time (struct timespec start, struct timespec stop)
631{
632 return (double)(stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec)/BILLION;
633}
634
643gchar * calculation_time (gboolean modelv, double ctime)
644{
645 int i, j, k;
646 gchar * t_string = (modelv) ? _("\n \tAnalysis was performed in: "): "";
647 if (ctime < 60.0)
648 {
649 return g_strdup_printf ("%s%f s", t_string, ctime);
650 }
651 else if (ctime < 3600.0)
652 {
653 i = ctime/60.0;
654 return g_strdup_printf ("%s%d m %f s", t_string, i, ctime-i*60.0);
655 }
656 else if (ctime < 86400.0)
657 {
658 // Really ?!
659 i = ctime/3600.0;
660 j = (ctime - i*3600.0)/60.0;
661 return g_strdup_printf ("%s%d h %d m %f s", t_string, i, j, ctime-i*3600.0-j*60.0);
662 }
663 else
664 {
665 // Seriously ?!
666 i = ctime/86400.0;
667 j = (ctime - i*86400.0)/3600.0;
668 k = (ctime - i*86400.0 - j*3600.0)/60.0;
669 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);
670 }
671}
float val
Definition dlp_init.c:117
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:317
gchar * PACKAGE_BMP
Definition global.c:98
gchar * PACKAGE_SET
Definition global.c:107
gboolean reading_input
Definition global.c:186
double **** allocqdouble(int wal, int xal, int yal, int zal)
allocate a double **** pointer
Definition global.c:509
gchar * ATOMES_CONFIG
Definition global.c:139
float ** allocdfloat(int xal, int yal)
allocate a float ** pointer
Definition global.c:401
gchar * PACKAGE_SGTP
Definition global.c:130
gchar * PACKAGE_SGMI
Definition global.c:136
gchar * PACKAGE_SGTI
Definition global.c:129
GtkStatusbar * statusbar
Definition global.c:220
GtkWidget * register_button
Definition global.c:217
int mol_update
Definition global.c:175
gchar * workspacefile
Definition global.c:159
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:595
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:547
int *** alloctint(int xal, int yal, int zal)
allocate an int *** pointer
Definition global.c:340
char * ifbug
Definition global.c:145
gchar * PACKAGE_DOTG
Definition global.c:117
gchar * PACKAGE_TIFF
Definition global.c:99
gchar * PACKAGE_LAGPL
Definition global.c:109
gchar * PACKAGE_LOGO
Definition global.c:108
double pi
Definition global.c:202
#define BILLION
Definition global.c:82
gboolean newspace
Definition global.c:185
gchar * PACKAGE_DOTC
Definition global.c:113
gchar * PACKAGE_LIB_DIR
Definition global.c:89
gchar * PACKAGE_IMG
Definition global.c:92
gchar * PACKAGE_DFIN
Definition global.c:123
int dialog_id
Definition global.c:170
char * rings_type[5]
Definition global.c:147
GtkTextTag * tag
Definition global.c:219
GtkWidget * MainScrol[2]
Definition global.c:213
struct timespec start_time
Definition global.c:198
int activep
Definition global.c:162
gchar * PACKAGE_IMP
Definition global.c:90
GSimpleAction * edition_actions[3]
Definition global.c:204
int * pasted_todo
Definition global.c:178
gchar * PACKAGE_DOTE
Definition global.c:115
int inactep
Definition global.c:165
gboolean in_movie_encoding
Definition global.c:184
gchar * PACKAGE_DOTH
Definition global.c:118
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:241
double * xsk
Definition global.c:180
gchar * PACKAGE_SGMP
Definition global.c:135
int activef
Definition global.c:164
gboolean tmp_adv_bonding[2]
Definition global.c:187
gchar * PACKAGE_DFAN
Definition global.c:120
gchar * PACKAGE_SGTR
Definition global.c:128
GdkPixbuf * OGLC
Definition global.c:229
gchar * PACKAGE_DFDI
Definition global.c:121
gchar * PACKAGE_DFTD
Definition global.c:122
char * untime[5]
Definition global.c:153
GMainLoop * Event_loop[5]
Definition global.c:182
gboolean silent_input
Definition global.c:192
gchar * PACKAGE_SGCF
Definition global.c:126
double ** allocddouble(int xal, int yal)
allocate a double ** pointer
Definition global.c:462
int activew
Definition global.c:166
GtkApplication * AtomesApp
Definition global.c:206
gchar * PACKAGE_DFBD
Definition global.c:119
gchar * PACKAGE_CON
Definition global.c:91
gchar * PACKAGE_SGHP
Definition global.c:127
int nprojects
Definition global.c:161
GtkWidget * MainFrame[2]
Definition global.c:209
GtkWidget * atomes_shortcuts
Definition global.c:215
int activev
Definition global.c:163
gboolean selected_status
Definition global.c:191
int frag_update
Definition global.c:174
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:446
gchar * PACKAGE_OGL
Definition global.c:103
GtkWidget * MainWindow
Definition global.c:207
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:643
gchar * PACKAGE_DOTF
Definition global.c:116
GdkPixbuf * OGLM
Definition global.c:228
gchar * PACKAGE_EPS
Definition global.c:95
gchar * PACKAGE_DOTA
Definition global.c:111
gchar * PACKAGE_OGLM
Definition global.c:104
gchar * PACKAGE_SGOC
Definition global.c:133
gboolean column_label
Definition global.c:188
gchar * projfile
Definition global.c:144
gchar ** duplicate_strings(int num, gchar **old_val)
copy a list of strings
Definition global.c:531
gchar * PACKAGE_SGOF
Definition global.c:134
gchar * ATOMES_URL
Definition global.c:140
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:579
int bonds_update
Definition global.c:173
gboolean atomes_render_image
Definition global.c:196
gchar * PACKAGE_SGOP
Definition global.c:131
gboolean * duplicate_bool(int num, gboolean *old_val)
copy a list of gboolean
Definition global.c:563
GdkPixbuf * SETTINGS
Definition global.c:226
gchar * PACKAGE_OGLC
Definition global.c:105
gboolean check_label
Definition global.c:189
double *** alloctdouble(int xal, int yal, int zal)
allocate a double *** pointer
Definition global.c:485
double opac
Definition global.c:201
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
gchar * mode_name[2]
Definition global.c:141
gchar * PACKAGE_TD
Definition global.c:101
GdkPixbuf * THEBD
Definition global.c:224
gboolean object_motion
Definition global.c:190
gchar * PACKAGE_SVG
Definition global.c:94
gchar * PACKAGE_SGTC
Definition global.c:137
gchar * PACKAGE_SGCP
Definition global.c:124
GdkPixbuf * OGL
Definition global.c:227
gboolean *** alloctbool(int xal, int yal, int zal)
allocate a gboolean *** pointer
Definition global.c:280
GdkPixbuf * RUN
Definition global.c:230
GdkPixbuf * THETD
Definition global.c:222
gboolean ** allocdbool(int xal, int yal)
allocate a gboolean ** pointer
Definition global.c:257
GtkWidget * atomes_logo
Definition global.c:214
gchar * PACKAGE_PRO
Definition global.c:106
GtkWidget * progressbar
Definition global.c:212
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:630
gchar * PACKAGE_LABOUT
Definition global.c:110
GdkPixbuf * SETTING
Definition global.c:225
gchar * ATOMES_CONFIG_DIR
Definition global.c:138
int atomes_visual
Definition global.c:168
#define i18n(String)
Definition global.c:80
int **** allocqint(int wal, int xal, int yal, int zal)
allocate an int **** pointer
Definition global.c:364
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:385
struct timespec stop_time
Definition global.c:199
gchar * bravais_img[14]
Definition global.c:142
gchar * PACKAGE_MOL
Definition global.c:102
int statusval
Definition global.c:167
gboolean cif_use_symmetry_positions
Definition global.c:193
int reading_step_limit
Definition global.c:172
gchar * PACKAGE_VOID
Definition global.c:100
gchar * PACKAGE_DOTB
Definition global.c:112
GtkWidget * curvetoolbox
Definition global.c:211
GdkPixbuf * THEMO
Definition global.c:223
gchar * PACKAGE_PDF
Definition global.c:93
double string_to_double(gpointer string)
convert string to double
Definition global.c:611
GtkWidget * pop
Definition global.c:210
gchar * ifield[8]
Definition global.c:143
gchar * PACKAGE_SGOI
Definition global.c:132
gchar * PACKAGE_JPG
Definition global.c:97
float *** alloctfloat(int xal, int yal, int zal)
allocate a float *** pointer
Definition global.c:424
gchar * PACKAGE_SGCI
Definition global.c:125
GtkWidget * calc_dialog
Definition global.c:216
gchar * PACKAGE_DOTD
Definition global.c:114
int tmp_pixels[2]
Definition global.c:177
GtkWidget * MainView
Definition global.c:208
gboolean atomes_from_libreoffice
Definition global.c:195
gchar * PACKAGE_PNG
Definition global.c:96