atomes 1.1.16
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 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 <stdio.h>
65#include <stdlib.h>
66#include <sys/types.h>
67#include <sys/stat.h>
68
69#include <gtk/gtk.h>
70#include <gdk/gdk.h>
71
72#define BILLION 1000000000L;
73
74#ifdef G_OS_WIN32
75gchar * PACKAGE_PREFIX = NULL;
76gchar * PACKAGE_LIBEXEC = NULL;
77#endif
78gchar * PACKAGE_LIB_DIR = NULL;
79gchar * PACKAGE_IMP = NULL;
80gchar * PACKAGE_CON = NULL;
81gchar * PACKAGE_IMG = NULL;
82gchar * PACKAGE_PDF = NULL;
83gchar * PACKAGE_SVG = NULL;
84gchar * PACKAGE_EPS = NULL;
85gchar * PACKAGE_PNG = NULL;
86gchar * PACKAGE_JPG = NULL;
87gchar * PACKAGE_BMP = NULL;
88gchar * PACKAGE_TIFF = NULL;
89gchar * PACKAGE_VOID = NULL;
90gchar * PACKAGE_GR = NULL;
91gchar * PACKAGE_SQ = NULL;
92gchar * PACKAGE_BD = NULL;
93gchar * PACKAGE_AN = NULL;
94gchar * PACKAGE_RI = NULL;
95gchar * PACKAGE_CH = NULL;
96gchar * PACKAGE_SP = NULL;
97gchar * PACKAGE_MS = NULL;
98gchar * PACKAGE_TD = NULL;
99gchar * PACKAGE_MOL = NULL;
100gchar * PACKAGE_OGL = NULL;
101gchar * PACKAGE_OGLM = NULL;
102gchar * PACKAGE_OGLC = NULL;
103gchar * PACKAGE_PRO = NULL;
104gchar * PACKAGE_SET = NULL;
105gchar * PACKAGE_LOGO = NULL;
106gchar * PACKAGE_LAGPL = NULL;
107gchar * PACKAGE_LABOUT = NULL;
108gchar * PACKAGE_DOTA = NULL;
109gchar * PACKAGE_DOTB = NULL;
110gchar * PACKAGE_DOTC = NULL;
111gchar * PACKAGE_DOTD = NULL;
112gchar * PACKAGE_DOTE = NULL;
113gchar * PACKAGE_DOTF = NULL;
114gchar * PACKAGE_DOTG = NULL;
115gchar * PACKAGE_DOTH = NULL;
116gchar * PACKAGE_DFBD = NULL;
117gchar * PACKAGE_DFAN = NULL;
118gchar * PACKAGE_DFDI = NULL;
119gchar * PACKAGE_DFTD = NULL;
120gchar * PACKAGE_DFIN = NULL;
121gchar * PACKAGE_SGCP = NULL;
122gchar * PACKAGE_SGCI = NULL;
123gchar * PACKAGE_SGCF = NULL;
124gchar * PACKAGE_SGHP = NULL;
125gchar * PACKAGE_SGTR = NULL;
126gchar * PACKAGE_SGTI = NULL;
127gchar * PACKAGE_SGTP = NULL;
128gchar * PACKAGE_SGOP = NULL;
129gchar * PACKAGE_SGOI = NULL;
130gchar * PACKAGE_SGOC = NULL;
131gchar * PACKAGE_SGOF = NULL;
132gchar * PACKAGE_SGMP = NULL;
133gchar * PACKAGE_SGMI = NULL;
134gchar * PACKAGE_SGTC = NULL;
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), Else = 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
197GSimpleAction * edition_actions[3];
198GSimpleAction * analyze_actions[9];
199
200GtkApplication * AtomesApp = NULL;
201GtkWidget * MainWindow = NULL;
202GtkWidget * MainView = NULL;
203GtkWidget * MainFrame[2];
204GtkWidget * pop = NULL;
205GtkWidget * curvetoolbox = NULL;
206GtkWidget * progressbar = NULL;
207GtkWidget * MainScrol[2];
208GtkWidget * atomes_logo = NULL;
209GtkWidget * atomes_shortcuts = NULL;
210GtkWidget * calc_dialog = NULL;
211GtkWidget * register_button = NULL;
212
213GtkTextTag * tag = NULL;
214GtkStatusbar * statusbar;
215
216GdkPixbuf * THETD = NULL;
217GdkPixbuf * THEMO = NULL;
218GdkPixbuf * THEBD = NULL;
219GdkPixbuf * SETTING = NULL;
220GdkPixbuf * SETTINGS = NULL;
221GdkPixbuf * OGL = NULL;
222GdkPixbuf * OGLM = NULL;
223GdkPixbuf * OGLC = NULL;
224GdkPixbuf * RUN = NULL;
225
226// Basic utility functions
227
254gboolean * allocbool (int val)
255{
256 gboolean * var = NULL;
257
258 var = g_malloc0 (val*sizeof*var);
259 return var;
260}
261
270gboolean ** allocdbool (int xal, int yal)
271{
272 gboolean ** var = NULL;
273 int i;
274
275 var = g_malloc (xal*sizeof*var);
276 for ( i = 0 ; i < xal ; i ++ )
277 {
278 /* allocation d'un tableau de tableau */
279 var[i] = allocbool(yal);
280 }
281 return var;
282}
283
293gboolean *** alloctbool (int xal, int yal, int zal)
294{
295 gboolean *** var = NULL;
296 int i;
297
298 var = g_malloc (xal*sizeof*var);
299 for ( i = 0 ; i < xal ; i ++ )
300 {
301 /* allocation d'un tableau de tableau */
302 var[i] = allocdbool(yal, zal);
303 }
304 return var;
305}
306
314int * allocint (int val)
315{
316 int * var = NULL;
317
318 var = g_malloc0 (val*sizeof*var);
319 return var;
320}
321
330int ** allocdint (int xal, int yal)
331{
332 int ** var = NULL;
333 int i;
334
335 var = g_malloc (xal*sizeof*var);
336 for ( i = 0 ; i < xal ; i ++ )
337 {
338 /* allocation d'un tableau de tableau */
339 var[i] = allocint(yal);
340 }
341 return var;
342}
343
353int *** alloctint (int xal, int yal, int zal)
354{
355 int *** var = NULL;
356 int i;
357
358 var = g_malloc (xal*sizeof*var);
359 for ( i = 0 ; i < xal ; i ++ )
360 {
361 /* allocation d'un tableau de tableau */
362 var[i] = allocdint(yal, zal);
363 }
364 return var;
365}
366
377int **** allocqint (int wal, int xal, int yal, int zal)
378{
379 int **** var = NULL;
380 int i;
381
382 var = g_malloc (wal*sizeof*var);
383 for ( i = 0 ; i < wal ; i ++ )
384 {
385 /* allocation d'un tableau de tableau */
386 var[i] = alloctint(xal, yal, zal);
387 }
388 return var;
389}
390
398float * allocfloat (int val)
399{
400 float * var = NULL;
401
402 var = g_malloc0 (val*sizeof*var);
403 return var;
404}
405
414float ** allocdfloat (int xal, int yal)
415{
416 float ** var = NULL;
417 int i;
418
419 var = g_malloc (xal*sizeof*var);
420 for ( i = 0 ; i < xal ; i ++ )
421 {
422 /* allocation d'un tableau de tableau */
423 var[i] = allocfloat(yal);
424 }
425 return var;
426}
427
437float *** alloctfloat (int xal, int yal, int zal)
438{
439 float *** var = NULL;
440 int i;
441
442 var = g_malloc (xal*sizeof*var);
443 for ( i = 0 ; i < xal ; i ++ )
444 {
445 /* allocation d'un tableau de tableau */
446 var[i] = allocdfloat (yal, zal);
447 }
448 return var;
449}
450
451
459double * allocdouble (int val)
460{
461 double * var = NULL;
462
463 var = g_malloc0 (val*sizeof*var);
464 return var;
465}
466
475double ** allocddouble (int xal, int yal)
476{
477 double ** var = NULL;
478 int i;
479
480 var = g_malloc (xal*sizeof*var);
481 for ( i = 0 ; i < xal ; i ++ )
482 {
483 /* allocation d'un tableau de tableau */
484 var[i] = allocdouble (yal);
485 }
486 return var;
487}
488
498double *** alloctdouble (int xal, int yal, int zal)
499{
500 double *** var = NULL;
501 int i;
502
503 var = g_malloc (xal*sizeof*var);
504 for ( i = 0 ; i < xal ; i ++ )
505 {
506 /* allocation d'un tableau de tableau */
507 var[i] = allocddouble (yal, zal);
508 }
509 return var;
510}
511
522double **** allocqdouble (int wal, int xal, int yal, int zal)
523{
524 double **** var = NULL;
525 int i;
526
527 var = g_malloc (wal*sizeof*var);
528 for ( i = 0 ; i < wal ; i ++ )
529 {
530 /* allocation d'un tableau de tableau */
531 var[i] = alloctdouble (xal, yal, zal);
532 }
533 return var;
534}
535
544gchar ** duplicate_strings (int num, gchar ** old_val)
545{
546 gchar ** new_val = g_malloc0 (num*sizeof*new_val);
547 int i;
548 for (i=0; i<num; i++) new_val[i] = g_strdup_printf ("%s", old_val[i]);
549 return new_val;
550}
551
560int * duplicate_int (int num, int * old_val)
561{
562 int * new_val = allocint (num);
563 int i;
564 for (i=0; i<num; i++) new_val[i] = old_val[i];
565 return new_val;
566}
567
576gboolean * duplicate_bool (int num, gboolean * old_val)
577{
578 gboolean * new_val = allocbool (num);
579 int i;
580 for (i=0; i<num; i++) new_val[i] = old_val[i];
581 return new_val;
582}
583
592float * duplicate_float (int num, float * old_val)
593{
594 float * new_val = allocfloat (num);
595 int i;
596 for (i=0; i<num; i++) new_val[i] = old_val[i];
597 return new_val;
598}
599
608double * duplicate_double (int num, double * old_val)
609{
610 double * new_val = allocdouble (num);
611 int i;
612 for (i=0; i<num; i++) new_val[i] = old_val[i];
613 return new_val;
614}
615
616
624double string_to_double (gpointer string)
625{
626 char * endPtr = NULL;
627 double value = strtod ((char *)string, & endPtr);
628 if (endPtr == (char *)string)
629 {
630 g_print ("Error in string format: %s - value == %lf\n", endPtr, value);
631 }
632 return value;
633}
634
643double get_calc_time (struct timespec start, struct timespec stop)
644{
645 return (double)(stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec)/BILLION;
646}
647
656gchar * calculation_time (gboolean modelv, double ctime)
657{
658 int i, j, k;
659 gchar * t_string = (modelv) ? "\n \tAnalysis was performed in: ": "";
660 if (ctime < 60.0)
661 {
662 return g_strdup_printf ("%s%f s", t_string, ctime);
663 }
664 else if (ctime < 3600.0)
665 {
666 i = ctime/60.0;
667 return g_strdup_printf ("%s%d m %f s", t_string, i, ctime-i*60.0);
668 }
669 else if (ctime < 86400.0)
670 {
671 // Really ?!
672 i = ctime/3600.0;
673 j = (ctime - i*3600.0)/60.0;
674 return g_strdup_printf ("%s%d h %d m %f s", t_string, i, j, ctime-i*3600.0-j*60.0);
675 }
676 else
677 {
678 // Seriously ?!
679 i = ctime/86400.0;
680 j = (ctime - i*86400.0)/3600.0;
681 k = (ctime - i*86400.0 - j*3600.0)/60.0;
682 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);
683 }
684}
float val
Definition dlp_init.c:117
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:330
gchar * PACKAGE_BMP
Definition global.c:87
gchar * PACKAGE_SET
Definition global.c:104
gboolean reading_input
Definition global.c:182
double **** allocqdouble(int wal, int xal, int yal, int zal)
allocate a double **** pointer
Definition global.c:522
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:414
gchar * PACKAGE_SGTP
Definition global.c:127
gchar * PACKAGE_SGMI
Definition global.c:133
gchar * PACKAGE_SGTI
Definition global.c:126
GtkStatusbar * statusbar
Definition global.c:214
GtkWidget * register_button
Definition global.c:211
int mol_update
Definition global.c:171
gchar * PACKAGE_AN
Definition global.c:93
gchar * workspacefile
Definition global.c:156
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:608
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:560
int *** alloctint(int xal, int yal, int zal)
allocate an int *** pointer
Definition global.c:353
char * ifbug
Definition global.c:141
gchar * PACKAGE_DOTG
Definition global.c:114
gchar * PACKAGE_TIFF
Definition global.c:88
gchar * PACKAGE_LAGPL
Definition global.c:106
gchar * PACKAGE_LOGO
Definition global.c:105
double pi
Definition global.c:195
#define BILLION
Definition global.c:72
gboolean newspace
Definition global.c:181
gchar * PACKAGE_DOTC
Definition global.c:110
gchar * PACKAGE_LIB_DIR
Definition global.c:78
gchar * PACKAGE_IMG
Definition global.c:81
gchar * PACKAGE_DFIN
Definition global.c:120
int dialog_id
Definition global.c:167
char * rings_type[5]
Definition global.c:143
GtkTextTag * tag
Definition global.c:213
gchar * PACKAGE_SP
Definition global.c:96
GtkWidget * MainScrol[2]
Definition global.c:207
struct timespec start_time
Definition global.c:191
int activep
Definition global.c:159
gchar * PACKAGE_IMP
Definition global.c:79
GSimpleAction * edition_actions[3]
Definition global.c:197
int * pasted_todo
Definition global.c:174
gchar * PACKAGE_DOTE
Definition global.c:112
int inactep
Definition global.c:162
gboolean in_movie_encoding
Definition global.c:180
gchar * PACKAGE_DOTH
Definition global.c:115
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:254
double * xsk
Definition global.c:176
gchar * PACKAGE_SGMP
Definition global.c:132
int activef
Definition global.c:161
gboolean tmp_adv_bonding[2]
Definition global.c:183
gchar * PACKAGE_DFAN
Definition global.c:117
gchar * PACKAGE_SGTR
Definition global.c:125
GdkPixbuf * OGLC
Definition global.c:223
gchar * PACKAGE_DFDI
Definition global.c:118
gchar * PACKAGE_DFTD
Definition global.c:119
GMainLoop * Event_loop[5]
Definition global.c:178
gboolean silent_input
Definition global.c:188
gchar * PACKAGE_SGCF
Definition global.c:123
double ** allocddouble(int xal, int yal)
allocate a double ** pointer
Definition global.c:475
int activew
Definition global.c:163
GtkApplication * AtomesApp
Definition global.c:200
gchar * PACKAGE_DFBD
Definition global.c:116
gchar * PACKAGE_CON
Definition global.c:80
gchar * PACKAGE_BD
Definition global.c:92
gchar * PACKAGE_SGHP
Definition global.c:124
int nprojects
Definition global.c:158
GtkWidget * MainFrame[2]
Definition global.c:203
gchar * PACKAGE_RI
Definition global.c:94
GtkWidget * atomes_shortcuts
Definition global.c:209
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:459
gchar * PACKAGE_OGL
Definition global.c:100
GtkWidget * MainWindow
Definition global.c:201
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:656
gchar * PACKAGE_DOTF
Definition global.c:113
gchar * PACKAGE_GR
Definition global.c:90
GdkPixbuf * OGLM
Definition global.c:222
gchar * PACKAGE_EPS
Definition global.c:84
gchar * PACKAGE_DOTA
Definition global.c:108
gchar * PACKAGE_OGLM
Definition global.c:101
gchar * PACKAGE_MS
Definition global.c:97
gchar * PACKAGE_SGOC
Definition global.c:130
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:544
gchar * PACKAGE_SGOF
Definition global.c:131
gchar * ATOMES_URL
Definition global.c:136
gchar * PACKAGE_CH
Definition global.c:95
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:592
int bonds_update
Definition global.c:169
gchar * PACKAGE_SGOP
Definition global.c:128
gboolean * duplicate_bool(int num, gboolean *old_val)
copy a list of gboolean
Definition global.c:576
GdkPixbuf * SETTINGS
Definition global.c:220
gchar * PACKAGE_OGLC
Definition global.c:102
gboolean check_label
Definition global.c:185
double *** alloctdouble(int xal, int yal, int zal)
allocate a double *** pointer
Definition global.c:498
double opac
Definition global.c:194
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
gchar * mode_name[2]
Definition global.c:137
gchar * PACKAGE_TD
Definition global.c:98
GdkPixbuf * THEBD
Definition global.c:218
gboolean object_motion
Definition global.c:186
gchar * PACKAGE_SVG
Definition global.c:83
gchar * PACKAGE_SGTC
Definition global.c:134
gchar * PACKAGE_SGCP
Definition global.c:121
GdkPixbuf * OGL
Definition global.c:221
gboolean *** alloctbool(int xal, int yal, int zal)
allocate a gboolean *** pointer
Definition global.c:293
GdkPixbuf * RUN
Definition global.c:224
GdkPixbuf * THETD
Definition global.c:216
gboolean ** allocdbool(int xal, int yal)
allocate a gboolean ** pointer
Definition global.c:270
GtkWidget * atomes_logo
Definition global.c:208
gchar * PACKAGE_PRO
Definition global.c:103
GtkWidget * progressbar
Definition global.c:206
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:643
gchar * PACKAGE_LABOUT
Definition global.c:107
GdkPixbuf * SETTING
Definition global.c:219
int atomes_visual
Definition global.c:165
int **** allocqint(int wal, int xal, int yal, int zal)
allocate an int **** pointer
Definition global.c:377
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:398
struct timespec stop_time
Definition global.c:192
gchar * bravais_img[14]
Definition global.c:138
gchar * PACKAGE_MOL
Definition global.c:99
int statusval
Definition global.c:164
gboolean cif_use_symmetry_positions
Definition global.c:189
GSimpleAction * analyze_actions[9]
Definition global.c:198
gchar * PACKAGE_VOID
Definition global.c:89
gchar * PACKAGE_DOTB
Definition global.c:109
GtkWidget * curvetoolbox
Definition global.c:205
GdkPixbuf * THEMO
Definition global.c:217
gchar * PACKAGE_PDF
Definition global.c:82
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
GtkWidget * pop
Definition global.c:204
gchar * ifield[8]
Definition global.c:139
gchar * PACKAGE_SGOI
Definition global.c:129
gchar * PACKAGE_JPG
Definition global.c:86
float *** alloctfloat(int xal, int yal, int zal)
allocate a float *** pointer
Definition global.c:437
gchar * PACKAGE_SGCI
Definition global.c:122
GtkWidget * calc_dialog
Definition global.c:210
gchar * PACKAGE_DOTD
Definition global.c:111
int tmp_pixels[2]
Definition global.c:173
gchar * PACKAGE_SQ
Definition global.c:91
GtkWidget * MainView
Definition global.c:202
gchar * PACKAGE_PNG
Definition global.c:85