atomes 1.3.2
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;
198
199struct timespec start_time;
200struct timespec stop_time;
201
202double opac = 0.75;
203double pi = 3.141592653589793238462643383279502884197;
204
205GSimpleAction * edition_actions[3];
206
207GtkApplication * atomes_app = NULL;
208GtkWidget * atomes_main_window = NULL;
209GtkWidget * MainView = NULL;
210GtkWidget * MainFrame[2];
211GtkWidget * pop = NULL;
212GtkWidget * curvetoolbox = NULL;
213GtkWidget * progressbar = NULL;
214GtkWidget * MainScrol[2];
215GtkWidget * atomes_logo = NULL;
216GtkWidget * atomes_shortcuts = NULL;
217GtkWidget * calc_dialog = NULL;
218GtkWidget * register_button = NULL;
219
220GtkTextTag * tag = NULL;
221GtkStatusbar * statusbar;
222
223GdkPixbuf * THETD = NULL;
224GdkPixbuf * THEMO = NULL;
225GdkPixbuf * THEBD = NULL;
226GdkPixbuf * SETTING = NULL;
227GdkPixbuf * SETTINGS = NULL;
228GdkPixbuf * OGL = NULL;
229GdkPixbuf * OGLM = NULL;
230GdkPixbuf * OGLC = NULL;
231GdkPixbuf * RUN = NULL;
232
233// Basic utility functions
234
242gboolean * allocbool (int val)
243{
244 gboolean * var = NULL;
245
246 var = g_malloc0(val*sizeof*var);
247 return var;
248}
249
258gboolean ** allocdbool (int xal, int yal)
259{
260 gboolean ** var = NULL;
261 int i;
262
263 var = g_malloc0(xal*sizeof*var);
264 for ( i = 0 ; i < xal ; i ++ )
265 {
266 /* allocation d'un tableau de tableau */
267 var[i] = allocbool(yal);
268 }
269 return var;
270}
271
281gboolean *** alloctbool (int xal, int yal, int zal)
282{
283 gboolean *** var = NULL;
284 int i;
285
286 var = g_malloc0(xal*sizeof*var);
287 for ( i = 0 ; i < xal ; i ++ )
288 {
289 /* allocation d'un tableau de tableau */
290 var[i] = allocdbool(yal, zal);
291 }
292 return var;
293}
294
302int * allocint (int val)
303{
304 int * var = NULL;
305
306 var = g_malloc0(val*sizeof*var);
307 return var;
308}
309
318int ** allocdint (int xal, int yal)
319{
320 int ** var = NULL;
321 int i;
322
323 var = g_malloc0(xal*sizeof*var);
324 for ( i = 0 ; i < xal ; i ++ )
325 {
326 /* allocation d'un tableau de tableau */
327 var[i] = allocint (yal);
328 }
329 return var;
330}
331
341int *** alloctint (int xal, int yal, int zal)
342{
343 int *** var = NULL;
344 int i;
345
346 var = g_malloc0(xal*sizeof*var);
347 for ( i = 0 ; i < xal ; i ++ )
348 {
349 /* allocation d'un tableau de tableau */
350 var[i] = allocdint (yal, zal);
351 }
352 return var;
353}
354
365int **** allocqint (int wal, int xal, int yal, int zal)
366{
367 int **** var = NULL;
368 int i;
369
370 var = g_malloc0(wal*sizeof*var);
371 for ( i = 0 ; i < wal ; i ++ )
372 {
373 /* allocation d'un tableau de tableau */
374 var[i] = alloctint (xal, yal, zal);
375 }
376 return var;
377}
378
386float * allocfloat (int val)
387{
388 float * var = NULL;
389
390 var = g_malloc0(val*sizeof*var);
391 return var;
392}
393
402float ** allocdfloat (int xal, int yal)
403{
404 float ** var = NULL;
405 int i;
406
407 var = g_malloc0(xal*sizeof*var);
408 for ( i = 0 ; i < xal ; i ++ )
409 {
410 /* allocation d'un tableau de tableau */
411 var[i] = allocfloat (yal);
412 }
413 return var;
414}
415
425float *** alloctfloat (int xal, int yal, int zal)
426{
427 float *** var = NULL;
428 int i;
429
430 var = g_malloc0(xal*sizeof*var);
431 for ( i = 0 ; i < xal ; i ++ )
432 {
433 /* allocation d'un tableau de tableau */
434 var[i] = allocdfloat (yal, zal);
435 }
436 return var;
437}
438
439
447double * allocdouble (int val)
448{
449 double * var = NULL;
450
451 var = g_malloc0(val*sizeof*var);
452 return var;
453}
454
463double ** allocddouble (int xal, int yal)
464{
465 double ** var = NULL;
466 int i;
467
468 var = g_malloc0(xal*sizeof*var);
469 for ( i = 0 ; i < xal ; i ++ )
470 {
471 /* allocation d'un tableau de tableau */
472 var[i] = allocdouble (yal);
473 }
474 return var;
475}
476
486double *** alloctdouble (int xal, int yal, int zal)
487{
488 double *** var = NULL;
489 int i;
490
491 var = g_malloc0(xal*sizeof*var);
492 for ( i = 0 ; i < xal ; i ++ )
493 {
494 /* allocation d'un tableau de tableau */
495 var[i] = allocddouble (yal, zal);
496 }
497 return var;
498}
499
510double **** allocqdouble (int wal, int xal, int yal, int zal)
511{
512 double **** var = NULL;
513 int i;
514
515 var = g_malloc0(wal*sizeof*var);
516 for ( i = 0 ; i < wal ; i ++ )
517 {
518 /* allocation d'un tableau de tableau */
519 var[i] = alloctdouble (xal, yal, zal);
520 }
521 return var;
522}
523
532gchar ** duplicate_strings (int num, gchar ** old_val)
533{
534 gchar ** new_val = g_malloc0(num*sizeof*new_val);
535 int i;
536 for (i=0; i<num; i++) new_val[i] = g_strdup_printf ("%s", old_val[i]);
537 return new_val;
538}
539
548int * duplicate_int (int num, int * old_val)
549{
550 int * new_val = allocint (num);
551 int i;
552 for (i=0; i<num; i++) new_val[i] = old_val[i];
553 return new_val;
554}
555
564gboolean * duplicate_bool (int num, gboolean * old_val)
565{
566 gboolean * new_val = allocbool (num);
567 int i;
568 for (i=0; i<num; i++) new_val[i] = old_val[i];
569 return new_val;
570}
571
580float * duplicate_float (int num, float * old_val)
581{
582 float * new_val = allocfloat (num);
583 int i;
584 for (i=0; i<num; i++) new_val[i] = old_val[i];
585 return new_val;
586}
587
596double * duplicate_double (int num, double * old_val)
597{
598 double * new_val = allocdouble (num);
599 int i;
600 for (i=0; i<num; i++) new_val[i] = old_val[i];
601 return new_val;
602}
603
604
612double string_to_double (gpointer string)
613{
614 char * endPtr = NULL;
615 double value = g_ascii_strtod ((char *)string, & endPtr);
616 if (endPtr == (char *)string)
617 {
618 g_warning (_("Error in string format: string = \"%s\" - value == %lf\n"), endPtr, value);
619 }
620 return value;
621}
622
631double get_calc_time (struct timespec start, struct timespec stop)
632{
633 return (double)(stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec)/BILLION;
634}
635
644gchar * calculation_time (gboolean modelv, double ctime)
645{
646 int i, j, k;
647 gchar * t_string = (modelv) ? _("\n \tAnalysis was performed in: "): "";
648 if (ctime < 60.0)
649 {
650 return g_strdup_printf ("%s%f s", t_string, ctime);
651 }
652 else if (ctime < 3600.0)
653 {
654 i = ctime/60.0;
655 return g_strdup_printf ("%s%d m %f s", t_string, i, ctime-i*60.0);
656 }
657 else if (ctime < 86400.0)
658 {
659 // Really ?!
660 i = ctime/3600.0;
661 j = (ctime - i*3600.0)/60.0;
662 return g_strdup_printf ("%s%d h %d m %f s", t_string, i, j, ctime-i*3600.0-j*60.0);
663 }
664 else
665 {
666 // Seriously ?!
667 i = ctime/86400.0;
668 j = (ctime - i*86400.0)/3600.0;
669 k = (ctime - i*86400.0 - j*3600.0)/60.0;
670 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);
671 }
672}
float val
Definition dlp_init.c:117
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:318
int atomes_convert_file
Definition global.c:197
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:510
gchar * ATOMES_CONFIG
Definition global.c:139
float ** allocdfloat(int xal, int yal)
allocate a float ** pointer
Definition global.c:402
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:221
GtkWidget * register_button
Definition global.c:218
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:596
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:548
int *** alloctint(int xal, int yal, int zal)
allocate an int *** pointer
Definition global.c:341
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:203
#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
GtkWidget * atomes_main_window
Definition global.c:208
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:220
GtkWidget * MainScrol[2]
Definition global.c:214
struct timespec start_time
Definition global.c:199
int activep
Definition global.c:162
gchar * PACKAGE_IMP
Definition global.c:90
GSimpleAction * edition_actions[3]
Definition global.c:205
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:242
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:230
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:463
int activew
Definition global.c:166
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:210
GtkWidget * atomes_shortcuts
Definition global.c:216
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:447
gchar * PACKAGE_OGL
Definition global.c:103
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:644
gchar * PACKAGE_DOTF
Definition global.c:116
GdkPixbuf * OGLM
Definition global.c:229
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:532
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:580
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:564
GdkPixbuf * SETTINGS
Definition global.c:227
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:486
double opac
Definition global.c:202
int * allocint(int val)
allocate an int * pointer
Definition global.c:302
gchar * mode_name[2]
Definition global.c:141
gchar * PACKAGE_TD
Definition global.c:101
GdkPixbuf * THEBD
Definition global.c:225
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:228
gboolean *** alloctbool(int xal, int yal, int zal)
allocate a gboolean *** pointer
Definition global.c:281
GdkPixbuf * RUN
Definition global.c:231
GdkPixbuf * THETD
Definition global.c:223
gboolean ** allocdbool(int xal, int yal)
allocate a gboolean ** pointer
Definition global.c:258
GtkWidget * atomes_logo
Definition global.c:215
gchar * PACKAGE_PRO
Definition global.c:106
GtkWidget * progressbar
Definition global.c:213
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:631
gchar * PACKAGE_LABOUT
Definition global.c:110
GdkPixbuf * SETTING
Definition global.c:226
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:365
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:386
struct timespec stop_time
Definition global.c:200
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:212
GdkPixbuf * THEMO
Definition global.c:224
GtkApplication * atomes_app
Definition global.c:207
gchar * PACKAGE_PDF
Definition global.c:93
double string_to_double(gpointer string)
convert string to double
Definition global.c:612
GtkWidget * pop
Definition global.c:211
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:425
gchar * PACKAGE_SGCI
Definition global.c:125
GtkWidget * calc_dialog
Definition global.c:217
gchar * PACKAGE_DOTD
Definition global.c:114
int tmp_pixels[2]
Definition global.c:177
GtkWidget * MainView
Definition global.c:209
gboolean atomes_from_libreoffice
Definition global.c:195
gchar * PACKAGE_PNG
Definition global.c:96