Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563516 views
1
#include "name.h"
2
#include "getput.h"
3
#include "sort.h"
4
#include "bravais.h"
5
#include "gmp.h"
6
#include "name.h"
7
#include "matrix.h"
8
#include "datei.h"
9
10
#define DATABASE_NAME TOPDIR "/tables/qcatalog/data"
11
int SFLAG;
12
int INFO_LEVEL;
13
14
static void write_groups_to_file (int *write_list, database *database, char *string)
15
{
16
char argument [80], inputfilename [300];
17
FILE *outputfile, *inputfile;
18
int i, data_char;
19
20
if (sscanf (string, "w%s", argument) == 1)
21
{
22
if (strcmp (argument, "-s"))
23
{
24
if ( (outputfile = fopen (argument, "w") ) == NULL)
25
{
26
perror ("Open output-file");
27
fprintf (stderr, "Could not open: %s./n", argument);
28
exit (EXIT_FAILURE);
29
}
30
}
31
else
32
{
33
printf("stdout\n");
34
outputfile = stdout;
35
}
36
}
37
else
38
{
39
fprintf (stdout, "Write to file: w <filename>\nWrite to stdout: w -s\n\n\n");
40
return;
41
}
42
43
for (i=0; i<database->nr; i++)
44
if (write_list[i] == ALL_MATCH)
45
{
46
sprintf (inputfilename,
47
TOPDIR "/tables/qcatalog/dim%i/dir.%s/ordnung.%i/%s/%s",
48
(database->entry [i]).degree,
49
(database->entry [i]).symbol,
50
(database->entry [i]).order,
51
(database->entry [i]).discriminant,
52
(database->entry [i]).abbreviation);
53
54
55
if ( (inputfile = fopen (inputfilename, "r") ) == NULL)
56
{
57
perror ("Open group-file");
58
fprintf (stderr, "Could not open: %s./n", inputfilename);
59
exit (EXIT_FAILURE);
60
}
61
62
while ( (data_char = fgetc (inputfile)) != EOF)
63
{
64
fputc (data_char, outputfile);
65
}
66
67
if (fclose (inputfile) == EOF)
68
{
69
perror ("Closing input-group-file");
70
exit (EXIT_FAILURE);
71
}
72
73
74
}
75
76
if (outputfile != stdout)
77
if (fclose (outputfile) == EOF)
78
{
79
perror ("Closing output-file");
80
exit (EXIT_FAILURE);
81
}
82
83
return;
84
}
85
86
void display_conditions (conditions *cond)
87
{
88
int i;
89
90
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
91
if ( (cond->exists) [i] == TRUE)
92
{
93
fprintf (stdout, " %s = ", name_element [i]);
94
(display_element [i]) (&(cond->entry));
95
}
96
}
97
98
/* This function tests how many possible arguments of type "sub_entry"
99
still exist with the choice of other conditions
100
given. "list_of_possible" returns the list of the elements still
101
possible given by the array number to look it up in the "database"
102
and the return value of this function is the number of possible
103
values. */
104
int possible_arguments (int *search_list, database *database,
105
int **list_of_possible, int sub_entry)
106
{
107
int i, j, counter = 0;
108
109
char *new_element;
110
111
new_element = (char *) malloc(database->nr * sizeof(char));
112
113
new_element = memset (new_element, TRUE, database->nr);
114
115
116
(*list_of_possible) = (int *) malloc(database->nr * sizeof(int));
117
118
for (i=0; i<database->nr; i++)
119
if (search_list [i] == ALL_MATCH && new_element[i] == TRUE)
120
{
121
(*list_of_possible)[counter] = i;
122
counter ++;
123
124
for (j=i+1; j< database->nr; j++)
125
if (search_list [j] == ALL_MATCH && new_element[j] == TRUE &&
126
(compare_element [sub_entry])( &(database->entry[i]),
127
&(database->entry[j]))
128
== 0)
129
new_element [j] = 0;
130
}
131
132
free (new_element);
133
134
(*list_of_possible) = (int *) realloc( (*list_of_possible), counter * sizeof(int));
135
136
return counter;
137
}
138
139
void display_info_text (int *search_list, database *database,
140
conditions *cond)
141
{
142
int i,
143
q_counter = 0,
144
z_counter = 0,
145
aff_counter = 0;
146
147
char part1[4];
148
149
fprintf (stdout, "Conditions: ");
150
display_conditions (cond);
151
152
153
for (i=0; i<database->nr; i++)
154
if (search_list [i] == ALL_MATCH){
155
q_counter ++;
156
z_counter += database->entry[i].zclasses;
157
aff_counter += database->entry[i].affine;
158
}
159
160
fprintf (stdout, "\nQ_Classes: # %i, Z_Classes: # %i, Affine Classes: #%i\n\n",q_counter, z_counter, aff_counter);
161
162
163
164
165
fprintf (stdout, "Possible Conditions: ");
166
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
167
if (strlen (name_element [i]) > 3)
168
{
169
part1[0] = (name_element [i]) [0],
170
part1[1] = (name_element [i]) [1],
171
part1[2] = (name_element [i]) [2],
172
part1[3] = '\00';
173
174
175
fprintf (stdout, "%3s(%s) ", part1, &(name_element [i][3]));
176
}
177
else
178
fprintf (stdout, "%s ", name_element [i]);
179
fprintf (stdout, "\n");
180
181
fprintf (stdout, "\n\ns set condition p possible data\n");
182
fprintf (stdout, "d delete condition l list group\n");
183
fprintf (stdout, "w write to file q quit\n\n\n");
184
185
}
186
187
int change_conditions (conditions *cond, char *string, char set_or_del)
188
{
189
char part1 [80], part2 [80];
190
191
int i;
192
193
if (set_or_del == SET_COND)
194
{
195
196
197
if (sscanf (string, "s%s %s", part1, part2) != 2)
198
{
199
fprintf (stdout, "Wrong syntax. Please use:\n s <cond> <value>\n\n\n");
200
return -1;
201
}
202
203
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
204
if ( (strlen (part1) == 3 && strncmp (part1, name_element [i], 3) == 0)
205
|| strcmp (part1, name_element [i]) == 0)
206
{
207
if ( (cond->exists) [i] == TRUE )
208
(delete_element [i]) ( &(cond->entry) );
209
(cond->exists) [i] = TRUE;
210
(load_element [i]) (part2, &(cond->entry) );
211
fprintf (stdout, "'%s' has been set to ", name_element [i]);
212
(display_element [i]) ( &(cond->entry) );
213
fprintf (stdout, ".\n\n");
214
return i;
215
}
216
217
}
218
else if (set_or_del == DEL_COND)
219
{
220
221
sscanf (string, "d%s", part1);
222
223
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
224
if ( (strlen (part1) == 3 && strncmp (part1, name_element [i], 3) == 0)
225
|| strcmp (part1, name_element [i]) == 0)
226
if ((cond->exists) [i] == TRUE)
227
{
228
(delete_element [i]) ( &(cond->entry) );
229
fprintf (stdout, "'%s' has been unset..\n\n\n", name_element [i]);
230
(cond->exists) [i] = FALSE;
231
return i;
232
}
233
else
234
return -1;
235
236
}
237
else if (set_or_del == DISPLAY_POSSIBLE)
238
{
239
240
sscanf (string, "p%s", part1);
241
242
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
243
if ( (strlen (part1) == 3 && strncmp (part1, name_element [i], 3) == 0)
244
|| strcmp (part1, name_element [i]) == 0)
245
return i;
246
247
248
}
249
250
fprintf (stdout, "\n\nWrong input!\n\n");
251
return -1;
252
}
253
254
int prompt_input (int *search_list, database *database, conditions *cond)
255
{
256
char string [80], part1 [80];
257
int i;
258
259
fprintf (stdout, "\n>");
260
for (i=0; i<80; i++)
261
if ( (string [i] = fgetc(stdin)) == '\n')
262
{
263
string [i] = '\000';
264
break;
265
}
266
267
sscanf (string, "%s", part1);
268
269
switch (part1[0])
270
{
271
case 'q':
272
return 1;
273
case 's':
274
if ( (i = change_conditions (cond, string, SET_COND)) == -1)
275
return 0;
276
else
277
apply_cond_to_display_list (cond, database, search_list, i);
278
break;
279
case 'd':
280
if ( (i = change_conditions (cond, string, DEL_COND)) == -1)
281
return 0;
282
else
283
unapply_cond_to_display_list (database, search_list, i);
284
break;
285
case 'p':
286
if ( (i = change_conditions (cond, string, DISPLAY_POSSIBLE)) == -1)
287
return 0;
288
else
289
{
290
int *list_of_possible;
291
int number_of_possible, j;
292
293
number_of_possible = possible_arguments (search_list, database,
294
&list_of_possible, i);
295
296
fprintf (stdout, "Possible input for %s:\n", name_element [i]);
297
for (j=0; j<number_of_possible; j++){
298
if ( ! (j % 4) )
299
fprintf (stdout, "\n");
300
else
301
fprintf (stdout, "\t");
302
(display_element [i]) ( & (database->entry[list_of_possible[j]]) );
303
}
304
305
fprintf (stdout, "\n\n");
306
307
308
free (list_of_possible);
309
310
}
311
break;
312
case 'l':
313
display_data_list (database, search_list);
314
return 0;
315
case 'w':
316
write_groups_to_file (search_list, database, string);
317
return 0;
318
default:
319
fprintf (stdout, "Command '%c' is not defined.\n", part1[0]);
320
return 0;
321
}
322
323
return 0;
324
}
325
326
void interactive_mode (int *search_list, database *database)
327
{
328
conditions *cond;
329
int i;
330
331
332
if ( (cond = (conditions *) malloc (sizeof (conditions)) ) == NULL ||
333
(cond->exists = (int *) malloc (NR_OF_ELEMENTS_IN_EACH_ENTRY *
334
sizeof (int)) ) == NULL )
335
{
336
perror ("interactive_mode");
337
exit (EXIT_FAILURE);
338
}
339
340
for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)
341
(cond->exists) [i] = FALSE;
342
343
344
while (1)
345
{
346
display_info_text (search_list, database, cond);
347
if (prompt_input (search_list, database, cond) != 0)
348
{
349
fprintf (stdout, "Program aborted\n");
350
break;
351
}
352
}
353
return;
354
}
355
356
int main (int argc, char *argv[])
357
{
358
int i, *display_list;
359
360
database *database;
361
362
bravais_TYP *G,
363
*H;
364
365
matrix_TYP *T;
366
367
char name[1024],
368
symb[1024];
369
370
extern int FILEANZ;
371
extern char **FILENAMES;
372
373
read_header (argc, argv);
374
375
if (is_option('h'))
376
INFO_LEVEL = optionnumber('h');
377
378
if (INFO_LEVEL == 8)
379
SFLAG = 1;
380
381
if (is_option('h') && INFO_LEVEL != 8)
382
{
383
printf("Usage: %s [file] [-T] [-h] [-i] [-s]\n",argv[0]);
384
printf("\n");
385
printf("file: bravais_TYP containing the finite unimodular group G.\n");
386
printf("\n");
387
printf("The program Q_catalog as two identities:\n");
388
printf("If called without an input file, it gives access to the\n");
389
printf("database of all Q-classes of finite unimodular groups of degree\n");
390
printf("up to 6. In this mode, the command 'h' will provide further help.\n");
391
printf("If called with an input file, it searches for the given group\n");
392
printf("in the database, and gives a unique name choosen for this\n");
393
printf("Q-class.\n");
394
printf("\n");
395
printf("Options:\n");
396
printf("-h : gives this help.\n");
397
printf("-T : calculate a transformation matrix transforming the input\n");
398
printf(" group G into the group given in the catalog. (2nd mode only).\n");
399
printf("-i : output the group in the catalog which is Q-equivalent\n");
400
printf(" to the input group G. (2nd mode only).\n");
401
printf("-s : output the family symbol of G. (2nd mode only).\n");
402
printf("\n");
403
printf("Cf: Symbol, Bravais_type, Q_equiv, Bravais_catalog, Conj_bravais.\n");
404
exit (EXIT_SUCCESS);
405
}
406
407
if (FILEANZ == 1){
408
G = get_bravais(FILENAMES[0]);
409
410
database = load_database (DATABASE_NAME,G->dim);
411
412
display_list = (int *) malloc (database->nr * sizeof (int));
413
414
for (i=0; i<database->nr; i++)
415
display_list [i] = ALL_MATCH;
416
417
if (is_option('i')){
418
T = q_class_inf (G, database, name, symb, &H, NULL, is_option('T'));
419
}
420
else {
421
T = q_class_inf (G, database, name, symb, NULL, NULL, is_option('T'));
422
}
423
424
printf("Name of this Q-class: %s\n",name);
425
if (is_option('s'))
426
printf("symbol of the group %s\n",symb);
427
if (is_option('T')){
428
put_mat(T,NULL,"transformation matrix",0);
429
free_mat(T);
430
}
431
if (is_option('i')){
432
put_bravais(H,NULL,NULL);
433
free_bravais(H);
434
}
435
436
free_bravais(G);
437
438
}
439
else if (FILEANZ == 0){
440
database = load_database (DATABASE_NAME,0);
441
442
display_list = (int *) malloc (database->nr * sizeof (int));
443
444
for (i=0; i<database->nr; i++)
445
display_list [i] = ALL_MATCH;
446
447
interactive_mode (display_list, database);
448
}
449
else
450
{
451
fprintf (stderr, "Wrong number of files. Use <%s -h> for help.\n", argv[0]);
452
exit (EXIT_FAILURE);
453
}
454
/* display_data_list (database, display_list); */
455
456
free(display_list);
457
free_database (database);
458
if (INFO_LEVEL == 8) pointer_statistics(0,0);
459
460
return 0;
461
}
462
463