GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "name.h"1#include "getput.h"2#include "sort.h"3#include "bravais.h"4#include "gmp.h"5#include "name.h"6#include "matrix.h"7#include "datei.h"89#define DATABASE_NAME TOPDIR "/tables/qcatalog/data"10int SFLAG;11int INFO_LEVEL;1213static void write_groups_to_file (int *write_list, database *database, char *string)14{15char argument [80], inputfilename [300];16FILE *outputfile, *inputfile;17int i, data_char;1819if (sscanf (string, "w%s", argument) == 1)20{21if (strcmp (argument, "-s"))22{23if ( (outputfile = fopen (argument, "w") ) == NULL)24{25perror ("Open output-file");26fprintf (stderr, "Could not open: %s./n", argument);27exit (EXIT_FAILURE);28}29}30else31{32printf("stdout\n");33outputfile = stdout;34}35}36else37{38fprintf (stdout, "Write to file: w <filename>\nWrite to stdout: w -s\n\n\n");39return;40}4142for (i=0; i<database->nr; i++)43if (write_list[i] == ALL_MATCH)44{45sprintf (inputfilename,46TOPDIR "/tables/qcatalog/dim%i/dir.%s/ordnung.%i/%s/%s",47(database->entry [i]).degree,48(database->entry [i]).symbol,49(database->entry [i]).order,50(database->entry [i]).discriminant,51(database->entry [i]).abbreviation);525354if ( (inputfile = fopen (inputfilename, "r") ) == NULL)55{56perror ("Open group-file");57fprintf (stderr, "Could not open: %s./n", inputfilename);58exit (EXIT_FAILURE);59}6061while ( (data_char = fgetc (inputfile)) != EOF)62{63fputc (data_char, outputfile);64}6566if (fclose (inputfile) == EOF)67{68perror ("Closing input-group-file");69exit (EXIT_FAILURE);70}717273}7475if (outputfile != stdout)76if (fclose (outputfile) == EOF)77{78perror ("Closing output-file");79exit (EXIT_FAILURE);80}8182return;83}8485void display_conditions (conditions *cond)86{87int i;8889for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)90if ( (cond->exists) [i] == TRUE)91{92fprintf (stdout, " %s = ", name_element [i]);93(display_element [i]) (&(cond->entry));94}95}9697/* This function tests how many possible arguments of type "sub_entry"98still exist with the choice of other conditions99given. "list_of_possible" returns the list of the elements still100possible given by the array number to look it up in the "database"101and the return value of this function is the number of possible102values. */103int possible_arguments (int *search_list, database *database,104int **list_of_possible, int sub_entry)105{106int i, j, counter = 0;107108char *new_element;109110new_element = (char *) malloc(database->nr * sizeof(char));111112new_element = memset (new_element, TRUE, database->nr);113114115(*list_of_possible) = (int *) malloc(database->nr * sizeof(int));116117for (i=0; i<database->nr; i++)118if (search_list [i] == ALL_MATCH && new_element[i] == TRUE)119{120(*list_of_possible)[counter] = i;121counter ++;122123for (j=i+1; j< database->nr; j++)124if (search_list [j] == ALL_MATCH && new_element[j] == TRUE &&125(compare_element [sub_entry])( &(database->entry[i]),126&(database->entry[j]))127== 0)128new_element [j] = 0;129}130131free (new_element);132133(*list_of_possible) = (int *) realloc( (*list_of_possible), counter * sizeof(int));134135return counter;136}137138void display_info_text (int *search_list, database *database,139conditions *cond)140{141int i,142q_counter = 0,143z_counter = 0,144aff_counter = 0;145146char part1[4];147148fprintf (stdout, "Conditions: ");149display_conditions (cond);150151152for (i=0; i<database->nr; i++)153if (search_list [i] == ALL_MATCH){154q_counter ++;155z_counter += database->entry[i].zclasses;156aff_counter += database->entry[i].affine;157}158159fprintf (stdout, "\nQ_Classes: # %i, Z_Classes: # %i, Affine Classes: #%i\n\n",q_counter, z_counter, aff_counter);160161162163164fprintf (stdout, "Possible Conditions: ");165for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)166if (strlen (name_element [i]) > 3)167{168part1[0] = (name_element [i]) [0],169part1[1] = (name_element [i]) [1],170part1[2] = (name_element [i]) [2],171part1[3] = '\00';172173174fprintf (stdout, "%3s(%s) ", part1, &(name_element [i][3]));175}176else177fprintf (stdout, "%s ", name_element [i]);178fprintf (stdout, "\n");179180fprintf (stdout, "\n\ns set condition p possible data\n");181fprintf (stdout, "d delete condition l list group\n");182fprintf (stdout, "w write to file q quit\n\n\n");183184}185186int change_conditions (conditions *cond, char *string, char set_or_del)187{188char part1 [80], part2 [80];189190int i;191192if (set_or_del == SET_COND)193{194195196if (sscanf (string, "s%s %s", part1, part2) != 2)197{198fprintf (stdout, "Wrong syntax. Please use:\n s <cond> <value>\n\n\n");199return -1;200}201202for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)203if ( (strlen (part1) == 3 && strncmp (part1, name_element [i], 3) == 0)204|| strcmp (part1, name_element [i]) == 0)205{206if ( (cond->exists) [i] == TRUE )207(delete_element [i]) ( &(cond->entry) );208(cond->exists) [i] = TRUE;209(load_element [i]) (part2, &(cond->entry) );210fprintf (stdout, "'%s' has been set to ", name_element [i]);211(display_element [i]) ( &(cond->entry) );212fprintf (stdout, ".\n\n");213return i;214}215216}217else if (set_or_del == DEL_COND)218{219220sscanf (string, "d%s", part1);221222for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)223if ( (strlen (part1) == 3 && strncmp (part1, name_element [i], 3) == 0)224|| strcmp (part1, name_element [i]) == 0)225if ((cond->exists) [i] == TRUE)226{227(delete_element [i]) ( &(cond->entry) );228fprintf (stdout, "'%s' has been unset..\n\n\n", name_element [i]);229(cond->exists) [i] = FALSE;230return i;231}232else233return -1;234235}236else if (set_or_del == DISPLAY_POSSIBLE)237{238239sscanf (string, "p%s", part1);240241for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)242if ( (strlen (part1) == 3 && strncmp (part1, name_element [i], 3) == 0)243|| strcmp (part1, name_element [i]) == 0)244return i;245246247}248249fprintf (stdout, "\n\nWrong input!\n\n");250return -1;251}252253int prompt_input (int *search_list, database *database, conditions *cond)254{255char string [80], part1 [80];256int i;257258fprintf (stdout, "\n>");259for (i=0; i<80; i++)260if ( (string [i] = fgetc(stdin)) == '\n')261{262string [i] = '\000';263break;264}265266sscanf (string, "%s", part1);267268switch (part1[0])269{270case 'q':271return 1;272case 's':273if ( (i = change_conditions (cond, string, SET_COND)) == -1)274return 0;275else276apply_cond_to_display_list (cond, database, search_list, i);277break;278case 'd':279if ( (i = change_conditions (cond, string, DEL_COND)) == -1)280return 0;281else282unapply_cond_to_display_list (database, search_list, i);283break;284case 'p':285if ( (i = change_conditions (cond, string, DISPLAY_POSSIBLE)) == -1)286return 0;287else288{289int *list_of_possible;290int number_of_possible, j;291292number_of_possible = possible_arguments (search_list, database,293&list_of_possible, i);294295fprintf (stdout, "Possible input for %s:\n", name_element [i]);296for (j=0; j<number_of_possible; j++){297if ( ! (j % 4) )298fprintf (stdout, "\n");299else300fprintf (stdout, "\t");301(display_element [i]) ( & (database->entry[list_of_possible[j]]) );302}303304fprintf (stdout, "\n\n");305306307free (list_of_possible);308309}310break;311case 'l':312display_data_list (database, search_list);313return 0;314case 'w':315write_groups_to_file (search_list, database, string);316return 0;317default:318fprintf (stdout, "Command '%c' is not defined.\n", part1[0]);319return 0;320}321322return 0;323}324325void interactive_mode (int *search_list, database *database)326{327conditions *cond;328int i;329330331if ( (cond = (conditions *) malloc (sizeof (conditions)) ) == NULL ||332(cond->exists = (int *) malloc (NR_OF_ELEMENTS_IN_EACH_ENTRY *333sizeof (int)) ) == NULL )334{335perror ("interactive_mode");336exit (EXIT_FAILURE);337}338339for (i=0; i<NR_OF_ELEMENTS_IN_EACH_ENTRY; i++)340(cond->exists) [i] = FALSE;341342343while (1)344{345display_info_text (search_list, database, cond);346if (prompt_input (search_list, database, cond) != 0)347{348fprintf (stdout, "Program aborted\n");349break;350}351}352return;353}354355int main (int argc, char *argv[])356{357int i, *display_list;358359database *database;360361bravais_TYP *G,362*H;363364matrix_TYP *T;365366char name[1024],367symb[1024];368369extern int FILEANZ;370extern char **FILENAMES;371372read_header (argc, argv);373374if (is_option('h'))375INFO_LEVEL = optionnumber('h');376377if (INFO_LEVEL == 8)378SFLAG = 1;379380if (is_option('h') && INFO_LEVEL != 8)381{382printf("Usage: %s [file] [-T] [-h] [-i] [-s]\n",argv[0]);383printf("\n");384printf("file: bravais_TYP containing the finite unimodular group G.\n");385printf("\n");386printf("The program Q_catalog as two identities:\n");387printf("If called without an input file, it gives access to the\n");388printf("database of all Q-classes of finite unimodular groups of degree\n");389printf("up to 6. In this mode, the command 'h' will provide further help.\n");390printf("If called with an input file, it searches for the given group\n");391printf("in the database, and gives a unique name choosen for this\n");392printf("Q-class.\n");393printf("\n");394printf("Options:\n");395printf("-h : gives this help.\n");396printf("-T : calculate a transformation matrix transforming the input\n");397printf(" group G into the group given in the catalog. (2nd mode only).\n");398printf("-i : output the group in the catalog which is Q-equivalent\n");399printf(" to the input group G. (2nd mode only).\n");400printf("-s : output the family symbol of G. (2nd mode only).\n");401printf("\n");402printf("Cf: Symbol, Bravais_type, Q_equiv, Bravais_catalog, Conj_bravais.\n");403exit (EXIT_SUCCESS);404}405406if (FILEANZ == 1){407G = get_bravais(FILENAMES[0]);408409database = load_database (DATABASE_NAME,G->dim);410411display_list = (int *) malloc (database->nr * sizeof (int));412413for (i=0; i<database->nr; i++)414display_list [i] = ALL_MATCH;415416if (is_option('i')){417T = q_class_inf (G, database, name, symb, &H, NULL, is_option('T'));418}419else {420T = q_class_inf (G, database, name, symb, NULL, NULL, is_option('T'));421}422423printf("Name of this Q-class: %s\n",name);424if (is_option('s'))425printf("symbol of the group %s\n",symb);426if (is_option('T')){427put_mat(T,NULL,"transformation matrix",0);428free_mat(T);429}430if (is_option('i')){431put_bravais(H,NULL,NULL);432free_bravais(H);433}434435free_bravais(G);436437}438else if (FILEANZ == 0){439database = load_database (DATABASE_NAME,0);440441display_list = (int *) malloc (database->nr * sizeof (int));442443for (i=0; i<database->nr; i++)444display_list [i] = ALL_MATCH;445446interactive_mode (display_list, database);447}448else449{450fprintf (stderr, "Wrong number of files. Use <%s -h> for help.\n", argv[0]);451exit (EXIT_FAILURE);452}453/* display_data_list (database, display_list); */454455free(display_list);456free_database (database);457if (INFO_LEVEL == 8) pointer_statistics(0,0);458459return 0;460}461462463