-
Notifications
You must be signed in to change notification settings - Fork 6
/
conv.c
214 lines (171 loc) · 4.61 KB
/
conv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include"typedef.h"
#include"getput.h"
#include"bravais.h"
#include"matrix.h"
#include"datei.h"
/* ---------------------------------------- */
/* Convert a single matrix in MAPLE format. */
/* ---------------------------------------- */
static void conv_mat_to_maple(matrix_TYP *A,
int i,
const char *name){
int j, k;
Check_mat(A);
if (!A->flags.Integral){
rat2kgv(A);
}
printf("%s%d := array(1..%d,1..%d,[\n", name, i+1, A->rows, A->cols);
for (j=0;j<A->rows;j++){
printf("[");
for (k=0;k<A->cols;k++){
printf(" %d",A->array.SZ[j][k]);
if (!A->flags.Integral){
printf("/%d",A->kgv);
}
if (k!=(A->cols-1)){
printf(",");
}
}
if (j != (A->rows-1)){
printf("],\n");
}
else{
printf("]");
}
}
printf("]):\n");
}
/* ---------------------------------------- */
/* Convert a single matrix in GAP format. */
/* ---------------------------------------- */
static void conv_mat_to_gap(matrix_TYP *A,
int i,
const char *name){
int j, k;
Check_mat(A);
if (!A->flags.Integral){
rat2kgv(A);
}
printf("%s%d := [", name, i+1);
for (j=0;j<A->rows;j++){
printf("[");
for (k=0;k<A->cols;k++){
printf(" %d",A->array.SZ[j][k]);
if (!A->flags.Integral){
printf("/%d",A->kgv);
}
if (k!=(A->cols-1)){
printf(",");
}
}
if (j != (A->rows-1)){
printf("],\n");
}
else{
printf("]");
}
}
printf("];;\n");
}
/* ---------------------------------------- */
/* Convert a single matrix in TeX format. */
/* ---------------------------------------- */
static void conv_mat_to_tex(matrix_TYP *A){
int j, k;
Check_mat(A);
if (!A->flags.Integral){
rat2kgv(A);
}
printf("\\left(\\begin{array}{");
for (j = 0; j < A->cols; j++)
printf("c");
printf("}\n");
for (j = 0; j < A->rows; j++){
for (k = 0;k < A->cols; k++){
if (A->array.SZ[j][k] % A->kgv == 0)
printf("%d ", A->array.SZ[j][k]/ A->kgv);
else
printf("%d/%d ", A->array.SZ[j][k], A->kgv);
if (k != A->cols - 1)
printf("& ");
}
printf("\\\\\n");
}
printf("\\end{array}\\right)\n");
}
/* ---------------------------------------- */
/* Main function. */
/* ---------------------------------------- */
int main (int argc, char *argv[])
{
int i,
anz,
flag;
matrix_TYP **A;
bravais_TYP *G;
const char *name;
read_header(argc, argv);
if(FILEANZ < 1 || (is_option('h') && optionnumber('h') == 0) )
{
printf("Usage: Conv 'file' ['name'] -g -G -m -M -t -T\n");
printf("\n");
printf("file: matrix_TYP or bravais_TYP (only generators are converted).\n");
printf("name: (optional) a word\n");
printf("\n");
printf("Converts the matrix_TYP into the format of other\n");
printf("programs available. The options specify the program,\n");
printf("and only one of them is allowed at one time.\n");
printf("First of all the number of matrices is printed.\n");
printf("The matrices are called 'name.1', 'name.2', ... or\n");
printf("if name isn't given 'a.1', 'a.2', ...\n");
printf("\n");
printf("-g or -G: GAP-format\n");
printf("-m or -M: MAPLE-format\n");
printf("-t or -T: TeX-format (the matrices aren't named and\n");
printf(" the number of matrices isn't given)\n");
printf("\n");
if (is_option('h')){
exit(0);
}
else{
exit(31);
}
}
G = get_bravais(FILENAMES[0]);
anz = G->gen_no;
A = G->gen;
if (FILEANZ < 2)
name = "a";
else
name = FILENAMES[1];
flag = 0;
if (is_option('t') || is_option('T'))
flag = 3;
if (is_option('m') || is_option('M'))
flag = 2;
if (is_option('g') || is_option('G'))
flag = 1;
if (flag > 0 && flag < 3)
printf("%sNo := %i", name, anz);
switch(flag){
case 2:
printf(":\n");
for (i = 0; i < anz; i++)
conv_mat_to_maple(A[i], i, name);
break;
case 1:
printf(";;\n");
for (i = 0; i < anz; i++)
conv_mat_to_gap(A[i], i, name);
break;
case 3:
for (i = 0; i < anz; i++)
conv_mat_to_tex(A[i]);
break;
default:
printf("\nYou must specify at least one option. Try -h first.\n");
}
A = NULL;
free_bravais(G);
exit(0);
}