2
#if !(defined __MSC__) && !(defined __ABSC__)
15
#if (defined __MSC__) || (defined __ABSC__)
16
/** only used for x=dir[1024] **/
18
#define getwd(x) _getcwd(x,1024)
20
#define getwd(x) getcwd_(x,1024)
25
#include "../machine.h"
31
extern char* my_basename();
32
extern int CheckGraphName();
34
extern char* dirname();
35
extern char *StripGraph();
39
static int CompString(s1, s2)
42
return strcmp((char*)*s1,(char*)*s2);
45
static char description[2*MAXNAM];
47
void C2F(loadg)(path,lpath,name,lname,directed,n,tail,head,
48
node_name,node_type,node_x,node_y,node_color,node_diam,node_border,
49
node_font_size,node_demand,
50
edge_name,edge_color,edge_width,edge_hi_width,edge_font_size,
51
edge_length,edge_cost,edge_min_cap,edge_max_cap,edge_q_weight,edge_q_orig,
53
default_node_diam,default_node_border,default_edge_width,
54
default_edge_hi_width,default_font_size,
56
char *path; int *lpath,*directed,*n,**tail,**head;
57
char **name; int *lname;
59
int **node_type,**node_x,**node_y,**node_color,**node_diam,**node_border;
63
int **edge_color,**edge_width,**edge_hi_width,**edge_font_size;
64
double **edge_length,**edge_cost,**edge_min_cap,**edge_max_cap;
65
double **edge_q_weight,**edge_q_orig,**edge_weight;
66
int *default_node_diam,*default_node_border,*default_edge_width;
67
int *default_edge_hi_width,*default_font_size;
74
#if !(defined __MSC__) && !(defined __ABSC__)
77
char fname[2 * MAXNAM];
78
char line[5 * MAXNAM];
79
char strname[MAXNAM], head_name[MAXNAM], tail_name[MAXNAM];
88
#if !(defined __MSC__) && !(defined __ABSC__)
89
if ((dirp=opendir(path)) != NULL) {
90
sprintf(description,"\"%s\" is a directory",path);
96
if (dirname(path) == NULL) getwd(dir);
97
else strcpy(dir,dirname(path));
98
#if !(defined __MSC__) && !(defined __ABSC__)
99
if ((dirp=opendir(dir)) == NULL) {
100
sprintf(description,"Directory \"%s\" does not exist",dir);
106
pname = StripGraph(my_basename(path));
108
*lname = strlen(pname);
110
if ((*name = (char *)malloc((unsigned)sizeof(char)*(*lname + 1)))
112
cerro("Running out of memory");
116
#if !(defined __MSC__) && !(defined __ABSC__)
117
if(!CheckGraphName(*name,dir)) {
118
sprintf(description,"Graph file \"%s/%s.graph\" does not exist",dir,*name);
124
dsize = sizeof(double);
129
strcat(fname,".graph");
130
fg = fopen(fname,"r");
132
sprintf(description,"Unable to open file \"%s/%s.graph\"",dir,*name);
136
/* read graph from graph file */
138
fgets(line,5 * MAXNAM,fg);
139
fgets(line,5 * MAXNAM,fg);
140
*default_node_diam = NODEDIAM;
141
*default_node_border = NODEW;
142
*default_edge_width = ARCW;
143
*default_edge_hi_width = ARCH;
144
*default_font_size = DRAWFONTSIZE;
145
sscanf(line,"%d %d %d %d %d %d",directed,default_node_diam,
146
default_node_border,default_edge_width,
147
default_edge_hi_width,default_font_size);
148
if (*default_node_diam == 0) *default_node_diam = NODEDIAM;
149
if (*default_node_border == 0) *default_node_border = NODEW;
150
if (*default_edge_width == 0) *default_edge_width = ARCW;
151
if (*default_edge_hi_width == 0) *default_edge_hi_width = ARCH;
152
if (*default_font_size == 0) *default_font_size = DRAWFONTSIZE;
153
fgets(line,5 * MAXNAM,fg);
154
fgets(line,5 * MAXNAM,fg);
155
sscanf(line,"%d",ma);
156
fgets(line,5 * MAXNAM,fg);
157
fgets(line,5 * MAXNAM,fg);
158
sscanf(line,"%d",ndim);
160
fgets(line,5 * MAXNAM,fg);
161
fgets(line,5 * MAXNAM,fg);
162
fgets(line,5 * MAXNAM,fg);
163
fgets(line,5 * MAXNAM,fg);
164
fgets(line,5 * MAXNAM,fg);
166
/* alloc memory for nodes */
167
s = sizeof(char *) * *ndim;
168
if ((*node_name = (char **)malloc(s)) == NULL) {
169
cerro("Running out of memory");
173
if ((*node_type = (int *)malloc(s)) == NULL) {
174
cerro("Running out of memory");
177
if ((*node_x = (int *)malloc(s)) == NULL) {
178
cerro("Running out of memory");
181
if ((*node_y = (int *)malloc(s)) == NULL) {
182
cerro("Running out of memory");
185
if ((*node_color = (int *)malloc(s)) == NULL) {
186
cerro("Running out of memory");
189
if ((*node_diam = (int *)malloc(s)) == NULL) {
190
cerro("Running out of memory");
193
if ((*node_border = (int *)malloc(s)) == NULL) {
194
cerro("Running out of memory");
197
if ((*node_font_size = (int *)malloc(s)) == NULL) {
198
cerro("Running out of memory");
202
if ((*node_demand = (double *)malloc(s)) == NULL) {
203
cerro("Running out of memory");
207
/* alloc memory for edges */
208
s = sizeof(char *) * *ma;
209
if ((*edge_name = (char **)malloc(s)) == NULL) {
210
cerro("Running out of memory");
214
if ((*head = (int *)malloc(s)) == NULL) {
215
cerro("Running out of memory");
218
if ((*tail = (int *)malloc(s)) == NULL) {
219
cerro("Running out of memory");
222
if ((*edge_color = (int *)malloc(s)) == NULL) {
223
cerro("Running out of memory");
226
if ((*edge_width = (int *)malloc(s)) == NULL) {
227
cerro("Running out of memory");
230
if ((*edge_hi_width = (int *)malloc(s)) == NULL) {
231
cerro("Running out of memory");
234
if ((*edge_font_size = (int *)malloc(s)) == NULL) {
235
cerro("Running out of memory");
239
if ((*edge_length = (double *)malloc(s)) == NULL) {
240
cerro("Running out of memory");
243
if ((*edge_cost = (double *)malloc(s)) == NULL) {
244
cerro("Running out of memory");
247
if ((*edge_min_cap = (double *)malloc(s)) == NULL) {
248
cerro("Running out of memory");
251
if ((*edge_max_cap = (double *)malloc(s)) == NULL) {
252
cerro("Running out of memory");
255
if ((*edge_q_weight = (double *)malloc(s)) == NULL) {
256
cerro("Running out of memory");
259
if ((*edge_q_orig = (double *)malloc(s)) == NULL) {
260
cerro("Running out of memory");
263
if ((*edge_weight = (double *)malloc(s)) == NULL) {
264
cerro("Running out of memory");
268
/* jump to node description */
269
for (i = 0; i < 2 * *ma; i++)
270
fgets(line,5 * MAXNAM,fg);
272
fgets(line,5 * MAXNAM,fg);
273
fgets(line,5 * MAXNAM,fg);
274
fgets(line,5 * MAXNAM,fg);
275
fgets(line,5 * MAXNAM,fg);
276
fgets(line,5 * MAXNAM,fg);
277
fgets(line,5 * MAXNAM,fg);
280
for (i = 0; i < *ndim; i++) {
281
fgets(line,5 * MAXNAM,fg);
283
sscanf(line,"%s %d",strname,&((*node_type)[i]));
284
if (((*node_name)[i] = (char *)malloc(strlen(strname)+1)) == NULL) {
285
cerro("Running out of memory");
288
strcpy((*node_name)[i],strname);
289
fgets(line,5 * MAXNAM,fg);
292
(*node_color)[i] = 0;
294
(*node_border)[i] = 0;
295
(*node_font_size)[i] = 0;
296
sscanf(line,"%d %d %d %d %d %d",
297
&((*node_x)[i]),&((*node_y)[i]),&((*node_color)[i]),
298
&((*node_diam)[i]),&((*node_border)[i]),&((*node_font_size)[i]));
299
fgets(line,5 * MAXNAM,fg);
300
sscanf(line,"%le",&((*node_demand)[i]));
301
if ((node.key = (char *)malloc(strlen(strname)+1)) == NULL) {
302
cerro("Running out of memory");
305
strcpy(node.key,strname);
306
sprintf(strname,"%d",i+1);
307
if ((node.data = (char *)malloc(strlen(strname)+1)) == NULL) {
308
cerro("Running out of memory");
311
strcpy(node.data,strname);
312
myhsearch(node,ENTER);
315
/* check uniqueness of node names */
317
if ((lar = (char **)malloc(sizeof(char *) * *ndim)) == NULL) {
318
cerro("Running out of memory");
321
for (i = 0; i < *ndim; i++) lar[i] = (*node_name)[i];
322
qsort((char*)lar,*ndim,sizeof(char*),(PF)CompString);
323
for (i = 0; i < *ndim - 1; i++) {
324
if (!strcmp(lar[i],lar[i+1])) {
326
"Bad graph file. Node \"%s\" is duplicated",lar[i]);
332
if (!strcmp(lar[*ndim - 2],lar[*ndim - 1])) {
334
"Bad graph file. Node \"%s\" is duplicated",lar[*ndim - 2]);
342
/* rewind and go to arc description */
344
for (i = 0; i < 11; i++)
345
fgets(line,5 * MAXNAM,fg);
346
for (i = 0; i < *ma; i++) {
347
fgets(line,5 * MAXNAM,fg);
348
(*edge_color)[i] = 0;
349
(*edge_width)[i] = 0;
350
(*edge_hi_width)[i] = 0;
351
(*edge_font_size)[i] = 0;
352
sscanf(line,"%s %s %s %d %d %d %d\n",strname,
354
&((*edge_color)[i]),&((*edge_width)[i]),&((*edge_hi_width)[i]),
355
&((*edge_font_size)[i]));
356
if (((*edge_name)[i] = (char *)malloc(strlen(strname)+1)) == NULL) {
357
cerro("Running out of memory");
360
strcpy((*edge_name)[i],strname);
362
if ((node.key = (char *)malloc(strlen(head_name)+1)) == NULL) {
363
cerro("Running out of memory");
366
strcpy(node.key,head_name);
367
found = myhsearch(node,FIND);
370
"Bad graph file. Node \"%s\" referenced by arc \"%s\" not found",
371
head_name,(*edge_name)[i]);
375
(*head)[i] = atoi(found->data);
376
if ((node.key = (char *)malloc(strlen(tail_name)+1)) == NULL) {
377
cerro("Running out of memory");
380
strcpy(node.key,tail_name);
381
found = myhsearch(node,FIND);
384
"Bad graph file. Node \"%s\" referenced by arc \"%s\" not found",
385
tail_name,(*edge_name)[i]);
389
(*tail)[i] = atoi(found->data);
391
fgets(line,5 * MAXNAM,fg);
392
sscanf(line,"%le %le %le %le %le %le %le",
393
&((*edge_cost)[i]),&((*edge_min_cap)[i]),
394
&((*edge_max_cap)[i]),&((*edge_length)[i]),
395
&((*edge_q_weight)[i]),&((*edge_q_orig)[i]),
396
&((*edge_weight)[i]));
400
/** #endif**/ /** __MSC__ **/