~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to interfaces/shell/interface.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C -*-  */
 
2
/* 
 
3
   IGraph library.
 
4
   Copyright (C) 2007  Gabor Csardi <csardi@rmki.kfki.hu>
 
5
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
 
6
   
 
7
   This program is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (at your option) any later version.
 
11
   
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
   
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with this program; if not, write to the Free Software
 
19
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
 
20
   02110-1301 USA
 
21
 
 
22
*/
 
23
 
 
24
#define _GNU_SOURCE
 
25
 
 
26
#include <libgen.h>
 
27
#include <string.h>
 
28
#include <stdio.h>
 
29
#include <getopt.h>
 
30
#include <stdlib.h>
 
31
#include <stdarg.h>
 
32
#include <errno.h>
 
33
#include <limits.h>
 
34
#include <ctype.h>
 
35
 
 
36
#include "igraph.h"
 
37
 
 
38
/* ------------------------------------------------------------------------ */
 
39
/* Conversion & other common functions first                                */
 
40
/* ------------------------------------------------------------------------ */
 
41
 
 
42
 
 
43
int shell_igraph_usage(int argc, char **argv) {
 
44
  printf("Command line interface to igraph\n");
 
45
  return 0;
 
46
}
 
47
 
 
48
int shell_skip_whitespace(FILE *fin) {
 
49
  int c;
 
50
  c=fgetc(fin);
 
51
  while (isspace(c)) {
 
52
    c=fgetc(fin);
 
53
  }
 
54
  if (c!=EOF) { ungetc(c, fin); }
 
55
  return 0;
 
56
}
 
57
 
 
58
FILE *shell_open_file(const char *where, const char *mode) {  
 
59
  static const char *input="input";
 
60
  static const char *output="output";
 
61
  FILE *f;
 
62
 
 
63
  if (!strcmp(where, "-")) {
 
64
    if (!strcmp(mode, "r")) {
 
65
      return stdin;
 
66
    } else if (!strcmp(mode, "w")) {
 
67
      return stdout;
 
68
    }
 
69
  }
 
70
 
 
71
  f=fopen(where, mode);
 
72
  if (!f) {
 
73
    fprintf(stderr, "Cannot open %s file: `%s'\n", 
 
74
            !strcmp(mode, "r") ? input : output, where);
 
75
    exit(1);
 
76
  }
 
77
  return f;
 
78
 
79
 
 
80
int shell_read_graph(igraph_t *graph, const char *where) {
 
81
  FILE *fin=shell_open_file(where, "r");
 
82
  igraph_read_graph_graphml(graph, fin, 0);
 
83
  fclose(fin);
 
84
  return 0;
 
85
}
 
86
 
 
87
int shell_write_graph(const igraph_t *graph, const char *where) {
 
88
  FILE *fout=shell_open_file(where, "w");
 
89
  igraph_write_graph_graphml(graph, fout);
 
90
  fclose(fout);
 
91
  return 0;
 
92
}
 
93
 
 
94
int shell_read_vector(igraph_vector_t *v, const char *where) {
 
95
  FILE *fin=shell_open_file(where, "r");
 
96
  igraph_real_t n;
 
97
  int ret=1;
 
98
  igraph_vector_init(v, 0);
 
99
  while (ret > 0) {
 
100
    ret=fscanf(fin, "%lf", &n);
 
101
    if (ret > 0) { 
 
102
      igraph_vector_push_back(v, n);
 
103
    }
 
104
  }
 
105
  fclose(fin);
 
106
  if (ret != EOF) {
 
107
    fprintf(stderr, "Error reading vector from file: `%s'\n", where);
 
108
    exit(1);
 
109
  }
 
110
 
 
111
  return 0;
 
112
}
 
113
 
 
114
int shell_write_a_vector(const igraph_vector_t *v, FILE *fout, const char *where) {
 
115
  int ret=1;
 
116
  long int i, n=igraph_vector_size(v);
 
117
  if (n>0) { ret=fprintf(fout, "%g", VECTOR(*v)[0]); }
 
118
  if (ret <= 0) { 
 
119
    fprintf(stderr, "Cannot write vector to `%s'\n", where);
 
120
    fclose(fout);
 
121
    exit(1);
 
122
  }
 
123
  for (i=1; i<n; i++) {
 
124
    ret=fprintf(fout, " %g", VECTOR(*v)[i]);
 
125
    if (ret <= 0) { 
 
126
      fprintf(stderr, "Cannot write vector to `%s'\n", where);
 
127
      fclose(fout);
 
128
      exit(1);
 
129
    }
 
130
  }
 
131
  fprintf(fout, "\n");
 
132
  return 0;
 
133
}  
 
134
 
 
135
int shell_write_vector(const igraph_vector_t *v, const char *where) {
 
136
  FILE *fout=shell_open_file(where, "w");
 
137
  shell_write_a_vector(v, fout, where);
 
138
  fclose(fout);  
 
139
  return 0;
 
140
}
 
141
 
 
142
int shell_read_a_matrix(igraph_matrix_t *m, FILE *fin, const char *where) {
 
143
  long int ncol, nrow, i, j;
 
144
  igraph_real_t n;
 
145
  int ret;
 
146
  if (2 != fscanf(fin, "%li %li", &nrow, &ncol)) {
 
147
    fprintf(stderr, "Error reading matrix from file '%s'\n", where);
 
148
    fclose(fin);
 
149
    exit(1);
 
150
  }
 
151
  igraph_matrix_init(m,nrow,ncol);
 
152
  for (i=0; i<nrow; i++) {
 
153
    for (j=0; j<ncol; j++) {
 
154
      ret=fscanf(fin, "%lf", &n);
 
155
      if (ret <= 0) { 
 
156
        fprintf(stderr, "Error reading matrix from file '%s'\n", where);
 
157
        fclose(fin);
 
158
        exit(1);
 
159
      }
 
160
      MATRIX(*m, i, j)=n;
 
161
    }
 
162
  }
 
163
  return 0;
 
164
}
 
165
 
 
166
int shell_read_matrix(igraph_matrix_t *m, const char *where) {
 
167
  FILE *fin=shell_open_file(where, "r");
 
168
  shell_read_a_matrix(m, fin, where);
 
169
  fclose(fin);      
 
170
  return 0;
 
171
}
 
172
 
 
173
int shell_write_matrix(const igraph_matrix_t *m, const char *where) {
 
174
  FILE *fout=shell_open_file(where, "w");
 
175
  long int nrow=igraph_matrix_nrow(m);
 
176
  long int ncol=igraph_matrix_ncol(m);
 
177
  long int i, j;
 
178
    
 
179
  if (0>fprintf(fout, "%li %li\n", nrow, ncol)) {
 
180
    fprintf(stderr, "Error writing matrix to file '%s'.\n", where);
 
181
    fclose(fout);
 
182
    exit(1);
 
183
  }
 
184
 
 
185
  for (i=0; i<nrow; i++) {
 
186
    for (j=0; j<ncol; j++) {
 
187
      if (j!=0) { fprintf(fout, " "); }
 
188
      if (0>fprintf(fout, "%g", MATRIX(*m, i, j))) {
 
189
        fprintf(stderr, "Error writing matrix to file '%s'.\n", where);
 
190
        fclose(fout);
 
191
        exit(1);
 
192
      }
 
193
    }
 
194
    fprintf(fout, "\n");
 
195
  }
 
196
  fclose(fout);
 
197
  
 
198
  return 0;
 
199
}
 
200
 
 
201
int shell_read_integer(igraph_integer_t *n, const char *where) {
 
202
  long int nn;
 
203
  int ret=sscanf(where, "%li", &nn);
 
204
  if (ret == EOF || ret == 0) {
 
205
    fprintf(stderr, "Error, cannot interpret '%s' as integer\n", where);
 
206
    exit(1);
 
207
  }
 
208
  *n=nn;
 
209
  return 0;
 
210
}
 
211
 
 
212
int shell_write_integer(igraph_integer_t n, const char *where) {
 
213
  FILE *fout=shell_open_file(where, "w");
 
214
  int ret=fprintf(fout, "%li\n", (long int)n);
 
215
  if (ret <= 0) { 
 
216
    fprintf(stderr, "Cannot write integer to '%s'\n", where);
 
217
    fclose(fout);
 
218
    exit(1);
 
219
  }
 
220
  return 0;
 
221
}
 
222
 
 
223
int shell_read_boolean(igraph_bool_t *b, const char *where) {
 
224
  if (strlen(where)==0 || 
 
225
      where[0]=='0' ||
 
226
      where[0]=='F' ||
 
227
      where[0]=='f') {
 
228
    *b=0;
 
229
  } else {
 
230
    *b=1;
 
231
  }
 
232
  return 0;
 
233
}
 
234
 
 
235
int shell_write_boolean(igraph_bool_t b, const char *where) {
 
236
  int bb= b==0 ? 0 : 1;
 
237
  FILE *fout=shell_open_file(where, "w");
 
238
  int ret=fprintf(fout, "%i\n", bb);
 
239
  if (ret <= 0) { 
 
240
    fprintf(stderr, "Cannot write integer to '%s'\n", where);
 
241
    fclose(fout);
 
242
    exit(1);
 
243
  }  
 
244
  return 0;
 
245
}
 
246
 
 
247
int shell_read_real(igraph_real_t *b, const char *where) {
 
248
  int ret=sscanf(where, "%lf", b);
 
249
  if (ret == EOF || ret == 0) {
 
250
    fprintf(stderr, "Error, cannot interpret '%s' as real\n", where);
 
251
    exit(1);
 
252
  }  
 
253
  return 0;
 
254
}
 
255
 
 
256
int shell_write_real(igraph_real_t b, const char *where) {
 
257
  FILE *fout=shell_open_file(where, "w");
 
258
  int ret=fprintf(fout, "%g\n", (double)b);
 
259
  if (ret <= 0) { 
 
260
    fprintf(stderr, "Cannot write real to `%s'\n", where);
 
261
    fclose(fout);
 
262
    exit(1);
 
263
  }
 
264
  return 0;
 
265
}
 
266
 
 
267
int shell_read_enum(void* value, const char *where, ...) {
 
268
  int result=-1, *p=value;
 
269
  va_list args;
 
270
  va_start(args, where);
 
271
  
 
272
  while (1) {
 
273
    char *name=va_arg(args, char*);
 
274
    int code;
 
275
    if (name) {
 
276
      code=va_arg(args, int);
 
277
      if (!strcmp(optarg, name)) {
 
278
        result=code;
 
279
        break;
 
280
      }
 
281
    } else {
 
282
      break;
 
283
    }
 
284
  }
 
285
  
 
286
  if (result==-1) {
 
287
    fprintf(stderr, "Cannot interpret argument: '%s'.\n", where);
 
288
    exit(1);
 
289
  }   
 
290
 
 
291
  *p=result;
 
292
 
 
293
  return 0;
 
294
}
 
295
 
 
296
int shell_read_int(int *value, const char *where) {
 
297
  long int li=strtol(where, 0, 10);
 
298
  if (errno || li<INT_MIN || li>INT_MAX) {
 
299
    fprintf(stderr, "Integer too small/big: '%s'.\n", where);
 
300
  }
 
301
  *value=li;
 
302
  return 0;
 
303
}
 
304
 
 
305
int shell_read_longint(long int *value, const char *where) {
 
306
  long int li=strtol(where, 0, 10);
 
307
  if (errno) {
 
308
    fprintf(stderr, "Long integer too small/big: '%s'.\n", where);
 
309
  }
 
310
  *value=li;
 
311
  return 0;
 
312
}
 
313
 
 
314
int shell_read_file(FILE **file, const char *where, const char *mode) {
 
315
  *file=fopen(where, mode);
 
316
  if (!*file) {
 
317
    fprintf(stderr, "Cannot open file '%s'\n", where);
 
318
  }
 
319
  return 0;
 
320
}
 
321
 
 
322
int shell_read_matrixlist(igraph_vector_ptr_t *list, const char *where) {
 
323
  FILE *fin=shell_open_file(where, "r");
 
324
  igraph_vector_ptr_init(list, 0);
 
325
  shell_skip_whitespace(fin);
 
326
  while (!feof(fin)) {
 
327
    igraph_matrix_t *m=malloc(sizeof(igraph_matrix_t));
 
328
    shell_read_a_matrix(m, fin, where);
 
329
    igraph_vector_ptr_push_back(list, m);
 
330
    shell_skip_whitespace(fin);
 
331
  }
 
332
  fclose(fin);
 
333
  return 0;
 
334
}
 
335
 
 
336
int shell_read_graphlist(igraph_vector_ptr_t *list, const char *where) {
 
337
  FILE *fin=shell_open_file(where, "r");
 
338
  igraph_vector_ptr_init(list, 0);
 
339
  shell_skip_whitespace(fin);
 
340
  while (!feof(fin)) {
 
341
    igraph_t *g=malloc(sizeof(igraph_t));
 
342
    igraph_read_graph_graphml(g, fin, 0);
 
343
    igraph_vector_ptr_push_back(list, g);
 
344
    shell_skip_whitespace(fin);
 
345
  }
 
346
  fclose(fin);
 
347
  return 0;
 
348
}
 
349
 
 
350
int shell_read_strvector(igraph_strvector_t *str, const char *where) {
 
351
  FILE *fin=shell_open_file(where, "r");
 
352
  char *buffer=calloc(1000, sizeof(char));
 
353
  size_t size;
 
354
  int c;
 
355
  igraph_strvector_init(str, 0);
 
356
  while(1) {
 
357
    getline(&buffer, &size, fin);
 
358
    igraph_strvector_add(str, buffer);
 
359
    c=getc(fin);
 
360
    if (!feof(fin)) {
 
361
      ungetc(c, fin);
 
362
    } else {
 
363
      break;
 
364
    }
 
365
  }
 
366
  fclose(fin);
 
367
  free(buffer);
 
368
  
 
369
  return 0;
 
370
}
 
371
 
 
372
int shell_write_vectorlist(igraph_vector_ptr_t *v, const char *where) {
 
373
  FILE *fout=shell_open_file(where, "w");
 
374
  long int i, n=igraph_vector_ptr_size(v);
 
375
  for (i=0; i<n; i++) {
 
376
    shell_write_a_vector(VECTOR(*v)[i], fout, where);
 
377
  }
 
378
  fclose(fout);
 
379
  return 0;
 
380
}
 
381
 
 
382
int shell_write_vector_bool(igraph_vector_bool_t *v, const char *where) {
 
383
  FILE *fout=shell_open_file(where, "w");
 
384
  int ret=1;
 
385
  long int i, n=igraph_vector_bool_size(v);
 
386
  if (n>0) { ret=fprintf(fout, "%i", VECTOR(*v)[0]==0 ? 0 : 1); }
 
387
  if (ret <= 0) { 
 
388
    fprintf(stderr, "Cannot write vector to `%s'\n", where);
 
389
    fclose(fout);
 
390
    exit(1);
 
391
  }
 
392
  for (i=1; i<n; i++) {
 
393
    ret=fprintf(fout, " %i", VECTOR(*v)[i]==0 ? 0 : 1);
 
394
    if (ret <= 0) { 
 
395
      fprintf(stderr, "Cannot write vector to `%s'\n", where);
 
396
      fclose(fout);
 
397
      exit(1);
 
398
    }
 
399
  }
 
400
  fprintf(fout, "\n");
 
401
  fclose(fout);
 
402
  return 0;
 
403
}  
 
404
 
 
405
int shell_write_graphlist(igraph_vector_ptr_t *v, const char *where) {
 
406
  FILE *fout=shell_open_file(where, "w");
 
407
  long int i, n=igraph_vector_ptr_size(v);
 
408
  for (i=0; i<n; i++) {
 
409
    igraph_write_graph_graphml(VECTOR(*v)[i], fout);
 
410
  }
 
411
  fclose(fout);
 
412
  return 0;
 
413
}
 
414
 
 
415
int shell_free_graphlist(igraph_vector_ptr_t *v) {
 
416
  long int i, n=igraph_vector_ptr_size(v);
 
417
  for (i=0; i<n; i++) {
 
418
    igraph_destroy(VECTOR(*v)[i]);
 
419
    free(VECTOR(*v)[i]);
 
420
    VECTOR(*v)[i]=0;
 
421
  }
 
422
  return 0;
 
423
}
 
424
 
 
425
int shell_free_matrixlist(igraph_vector_ptr_t *v) {
 
426
  long int i, n=igraph_vector_ptr_size(v);
 
427
  for (i=0; i<n; i++) {
 
428
    igraph_matrix_destroy(VECTOR(*v)[i]);
 
429
    free(VECTOR(*v)[i]);
 
430
    VECTOR(*v)[i]=0;
 
431
  }
 
432
  return 0;
 
433
}
 
434
 
 
435
int shell_free_vectorlist(igraph_vector_ptr_t *v) {
 
436
  long int i, n=igraph_vector_ptr_size(v);
 
437
  for (i=0; i<n; i++) {
 
438
    igraph_vector_destroy(VECTOR(*v)[i]);
 
439
    free(VECTOR(*v)[i]);
 
440
    VECTOR(*v)[i]=0;
 
441
  }
 
442
  return 0;
 
443
}
 
444
 
 
445
/* ------------------------------------------------------------------------ */
 
446
/* Stimulus generated interface next                                        */
 
447
/* ------------------------------------------------------------------------ */
 
448
 
 
449
 
 
450
/* Function prototypes first */
 
451
 
 
452
int shell_igraph_empty(int argc, char **argv);
 
453
int shell_igraph_add_edges(int argc, char **argv);
 
454
int shell_igraph_add_vertices(int argc, char **argv);
 
455
int shell_igraph_delete_edges(int argc, char **argv);
 
456
int shell_igraph_delete_vertices(int argc, char **argv);
 
457
int shell_igraph_vcount(int argc, char **argv);
 
458
int shell_igraph_ecount(int argc, char **argv);
 
459
int shell_igraph_neighbors(int argc, char **argv);
 
460
int shell_igraph_is_directed(int argc, char **argv);
 
461
int shell_igraph_degree(int argc, char **argv);
 
462
int shell_igraph_edge(int argc, char **argv);
 
463
int shell_igraph_edges(int argc, char **argv);
 
464
int shell_igraph_get_eid(int argc, char **argv);
 
465
int shell_igraph_get_eids(int argc, char **argv);
 
466
int shell_igraph_adjacent(int argc, char **argv);
 
467
int shell_igraph_create(int argc, char **argv);
 
468
int shell_igraph_adjacency(int argc, char **argv);
 
469
int shell_igraph_star(int argc, char **argv);
 
470
int shell_igraph_lattice(int argc, char **argv);
 
471
int shell_igraph_ring(int argc, char **argv);
 
472
int shell_igraph_tree(int argc, char **argv);
 
473
int shell_igraph_full(int argc, char **argv);
 
474
int shell_igraph_full_citation(int argc, char **argv);
 
475
int shell_igraph_atlas(int argc, char **argv);
 
476
int shell_igraph_extended_chordal_ring(int argc, char **argv);
 
477
int shell_igraph_connect_neighborhood(int argc, char **argv);
 
478
int shell_igraph_linegraph(int argc, char **argv);
 
479
int shell_igraph_de_bruijn(int argc, char **argv);
 
480
int shell_igraph_kautz(int argc, char **argv);
 
481
int shell_igraph_famous(int argc, char **argv);
 
482
int shell_igraph_lcf_vector(int argc, char **argv);
 
483
int shell_igraph_adjlist(int argc, char **argv);
 
484
int shell_igraph_full_bipartite(int argc, char **argv);
 
485
int shell_igraph_barabasi_game(int argc, char **argv);
 
486
int shell_igraph_nonlinear_barabasi_game(int argc, char **argv);
 
487
int shell_igraph_erdos_renyi_game_gnp(int argc, char **argv);
 
488
int shell_igraph_erdos_renyi_game_gnm(int argc, char **argv);
 
489
int shell_igraph_degree_sequence_game(int argc, char **argv);
 
490
int shell_igraph_growing_random_game(int argc, char **argv);
 
491
int shell_igraph_barabasi_aging_game(int argc, char **argv);
 
492
int shell_igraph_recent_degree_game(int argc, char **argv);
 
493
int shell_igraph_recent_degree_aging_game(int argc, char **argv);
 
494
int shell_igraph_callaway_traits_game(int argc, char **argv);
 
495
int shell_igraph_establishment_game(int argc, char **argv);
 
496
int shell_igraph_grg_game(int argc, char **argv);
 
497
int shell_igraph_preference_game(int argc, char **argv);
 
498
int shell_igraph_asymmetric_preference_game(int argc, char **argv);
 
499
int shell_igraph_rewire_edges(int argc, char **argv);
 
500
int shell_igraph_watts_strogatz_game(int argc, char **argv);
 
501
int shell_igraph_lastcit_game(int argc, char **argv);
 
502
int shell_igraph_cited_type_game(int argc, char **argv);
 
503
int shell_igraph_citing_cited_type_game(int argc, char **argv);
 
504
int shell_igraph_forest_fire_game(int argc, char **argv);
 
505
int shell_igraph_are_connected(int argc, char **argv);
 
506
int shell_igraph_diameter(int argc, char **argv);
 
507
int shell_igraph_diameter_dijkstra(int argc, char **argv);
 
508
int shell_igraph_minimum_spanning_tree_unweighted(int argc, char **argv);
 
509
int shell_igraph_minimum_spanning_tree_prim(int argc, char **argv);
 
510
int shell_igraph_closeness(int argc, char **argv);
 
511
int shell_igraph_closeness_estimate(int argc, char **argv);
 
512
int shell_igraph_shortest_paths(int argc, char **argv);
 
513
int shell_igraph_get_shortest_paths(int argc, char **argv);
 
514
int shell_igraph_get_all_shortest_paths(int argc, char **argv);
 
515
int shell_igraph_shortest_paths_dijkstra(int argc, char **argv);
 
516
int shell_igraph_shortest_paths_bellman_ford(int argc, char **argv);
 
517
int shell_igraph_subcomponent(int argc, char **argv);
 
518
int shell_igraph_betweenness(int argc, char **argv);
 
519
int shell_igraph_betweenness_estimate(int argc, char **argv);
 
520
int shell_igraph_edge_betweenness(int argc, char **argv);
 
521
int shell_igraph_edge_betweenness_estimate(int argc, char **argv);
 
522
int shell_igraph_pagerank_old(int argc, char **argv);
 
523
int shell_igraph_pagerank(int argc, char **argv);
 
524
int shell_igraph_rewire(int argc, char **argv);
 
525
int shell_igraph_subgraph(int argc, char **argv);
 
526
int shell_igraph_average_path_length(int argc, char **argv);
 
527
int shell_igraph_path_length_hist(int argc, char **argv);
 
528
int shell_igraph_simplify(int argc, char **argv);
 
529
int shell_igraph_transitivity_undirected(int argc, char **argv);
 
530
int shell_igraph_transitivity_local_undirected(int argc, char **argv);
 
531
int shell_igraph_transitivity_avglocal_undirected(int argc, char **argv);
 
532
int shell_igraph_reciprocity(int argc, char **argv);
 
533
int shell_igraph_constraint(int argc, char **argv);
 
534
int shell_igraph_maxdegree(int argc, char **argv);
 
535
int shell_igraph_density(int argc, char **argv);
 
536
int shell_igraph_neighborhood_size(int argc, char **argv);
 
537
int shell_igraph_neighborhood(int argc, char **argv);
 
538
int shell_igraph_neighborhood_graphs(int argc, char **argv);
 
539
int shell_igraph_topological_sorting(int argc, char **argv);
 
540
int shell_igraph_is_loop(int argc, char **argv);
 
541
int shell_igraph_is_simple(int argc, char **argv);
 
542
int shell_igraph_is_multiple(int argc, char **argv);
 
543
int shell_igraph_count_multiple(int argc, char **argv);
 
544
int shell_igraph_girth(int argc, char **argv);
 
545
int shell_igraph_add_edge(int argc, char **argv);
 
546
int shell_igraph_eigenvector_centrality(int argc, char **argv);
 
547
int shell_igraph_hub_score(int argc, char **argv);
 
548
int shell_igraph_authority_score(int argc, char **argv);
 
549
int shell_igraph_arpack_rssolve(int argc, char **argv);
 
550
int shell_igraph_arpack_rnsolve(int argc, char **argv);
 
551
int shell_igraph_arpack_unpack_complex(int argc, char **argv);
 
552
int shell_igraph_unfold_tree(int argc, char **argv);
 
553
int shell_igraph_laplacian(int argc, char **argv);
 
554
int shell_igraph_is_mutual(int argc, char **argv);
 
555
int shell_igraph_avg_nearest_neighbor_degree(int argc, char **argv);
 
556
int shell_igraph_strength(int argc, char **argv);
 
557
int shell_igraph_bipartite_projection_size(int argc, char **argv);
 
558
int shell_igraph_bipartite_projection(int argc, char **argv);
 
559
int shell_igraph_create_bipartite(int argc, char **argv);
 
560
int shell_igraph_incidence(int argc, char **argv);
 
561
int shell_igraph_get_incidence(int argc, char **argv);
 
562
int shell_igraph_is_bipartite(int argc, char **argv);
 
563
int shell_igraph_clusters(int argc, char **argv);
 
564
int shell_igraph_is_connected(int argc, char **argv);
 
565
int shell_igraph_decompose(int argc, char **argv);
 
566
int shell_igraph_articulation_points(int argc, char **argv);
 
567
int shell_igraph_biconnected_components(int argc, char **argv);
 
568
int shell_igraph_cliques(int argc, char **argv);
 
569
int shell_igraph_largest_cliques(int argc, char **argv);
 
570
int shell_igraph_maximal_cliques(int argc, char **argv);
 
571
int shell_igraph_clique_number(int argc, char **argv);
 
572
int shell_igraph_independent_vertex_sets(int argc, char **argv);
 
573
int shell_igraph_largest_independent_vertex_sets(int argc, char **argv);
 
574
int shell_igraph_maximal_independent_vertex_sets(int argc, char **argv);
 
575
int shell_igraph_independence_number(int argc, char **argv);
 
576
int shell_igraph_layout_random(int argc, char **argv);
 
577
int shell_igraph_layout_circle(int argc, char **argv);
 
578
int shell_igraph_layout_fruchterman_reingold(int argc, char **argv);
 
579
int shell_igraph_layout_grid_fruchterman_reingold(int argc, char **argv);
 
580
int shell_igraph_layout_kamada_kawai(int argc, char **argv);
 
581
int shell_igraph_layout_lgl(int argc, char **argv);
 
582
int shell_igraph_layout_reingold_tilford(int argc, char **argv);
 
583
int shell_igraph_layout_reingold_tilford_circular(int argc, char **argv);
 
584
int shell_igraph_layout_random_3d(int argc, char **argv);
 
585
int shell_igraph_layout_sphere(int argc, char **argv);
 
586
int shell_igraph_layout_fruchterman_reingold_3d(int argc, char **argv);
 
587
int shell_igraph_layout_kamada_kawai_3d(int argc, char **argv);
 
588
int shell_igraph_layout_graphopt(int argc, char **argv);
 
589
int shell_igraph_layout_drl(int argc, char **argv);
 
590
int shell_igraph_layout_drl_3d(int argc, char **argv);
 
591
int shell_igraph_layout_merge_dla(int argc, char **argv);
 
592
int shell_igraph_cocitation(int argc, char **argv);
 
593
int shell_igraph_bibcoupling(int argc, char **argv);
 
594
int shell_igraph_similarity_jaccard(int argc, char **argv);
 
595
int shell_igraph_similarity_dice(int argc, char **argv);
 
596
int shell_igraph_similarity_inverse_log_weighted(int argc, char **argv);
 
597
int shell_igraph_community_spinglass(int argc, char **argv);
 
598
int shell_igraph_community_spinglass_single(int argc, char **argv);
 
599
int shell_igraph_community_walktrap(int argc, char **argv);
 
600
int shell_igraph_community_edge_betweenness(int argc, char **argv);
 
601
int shell_igraph_community_eb_get_merges(int argc, char **argv);
 
602
int shell_igraph_community_fastgreedy(int argc, char **argv);
 
603
int shell_igraph_community_to_membership(int argc, char **argv);
 
604
int shell_igraph_le_community_to_membership(int argc, char **argv);
 
605
int shell_igraph_modularity(int argc, char **argv);
 
606
int shell_igraph_community_leading_eigenvector(int argc, char **argv);
 
607
int shell_igraph_community_leading_eigenvector_naive(int argc, char **argv);
 
608
int shell_igraph_community_leading_eigenvector_step(int argc, char **argv);
 
609
int shell_igraph_community_label_propagation(int argc, char **argv);
 
610
int shell_igraph_get_adjacency(int argc, char **argv);
 
611
int shell_igraph_get_edgelist(int argc, char **argv);
 
612
int shell_igraph_to_directed(int argc, char **argv);
 
613
int shell_igraph_to_undirected(int argc, char **argv);
 
614
int shell_igraph_read_graph_edgelist(int argc, char **argv);
 
615
int shell_igraph_read_graph_ncol(int argc, char **argv);
 
616
int shell_igraph_read_graph_lgl(int argc, char **argv);
 
617
int shell_igraph_read_graph_pajek(int argc, char **argv);
 
618
int shell_igraph_read_graph_graphml(int argc, char **argv);
 
619
int shell_igraph_read_graph_dimacs(int argc, char **argv);
 
620
int shell_igraph_read_graph_graphdb(int argc, char **argv);
 
621
int shell_igraph_read_graph_gml(int argc, char **argv);
 
622
int shell_igraph_write_graph_edgelist(int argc, char **argv);
 
623
int shell_igraph_write_graph_ncol(int argc, char **argv);
 
624
int shell_igraph_write_graph_lgl(int argc, char **argv);
 
625
int shell_igraph_write_graph_graphml(int argc, char **argv);
 
626
int shell_igraph_write_graph_pajek(int argc, char **argv);
 
627
int shell_igraph_write_graph_dimacs(int argc, char **argv);
 
628
int shell_igraph_write_graph_gml(int argc, char **argv);
 
629
int shell_igraph_write_graph_dot(int argc, char **argv);
 
630
int shell_igraph_motifs_randesu(int argc, char **argv);
 
631
int shell_igraph_motifs_randesu_estimate(int argc, char **argv);
 
632
int shell_igraph_motifs_randesu_no(int argc, char **argv);
 
633
int shell_igraph_dyad_census(int argc, char **argv);
 
634
int shell_igraph_triad_census(int argc, char **argv);
 
635
int shell_igraph_disjoint_union(int argc, char **argv);
 
636
int shell_igraph_disjoint_union_many(int argc, char **argv);
 
637
int shell_igraph_union(int argc, char **argv);
 
638
int shell_igraph_union_many(int argc, char **argv);
 
639
int shell_igraph_intersection(int argc, char **argv);
 
640
int shell_igraph_intersection_many(int argc, char **argv);
 
641
int shell_igraph_difference(int argc, char **argv);
 
642
int shell_igraph_complementer(int argc, char **argv);
 
643
int shell_igraph_compose(int argc, char **argv);
 
644
int shell_igraph_maxflow_value(int argc, char **argv);
 
645
int shell_igraph_mincut_value(int argc, char **argv);
 
646
int shell_igraph_st_mincut_value(int argc, char **argv);
 
647
int shell_igraph_mincut(int argc, char **argv);
 
648
int shell_igraph_st_vertex_connectivity(int argc, char **argv);
 
649
int shell_igraph_vertex_connectivity(int argc, char **argv);
 
650
int shell_igraph_st_edge_connectivity(int argc, char **argv);
 
651
int shell_igraph_edge_connectivity(int argc, char **argv);
 
652
int shell_igraph_edge_disjoint_paths(int argc, char **argv);
 
653
int shell_igraph_vertex_disjoint_paths(int argc, char **argv);
 
654
int shell_igraph_adhesion(int argc, char **argv);
 
655
int shell_igraph_cohesion(int argc, char **argv);
 
656
int shell_igraph_coreness(int argc, char **argv);
 
657
int shell_igraph_isoclass(int argc, char **argv);
 
658
int shell_igraph_isomorphic(int argc, char **argv);
 
659
int shell_igraph_isoclass_subgraph(int argc, char **argv);
 
660
int shell_igraph_isoclass_create(int argc, char **argv);
 
661
int shell_igraph_isomorphic_vf2(int argc, char **argv);
 
662
int shell_igraph_count_isomorphisms_vf2(int argc, char **argv);
 
663
int shell_igraph_get_isomorphisms_vf2(int argc, char **argv);
 
664
int shell_igraph_subisomorphic_vf2(int argc, char **argv);
 
665
int shell_igraph_count_subisomorphisms_vf2(int argc, char **argv);
 
666
int shell_igraph_get_subisomorphisms_vf2(int argc, char **argv);
 
667
int shell_igraph_isomorphic_34(int argc, char **argv);
 
668
int shell_igraph_canonical_permutation(int argc, char **argv);
 
669
int shell_igraph_permute_vertices(int argc, char **argv);
 
670
int shell_igraph_isomorphic_bliss(int argc, char **argv);
 
671
int shell_igraph_automorphisms(int argc, char **argv);
 
672
int shell_igraph_running_mean(int argc, char **argv);
 
673
int shell_igraph_random_sample(int argc, char **argv);
 
674
int shell_igraph_convex_hull(int argc, char **argv);
 
675
int shell_igraph_revolver_ml_d(int argc, char **argv);
 
676
int shell_igraph_revolver_probs_d(int argc, char **argv);
 
677
int shell_igraph_revolver_ml_de(int argc, char **argv);
 
678
int shell_igraph_revolver_probs_de(int argc, char **argv);
 
679
int shell_igraph_revolver_ml_ade(int argc, char **argv);
 
680
int shell_igraph_revolver_probs_ade(int argc, char **argv);
 
681
int shell_igraph_revolver_ml_f(int argc, char **argv);
 
682
int shell_igraph_revolver_ml_df(int argc, char **argv);
 
683
int shell_igraph_revolver_ml_l(int argc, char **argv);
 
684
int shell_igraph_revolver_ml_ad(int argc, char **argv);
 
685
int shell_igraph_revolver_probs_ad(int argc, char **argv);
 
686
int shell_igraph_revolver_ml_D_alpha(int argc, char **argv);
 
687
int shell_igraph_revolver_ml_D_alpha_a(int argc, char **argv);
 
688
int shell_igraph_revolver_ml_DE_alpha_a(int argc, char **argv);
 
689
int shell_igraph_revolver_ml_AD_alpha_a_beta(int argc, char **argv);
 
690
int shell_igraph_revolver_ml_AD_dpareto(int argc, char **argv);
 
691
int shell_igraph_revolver_ml_AD_dpareto_eval(int argc, char **argv);
 
692
int shell_igraph_revolver_ml_ADE_alpha_a_beta(int argc, char **argv);
 
693
int shell_igraph_revolver_ml_ADE_dpareto(int argc, char **argv);
 
694
int shell_igraph_revolver_ml_ADE_dpareto_eval(int argc, char **argv);
 
695
int shell_igraph_revolver_ml_ADE_dpareto_evalf(int argc, char **argv);
 
696
int shell_igraph_revolver_probs_ADE_dpareto(int argc, char **argv);
 
697
int shell_igraph_convergence_degree(int argc, char **argv);
 
698
 
 
699
/* The main function */
 
700
 
 
701
int main(int argc, char **argv) {
 
702
 
 
703
  const char *base=basename(argv[0]);
 
704
 
 
705
  if (!strcasecmp(base, "igraph_empty")) {
 
706
    return shell_igraph_empty(argc, argv);
 
707
  } else if (!strcasecmp(base, "igraph_add_edges")) {
 
708
    return shell_igraph_add_edges(argc, argv);
 
709
  } else if (!strcasecmp(base, "igraph_add_vertices")) {
 
710
    return shell_igraph_add_vertices(argc, argv);
 
711
  } else if (!strcasecmp(base, "igraph_delete_edges")) {
 
712
    return shell_igraph_delete_edges(argc, argv);
 
713
  } else if (!strcasecmp(base, "igraph_delete_vertices")) {
 
714
    return shell_igraph_delete_vertices(argc, argv);
 
715
  } else if (!strcasecmp(base, "igraph_vcount")) {
 
716
    return shell_igraph_vcount(argc, argv);
 
717
  } else if (!strcasecmp(base, "igraph_ecount")) {
 
718
    return shell_igraph_ecount(argc, argv);
 
719
  } else if (!strcasecmp(base, "igraph_neighbors")) {
 
720
    return shell_igraph_neighbors(argc, argv);
 
721
  } else if (!strcasecmp(base, "igraph_is_directed")) {
 
722
    return shell_igraph_is_directed(argc, argv);
 
723
  } else if (!strcasecmp(base, "igraph_degree")) {
 
724
    return shell_igraph_degree(argc, argv);
 
725
  } else if (!strcasecmp(base, "igraph_edge")) {
 
726
    return shell_igraph_edge(argc, argv);
 
727
  } else if (!strcasecmp(base, "igraph_edges")) {
 
728
    return shell_igraph_edges(argc, argv);
 
729
  } else if (!strcasecmp(base, "igraph_get_eid")) {
 
730
    return shell_igraph_get_eid(argc, argv);
 
731
  } else if (!strcasecmp(base, "igraph_get_eids")) {
 
732
    return shell_igraph_get_eids(argc, argv);
 
733
  } else if (!strcasecmp(base, "igraph_adjacent")) {
 
734
    return shell_igraph_adjacent(argc, argv);
 
735
  } else if (!strcasecmp(base, "igraph_create")) {
 
736
    return shell_igraph_create(argc, argv);
 
737
  } else if (!strcasecmp(base, "igraph_adjacency")) {
 
738
    return shell_igraph_adjacency(argc, argv);
 
739
  } else if (!strcasecmp(base, "igraph_star")) {
 
740
    return shell_igraph_star(argc, argv);
 
741
  } else if (!strcasecmp(base, "igraph_lattice")) {
 
742
    return shell_igraph_lattice(argc, argv);
 
743
  } else if (!strcasecmp(base, "igraph_ring")) {
 
744
    return shell_igraph_ring(argc, argv);
 
745
  } else if (!strcasecmp(base, "igraph_tree")) {
 
746
    return shell_igraph_tree(argc, argv);
 
747
  } else if (!strcasecmp(base, "igraph_full")) {
 
748
    return shell_igraph_full(argc, argv);
 
749
  } else if (!strcasecmp(base, "igraph_full_citation")) {
 
750
    return shell_igraph_full_citation(argc, argv);
 
751
  } else if (!strcasecmp(base, "igraph_atlas")) {
 
752
    return shell_igraph_atlas(argc, argv);
 
753
  } else if (!strcasecmp(base, "igraph_extended_chordal_ring")) {
 
754
    return shell_igraph_extended_chordal_ring(argc, argv);
 
755
  } else if (!strcasecmp(base, "igraph_connect_neighborhood")) {
 
756
    return shell_igraph_connect_neighborhood(argc, argv);
 
757
  } else if (!strcasecmp(base, "igraph_linegraph")) {
 
758
    return shell_igraph_linegraph(argc, argv);
 
759
  } else if (!strcasecmp(base, "igraph_de_bruijn")) {
 
760
    return shell_igraph_de_bruijn(argc, argv);
 
761
  } else if (!strcasecmp(base, "igraph_kautz")) {
 
762
    return shell_igraph_kautz(argc, argv);
 
763
  } else if (!strcasecmp(base, "igraph_famous")) {
 
764
    return shell_igraph_famous(argc, argv);
 
765
  } else if (!strcasecmp(base, "igraph_lcf_vector")) {
 
766
    return shell_igraph_lcf_vector(argc, argv);
 
767
  } else if (!strcasecmp(base, "igraph_adjlist")) {
 
768
    return shell_igraph_adjlist(argc, argv);
 
769
  } else if (!strcasecmp(base, "igraph_full_bipartite")) {
 
770
    return shell_igraph_full_bipartite(argc, argv);
 
771
  } else if (!strcasecmp(base, "igraph_barabasi_game")) {
 
772
    return shell_igraph_barabasi_game(argc, argv);
 
773
  } else if (!strcasecmp(base, "igraph_nonlinear_barabasi_game")) {
 
774
    return shell_igraph_nonlinear_barabasi_game(argc, argv);
 
775
  } else if (!strcasecmp(base, "igraph_erdos_renyi_game_gnp")) {
 
776
    return shell_igraph_erdos_renyi_game_gnp(argc, argv);
 
777
  } else if (!strcasecmp(base, "igraph_erdos_renyi_game_gnm")) {
 
778
    return shell_igraph_erdos_renyi_game_gnm(argc, argv);
 
779
  } else if (!strcasecmp(base, "igraph_degree_sequence_game")) {
 
780
    return shell_igraph_degree_sequence_game(argc, argv);
 
781
  } else if (!strcasecmp(base, "igraph_growing_random_game")) {
 
782
    return shell_igraph_growing_random_game(argc, argv);
 
783
  } else if (!strcasecmp(base, "igraph_barabasi_aging_game")) {
 
784
    return shell_igraph_barabasi_aging_game(argc, argv);
 
785
  } else if (!strcasecmp(base, "igraph_recent_degree_game")) {
 
786
    return shell_igraph_recent_degree_game(argc, argv);
 
787
  } else if (!strcasecmp(base, "igraph_recent_degree_aging_game")) {
 
788
    return shell_igraph_recent_degree_aging_game(argc, argv);
 
789
  } else if (!strcasecmp(base, "igraph_callaway_traits_game")) {
 
790
    return shell_igraph_callaway_traits_game(argc, argv);
 
791
  } else if (!strcasecmp(base, "igraph_establishment_game")) {
 
792
    return shell_igraph_establishment_game(argc, argv);
 
793
  } else if (!strcasecmp(base, "igraph_grg_game")) {
 
794
    return shell_igraph_grg_game(argc, argv);
 
795
  } else if (!strcasecmp(base, "igraph_preference_game")) {
 
796
    return shell_igraph_preference_game(argc, argv);
 
797
  } else if (!strcasecmp(base, "igraph_asymmetric_preference_game")) {
 
798
    return shell_igraph_asymmetric_preference_game(argc, argv);
 
799
  } else if (!strcasecmp(base, "igraph_rewire_edges")) {
 
800
    return shell_igraph_rewire_edges(argc, argv);
 
801
  } else if (!strcasecmp(base, "igraph_watts_strogatz_game")) {
 
802
    return shell_igraph_watts_strogatz_game(argc, argv);
 
803
  } else if (!strcasecmp(base, "igraph_lastcit_game")) {
 
804
    return shell_igraph_lastcit_game(argc, argv);
 
805
  } else if (!strcasecmp(base, "igraph_cited_type_game")) {
 
806
    return shell_igraph_cited_type_game(argc, argv);
 
807
  } else if (!strcasecmp(base, "igraph_citing_cited_type_game")) {
 
808
    return shell_igraph_citing_cited_type_game(argc, argv);
 
809
  } else if (!strcasecmp(base, "igraph_forest_fire_game")) {
 
810
    return shell_igraph_forest_fire_game(argc, argv);
 
811
  } else if (!strcasecmp(base, "igraph_are_connected")) {
 
812
    return shell_igraph_are_connected(argc, argv);
 
813
  } else if (!strcasecmp(base, "igraph_diameter")) {
 
814
    return shell_igraph_diameter(argc, argv);
 
815
  } else if (!strcasecmp(base, "igraph_diameter_dijkstra")) {
 
816
    return shell_igraph_diameter_dijkstra(argc, argv);
 
817
  } else if (!strcasecmp(base, "igraph_minimum_spanning_tree_unweighted")) {
 
818
    return shell_igraph_minimum_spanning_tree_unweighted(argc, argv);
 
819
  } else if (!strcasecmp(base, "igraph_minimum_spanning_tree_prim")) {
 
820
    return shell_igraph_minimum_spanning_tree_prim(argc, argv);
 
821
  } else if (!strcasecmp(base, "igraph_closeness")) {
 
822
    return shell_igraph_closeness(argc, argv);
 
823
  } else if (!strcasecmp(base, "igraph_closeness_estimate")) {
 
824
    return shell_igraph_closeness_estimate(argc, argv);
 
825
  } else if (!strcasecmp(base, "igraph_shortest_paths")) {
 
826
    return shell_igraph_shortest_paths(argc, argv);
 
827
  } else if (!strcasecmp(base, "igraph_get_shortest_paths")) {
 
828
    return shell_igraph_get_shortest_paths(argc, argv);
 
829
  } else if (!strcasecmp(base, "igraph_get_all_shortest_paths")) {
 
830
    return shell_igraph_get_all_shortest_paths(argc, argv);
 
831
  } else if (!strcasecmp(base, "igraph_shortest_paths_dijkstra")) {
 
832
    return shell_igraph_shortest_paths_dijkstra(argc, argv);
 
833
  } else if (!strcasecmp(base, "igraph_shortest_paths_bellman_ford")) {
 
834
    return shell_igraph_shortest_paths_bellman_ford(argc, argv);
 
835
  } else if (!strcasecmp(base, "igraph_subcomponent")) {
 
836
    return shell_igraph_subcomponent(argc, argv);
 
837
  } else if (!strcasecmp(base, "igraph_betweenness")) {
 
838
    return shell_igraph_betweenness(argc, argv);
 
839
  } else if (!strcasecmp(base, "igraph_betweenness_estimate")) {
 
840
    return shell_igraph_betweenness_estimate(argc, argv);
 
841
  } else if (!strcasecmp(base, "igraph_edge_betweenness")) {
 
842
    return shell_igraph_edge_betweenness(argc, argv);
 
843
  } else if (!strcasecmp(base, "igraph_edge_betweenness_estimate")) {
 
844
    return shell_igraph_edge_betweenness_estimate(argc, argv);
 
845
  } else if (!strcasecmp(base, "igraph_pagerank_old")) {
 
846
    return shell_igraph_pagerank_old(argc, argv);
 
847
  } else if (!strcasecmp(base, "igraph_pagerank")) {
 
848
    return shell_igraph_pagerank(argc, argv);
 
849
  } else if (!strcasecmp(base, "igraph_rewire")) {
 
850
    return shell_igraph_rewire(argc, argv);
 
851
  } else if (!strcasecmp(base, "igraph_subgraph")) {
 
852
    return shell_igraph_subgraph(argc, argv);
 
853
  } else if (!strcasecmp(base, "igraph_average_path_length")) {
 
854
    return shell_igraph_average_path_length(argc, argv);
 
855
  } else if (!strcasecmp(base, "igraph_path_length_hist")) {
 
856
    return shell_igraph_path_length_hist(argc, argv);
 
857
  } else if (!strcasecmp(base, "igraph_simplify")) {
 
858
    return shell_igraph_simplify(argc, argv);
 
859
  } else if (!strcasecmp(base, "igraph_transitivity_undirected")) {
 
860
    return shell_igraph_transitivity_undirected(argc, argv);
 
861
  } else if (!strcasecmp(base, "igraph_transitivity_local_undirected")) {
 
862
    return shell_igraph_transitivity_local_undirected(argc, argv);
 
863
  } else if (!strcasecmp(base, "igraph_transitivity_avglocal_undirected")) {
 
864
    return shell_igraph_transitivity_avglocal_undirected(argc, argv);
 
865
  } else if (!strcasecmp(base, "igraph_reciprocity")) {
 
866
    return shell_igraph_reciprocity(argc, argv);
 
867
  } else if (!strcasecmp(base, "igraph_constraint")) {
 
868
    return shell_igraph_constraint(argc, argv);
 
869
  } else if (!strcasecmp(base, "igraph_maxdegree")) {
 
870
    return shell_igraph_maxdegree(argc, argv);
 
871
  } else if (!strcasecmp(base, "igraph_density")) {
 
872
    return shell_igraph_density(argc, argv);
 
873
  } else if (!strcasecmp(base, "igraph_neighborhood_size")) {
 
874
    return shell_igraph_neighborhood_size(argc, argv);
 
875
  } else if (!strcasecmp(base, "igraph_neighborhood")) {
 
876
    return shell_igraph_neighborhood(argc, argv);
 
877
  } else if (!strcasecmp(base, "igraph_neighborhood_graphs")) {
 
878
    return shell_igraph_neighborhood_graphs(argc, argv);
 
879
  } else if (!strcasecmp(base, "igraph_topological_sorting")) {
 
880
    return shell_igraph_topological_sorting(argc, argv);
 
881
  } else if (!strcasecmp(base, "igraph_is_loop")) {
 
882
    return shell_igraph_is_loop(argc, argv);
 
883
  } else if (!strcasecmp(base, "igraph_is_simple")) {
 
884
    return shell_igraph_is_simple(argc, argv);
 
885
  } else if (!strcasecmp(base, "igraph_is_multiple")) {
 
886
    return shell_igraph_is_multiple(argc, argv);
 
887
  } else if (!strcasecmp(base, "igraph_count_multiple")) {
 
888
    return shell_igraph_count_multiple(argc, argv);
 
889
  } else if (!strcasecmp(base, "igraph_girth")) {
 
890
    return shell_igraph_girth(argc, argv);
 
891
  } else if (!strcasecmp(base, "igraph_add_edge")) {
 
892
    return shell_igraph_add_edge(argc, argv);
 
893
  } else if (!strcasecmp(base, "igraph_eigenvector_centrality")) {
 
894
    return shell_igraph_eigenvector_centrality(argc, argv);
 
895
  } else if (!strcasecmp(base, "igraph_hub_score")) {
 
896
    return shell_igraph_hub_score(argc, argv);
 
897
  } else if (!strcasecmp(base, "igraph_authority_score")) {
 
898
    return shell_igraph_authority_score(argc, argv);
 
899
  } else if (!strcasecmp(base, "igraph_arpack_rssolve")) {
 
900
    return shell_igraph_arpack_rssolve(argc, argv);
 
901
  } else if (!strcasecmp(base, "igraph_arpack_rnsolve")) {
 
902
    return shell_igraph_arpack_rnsolve(argc, argv);
 
903
  } else if (!strcasecmp(base, "igraph_arpack_unpack_complex")) {
 
904
    return shell_igraph_arpack_unpack_complex(argc, argv);
 
905
  } else if (!strcasecmp(base, "igraph_unfold_tree")) {
 
906
    return shell_igraph_unfold_tree(argc, argv);
 
907
  } else if (!strcasecmp(base, "igraph_laplacian")) {
 
908
    return shell_igraph_laplacian(argc, argv);
 
909
  } else if (!strcasecmp(base, "igraph_is_mutual")) {
 
910
    return shell_igraph_is_mutual(argc, argv);
 
911
  } else if (!strcasecmp(base, "igraph_avg_nearest_neighbor_degree")) {
 
912
    return shell_igraph_avg_nearest_neighbor_degree(argc, argv);
 
913
  } else if (!strcasecmp(base, "igraph_strength")) {
 
914
    return shell_igraph_strength(argc, argv);
 
915
  } else if (!strcasecmp(base, "igraph_bipartite_projection_size")) {
 
916
    return shell_igraph_bipartite_projection_size(argc, argv);
 
917
  } else if (!strcasecmp(base, "igraph_bipartite_projection")) {
 
918
    return shell_igraph_bipartite_projection(argc, argv);
 
919
  } else if (!strcasecmp(base, "igraph_create_bipartite")) {
 
920
    return shell_igraph_create_bipartite(argc, argv);
 
921
  } else if (!strcasecmp(base, "igraph_incidence")) {
 
922
    return shell_igraph_incidence(argc, argv);
 
923
  } else if (!strcasecmp(base, "igraph_get_incidence")) {
 
924
    return shell_igraph_get_incidence(argc, argv);
 
925
  } else if (!strcasecmp(base, "igraph_is_bipartite")) {
 
926
    return shell_igraph_is_bipartite(argc, argv);
 
927
  } else if (!strcasecmp(base, "igraph_clusters")) {
 
928
    return shell_igraph_clusters(argc, argv);
 
929
  } else if (!strcasecmp(base, "igraph_is_connected")) {
 
930
    return shell_igraph_is_connected(argc, argv);
 
931
  } else if (!strcasecmp(base, "igraph_decompose")) {
 
932
    return shell_igraph_decompose(argc, argv);
 
933
  } else if (!strcasecmp(base, "igraph_articulation_points")) {
 
934
    return shell_igraph_articulation_points(argc, argv);
 
935
  } else if (!strcasecmp(base, "igraph_biconnected_components")) {
 
936
    return shell_igraph_biconnected_components(argc, argv);
 
937
  } else if (!strcasecmp(base, "igraph_cliques")) {
 
938
    return shell_igraph_cliques(argc, argv);
 
939
  } else if (!strcasecmp(base, "igraph_largest_cliques")) {
 
940
    return shell_igraph_largest_cliques(argc, argv);
 
941
  } else if (!strcasecmp(base, "igraph_maximal_cliques")) {
 
942
    return shell_igraph_maximal_cliques(argc, argv);
 
943
  } else if (!strcasecmp(base, "igraph_clique_number")) {
 
944
    return shell_igraph_clique_number(argc, argv);
 
945
  } else if (!strcasecmp(base, "igraph_independent_vertex_sets")) {
 
946
    return shell_igraph_independent_vertex_sets(argc, argv);
 
947
  } else if (!strcasecmp(base, "igraph_largest_independent_vertex_sets")) {
 
948
    return shell_igraph_largest_independent_vertex_sets(argc, argv);
 
949
  } else if (!strcasecmp(base, "igraph_maximal_independent_vertex_sets")) {
 
950
    return shell_igraph_maximal_independent_vertex_sets(argc, argv);
 
951
  } else if (!strcasecmp(base, "igraph_independence_number")) {
 
952
    return shell_igraph_independence_number(argc, argv);
 
953
  } else if (!strcasecmp(base, "igraph_layout_random")) {
 
954
    return shell_igraph_layout_random(argc, argv);
 
955
  } else if (!strcasecmp(base, "igraph_layout_circle")) {
 
956
    return shell_igraph_layout_circle(argc, argv);
 
957
  } else if (!strcasecmp(base, "igraph_layout_fruchterman_reingold")) {
 
958
    return shell_igraph_layout_fruchterman_reingold(argc, argv);
 
959
  } else if (!strcasecmp(base, "igraph_layout_grid_fruchterman_reingold")) {
 
960
    return shell_igraph_layout_grid_fruchterman_reingold(argc, argv);
 
961
  } else if (!strcasecmp(base, "igraph_layout_kamada_kawai")) {
 
962
    return shell_igraph_layout_kamada_kawai(argc, argv);
 
963
  } else if (!strcasecmp(base, "igraph_layout_lgl")) {
 
964
    return shell_igraph_layout_lgl(argc, argv);
 
965
  } else if (!strcasecmp(base, "igraph_layout_reingold_tilford")) {
 
966
    return shell_igraph_layout_reingold_tilford(argc, argv);
 
967
  } else if (!strcasecmp(base, "igraph_layout_reingold_tilford_circular")) {
 
968
    return shell_igraph_layout_reingold_tilford_circular(argc, argv);
 
969
  } else if (!strcasecmp(base, "igraph_layout_random_3d")) {
 
970
    return shell_igraph_layout_random_3d(argc, argv);
 
971
  } else if (!strcasecmp(base, "igraph_layout_sphere")) {
 
972
    return shell_igraph_layout_sphere(argc, argv);
 
973
  } else if (!strcasecmp(base, "igraph_layout_fruchterman_reingold_3d")) {
 
974
    return shell_igraph_layout_fruchterman_reingold_3d(argc, argv);
 
975
  } else if (!strcasecmp(base, "igraph_layout_kamada_kawai_3d")) {
 
976
    return shell_igraph_layout_kamada_kawai_3d(argc, argv);
 
977
  } else if (!strcasecmp(base, "igraph_layout_graphopt")) {
 
978
    return shell_igraph_layout_graphopt(argc, argv);
 
979
  } else if (!strcasecmp(base, "igraph_layout_drl")) {
 
980
    return shell_igraph_layout_drl(argc, argv);
 
981
  } else if (!strcasecmp(base, "igraph_layout_drl_3d")) {
 
982
    return shell_igraph_layout_drl_3d(argc, argv);
 
983
  } else if (!strcasecmp(base, "igraph_layout_merge_dla")) {
 
984
    return shell_igraph_layout_merge_dla(argc, argv);
 
985
  } else if (!strcasecmp(base, "igraph_cocitation")) {
 
986
    return shell_igraph_cocitation(argc, argv);
 
987
  } else if (!strcasecmp(base, "igraph_bibcoupling")) {
 
988
    return shell_igraph_bibcoupling(argc, argv);
 
989
  } else if (!strcasecmp(base, "igraph_similarity_jaccard")) {
 
990
    return shell_igraph_similarity_jaccard(argc, argv);
 
991
  } else if (!strcasecmp(base, "igraph_similarity_dice")) {
 
992
    return shell_igraph_similarity_dice(argc, argv);
 
993
  } else if (!strcasecmp(base, "igraph_similarity_inverse_log_weighted")) {
 
994
    return shell_igraph_similarity_inverse_log_weighted(argc, argv);
 
995
  } else if (!strcasecmp(base, "igraph_community_spinglass")) {
 
996
    return shell_igraph_community_spinglass(argc, argv);
 
997
  } else if (!strcasecmp(base, "igraph_community_spinglass_single")) {
 
998
    return shell_igraph_community_spinglass_single(argc, argv);
 
999
  } else if (!strcasecmp(base, "igraph_community_walktrap")) {
 
1000
    return shell_igraph_community_walktrap(argc, argv);
 
1001
  } else if (!strcasecmp(base, "igraph_community_edge_betweenness")) {
 
1002
    return shell_igraph_community_edge_betweenness(argc, argv);
 
1003
  } else if (!strcasecmp(base, "igraph_community_eb_get_merges")) {
 
1004
    return shell_igraph_community_eb_get_merges(argc, argv);
 
1005
  } else if (!strcasecmp(base, "igraph_community_fastgreedy")) {
 
1006
    return shell_igraph_community_fastgreedy(argc, argv);
 
1007
  } else if (!strcasecmp(base, "igraph_community_to_membership")) {
 
1008
    return shell_igraph_community_to_membership(argc, argv);
 
1009
  } else if (!strcasecmp(base, "igraph_le_community_to_membership")) {
 
1010
    return shell_igraph_le_community_to_membership(argc, argv);
 
1011
  } else if (!strcasecmp(base, "igraph_modularity")) {
 
1012
    return shell_igraph_modularity(argc, argv);
 
1013
  } else if (!strcasecmp(base, "igraph_community_leading_eigenvector")) {
 
1014
    return shell_igraph_community_leading_eigenvector(argc, argv);
 
1015
  } else if (!strcasecmp(base, "igraph_community_leading_eigenvector_naive")) {
 
1016
    return shell_igraph_community_leading_eigenvector_naive(argc, argv);
 
1017
  } else if (!strcasecmp(base, "igraph_community_leading_eigenvector_step")) {
 
1018
    return shell_igraph_community_leading_eigenvector_step(argc, argv);
 
1019
  } else if (!strcasecmp(base, "igraph_community_label_propagation")) {
 
1020
    return shell_igraph_community_label_propagation(argc, argv);
 
1021
  } else if (!strcasecmp(base, "igraph_get_adjacency")) {
 
1022
    return shell_igraph_get_adjacency(argc, argv);
 
1023
  } else if (!strcasecmp(base, "igraph_get_edgelist")) {
 
1024
    return shell_igraph_get_edgelist(argc, argv);
 
1025
  } else if (!strcasecmp(base, "igraph_to_directed")) {
 
1026
    return shell_igraph_to_directed(argc, argv);
 
1027
  } else if (!strcasecmp(base, "igraph_to_undirected")) {
 
1028
    return shell_igraph_to_undirected(argc, argv);
 
1029
  } else if (!strcasecmp(base, "igraph_read_graph_edgelist")) {
 
1030
    return shell_igraph_read_graph_edgelist(argc, argv);
 
1031
  } else if (!strcasecmp(base, "igraph_read_graph_ncol")) {
 
1032
    return shell_igraph_read_graph_ncol(argc, argv);
 
1033
  } else if (!strcasecmp(base, "igraph_read_graph_lgl")) {
 
1034
    return shell_igraph_read_graph_lgl(argc, argv);
 
1035
  } else if (!strcasecmp(base, "igraph_read_graph_pajek")) {
 
1036
    return shell_igraph_read_graph_pajek(argc, argv);
 
1037
  } else if (!strcasecmp(base, "igraph_read_graph_graphml")) {
 
1038
    return shell_igraph_read_graph_graphml(argc, argv);
 
1039
  } else if (!strcasecmp(base, "igraph_read_graph_dimacs")) {
 
1040
    return shell_igraph_read_graph_dimacs(argc, argv);
 
1041
  } else if (!strcasecmp(base, "igraph_read_graph_graphdb")) {
 
1042
    return shell_igraph_read_graph_graphdb(argc, argv);
 
1043
  } else if (!strcasecmp(base, "igraph_read_graph_gml")) {
 
1044
    return shell_igraph_read_graph_gml(argc, argv);
 
1045
  } else if (!strcasecmp(base, "igraph_write_graph_edgelist")) {
 
1046
    return shell_igraph_write_graph_edgelist(argc, argv);
 
1047
  } else if (!strcasecmp(base, "igraph_write_graph_ncol")) {
 
1048
    return shell_igraph_write_graph_ncol(argc, argv);
 
1049
  } else if (!strcasecmp(base, "igraph_write_graph_lgl")) {
 
1050
    return shell_igraph_write_graph_lgl(argc, argv);
 
1051
  } else if (!strcasecmp(base, "igraph_write_graph_graphml")) {
 
1052
    return shell_igraph_write_graph_graphml(argc, argv);
 
1053
  } else if (!strcasecmp(base, "igraph_write_graph_pajek")) {
 
1054
    return shell_igraph_write_graph_pajek(argc, argv);
 
1055
  } else if (!strcasecmp(base, "igraph_write_graph_dimacs")) {
 
1056
    return shell_igraph_write_graph_dimacs(argc, argv);
 
1057
  } else if (!strcasecmp(base, "igraph_write_graph_gml")) {
 
1058
    return shell_igraph_write_graph_gml(argc, argv);
 
1059
  } else if (!strcasecmp(base, "igraph_write_graph_dot")) {
 
1060
    return shell_igraph_write_graph_dot(argc, argv);
 
1061
  } else if (!strcasecmp(base, "igraph_motifs_randesu")) {
 
1062
    return shell_igraph_motifs_randesu(argc, argv);
 
1063
  } else if (!strcasecmp(base, "igraph_motifs_randesu_estimate")) {
 
1064
    return shell_igraph_motifs_randesu_estimate(argc, argv);
 
1065
  } else if (!strcasecmp(base, "igraph_motifs_randesu_no")) {
 
1066
    return shell_igraph_motifs_randesu_no(argc, argv);
 
1067
  } else if (!strcasecmp(base, "igraph_dyad_census")) {
 
1068
    return shell_igraph_dyad_census(argc, argv);
 
1069
  } else if (!strcasecmp(base, "igraph_triad_census")) {
 
1070
    return shell_igraph_triad_census(argc, argv);
 
1071
  } else if (!strcasecmp(base, "igraph_disjoint_union")) {
 
1072
    return shell_igraph_disjoint_union(argc, argv);
 
1073
  } else if (!strcasecmp(base, "igraph_disjoint_union_many")) {
 
1074
    return shell_igraph_disjoint_union_many(argc, argv);
 
1075
  } else if (!strcasecmp(base, "igraph_union")) {
 
1076
    return shell_igraph_union(argc, argv);
 
1077
  } else if (!strcasecmp(base, "igraph_union_many")) {
 
1078
    return shell_igraph_union_many(argc, argv);
 
1079
  } else if (!strcasecmp(base, "igraph_intersection")) {
 
1080
    return shell_igraph_intersection(argc, argv);
 
1081
  } else if (!strcasecmp(base, "igraph_intersection_many")) {
 
1082
    return shell_igraph_intersection_many(argc, argv);
 
1083
  } else if (!strcasecmp(base, "igraph_difference")) {
 
1084
    return shell_igraph_difference(argc, argv);
 
1085
  } else if (!strcasecmp(base, "igraph_complementer")) {
 
1086
    return shell_igraph_complementer(argc, argv);
 
1087
  } else if (!strcasecmp(base, "igraph_compose")) {
 
1088
    return shell_igraph_compose(argc, argv);
 
1089
  } else if (!strcasecmp(base, "igraph_maxflow_value")) {
 
1090
    return shell_igraph_maxflow_value(argc, argv);
 
1091
  } else if (!strcasecmp(base, "igraph_mincut_value")) {
 
1092
    return shell_igraph_mincut_value(argc, argv);
 
1093
  } else if (!strcasecmp(base, "igraph_st_mincut_value")) {
 
1094
    return shell_igraph_st_mincut_value(argc, argv);
 
1095
  } else if (!strcasecmp(base, "igraph_mincut")) {
 
1096
    return shell_igraph_mincut(argc, argv);
 
1097
  } else if (!strcasecmp(base, "igraph_st_vertex_connectivity")) {
 
1098
    return shell_igraph_st_vertex_connectivity(argc, argv);
 
1099
  } else if (!strcasecmp(base, "igraph_vertex_connectivity")) {
 
1100
    return shell_igraph_vertex_connectivity(argc, argv);
 
1101
  } else if (!strcasecmp(base, "igraph_st_edge_connectivity")) {
 
1102
    return shell_igraph_st_edge_connectivity(argc, argv);
 
1103
  } else if (!strcasecmp(base, "igraph_edge_connectivity")) {
 
1104
    return shell_igraph_edge_connectivity(argc, argv);
 
1105
  } else if (!strcasecmp(base, "igraph_edge_disjoint_paths")) {
 
1106
    return shell_igraph_edge_disjoint_paths(argc, argv);
 
1107
  } else if (!strcasecmp(base, "igraph_vertex_disjoint_paths")) {
 
1108
    return shell_igraph_vertex_disjoint_paths(argc, argv);
 
1109
  } else if (!strcasecmp(base, "igraph_adhesion")) {
 
1110
    return shell_igraph_adhesion(argc, argv);
 
1111
  } else if (!strcasecmp(base, "igraph_cohesion")) {
 
1112
    return shell_igraph_cohesion(argc, argv);
 
1113
  } else if (!strcasecmp(base, "igraph_coreness")) {
 
1114
    return shell_igraph_coreness(argc, argv);
 
1115
  } else if (!strcasecmp(base, "igraph_isoclass")) {
 
1116
    return shell_igraph_isoclass(argc, argv);
 
1117
  } else if (!strcasecmp(base, "igraph_isomorphic")) {
 
1118
    return shell_igraph_isomorphic(argc, argv);
 
1119
  } else if (!strcasecmp(base, "igraph_isoclass_subgraph")) {
 
1120
    return shell_igraph_isoclass_subgraph(argc, argv);
 
1121
  } else if (!strcasecmp(base, "igraph_isoclass_create")) {
 
1122
    return shell_igraph_isoclass_create(argc, argv);
 
1123
  } else if (!strcasecmp(base, "igraph_isomorphic_vf2")) {
 
1124
    return shell_igraph_isomorphic_vf2(argc, argv);
 
1125
  } else if (!strcasecmp(base, "igraph_count_isomorphisms_vf2")) {
 
1126
    return shell_igraph_count_isomorphisms_vf2(argc, argv);
 
1127
  } else if (!strcasecmp(base, "igraph_get_isomorphisms_vf2")) {
 
1128
    return shell_igraph_get_isomorphisms_vf2(argc, argv);
 
1129
  } else if (!strcasecmp(base, "igraph_subisomorphic_vf2")) {
 
1130
    return shell_igraph_subisomorphic_vf2(argc, argv);
 
1131
  } else if (!strcasecmp(base, "igraph_count_subisomorphisms_vf2")) {
 
1132
    return shell_igraph_count_subisomorphisms_vf2(argc, argv);
 
1133
  } else if (!strcasecmp(base, "igraph_get_subisomorphisms_vf2")) {
 
1134
    return shell_igraph_get_subisomorphisms_vf2(argc, argv);
 
1135
  } else if (!strcasecmp(base, "igraph_isomorphic_34")) {
 
1136
    return shell_igraph_isomorphic_34(argc, argv);
 
1137
  } else if (!strcasecmp(base, "igraph_canonical_permutation")) {
 
1138
    return shell_igraph_canonical_permutation(argc, argv);
 
1139
  } else if (!strcasecmp(base, "igraph_permute_vertices")) {
 
1140
    return shell_igraph_permute_vertices(argc, argv);
 
1141
  } else if (!strcasecmp(base, "igraph_isomorphic_bliss")) {
 
1142
    return shell_igraph_isomorphic_bliss(argc, argv);
 
1143
  } else if (!strcasecmp(base, "igraph_automorphisms")) {
 
1144
    return shell_igraph_automorphisms(argc, argv);
 
1145
  } else if (!strcasecmp(base, "igraph_running_mean")) {
 
1146
    return shell_igraph_running_mean(argc, argv);
 
1147
  } else if (!strcasecmp(base, "igraph_random_sample")) {
 
1148
    return shell_igraph_random_sample(argc, argv);
 
1149
  } else if (!strcasecmp(base, "igraph_convex_hull")) {
 
1150
    return shell_igraph_convex_hull(argc, argv);
 
1151
  } else if (!strcasecmp(base, "igraph_revolver_ml_d")) {
 
1152
    return shell_igraph_revolver_ml_d(argc, argv);
 
1153
  } else if (!strcasecmp(base, "igraph_revolver_probs_d")) {
 
1154
    return shell_igraph_revolver_probs_d(argc, argv);
 
1155
  } else if (!strcasecmp(base, "igraph_revolver_ml_de")) {
 
1156
    return shell_igraph_revolver_ml_de(argc, argv);
 
1157
  } else if (!strcasecmp(base, "igraph_revolver_probs_de")) {
 
1158
    return shell_igraph_revolver_probs_de(argc, argv);
 
1159
  } else if (!strcasecmp(base, "igraph_revolver_ml_ade")) {
 
1160
    return shell_igraph_revolver_ml_ade(argc, argv);
 
1161
  } else if (!strcasecmp(base, "igraph_revolver_probs_ade")) {
 
1162
    return shell_igraph_revolver_probs_ade(argc, argv);
 
1163
  } else if (!strcasecmp(base, "igraph_revolver_ml_f")) {
 
1164
    return shell_igraph_revolver_ml_f(argc, argv);
 
1165
  } else if (!strcasecmp(base, "igraph_revolver_ml_df")) {
 
1166
    return shell_igraph_revolver_ml_df(argc, argv);
 
1167
  } else if (!strcasecmp(base, "igraph_revolver_ml_l")) {
 
1168
    return shell_igraph_revolver_ml_l(argc, argv);
 
1169
  } else if (!strcasecmp(base, "igraph_revolver_ml_ad")) {
 
1170
    return shell_igraph_revolver_ml_ad(argc, argv);
 
1171
  } else if (!strcasecmp(base, "igraph_revolver_probs_ad")) {
 
1172
    return shell_igraph_revolver_probs_ad(argc, argv);
 
1173
  } else if (!strcasecmp(base, "igraph_revolver_ml_D_alpha")) {
 
1174
    return shell_igraph_revolver_ml_D_alpha(argc, argv);
 
1175
  } else if (!strcasecmp(base, "igraph_revolver_ml_D_alpha_a")) {
 
1176
    return shell_igraph_revolver_ml_D_alpha_a(argc, argv);
 
1177
  } else if (!strcasecmp(base, "igraph_revolver_ml_DE_alpha_a")) {
 
1178
    return shell_igraph_revolver_ml_DE_alpha_a(argc, argv);
 
1179
  } else if (!strcasecmp(base, "igraph_revolver_ml_AD_alpha_a_beta")) {
 
1180
    return shell_igraph_revolver_ml_AD_alpha_a_beta(argc, argv);
 
1181
  } else if (!strcasecmp(base, "igraph_revolver_ml_AD_dpareto")) {
 
1182
    return shell_igraph_revolver_ml_AD_dpareto(argc, argv);
 
1183
  } else if (!strcasecmp(base, "igraph_revolver_ml_AD_dpareto_eval")) {
 
1184
    return shell_igraph_revolver_ml_AD_dpareto_eval(argc, argv);
 
1185
  } else if (!strcasecmp(base, "igraph_revolver_ml_ADE_alpha_a_beta")) {
 
1186
    return shell_igraph_revolver_ml_ADE_alpha_a_beta(argc, argv);
 
1187
  } else if (!strcasecmp(base, "igraph_revolver_ml_ADE_dpareto")) {
 
1188
    return shell_igraph_revolver_ml_ADE_dpareto(argc, argv);
 
1189
  } else if (!strcasecmp(base, "igraph_revolver_ml_ADE_dpareto_eval")) {
 
1190
    return shell_igraph_revolver_ml_ADE_dpareto_eval(argc, argv);
 
1191
  } else if (!strcasecmp(base, "igraph_revolver_ml_ADE_dpareto_evalf")) {
 
1192
    return shell_igraph_revolver_ml_ADE_dpareto_evalf(argc, argv);
 
1193
  } else if (!strcasecmp(base, "igraph_revolver_probs_ADE_dpareto")) {
 
1194
    return shell_igraph_revolver_probs_ADE_dpareto(argc, argv);
 
1195
  } else if (!strcasecmp(base, "igraph_convergence_degree")) {
 
1196
    return shell_igraph_convergence_degree(argc, argv);
 
1197
  } else {
 
1198
    printf("Unknown function, exiting\n");
 
1199
  }
 
1200
 
 
1201
  shell_igraph_usage(argc, argv);
 
1202
  return 0;
 
1203
 
 
1204
}
 
1205
 
 
1206
/* The functions themselves at last */
 
1207
 
 
1208
/*-------------------------------------------/
 
1209
/ igraph_empty                               /
 
1210
/-------------------------------------------*/
 
1211
void shell_igraph_empty_usage(char **argv) {
 
1212
  printf("%s --graph=<graph> --n=<n> --directed=<directed>\n", basename(argv[0]));
 
1213
  exit(1);
 
1214
}
 
1215
 
 
1216
int shell_igraph_empty(int argc, char **argv) {
 
1217
 
 
1218
  igraph_t graph;
 
1219
  igraph_integer_t n=0;
 
1220
  igraph_bool_t directed=1;
 
1221
  char* shell_arg_graph=0;
 
1222
  int shell_result;
 
1223
 
 
1224
 
 
1225
  int shell_seen[3];
 
1226
  int shell_index=-1;
 
1227
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1228
                                   { "n",required_argument,0,1 },
 
1229
                                   { "directed",required_argument,0,2 },
 
1230
                                   { "help",no_argument,0,3 },
 
1231
                                   { 0,0,0,0 }
 
1232
                                 };
 
1233
 
 
1234
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1235
  memset(shell_seen, 0, 3*sizeof(int));
 
1236
  shell_seen[1]=2;
 
1237
  shell_seen[2]=2;
 
1238
  
 
1239
  /* Parse arguments and read input */
 
1240
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1241
 
 
1242
    if (shell_index==-1) {
 
1243
      exit(1);
 
1244
    }
 
1245
 
 
1246
    if (shell_seen[shell_index]==1) {
 
1247
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1248
              shell_options[shell_index].name);
 
1249
      exit(1);
 
1250
    }
 
1251
    shell_seen[shell_index]=1;  
 
1252
 
 
1253
    switch (shell_index) {
 
1254
    case 0: /* graph */
 
1255
      shell_arg_graph=strdup(optarg);
 
1256
      break;
 
1257
    case 1: /* n */
 
1258
      shell_read_integer(&n, optarg);
 
1259
      break;
 
1260
    case 2: /* directed */
 
1261
      shell_read_boolean(&directed, optarg);
 
1262
      break;
 
1263
    case 3:
 
1264
      shell_igraph_empty_usage(argv);
 
1265
      break;
 
1266
    default:
 
1267
      break;
 
1268
    }
 
1269
 
 
1270
    shell_index=-1;
 
1271
  }
 
1272
 
 
1273
  /* Check that we have all arguments */
 
1274
  for (shell_index=0; shell_index<3; shell_index++) {
 
1275
    if (!shell_seen[shell_index]) {
 
1276
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1277
              shell_options[shell_index].name);
 
1278
      exit(1);
 
1279
    }
 
1280
  }
 
1281
 
 
1282
  /* Do the operation */
 
1283
  shell_result=igraph_empty(&graph, n, directed);
 
1284
 
 
1285
  /* Write the result */
 
1286
  shell_write_graph(&graph, shell_arg_graph); 
 
1287
  igraph_destroy(&graph);
 
1288
 
 
1289
  return 0;
 
1290
}
 
1291
 
 
1292
/*-------------------------------------------/
 
1293
/ igraph_add_edges                           /
 
1294
/-------------------------------------------*/
 
1295
void shell_igraph_add_edges_usage(char **argv) {
 
1296
  printf("%s --graph=<graph> --graph-out=<graph-out> --edges=<edges>\n", basename(argv[0]));
 
1297
  exit(1);
 
1298
}
 
1299
 
 
1300
int shell_igraph_add_edges(int argc, char **argv) {
 
1301
 
 
1302
  igraph_t graph;
 
1303
  igraph_vector_t edges;
 
1304
 
 
1305
  char* shell_arg_graph=0;
 
1306
  int shell_result;
 
1307
 
 
1308
 
 
1309
  int shell_seen[3];
 
1310
  int shell_index=-1;
 
1311
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1312
                                   { "graph-out",required_argument,0,1 },
 
1313
                                   { "edges",required_argument,0,2 },
 
1314
                                   { "help",no_argument,0,3 },
 
1315
                                   { 0,0,0,0 }
 
1316
                                 };
 
1317
 
 
1318
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1319
  memset(shell_seen, 0, 3*sizeof(int));
 
1320
 
 
1321
  
 
1322
  /* Parse arguments and read input */
 
1323
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1324
 
 
1325
    if (shell_index==-1) {
 
1326
      exit(1);
 
1327
    }
 
1328
 
 
1329
    if (shell_seen[shell_index]==1) {
 
1330
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1331
              shell_options[shell_index].name);
 
1332
      exit(1);
 
1333
    }
 
1334
    shell_seen[shell_index]=1;  
 
1335
 
 
1336
    switch (shell_index) {
 
1337
    case 0: /* graph */
 
1338
      shell_read_graph(&graph, optarg);
 
1339
      break;
 
1340
    case 1: /* graph-out */
 
1341
      shell_arg_graph=strdup(optarg);
 
1342
      break;
 
1343
    case 2: /* edges */
 
1344
      shell_read_vector(&edges, optarg);
 
1345
      break;
 
1346
    case 3:
 
1347
      shell_igraph_add_edges_usage(argv);
 
1348
      break;
 
1349
    default:
 
1350
      break;
 
1351
    }
 
1352
 
 
1353
    shell_index=-1;
 
1354
  }
 
1355
 
 
1356
  /* Check that we have all arguments */
 
1357
  for (shell_index=0; shell_index<3; shell_index++) {
 
1358
    if (!shell_seen[shell_index]) {
 
1359
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1360
              shell_options[shell_index].name);
 
1361
      exit(1);
 
1362
    }
 
1363
  }
 
1364
 
 
1365
  /* Do the operation */
 
1366
  shell_result=igraph_add_edges(&graph, &edges, 0);
 
1367
 
 
1368
  /* Write the result */
 
1369
  igraph_destroy(&graph);
 
1370
  shell_write_graph(&graph, shell_arg_graph); 
 
1371
  igraph_destroy(&graph);
 
1372
  igraph_vector_destroy(&edges);
 
1373
 
 
1374
  return 0;
 
1375
}
 
1376
 
 
1377
/*-------------------------------------------/
 
1378
/ igraph_add_vertices                        /
 
1379
/-------------------------------------------*/
 
1380
void shell_igraph_add_vertices_usage(char **argv) {
 
1381
  printf("%s --graph=<graph> --graph-out=<graph-out> --nv=<nv>\n", basename(argv[0]));
 
1382
  exit(1);
 
1383
}
 
1384
 
 
1385
int shell_igraph_add_vertices(int argc, char **argv) {
 
1386
 
 
1387
  igraph_t graph;
 
1388
  igraph_integer_t nv;
 
1389
 
 
1390
  char* shell_arg_graph=0;
 
1391
  int shell_result;
 
1392
 
 
1393
 
 
1394
  int shell_seen[3];
 
1395
  int shell_index=-1;
 
1396
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1397
                                   { "graph-out",required_argument,0,1 },
 
1398
                                   { "nv",required_argument,0,2 },
 
1399
                                   { "help",no_argument,0,3 },
 
1400
                                   { 0,0,0,0 }
 
1401
                                 };
 
1402
 
 
1403
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1404
  memset(shell_seen, 0, 3*sizeof(int));
 
1405
 
 
1406
  
 
1407
  /* Parse arguments and read input */
 
1408
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1409
 
 
1410
    if (shell_index==-1) {
 
1411
      exit(1);
 
1412
    }
 
1413
 
 
1414
    if (shell_seen[shell_index]==1) {
 
1415
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1416
              shell_options[shell_index].name);
 
1417
      exit(1);
 
1418
    }
 
1419
    shell_seen[shell_index]=1;  
 
1420
 
 
1421
    switch (shell_index) {
 
1422
    case 0: /* graph */
 
1423
      shell_read_graph(&graph, optarg);
 
1424
      break;
 
1425
    case 1: /* graph-out */
 
1426
      shell_arg_graph=strdup(optarg);
 
1427
      break;
 
1428
    case 2: /* nv */
 
1429
      shell_read_integer(&nv, optarg);
 
1430
      break;
 
1431
    case 3:
 
1432
      shell_igraph_add_vertices_usage(argv);
 
1433
      break;
 
1434
    default:
 
1435
      break;
 
1436
    }
 
1437
 
 
1438
    shell_index=-1;
 
1439
  }
 
1440
 
 
1441
  /* Check that we have all arguments */
 
1442
  for (shell_index=0; shell_index<3; shell_index++) {
 
1443
    if (!shell_seen[shell_index]) {
 
1444
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1445
              shell_options[shell_index].name);
 
1446
      exit(1);
 
1447
    }
 
1448
  }
 
1449
 
 
1450
  /* Do the operation */
 
1451
  shell_result=igraph_add_vertices(&graph, nv, 0);
 
1452
 
 
1453
  /* Write the result */
 
1454
  igraph_destroy(&graph);
 
1455
  shell_write_graph(&graph, shell_arg_graph); 
 
1456
  igraph_destroy(&graph);
 
1457
 
 
1458
  return 0;
 
1459
}
 
1460
 
 
1461
/*-------------------------------------------/
 
1462
/ igraph_delete_edges                        /
 
1463
/-------------------------------------------*/
 
1464
void shell_igraph_delete_edges_usage(char **argv) {
 
1465
  printf("%s --graph=<graph> --graph-out=<graph-out> --edges=<edges>\n", basename(argv[0]));
 
1466
  exit(1);
 
1467
}
 
1468
 
 
1469
int shell_igraph_delete_edges(int argc, char **argv) {
 
1470
 
 
1471
  igraph_t graph;
 
1472
  igraph_vector_t v_edges; igraph_es_t edges;
 
1473
  char* shell_arg_graph=0;
 
1474
  int shell_result;
 
1475
 
 
1476
 
 
1477
  int shell_seen[3];
 
1478
  int shell_index=-1;
 
1479
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1480
                                   { "graph-out",required_argument,0,1 },
 
1481
                                   { "edges",required_argument,0,2 },
 
1482
                                   { "help",no_argument,0,3 },
 
1483
                                   { 0,0,0,0 }
 
1484
                                 };
 
1485
 
 
1486
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1487
  memset(shell_seen, 0, 3*sizeof(int));
 
1488
 
 
1489
  
 
1490
  /* Parse arguments and read input */
 
1491
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1492
 
 
1493
    if (shell_index==-1) {
 
1494
      exit(1);
 
1495
    }
 
1496
 
 
1497
    if (shell_seen[shell_index]==1) {
 
1498
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1499
              shell_options[shell_index].name);
 
1500
      exit(1);
 
1501
    }
 
1502
    shell_seen[shell_index]=1;  
 
1503
 
 
1504
    switch (shell_index) {
 
1505
    case 0: /* graph */
 
1506
      shell_read_graph(&graph, optarg);
 
1507
      break;
 
1508
    case 1: /* graph-out */
 
1509
      shell_arg_graph=strdup(optarg);
 
1510
      break;
 
1511
    case 2: /* edges */
 
1512
      shell_read_vector(&v_edges, optarg); igraph_es_vector(&edges, &v_edges);
 
1513
      break;
 
1514
    case 3:
 
1515
      shell_igraph_delete_edges_usage(argv);
 
1516
      break;
 
1517
    default:
 
1518
      break;
 
1519
    }
 
1520
 
 
1521
    shell_index=-1;
 
1522
  }
 
1523
 
 
1524
  /* Check that we have all arguments */
 
1525
  for (shell_index=0; shell_index<3; shell_index++) {
 
1526
    if (!shell_seen[shell_index]) {
 
1527
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1528
              shell_options[shell_index].name);
 
1529
      exit(1);
 
1530
    }
 
1531
  }
 
1532
 
 
1533
  /* Do the operation */
 
1534
  shell_result=igraph_delete_edges(&graph, edges);
 
1535
 
 
1536
  /* Write the result */
 
1537
  igraph_destroy(&graph);
 
1538
  shell_write_graph(&graph, shell_arg_graph); 
 
1539
  igraph_destroy(&graph);
 
1540
  if (!igraph_es_is_all(&edges)) { igraph_es_destroy(&edges); }
 
1541
 
 
1542
  return 0;
 
1543
}
 
1544
 
 
1545
/*-------------------------------------------/
 
1546
/ igraph_delete_vertices                     /
 
1547
/-------------------------------------------*/
 
1548
void shell_igraph_delete_vertices_usage(char **argv) {
 
1549
  printf("%s --graph=<graph> --graph-out=<graph-out> --vertices=<vertices>\n", basename(argv[0]));
 
1550
  exit(1);
 
1551
}
 
1552
 
 
1553
int shell_igraph_delete_vertices(int argc, char **argv) {
 
1554
 
 
1555
  igraph_t graph;
 
1556
  igraph_vector_t v_vertices; igraph_vs_t vertices;
 
1557
  char* shell_arg_graph=0;
 
1558
  int shell_result;
 
1559
 
 
1560
 
 
1561
  int shell_seen[3];
 
1562
  int shell_index=-1;
 
1563
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1564
                                   { "graph-out",required_argument,0,1 },
 
1565
                                   { "vertices",required_argument,0,2 },
 
1566
                                   { "help",no_argument,0,3 },
 
1567
                                   { 0,0,0,0 }
 
1568
                                 };
 
1569
 
 
1570
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1571
  memset(shell_seen, 0, 3*sizeof(int));
 
1572
 
 
1573
  
 
1574
  /* Parse arguments and read input */
 
1575
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1576
 
 
1577
    if (shell_index==-1) {
 
1578
      exit(1);
 
1579
    }
 
1580
 
 
1581
    if (shell_seen[shell_index]==1) {
 
1582
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1583
              shell_options[shell_index].name);
 
1584
      exit(1);
 
1585
    }
 
1586
    shell_seen[shell_index]=1;  
 
1587
 
 
1588
    switch (shell_index) {
 
1589
    case 0: /* graph */
 
1590
      shell_read_graph(&graph, optarg);
 
1591
      break;
 
1592
    case 1: /* graph-out */
 
1593
      shell_arg_graph=strdup(optarg);
 
1594
      break;
 
1595
    case 2: /* vertices */
 
1596
      shell_read_vector(&v_vertices, optarg); igraph_vs_vector(&vertices, &v_vertices);
 
1597
      break;
 
1598
    case 3:
 
1599
      shell_igraph_delete_vertices_usage(argv);
 
1600
      break;
 
1601
    default:
 
1602
      break;
 
1603
    }
 
1604
 
 
1605
    shell_index=-1;
 
1606
  }
 
1607
 
 
1608
  /* Check that we have all arguments */
 
1609
  for (shell_index=0; shell_index<3; shell_index++) {
 
1610
    if (!shell_seen[shell_index]) {
 
1611
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1612
              shell_options[shell_index].name);
 
1613
      exit(1);
 
1614
    }
 
1615
  }
 
1616
 
 
1617
  /* Do the operation */
 
1618
  shell_result=igraph_delete_vertices(&graph, vertices);
 
1619
 
 
1620
  /* Write the result */
 
1621
  igraph_destroy(&graph);
 
1622
  shell_write_graph(&graph, shell_arg_graph); 
 
1623
  igraph_destroy(&graph);
 
1624
  if (!igraph_vs_is_all(&vertices)) { igraph_vector_destroy(&v_vertices); }
 
1625
 
 
1626
  return 0;
 
1627
}
 
1628
 
 
1629
/*-------------------------------------------/
 
1630
/ igraph_vcount                              /
 
1631
/-------------------------------------------*/
 
1632
void shell_igraph_vcount_usage(char **argv) {
 
1633
  printf("%s --graph=<graph>\n", basename(argv[0]));
 
1634
  exit(1);
 
1635
}
 
1636
 
 
1637
int shell_igraph_vcount(int argc, char **argv) {
 
1638
 
 
1639
  igraph_t graph;
 
1640
  igraph_integer_t shell_result;
 
1641
  char *shell_arg_shell_result="-";
 
1642
 
 
1643
  int shell_seen[1];
 
1644
  int shell_index=-1;
 
1645
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1646
                                   { "help",no_argument,0,1 },
 
1647
                                   { 0,0,0,0 }
 
1648
                                 };
 
1649
 
 
1650
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1651
  memset(shell_seen, 0, 1*sizeof(int));
 
1652
 
 
1653
  
 
1654
  /* Parse arguments and read input */
 
1655
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1656
 
 
1657
    if (shell_index==-1) {
 
1658
      exit(1);
 
1659
    }
 
1660
 
 
1661
    if (shell_seen[shell_index]==1) {
 
1662
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1663
              shell_options[shell_index].name);
 
1664
      exit(1);
 
1665
    }
 
1666
    shell_seen[shell_index]=1;  
 
1667
 
 
1668
    switch (shell_index) {
 
1669
    case 0: /* graph */
 
1670
      shell_read_graph(&graph, optarg);
 
1671
      break;
 
1672
    case 1:
 
1673
      shell_igraph_vcount_usage(argv);
 
1674
      break;
 
1675
    default:
 
1676
      break;
 
1677
    }
 
1678
 
 
1679
    shell_index=-1;
 
1680
  }
 
1681
 
 
1682
  /* Check that we have all arguments */
 
1683
  for (shell_index=0; shell_index<1; shell_index++) {
 
1684
    if (!shell_seen[shell_index]) {
 
1685
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1686
              shell_options[shell_index].name);
 
1687
      exit(1);
 
1688
    }
 
1689
  }
 
1690
 
 
1691
  /* Do the operation */
 
1692
  shell_result=igraph_vcount(&graph);
 
1693
 
 
1694
  /* Write the result */
 
1695
  igraph_destroy(&graph);
 
1696
 
 
1697
  return 0;
 
1698
}
 
1699
 
 
1700
/*-------------------------------------------/
 
1701
/ igraph_ecount                              /
 
1702
/-------------------------------------------*/
 
1703
void shell_igraph_ecount_usage(char **argv) {
 
1704
  printf("%s --graph=<graph>\n", basename(argv[0]));
 
1705
  exit(1);
 
1706
}
 
1707
 
 
1708
int shell_igraph_ecount(int argc, char **argv) {
 
1709
 
 
1710
  igraph_t graph;
 
1711
  igraph_integer_t shell_result;
 
1712
  char *shell_arg_shell_result="-";
 
1713
 
 
1714
  int shell_seen[1];
 
1715
  int shell_index=-1;
 
1716
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1717
                                   { "help",no_argument,0,1 },
 
1718
                                   { 0,0,0,0 }
 
1719
                                 };
 
1720
 
 
1721
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1722
  memset(shell_seen, 0, 1*sizeof(int));
 
1723
 
 
1724
  
 
1725
  /* Parse arguments and read input */
 
1726
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1727
 
 
1728
    if (shell_index==-1) {
 
1729
      exit(1);
 
1730
    }
 
1731
 
 
1732
    if (shell_seen[shell_index]==1) {
 
1733
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1734
              shell_options[shell_index].name);
 
1735
      exit(1);
 
1736
    }
 
1737
    shell_seen[shell_index]=1;  
 
1738
 
 
1739
    switch (shell_index) {
 
1740
    case 0: /* graph */
 
1741
      shell_read_graph(&graph, optarg);
 
1742
      break;
 
1743
    case 1:
 
1744
      shell_igraph_ecount_usage(argv);
 
1745
      break;
 
1746
    default:
 
1747
      break;
 
1748
    }
 
1749
 
 
1750
    shell_index=-1;
 
1751
  }
 
1752
 
 
1753
  /* Check that we have all arguments */
 
1754
  for (shell_index=0; shell_index<1; shell_index++) {
 
1755
    if (!shell_seen[shell_index]) {
 
1756
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1757
              shell_options[shell_index].name);
 
1758
      exit(1);
 
1759
    }
 
1760
  }
 
1761
 
 
1762
  /* Do the operation */
 
1763
  shell_result=igraph_ecount(&graph);
 
1764
 
 
1765
  /* Write the result */
 
1766
  igraph_destroy(&graph);
 
1767
 
 
1768
  return 0;
 
1769
}
 
1770
 
 
1771
/*-------------------------------------------/
 
1772
/ igraph_neighbors                           /
 
1773
/-------------------------------------------*/
 
1774
void shell_igraph_neighbors_usage(char **argv) {
 
1775
  printf("%s --graph=<graph> --neis=<neis> --vid=<vid> --mode=<mode>\n", basename(argv[0]));
 
1776
  exit(1);
 
1777
}
 
1778
 
 
1779
int shell_igraph_neighbors(int argc, char **argv) {
 
1780
 
 
1781
  igraph_t graph;
 
1782
  igraph_vector_t neis;
 
1783
  igraph_integer_t vid;
 
1784
  igraph_neimode_t mode=IGRAPH_ALL;
 
1785
  char* shell_arg_neis=0;
 
1786
  int shell_result;
 
1787
 
 
1788
 
 
1789
  int shell_seen[4];
 
1790
  int shell_index=-1;
 
1791
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1792
                                   { "neis",required_argument,0,1 },
 
1793
                                   { "vid",required_argument,0,2 },
 
1794
                                   { "mode",required_argument,0,3 },
 
1795
                                   { "help",no_argument,0,4 },
 
1796
                                   { 0,0,0,0 }
 
1797
                                 };
 
1798
 
 
1799
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1800
  memset(shell_seen, 0, 4*sizeof(int));
 
1801
  shell_seen[3]=2;
 
1802
  
 
1803
  /* Parse arguments and read input */
 
1804
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1805
 
 
1806
    if (shell_index==-1) {
 
1807
      exit(1);
 
1808
    }
 
1809
 
 
1810
    if (shell_seen[shell_index]==1) {
 
1811
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1812
              shell_options[shell_index].name);
 
1813
      exit(1);
 
1814
    }
 
1815
    shell_seen[shell_index]=1;  
 
1816
 
 
1817
    switch (shell_index) {
 
1818
    case 0: /* graph */
 
1819
      shell_read_graph(&graph, optarg);
 
1820
      break;
 
1821
    case 1: /* neis */
 
1822
      shell_arg_neis=strdup(optarg); 
 
1823
  igraph_vector_init(&neis, 0);
 
1824
      break;
 
1825
    case 2: /* vid */
 
1826
      shell_read_integer(&vid, optarg);
 
1827
      break;
 
1828
    case 3: /* mode */
 
1829
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
1830
      break;
 
1831
    case 4:
 
1832
      shell_igraph_neighbors_usage(argv);
 
1833
      break;
 
1834
    default:
 
1835
      break;
 
1836
    }
 
1837
 
 
1838
    shell_index=-1;
 
1839
  }
 
1840
 
 
1841
  /* Check that we have all arguments */
 
1842
  for (shell_index=0; shell_index<4; shell_index++) {
 
1843
    if (!shell_seen[shell_index]) {
 
1844
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1845
              shell_options[shell_index].name);
 
1846
      exit(1);
 
1847
    }
 
1848
  }
 
1849
 
 
1850
  /* Do the operation */
 
1851
  shell_result=igraph_neighbors(&graph, &neis, vid, mode);
 
1852
 
 
1853
  /* Write the result */
 
1854
  igraph_destroy(&graph);
 
1855
  shell_write_vector(&neis, shell_arg_neis); 
 
1856
  igraph_vector_destroy(&neis);
 
1857
 
 
1858
  return 0;
 
1859
}
 
1860
 
 
1861
/*-------------------------------------------/
 
1862
/ igraph_is_directed                         /
 
1863
/-------------------------------------------*/
 
1864
void shell_igraph_is_directed_usage(char **argv) {
 
1865
  printf("%s --graph=<graph>\n", basename(argv[0]));
 
1866
  exit(1);
 
1867
}
 
1868
 
 
1869
int shell_igraph_is_directed(int argc, char **argv) {
 
1870
 
 
1871
  igraph_t graph;
 
1872
  igraph_bool_t shell_result;
 
1873
  char *shell_arg_shell_result="-";
 
1874
 
 
1875
  int shell_seen[1];
 
1876
  int shell_index=-1;
 
1877
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1878
                                   { "help",no_argument,0,1 },
 
1879
                                   { 0,0,0,0 }
 
1880
                                 };
 
1881
 
 
1882
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1883
  memset(shell_seen, 0, 1*sizeof(int));
 
1884
 
 
1885
  
 
1886
  /* Parse arguments and read input */
 
1887
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1888
 
 
1889
    if (shell_index==-1) {
 
1890
      exit(1);
 
1891
    }
 
1892
 
 
1893
    if (shell_seen[shell_index]==1) {
 
1894
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1895
              shell_options[shell_index].name);
 
1896
      exit(1);
 
1897
    }
 
1898
    shell_seen[shell_index]=1;  
 
1899
 
 
1900
    switch (shell_index) {
 
1901
    case 0: /* graph */
 
1902
      shell_read_graph(&graph, optarg);
 
1903
      break;
 
1904
    case 1:
 
1905
      shell_igraph_is_directed_usage(argv);
 
1906
      break;
 
1907
    default:
 
1908
      break;
 
1909
    }
 
1910
 
 
1911
    shell_index=-1;
 
1912
  }
 
1913
 
 
1914
  /* Check that we have all arguments */
 
1915
  for (shell_index=0; shell_index<1; shell_index++) {
 
1916
    if (!shell_seen[shell_index]) {
 
1917
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
1918
              shell_options[shell_index].name);
 
1919
      exit(1);
 
1920
    }
 
1921
  }
 
1922
 
 
1923
  /* Do the operation */
 
1924
  shell_result=igraph_is_directed(&graph);
 
1925
 
 
1926
  /* Write the result */
 
1927
  igraph_destroy(&graph);
 
1928
 
 
1929
  return 0;
 
1930
}
 
1931
 
 
1932
/*-------------------------------------------/
 
1933
/ igraph_degree                              /
 
1934
/-------------------------------------------*/
 
1935
void shell_igraph_degree_usage(char **argv) {
 
1936
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode> --loops=<loops>\n", basename(argv[0]));
 
1937
  exit(1);
 
1938
}
 
1939
 
 
1940
int shell_igraph_degree(int argc, char **argv) {
 
1941
 
 
1942
  igraph_t graph;
 
1943
  igraph_vector_t res;
 
1944
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
1945
  igraph_neimode_t mode=IGRAPH_ALL;
 
1946
  igraph_bool_t loops;
 
1947
  char* shell_arg_res=0;
 
1948
  int shell_result;
 
1949
 
 
1950
 
 
1951
  int shell_seen[5];
 
1952
  int shell_index=-1;
 
1953
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
1954
                                   { "res",required_argument,0,1 },
 
1955
                                   { "vids",required_argument,0,2 },
 
1956
                                   { "mode",required_argument,0,3 },
 
1957
                                   { "loops",required_argument,0,4 },
 
1958
                                   { "help",no_argument,0,5 },
 
1959
                                   { 0,0,0,0 }
 
1960
                                 };
 
1961
 
 
1962
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
1963
  memset(shell_seen, 0, 5*sizeof(int));
 
1964
  shell_seen[2]=2;
 
1965
  shell_seen[3]=2;
 
1966
  
 
1967
  /* Parse arguments and read input */
 
1968
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
1969
 
 
1970
    if (shell_index==-1) {
 
1971
      exit(1);
 
1972
    }
 
1973
 
 
1974
    if (shell_seen[shell_index]==1) {
 
1975
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
1976
              shell_options[shell_index].name);
 
1977
      exit(1);
 
1978
    }
 
1979
    shell_seen[shell_index]=1;  
 
1980
 
 
1981
    switch (shell_index) {
 
1982
    case 0: /* graph */
 
1983
      shell_read_graph(&graph, optarg);
 
1984
      break;
 
1985
    case 1: /* res */
 
1986
      shell_arg_res=strdup(optarg); 
 
1987
  igraph_vector_init(&res, 0);
 
1988
      break;
 
1989
    case 2: /* vids */
 
1990
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
1991
      break;
 
1992
    case 3: /* mode */
 
1993
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
1994
      break;
 
1995
    case 4: /* loops */
 
1996
      shell_read_boolean(&loops, optarg);
 
1997
      break;
 
1998
    case 5:
 
1999
      shell_igraph_degree_usage(argv);
 
2000
      break;
 
2001
    default:
 
2002
      break;
 
2003
    }
 
2004
 
 
2005
    shell_index=-1;
 
2006
  }
 
2007
 
 
2008
  /* Check that we have all arguments */
 
2009
  for (shell_index=0; shell_index<5; shell_index++) {
 
2010
    if (!shell_seen[shell_index]) {
 
2011
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2012
              shell_options[shell_index].name);
 
2013
      exit(1);
 
2014
    }
 
2015
  }
 
2016
 
 
2017
  /* Do the operation */
 
2018
  shell_result=igraph_degree(&graph, &res, vids, mode, loops);
 
2019
 
 
2020
  /* Write the result */
 
2021
  igraph_destroy(&graph);
 
2022
  shell_write_vector(&res, shell_arg_res); 
 
2023
  igraph_vector_destroy(&res);
 
2024
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
2025
 
 
2026
  return 0;
 
2027
}
 
2028
 
 
2029
/*-------------------------------------------/
 
2030
/ igraph_edge                                /
 
2031
/-------------------------------------------*/
 
2032
void shell_igraph_edge_usage(char **argv) {
 
2033
  printf("%s --graph=<graph> --eid=<eid> --from=<from> --to=<to>\n", basename(argv[0]));
 
2034
  exit(1);
 
2035
}
 
2036
 
 
2037
int shell_igraph_edge(int argc, char **argv) {
 
2038
 
 
2039
  igraph_t graph;
 
2040
  igraph_integer_t eid;
 
2041
  igraph_integer_t from;
 
2042
  igraph_integer_t to;
 
2043
  char* shell_arg_from=0;
 
2044
  char* shell_arg_to=0;
 
2045
  int shell_result;
 
2046
 
 
2047
 
 
2048
  int shell_seen[4];
 
2049
  int shell_index=-1;
 
2050
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2051
                                   { "eid",required_argument,0,1 },
 
2052
                                   { "from",required_argument,0,2 },
 
2053
                                   { "to",required_argument,0,3 },
 
2054
                                   { "help",no_argument,0,4 },
 
2055
                                   { 0,0,0,0 }
 
2056
                                 };
 
2057
 
 
2058
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2059
  memset(shell_seen, 0, 4*sizeof(int));
 
2060
 
 
2061
  
 
2062
  /* Parse arguments and read input */
 
2063
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2064
 
 
2065
    if (shell_index==-1) {
 
2066
      exit(1);
 
2067
    }
 
2068
 
 
2069
    if (shell_seen[shell_index]==1) {
 
2070
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2071
              shell_options[shell_index].name);
 
2072
      exit(1);
 
2073
    }
 
2074
    shell_seen[shell_index]=1;  
 
2075
 
 
2076
    switch (shell_index) {
 
2077
    case 0: /* graph */
 
2078
      shell_read_graph(&graph, optarg);
 
2079
      break;
 
2080
    case 1: /* eid */
 
2081
      shell_read_integer(&eid, optarg);
 
2082
      break;
 
2083
    case 2: /* from */
 
2084
      shell_arg_from=strdup(optarg);
 
2085
      break;
 
2086
    case 3: /* to */
 
2087
      shell_arg_to=strdup(optarg);
 
2088
      break;
 
2089
    case 4:
 
2090
      shell_igraph_edge_usage(argv);
 
2091
      break;
 
2092
    default:
 
2093
      break;
 
2094
    }
 
2095
 
 
2096
    shell_index=-1;
 
2097
  }
 
2098
 
 
2099
  /* Check that we have all arguments */
 
2100
  for (shell_index=0; shell_index<4; shell_index++) {
 
2101
    if (!shell_seen[shell_index]) {
 
2102
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2103
              shell_options[shell_index].name);
 
2104
      exit(1);
 
2105
    }
 
2106
  }
 
2107
 
 
2108
  /* Do the operation */
 
2109
  shell_result=igraph_edge(&graph, eid, &from, &to);
 
2110
 
 
2111
  /* Write the result */
 
2112
  igraph_destroy(&graph);
 
2113
  shell_write_integer(from, shell_arg_from);
 
2114
  shell_write_integer(to, shell_arg_to);
 
2115
 
 
2116
  return 0;
 
2117
}
 
2118
 
 
2119
/*-------------------------------------------/
 
2120
/ igraph_edges                               /
 
2121
/-------------------------------------------*/
 
2122
void shell_igraph_edges_usage(char **argv) {
 
2123
  printf("%s --graph=<graph> --eids=<eids> --edges=<edges>\n", basename(argv[0]));
 
2124
  exit(1);
 
2125
}
 
2126
 
 
2127
int shell_igraph_edges(int argc, char **argv) {
 
2128
 
 
2129
  igraph_t graph;
 
2130
  igraph_vector_t v_eids; igraph_es_t eids;
 
2131
  igraph_vector_t edges;
 
2132
  char* shell_arg_edges=0;
 
2133
  int shell_result;
 
2134
 
 
2135
 
 
2136
  int shell_seen[3];
 
2137
  int shell_index=-1;
 
2138
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2139
                                   { "eids",required_argument,0,1 },
 
2140
                                   { "edges",required_argument,0,2 },
 
2141
                                   { "help",no_argument,0,3 },
 
2142
                                   { 0,0,0,0 }
 
2143
                                 };
 
2144
 
 
2145
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2146
  memset(shell_seen, 0, 3*sizeof(int));
 
2147
 
 
2148
  
 
2149
  /* Parse arguments and read input */
 
2150
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2151
 
 
2152
    if (shell_index==-1) {
 
2153
      exit(1);
 
2154
    }
 
2155
 
 
2156
    if (shell_seen[shell_index]==1) {
 
2157
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2158
              shell_options[shell_index].name);
 
2159
      exit(1);
 
2160
    }
 
2161
    shell_seen[shell_index]=1;  
 
2162
 
 
2163
    switch (shell_index) {
 
2164
    case 0: /* graph */
 
2165
      shell_read_graph(&graph, optarg);
 
2166
      break;
 
2167
    case 1: /* eids */
 
2168
      shell_read_vector(&v_eids, optarg); igraph_es_vector(&eids, &v_eids);
 
2169
      break;
 
2170
    case 2: /* edges */
 
2171
      shell_arg_edges=strdup(optarg); 
 
2172
  igraph_vector_init(&edges, 0);
 
2173
      break;
 
2174
    case 3:
 
2175
      shell_igraph_edges_usage(argv);
 
2176
      break;
 
2177
    default:
 
2178
      break;
 
2179
    }
 
2180
 
 
2181
    shell_index=-1;
 
2182
  }
 
2183
 
 
2184
  /* Check that we have all arguments */
 
2185
  for (shell_index=0; shell_index<3; shell_index++) {
 
2186
    if (!shell_seen[shell_index]) {
 
2187
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2188
              shell_options[shell_index].name);
 
2189
      exit(1);
 
2190
    }
 
2191
  }
 
2192
 
 
2193
  /* Do the operation */
 
2194
  shell_result=igraph_edges(&graph, eids, &edges);
 
2195
 
 
2196
  /* Write the result */
 
2197
  igraph_destroy(&graph);
 
2198
  if (!igraph_es_is_all(&eids)) { igraph_es_destroy(&eids); }
 
2199
  shell_write_vector(&edges, shell_arg_edges); 
 
2200
  igraph_vector_destroy(&edges);
 
2201
 
 
2202
  return 0;
 
2203
}
 
2204
 
 
2205
/*-------------------------------------------/
 
2206
/ igraph_get_eid                             /
 
2207
/-------------------------------------------*/
 
2208
void shell_igraph_get_eid_usage(char **argv) {
 
2209
  printf("%s --graph=<graph> --eid=<eid> --from=<from> --to=<to> --directed=<directed>\n", basename(argv[0]));
 
2210
  exit(1);
 
2211
}
 
2212
 
 
2213
int shell_igraph_get_eid(int argc, char **argv) {
 
2214
 
 
2215
  igraph_t graph;
 
2216
  igraph_integer_t eid;
 
2217
  igraph_integer_t from;
 
2218
  igraph_integer_t to;
 
2219
  igraph_bool_t directed=1;
 
2220
  char* shell_arg_eid=0;
 
2221
  int shell_result;
 
2222
 
 
2223
 
 
2224
  int shell_seen[5];
 
2225
  int shell_index=-1;
 
2226
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2227
                                   { "eid",required_argument,0,1 },
 
2228
                                   { "from",required_argument,0,2 },
 
2229
                                   { "to",required_argument,0,3 },
 
2230
                                   { "directed",required_argument,0,4 },
 
2231
                                   { "help",no_argument,0,5 },
 
2232
                                   { 0,0,0,0 }
 
2233
                                 };
 
2234
 
 
2235
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2236
  memset(shell_seen, 0, 5*sizeof(int));
 
2237
  shell_seen[4]=2;
 
2238
  
 
2239
  /* Parse arguments and read input */
 
2240
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2241
 
 
2242
    if (shell_index==-1) {
 
2243
      exit(1);
 
2244
    }
 
2245
 
 
2246
    if (shell_seen[shell_index]==1) {
 
2247
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2248
              shell_options[shell_index].name);
 
2249
      exit(1);
 
2250
    }
 
2251
    shell_seen[shell_index]=1;  
 
2252
 
 
2253
    switch (shell_index) {
 
2254
    case 0: /* graph */
 
2255
      shell_read_graph(&graph, optarg);
 
2256
      break;
 
2257
    case 1: /* eid */
 
2258
      shell_arg_eid=strdup(optarg);
 
2259
      break;
 
2260
    case 2: /* from */
 
2261
      shell_read_integer(&from, optarg);
 
2262
      break;
 
2263
    case 3: /* to */
 
2264
      shell_read_integer(&to, optarg);
 
2265
      break;
 
2266
    case 4: /* directed */
 
2267
      shell_read_boolean(&directed, optarg);
 
2268
      break;
 
2269
    case 5:
 
2270
      shell_igraph_get_eid_usage(argv);
 
2271
      break;
 
2272
    default:
 
2273
      break;
 
2274
    }
 
2275
 
 
2276
    shell_index=-1;
 
2277
  }
 
2278
 
 
2279
  /* Check that we have all arguments */
 
2280
  for (shell_index=0; shell_index<5; shell_index++) {
 
2281
    if (!shell_seen[shell_index]) {
 
2282
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2283
              shell_options[shell_index].name);
 
2284
      exit(1);
 
2285
    }
 
2286
  }
 
2287
 
 
2288
  /* Do the operation */
 
2289
  shell_result=igraph_get_eid(&graph, &eid, from, to, directed);
 
2290
 
 
2291
  /* Write the result */
 
2292
  igraph_destroy(&graph);
 
2293
  shell_write_integer(eid, shell_arg_eid);
 
2294
 
 
2295
  return 0;
 
2296
}
 
2297
 
 
2298
/*-------------------------------------------/
 
2299
/ igraph_get_eids                            /
 
2300
/-------------------------------------------*/
 
2301
void shell_igraph_get_eids_usage(char **argv) {
 
2302
  printf("%s --graph=<graph> --eids=<eids> --pairs=<pairs> --directed=<directed>\n", basename(argv[0]));
 
2303
  exit(1);
 
2304
}
 
2305
 
 
2306
int shell_igraph_get_eids(int argc, char **argv) {
 
2307
 
 
2308
  igraph_t graph;
 
2309
  igraph_vector_t eids;
 
2310
  igraph_vector_t pairs;
 
2311
  igraph_bool_t directed=1;
 
2312
  char* shell_arg_eids=0;
 
2313
  int shell_result;
 
2314
 
 
2315
 
 
2316
  int shell_seen[4];
 
2317
  int shell_index=-1;
 
2318
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2319
                                   { "eids",required_argument,0,1 },
 
2320
                                   { "pairs",required_argument,0,2 },
 
2321
                                   { "directed",required_argument,0,3 },
 
2322
                                   { "help",no_argument,0,4 },
 
2323
                                   { 0,0,0,0 }
 
2324
                                 };
 
2325
 
 
2326
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2327
  memset(shell_seen, 0, 4*sizeof(int));
 
2328
  shell_seen[3]=2;
 
2329
  
 
2330
  /* Parse arguments and read input */
 
2331
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2332
 
 
2333
    if (shell_index==-1) {
 
2334
      exit(1);
 
2335
    }
 
2336
 
 
2337
    if (shell_seen[shell_index]==1) {
 
2338
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2339
              shell_options[shell_index].name);
 
2340
      exit(1);
 
2341
    }
 
2342
    shell_seen[shell_index]=1;  
 
2343
 
 
2344
    switch (shell_index) {
 
2345
    case 0: /* graph */
 
2346
      shell_read_graph(&graph, optarg);
 
2347
      break;
 
2348
    case 1: /* eids */
 
2349
      shell_arg_eids=strdup(optarg); 
 
2350
  igraph_vector_init(&eids, 0);
 
2351
      break;
 
2352
    case 2: /* pairs */
 
2353
      shell_read_vector(&pairs, optarg);
 
2354
      break;
 
2355
    case 3: /* directed */
 
2356
      shell_read_boolean(&directed, optarg);
 
2357
      break;
 
2358
    case 4:
 
2359
      shell_igraph_get_eids_usage(argv);
 
2360
      break;
 
2361
    default:
 
2362
      break;
 
2363
    }
 
2364
 
 
2365
    shell_index=-1;
 
2366
  }
 
2367
 
 
2368
  /* Check that we have all arguments */
 
2369
  for (shell_index=0; shell_index<4; shell_index++) {
 
2370
    if (!shell_seen[shell_index]) {
 
2371
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2372
              shell_options[shell_index].name);
 
2373
      exit(1);
 
2374
    }
 
2375
  }
 
2376
 
 
2377
  /* Do the operation */
 
2378
  shell_result=igraph_get_eids(&graph, &eids, &pairs, directed);
 
2379
 
 
2380
  /* Write the result */
 
2381
  igraph_destroy(&graph);
 
2382
  shell_write_vector(&eids, shell_arg_eids); 
 
2383
  igraph_vector_destroy(&eids);
 
2384
  igraph_vector_destroy(&pairs);
 
2385
 
 
2386
  return 0;
 
2387
}
 
2388
 
 
2389
/*-------------------------------------------/
 
2390
/ igraph_adjacent                            /
 
2391
/-------------------------------------------*/
 
2392
void shell_igraph_adjacent_usage(char **argv) {
 
2393
  printf("%s --graph=<graph> --eids=<eids> --vid=<vid> --mode=<mode>\n", basename(argv[0]));
 
2394
  exit(1);
 
2395
}
 
2396
 
 
2397
int shell_igraph_adjacent(int argc, char **argv) {
 
2398
 
 
2399
  igraph_t graph;
 
2400
  igraph_vector_t eids;
 
2401
  igraph_integer_t vid;
 
2402
  igraph_neimode_t mode=IGRAPH_ALL;
 
2403
  char* shell_arg_eids=0;
 
2404
  int shell_result;
 
2405
 
 
2406
 
 
2407
  int shell_seen[4];
 
2408
  int shell_index=-1;
 
2409
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2410
                                   { "eids",required_argument,0,1 },
 
2411
                                   { "vid",required_argument,0,2 },
 
2412
                                   { "mode",required_argument,0,3 },
 
2413
                                   { "help",no_argument,0,4 },
 
2414
                                   { 0,0,0,0 }
 
2415
                                 };
 
2416
 
 
2417
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2418
  memset(shell_seen, 0, 4*sizeof(int));
 
2419
  shell_seen[3]=2;
 
2420
  
 
2421
  /* Parse arguments and read input */
 
2422
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2423
 
 
2424
    if (shell_index==-1) {
 
2425
      exit(1);
 
2426
    }
 
2427
 
 
2428
    if (shell_seen[shell_index]==1) {
 
2429
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2430
              shell_options[shell_index].name);
 
2431
      exit(1);
 
2432
    }
 
2433
    shell_seen[shell_index]=1;  
 
2434
 
 
2435
    switch (shell_index) {
 
2436
    case 0: /* graph */
 
2437
      shell_read_graph(&graph, optarg);
 
2438
      break;
 
2439
    case 1: /* eids */
 
2440
      shell_arg_eids=strdup(optarg); 
 
2441
  igraph_vector_init(&eids, 0);
 
2442
      break;
 
2443
    case 2: /* vid */
 
2444
      shell_read_integer(&vid, optarg);
 
2445
      break;
 
2446
    case 3: /* mode */
 
2447
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
2448
      break;
 
2449
    case 4:
 
2450
      shell_igraph_adjacent_usage(argv);
 
2451
      break;
 
2452
    default:
 
2453
      break;
 
2454
    }
 
2455
 
 
2456
    shell_index=-1;
 
2457
  }
 
2458
 
 
2459
  /* Check that we have all arguments */
 
2460
  for (shell_index=0; shell_index<4; shell_index++) {
 
2461
    if (!shell_seen[shell_index]) {
 
2462
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2463
              shell_options[shell_index].name);
 
2464
      exit(1);
 
2465
    }
 
2466
  }
 
2467
 
 
2468
  /* Do the operation */
 
2469
  shell_result=igraph_adjacent(&graph, &eids, vid, mode);
 
2470
 
 
2471
  /* Write the result */
 
2472
  igraph_destroy(&graph);
 
2473
  shell_write_vector(&eids, shell_arg_eids); 
 
2474
  igraph_vector_destroy(&eids);
 
2475
 
 
2476
  return 0;
 
2477
}
 
2478
 
 
2479
/*-------------------------------------------/
 
2480
/ igraph_create                              /
 
2481
/-------------------------------------------*/
 
2482
void shell_igraph_create_usage(char **argv) {
 
2483
  printf("%s --graph=<graph> --edges=<edges> --n=<n> --directed=<directed>\n", basename(argv[0]));
 
2484
  exit(1);
 
2485
}
 
2486
 
 
2487
int shell_igraph_create(int argc, char **argv) {
 
2488
 
 
2489
  igraph_t graph;
 
2490
  igraph_vector_t edges;
 
2491
  igraph_integer_t n=0;
 
2492
  igraph_bool_t directed=1;
 
2493
  char* shell_arg_graph=0;
 
2494
  int shell_result;
 
2495
 
 
2496
 
 
2497
  int shell_seen[4];
 
2498
  int shell_index=-1;
 
2499
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2500
                                   { "edges",required_argument,0,1 },
 
2501
                                   { "n",required_argument,0,2 },
 
2502
                                   { "directed",required_argument,0,3 },
 
2503
                                   { "help",no_argument,0,4 },
 
2504
                                   { 0,0,0,0 }
 
2505
                                 };
 
2506
 
 
2507
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2508
  memset(shell_seen, 0, 4*sizeof(int));
 
2509
  shell_seen[2]=2;
 
2510
  shell_seen[3]=2;
 
2511
  
 
2512
  /* Parse arguments and read input */
 
2513
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2514
 
 
2515
    if (shell_index==-1) {
 
2516
      exit(1);
 
2517
    }
 
2518
 
 
2519
    if (shell_seen[shell_index]==1) {
 
2520
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2521
              shell_options[shell_index].name);
 
2522
      exit(1);
 
2523
    }
 
2524
    shell_seen[shell_index]=1;  
 
2525
 
 
2526
    switch (shell_index) {
 
2527
    case 0: /* graph */
 
2528
      shell_arg_graph=strdup(optarg);
 
2529
      break;
 
2530
    case 1: /* edges */
 
2531
      shell_read_vector(&edges, optarg);
 
2532
      break;
 
2533
    case 2: /* n */
 
2534
      shell_read_integer(&n, optarg);
 
2535
      break;
 
2536
    case 3: /* directed */
 
2537
      shell_read_boolean(&directed, optarg);
 
2538
      break;
 
2539
    case 4:
 
2540
      shell_igraph_create_usage(argv);
 
2541
      break;
 
2542
    default:
 
2543
      break;
 
2544
    }
 
2545
 
 
2546
    shell_index=-1;
 
2547
  }
 
2548
 
 
2549
  /* Check that we have all arguments */
 
2550
  for (shell_index=0; shell_index<4; shell_index++) {
 
2551
    if (!shell_seen[shell_index]) {
 
2552
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2553
              shell_options[shell_index].name);
 
2554
      exit(1);
 
2555
    }
 
2556
  }
 
2557
 
 
2558
  /* Do the operation */
 
2559
  shell_result=igraph_create(&graph, &edges, n, directed);
 
2560
 
 
2561
  /* Write the result */
 
2562
  shell_write_graph(&graph, shell_arg_graph); 
 
2563
  igraph_destroy(&graph);
 
2564
  igraph_vector_destroy(&edges);
 
2565
 
 
2566
  return 0;
 
2567
}
 
2568
 
 
2569
/*-------------------------------------------/
 
2570
/ igraph_adjacency                           /
 
2571
/-------------------------------------------*/
 
2572
void shell_igraph_adjacency_usage(char **argv) {
 
2573
  printf("%s --graph=<graph> --adjmatrix=<adjmatrix> --mode=<mode>\n", basename(argv[0]));
 
2574
  exit(1);
 
2575
}
 
2576
 
 
2577
int shell_igraph_adjacency(int argc, char **argv) {
 
2578
 
 
2579
  igraph_t graph;
 
2580
  igraph_matrix_t adjmatrix;
 
2581
  igraph_adjacency_t mode=IGRAPH_ADJ_DIRECTED;
 
2582
  char* shell_arg_graph=0;
 
2583
  int shell_result;
 
2584
 
 
2585
 
 
2586
  int shell_seen[3];
 
2587
  int shell_index=-1;
 
2588
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2589
                                   { "adjmatrix",required_argument,0,1 },
 
2590
                                   { "mode",required_argument,0,2 },
 
2591
                                   { "help",no_argument,0,3 },
 
2592
                                   { 0,0,0,0 }
 
2593
                                 };
 
2594
 
 
2595
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2596
  memset(shell_seen, 0, 3*sizeof(int));
 
2597
  shell_seen[2]=2;
 
2598
  
 
2599
  /* Parse arguments and read input */
 
2600
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2601
 
 
2602
    if (shell_index==-1) {
 
2603
      exit(1);
 
2604
    }
 
2605
 
 
2606
    if (shell_seen[shell_index]==1) {
 
2607
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2608
              shell_options[shell_index].name);
 
2609
      exit(1);
 
2610
    }
 
2611
    shell_seen[shell_index]=1;  
 
2612
 
 
2613
    switch (shell_index) {
 
2614
    case 0: /* graph */
 
2615
      shell_arg_graph=strdup(optarg);
 
2616
      break;
 
2617
    case 1: /* adjmatrix */
 
2618
      shell_read_matrix(&adjmatrix, optarg);
 
2619
      break;
 
2620
    case 2: /* mode */
 
2621
      shell_read_enum(&mode, optarg, "directed", 0, "undirected", 1, 
 
2622
  "max", 1, "upper", 2, "lower", 3, "min", 4, "plus", 5, 0);
 
2623
      break;
 
2624
    case 3:
 
2625
      shell_igraph_adjacency_usage(argv);
 
2626
      break;
 
2627
    default:
 
2628
      break;
 
2629
    }
 
2630
 
 
2631
    shell_index=-1;
 
2632
  }
 
2633
 
 
2634
  /* Check that we have all arguments */
 
2635
  for (shell_index=0; shell_index<3; shell_index++) {
 
2636
    if (!shell_seen[shell_index]) {
 
2637
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2638
              shell_options[shell_index].name);
 
2639
      exit(1);
 
2640
    }
 
2641
  }
 
2642
 
 
2643
  /* Do the operation */
 
2644
  shell_result=igraph_adjacency(&graph, &adjmatrix, mode);
 
2645
 
 
2646
  /* Write the result */
 
2647
  shell_write_graph(&graph, shell_arg_graph); 
 
2648
  igraph_destroy(&graph);
 
2649
  igraph_matrix_destroy(&adjmatrix);
 
2650
 
 
2651
  return 0;
 
2652
}
 
2653
 
 
2654
/*-------------------------------------------/
 
2655
/ igraph_star                                /
 
2656
/-------------------------------------------*/
 
2657
void shell_igraph_star_usage(char **argv) {
 
2658
  printf("%s --graph=<graph> --n=<n> --mode=<mode> --center=<center>\n", basename(argv[0]));
 
2659
  exit(1);
 
2660
}
 
2661
 
 
2662
int shell_igraph_star(int argc, char **argv) {
 
2663
 
 
2664
  igraph_t graph;
 
2665
  igraph_integer_t n;
 
2666
  igraph_star_mode_t mode=IGRAPH_STAR_OUT;
 
2667
  igraph_integer_t center=0;
 
2668
  char* shell_arg_graph=0;
 
2669
  int shell_result;
 
2670
 
 
2671
 
 
2672
  int shell_seen[4];
 
2673
  int shell_index=-1;
 
2674
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2675
                                   { "n",required_argument,0,1 },
 
2676
                                   { "mode",required_argument,0,2 },
 
2677
                                   { "center",required_argument,0,3 },
 
2678
                                   { "help",no_argument,0,4 },
 
2679
                                   { 0,0,0,0 }
 
2680
                                 };
 
2681
 
 
2682
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2683
  memset(shell_seen, 0, 4*sizeof(int));
 
2684
  shell_seen[2]=2;
 
2685
  shell_seen[3]=2;
 
2686
  
 
2687
  /* Parse arguments and read input */
 
2688
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2689
 
 
2690
    if (shell_index==-1) {
 
2691
      exit(1);
 
2692
    }
 
2693
 
 
2694
    if (shell_seen[shell_index]==1) {
 
2695
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2696
              shell_options[shell_index].name);
 
2697
      exit(1);
 
2698
    }
 
2699
    shell_seen[shell_index]=1;  
 
2700
 
 
2701
    switch (shell_index) {
 
2702
    case 0: /* graph */
 
2703
      shell_arg_graph=strdup(optarg);
 
2704
      break;
 
2705
    case 1: /* n */
 
2706
      shell_read_integer(&n, optarg);
 
2707
      break;
 
2708
    case 2: /* mode */
 
2709
      shell_read_enum(&mode, optarg, "out", 0, "in", 1, "undirected", 2, 0);
 
2710
      break;
 
2711
    case 3: /* center */
 
2712
      shell_read_integer(&center, optarg);
 
2713
      break;
 
2714
    case 4:
 
2715
      shell_igraph_star_usage(argv);
 
2716
      break;
 
2717
    default:
 
2718
      break;
 
2719
    }
 
2720
 
 
2721
    shell_index=-1;
 
2722
  }
 
2723
 
 
2724
  /* Check that we have all arguments */
 
2725
  for (shell_index=0; shell_index<4; shell_index++) {
 
2726
    if (!shell_seen[shell_index]) {
 
2727
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2728
              shell_options[shell_index].name);
 
2729
      exit(1);
 
2730
    }
 
2731
  }
 
2732
 
 
2733
  /* Do the operation */
 
2734
  shell_result=igraph_star(&graph, n, mode, center);
 
2735
 
 
2736
  /* Write the result */
 
2737
  shell_write_graph(&graph, shell_arg_graph); 
 
2738
  igraph_destroy(&graph);
 
2739
 
 
2740
  return 0;
 
2741
}
 
2742
 
 
2743
/*-------------------------------------------/
 
2744
/ igraph_lattice                             /
 
2745
/-------------------------------------------*/
 
2746
void shell_igraph_lattice_usage(char **argv) {
 
2747
  printf("%s --graph=<graph> --dimvector=<dimvector> --nei=<nei> --directed=<directed> --mutual=<mutual> --circular=<circular>\n", basename(argv[0]));
 
2748
  exit(1);
 
2749
}
 
2750
 
 
2751
int shell_igraph_lattice(int argc, char **argv) {
 
2752
 
 
2753
  igraph_t graph;
 
2754
  igraph_vector_t dimvector;
 
2755
  igraph_integer_t nei=1;
 
2756
  igraph_bool_t directed=0;
 
2757
  igraph_bool_t mutual=0;
 
2758
  igraph_bool_t circular=0;
 
2759
  char* shell_arg_graph=0;
 
2760
  int shell_result;
 
2761
 
 
2762
 
 
2763
  int shell_seen[6];
 
2764
  int shell_index=-1;
 
2765
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2766
                                   { "dimvector",required_argument,0,1 },
 
2767
                                   { "nei",required_argument,0,2 },
 
2768
                                   { "directed",required_argument,0,3 },
 
2769
                                   { "mutual",required_argument,0,4 },
 
2770
                                   { "circular",required_argument,0,5 },
 
2771
                                   { "help",no_argument,0,6 },
 
2772
                                   { 0,0,0,0 }
 
2773
                                 };
 
2774
 
 
2775
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2776
  memset(shell_seen, 0, 6*sizeof(int));
 
2777
  shell_seen[2]=2;
 
2778
  shell_seen[3]=2;
 
2779
  shell_seen[4]=2;
 
2780
  shell_seen[5]=2;
 
2781
  
 
2782
  /* Parse arguments and read input */
 
2783
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2784
 
 
2785
    if (shell_index==-1) {
 
2786
      exit(1);
 
2787
    }
 
2788
 
 
2789
    if (shell_seen[shell_index]==1) {
 
2790
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2791
              shell_options[shell_index].name);
 
2792
      exit(1);
 
2793
    }
 
2794
    shell_seen[shell_index]=1;  
 
2795
 
 
2796
    switch (shell_index) {
 
2797
    case 0: /* graph */
 
2798
      shell_arg_graph=strdup(optarg);
 
2799
      break;
 
2800
    case 1: /* dimvector */
 
2801
      shell_read_vector(&dimvector, optarg);
 
2802
      break;
 
2803
    case 2: /* nei */
 
2804
      shell_read_integer(&nei, optarg);
 
2805
      break;
 
2806
    case 3: /* directed */
 
2807
      shell_read_boolean(&directed, optarg);
 
2808
      break;
 
2809
    case 4: /* mutual */
 
2810
      shell_read_boolean(&mutual, optarg);
 
2811
      break;
 
2812
    case 5: /* circular */
 
2813
      shell_read_boolean(&circular, optarg);
 
2814
      break;
 
2815
    case 6:
 
2816
      shell_igraph_lattice_usage(argv);
 
2817
      break;
 
2818
    default:
 
2819
      break;
 
2820
    }
 
2821
 
 
2822
    shell_index=-1;
 
2823
  }
 
2824
 
 
2825
  /* Check that we have all arguments */
 
2826
  for (shell_index=0; shell_index<6; shell_index++) {
 
2827
    if (!shell_seen[shell_index]) {
 
2828
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2829
              shell_options[shell_index].name);
 
2830
      exit(1);
 
2831
    }
 
2832
  }
 
2833
 
 
2834
  /* Do the operation */
 
2835
  shell_result=igraph_lattice(&graph, &dimvector, nei, directed, mutual, circular);
 
2836
 
 
2837
  /* Write the result */
 
2838
  shell_write_graph(&graph, shell_arg_graph); 
 
2839
  igraph_destroy(&graph);
 
2840
  igraph_vector_destroy(&dimvector);
 
2841
 
 
2842
  return 0;
 
2843
}
 
2844
 
 
2845
/*-------------------------------------------/
 
2846
/ igraph_ring                                /
 
2847
/-------------------------------------------*/
 
2848
void shell_igraph_ring_usage(char **argv) {
 
2849
  printf("%s --graph=<graph> --n=<n> --directed=<directed> --mutual=<mutual> --circular=<circular>\n", basename(argv[0]));
 
2850
  exit(1);
 
2851
}
 
2852
 
 
2853
int shell_igraph_ring(int argc, char **argv) {
 
2854
 
 
2855
  igraph_t graph;
 
2856
  igraph_integer_t n;
 
2857
  igraph_bool_t directed=0;
 
2858
  igraph_bool_t mutual=0;
 
2859
  igraph_bool_t circular=1;
 
2860
  char* shell_arg_graph=0;
 
2861
  int shell_result;
 
2862
 
 
2863
 
 
2864
  int shell_seen[5];
 
2865
  int shell_index=-1;
 
2866
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2867
                                   { "n",required_argument,0,1 },
 
2868
                                   { "directed",required_argument,0,2 },
 
2869
                                   { "mutual",required_argument,0,3 },
 
2870
                                   { "circular",required_argument,0,4 },
 
2871
                                   { "help",no_argument,0,5 },
 
2872
                                   { 0,0,0,0 }
 
2873
                                 };
 
2874
 
 
2875
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2876
  memset(shell_seen, 0, 5*sizeof(int));
 
2877
  shell_seen[2]=2;
 
2878
  shell_seen[3]=2;
 
2879
  shell_seen[4]=2;
 
2880
  
 
2881
  /* Parse arguments and read input */
 
2882
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2883
 
 
2884
    if (shell_index==-1) {
 
2885
      exit(1);
 
2886
    }
 
2887
 
 
2888
    if (shell_seen[shell_index]==1) {
 
2889
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2890
              shell_options[shell_index].name);
 
2891
      exit(1);
 
2892
    }
 
2893
    shell_seen[shell_index]=1;  
 
2894
 
 
2895
    switch (shell_index) {
 
2896
    case 0: /* graph */
 
2897
      shell_arg_graph=strdup(optarg);
 
2898
      break;
 
2899
    case 1: /* n */
 
2900
      shell_read_integer(&n, optarg);
 
2901
      break;
 
2902
    case 2: /* directed */
 
2903
      shell_read_boolean(&directed, optarg);
 
2904
      break;
 
2905
    case 3: /* mutual */
 
2906
      shell_read_boolean(&mutual, optarg);
 
2907
      break;
 
2908
    case 4: /* circular */
 
2909
      shell_read_boolean(&circular, optarg);
 
2910
      break;
 
2911
    case 5:
 
2912
      shell_igraph_ring_usage(argv);
 
2913
      break;
 
2914
    default:
 
2915
      break;
 
2916
    }
 
2917
 
 
2918
    shell_index=-1;
 
2919
  }
 
2920
 
 
2921
  /* Check that we have all arguments */
 
2922
  for (shell_index=0; shell_index<5; shell_index++) {
 
2923
    if (!shell_seen[shell_index]) {
 
2924
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
2925
              shell_options[shell_index].name);
 
2926
      exit(1);
 
2927
    }
 
2928
  }
 
2929
 
 
2930
  /* Do the operation */
 
2931
  shell_result=igraph_ring(&graph, n, directed, mutual, circular);
 
2932
 
 
2933
  /* Write the result */
 
2934
  shell_write_graph(&graph, shell_arg_graph); 
 
2935
  igraph_destroy(&graph);
 
2936
 
 
2937
  return 0;
 
2938
}
 
2939
 
 
2940
/*-------------------------------------------/
 
2941
/ igraph_tree                                /
 
2942
/-------------------------------------------*/
 
2943
void shell_igraph_tree_usage(char **argv) {
 
2944
  printf("%s --graph=<graph> --n=<n> --children=<children> --type=<type>\n", basename(argv[0]));
 
2945
  exit(1);
 
2946
}
 
2947
 
 
2948
int shell_igraph_tree(int argc, char **argv) {
 
2949
 
 
2950
  igraph_t graph;
 
2951
  igraph_integer_t n;
 
2952
  igraph_integer_t children=2;
 
2953
  igraph_tree_mode_t type=IGRAPH_TREE_OUT;
 
2954
  char* shell_arg_graph=0;
 
2955
  int shell_result;
 
2956
 
 
2957
 
 
2958
  int shell_seen[4];
 
2959
  int shell_index=-1;
 
2960
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
2961
                                   { "n",required_argument,0,1 },
 
2962
                                   { "children",required_argument,0,2 },
 
2963
                                   { "type",required_argument,0,3 },
 
2964
                                   { "help",no_argument,0,4 },
 
2965
                                   { 0,0,0,0 }
 
2966
                                 };
 
2967
 
 
2968
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
2969
  memset(shell_seen, 0, 4*sizeof(int));
 
2970
  shell_seen[2]=2;
 
2971
  shell_seen[3]=2;
 
2972
  
 
2973
  /* Parse arguments and read input */
 
2974
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
2975
 
 
2976
    if (shell_index==-1) {
 
2977
      exit(1);
 
2978
    }
 
2979
 
 
2980
    if (shell_seen[shell_index]==1) {
 
2981
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
2982
              shell_options[shell_index].name);
 
2983
      exit(1);
 
2984
    }
 
2985
    shell_seen[shell_index]=1;  
 
2986
 
 
2987
    switch (shell_index) {
 
2988
    case 0: /* graph */
 
2989
      shell_arg_graph=strdup(optarg);
 
2990
      break;
 
2991
    case 1: /* n */
 
2992
      shell_read_integer(&n, optarg);
 
2993
      break;
 
2994
    case 2: /* children */
 
2995
      shell_read_integer(&children, optarg);
 
2996
      break;
 
2997
    case 3: /* type */
 
2998
      shell_read_enum(&type, optarg, "out", 0, "in", 1, "undirected", 2, 0);
 
2999
      break;
 
3000
    case 4:
 
3001
      shell_igraph_tree_usage(argv);
 
3002
      break;
 
3003
    default:
 
3004
      break;
 
3005
    }
 
3006
 
 
3007
    shell_index=-1;
 
3008
  }
 
3009
 
 
3010
  /* Check that we have all arguments */
 
3011
  for (shell_index=0; shell_index<4; shell_index++) {
 
3012
    if (!shell_seen[shell_index]) {
 
3013
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3014
              shell_options[shell_index].name);
 
3015
      exit(1);
 
3016
    }
 
3017
  }
 
3018
 
 
3019
  /* Do the operation */
 
3020
  shell_result=igraph_tree(&graph, n, children, type);
 
3021
 
 
3022
  /* Write the result */
 
3023
  shell_write_graph(&graph, shell_arg_graph); 
 
3024
  igraph_destroy(&graph);
 
3025
 
 
3026
  return 0;
 
3027
}
 
3028
 
 
3029
/*-------------------------------------------/
 
3030
/ igraph_full                                /
 
3031
/-------------------------------------------*/
 
3032
void shell_igraph_full_usage(char **argv) {
 
3033
  printf("%s --graph=<graph> --n=<n> --directed=<directed> --loops=<loops>\n", basename(argv[0]));
 
3034
  exit(1);
 
3035
}
 
3036
 
 
3037
int shell_igraph_full(int argc, char **argv) {
 
3038
 
 
3039
  igraph_t graph;
 
3040
  igraph_integer_t n;
 
3041
  igraph_bool_t directed=0;
 
3042
  igraph_bool_t loops=0;
 
3043
  char* shell_arg_graph=0;
 
3044
  int shell_result;
 
3045
 
 
3046
 
 
3047
  int shell_seen[4];
 
3048
  int shell_index=-1;
 
3049
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3050
                                   { "n",required_argument,0,1 },
 
3051
                                   { "directed",required_argument,0,2 },
 
3052
                                   { "loops",required_argument,0,3 },
 
3053
                                   { "help",no_argument,0,4 },
 
3054
                                   { 0,0,0,0 }
 
3055
                                 };
 
3056
 
 
3057
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3058
  memset(shell_seen, 0, 4*sizeof(int));
 
3059
  shell_seen[2]=2;
 
3060
  shell_seen[3]=2;
 
3061
  
 
3062
  /* Parse arguments and read input */
 
3063
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3064
 
 
3065
    if (shell_index==-1) {
 
3066
      exit(1);
 
3067
    }
 
3068
 
 
3069
    if (shell_seen[shell_index]==1) {
 
3070
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3071
              shell_options[shell_index].name);
 
3072
      exit(1);
 
3073
    }
 
3074
    shell_seen[shell_index]=1;  
 
3075
 
 
3076
    switch (shell_index) {
 
3077
    case 0: /* graph */
 
3078
      shell_arg_graph=strdup(optarg);
 
3079
      break;
 
3080
    case 1: /* n */
 
3081
      shell_read_integer(&n, optarg);
 
3082
      break;
 
3083
    case 2: /* directed */
 
3084
      shell_read_boolean(&directed, optarg);
 
3085
      break;
 
3086
    case 3: /* loops */
 
3087
      shell_read_boolean(&loops, optarg);
 
3088
      break;
 
3089
    case 4:
 
3090
      shell_igraph_full_usage(argv);
 
3091
      break;
 
3092
    default:
 
3093
      break;
 
3094
    }
 
3095
 
 
3096
    shell_index=-1;
 
3097
  }
 
3098
 
 
3099
  /* Check that we have all arguments */
 
3100
  for (shell_index=0; shell_index<4; shell_index++) {
 
3101
    if (!shell_seen[shell_index]) {
 
3102
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3103
              shell_options[shell_index].name);
 
3104
      exit(1);
 
3105
    }
 
3106
  }
 
3107
 
 
3108
  /* Do the operation */
 
3109
  shell_result=igraph_full(&graph, n, directed, loops);
 
3110
 
 
3111
  /* Write the result */
 
3112
  shell_write_graph(&graph, shell_arg_graph); 
 
3113
  igraph_destroy(&graph);
 
3114
 
 
3115
  return 0;
 
3116
}
 
3117
 
 
3118
/*-------------------------------------------/
 
3119
/ igraph_full_citation                       /
 
3120
/-------------------------------------------*/
 
3121
void shell_igraph_full_citation_usage(char **argv) {
 
3122
  printf("%s --graph=<graph> --n=<n> --directed=<directed>\n", basename(argv[0]));
 
3123
  exit(1);
 
3124
}
 
3125
 
 
3126
int shell_igraph_full_citation(int argc, char **argv) {
 
3127
 
 
3128
  igraph_t graph;
 
3129
  igraph_integer_t n;
 
3130
  igraph_bool_t directed=1;
 
3131
  char* shell_arg_graph=0;
 
3132
  int shell_result;
 
3133
 
 
3134
 
 
3135
  int shell_seen[3];
 
3136
  int shell_index=-1;
 
3137
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3138
                                   { "n",required_argument,0,1 },
 
3139
                                   { "directed",required_argument,0,2 },
 
3140
                                   { "help",no_argument,0,3 },
 
3141
                                   { 0,0,0,0 }
 
3142
                                 };
 
3143
 
 
3144
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3145
  memset(shell_seen, 0, 3*sizeof(int));
 
3146
  shell_seen[2]=2;
 
3147
  
 
3148
  /* Parse arguments and read input */
 
3149
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3150
 
 
3151
    if (shell_index==-1) {
 
3152
      exit(1);
 
3153
    }
 
3154
 
 
3155
    if (shell_seen[shell_index]==1) {
 
3156
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3157
              shell_options[shell_index].name);
 
3158
      exit(1);
 
3159
    }
 
3160
    shell_seen[shell_index]=1;  
 
3161
 
 
3162
    switch (shell_index) {
 
3163
    case 0: /* graph */
 
3164
      shell_arg_graph=strdup(optarg);
 
3165
      break;
 
3166
    case 1: /* n */
 
3167
      shell_read_integer(&n, optarg);
 
3168
      break;
 
3169
    case 2: /* directed */
 
3170
      shell_read_boolean(&directed, optarg);
 
3171
      break;
 
3172
    case 3:
 
3173
      shell_igraph_full_citation_usage(argv);
 
3174
      break;
 
3175
    default:
 
3176
      break;
 
3177
    }
 
3178
 
 
3179
    shell_index=-1;
 
3180
  }
 
3181
 
 
3182
  /* Check that we have all arguments */
 
3183
  for (shell_index=0; shell_index<3; shell_index++) {
 
3184
    if (!shell_seen[shell_index]) {
 
3185
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3186
              shell_options[shell_index].name);
 
3187
      exit(1);
 
3188
    }
 
3189
  }
 
3190
 
 
3191
  /* Do the operation */
 
3192
  shell_result=igraph_full_citation(&graph, n, directed);
 
3193
 
 
3194
  /* Write the result */
 
3195
  shell_write_graph(&graph, shell_arg_graph); 
 
3196
  igraph_destroy(&graph);
 
3197
 
 
3198
  return 0;
 
3199
}
 
3200
 
 
3201
/*-------------------------------------------/
 
3202
/ igraph_atlas                               /
 
3203
/-------------------------------------------*/
 
3204
void shell_igraph_atlas_usage(char **argv) {
 
3205
  printf("%s --graph=<graph> --number=<number>\n", basename(argv[0]));
 
3206
  exit(1);
 
3207
}
 
3208
 
 
3209
int shell_igraph_atlas(int argc, char **argv) {
 
3210
 
 
3211
  igraph_t graph;
 
3212
  int number=0;
 
3213
  char* shell_arg_graph=0;
 
3214
  int shell_result;
 
3215
 
 
3216
 
 
3217
  int shell_seen[2];
 
3218
  int shell_index=-1;
 
3219
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3220
                                   { "number",required_argument,0,1 },
 
3221
                                   { "help",no_argument,0,2 },
 
3222
                                   { 0,0,0,0 }
 
3223
                                 };
 
3224
 
 
3225
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3226
  memset(shell_seen, 0, 2*sizeof(int));
 
3227
  shell_seen[1]=2;
 
3228
  
 
3229
  /* Parse arguments and read input */
 
3230
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3231
 
 
3232
    if (shell_index==-1) {
 
3233
      exit(1);
 
3234
    }
 
3235
 
 
3236
    if (shell_seen[shell_index]==1) {
 
3237
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3238
              shell_options[shell_index].name);
 
3239
      exit(1);
 
3240
    }
 
3241
    shell_seen[shell_index]=1;  
 
3242
 
 
3243
    switch (shell_index) {
 
3244
    case 0: /* graph */
 
3245
      shell_arg_graph=strdup(optarg);
 
3246
      break;
 
3247
    case 1: /* number */
 
3248
      shell_read_int(&number, optarg);
 
3249
      break;
 
3250
    case 2:
 
3251
      shell_igraph_atlas_usage(argv);
 
3252
      break;
 
3253
    default:
 
3254
      break;
 
3255
    }
 
3256
 
 
3257
    shell_index=-1;
 
3258
  }
 
3259
 
 
3260
  /* Check that we have all arguments */
 
3261
  for (shell_index=0; shell_index<2; shell_index++) {
 
3262
    if (!shell_seen[shell_index]) {
 
3263
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3264
              shell_options[shell_index].name);
 
3265
      exit(1);
 
3266
    }
 
3267
  }
 
3268
 
 
3269
  /* Do the operation */
 
3270
  shell_result=igraph_atlas(&graph, number);
 
3271
 
 
3272
  /* Write the result */
 
3273
  shell_write_graph(&graph, shell_arg_graph); 
 
3274
  igraph_destroy(&graph);
 
3275
 
 
3276
  return 0;
 
3277
}
 
3278
 
 
3279
/*-------------------------------------------/
 
3280
/ igraph_extended_chordal_ring               /
 
3281
/-------------------------------------------*/
 
3282
void shell_igraph_extended_chordal_ring_usage(char **argv) {
 
3283
  printf("%s --graph=<graph> --nodes=<nodes> --W=<W>\n", basename(argv[0]));
 
3284
  exit(1);
 
3285
}
 
3286
 
 
3287
int shell_igraph_extended_chordal_ring(int argc, char **argv) {
 
3288
 
 
3289
  igraph_t graph;
 
3290
  igraph_integer_t nodes;
 
3291
  igraph_matrix_t W;
 
3292
  char* shell_arg_graph=0;
 
3293
  int shell_result;
 
3294
 
 
3295
 
 
3296
  int shell_seen[3];
 
3297
  int shell_index=-1;
 
3298
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3299
                                   { "nodes",required_argument,0,1 },
 
3300
                                   { "W",required_argument,0,2 },
 
3301
                                   { "help",no_argument,0,3 },
 
3302
                                   { 0,0,0,0 }
 
3303
                                 };
 
3304
 
 
3305
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3306
  memset(shell_seen, 0, 3*sizeof(int));
 
3307
 
 
3308
  
 
3309
  /* Parse arguments and read input */
 
3310
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3311
 
 
3312
    if (shell_index==-1) {
 
3313
      exit(1);
 
3314
    }
 
3315
 
 
3316
    if (shell_seen[shell_index]==1) {
 
3317
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3318
              shell_options[shell_index].name);
 
3319
      exit(1);
 
3320
    }
 
3321
    shell_seen[shell_index]=1;  
 
3322
 
 
3323
    switch (shell_index) {
 
3324
    case 0: /* graph */
 
3325
      shell_arg_graph=strdup(optarg);
 
3326
      break;
 
3327
    case 1: /* nodes */
 
3328
      shell_read_integer(&nodes, optarg);
 
3329
      break;
 
3330
    case 2: /* W */
 
3331
      shell_read_matrix(&W, optarg);
 
3332
      break;
 
3333
    case 3:
 
3334
      shell_igraph_extended_chordal_ring_usage(argv);
 
3335
      break;
 
3336
    default:
 
3337
      break;
 
3338
    }
 
3339
 
 
3340
    shell_index=-1;
 
3341
  }
 
3342
 
 
3343
  /* Check that we have all arguments */
 
3344
  for (shell_index=0; shell_index<3; shell_index++) {
 
3345
    if (!shell_seen[shell_index]) {
 
3346
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3347
              shell_options[shell_index].name);
 
3348
      exit(1);
 
3349
    }
 
3350
  }
 
3351
 
 
3352
  /* Do the operation */
 
3353
  shell_result=igraph_extended_chordal_ring(&graph, nodes, &W);
 
3354
 
 
3355
  /* Write the result */
 
3356
  shell_write_graph(&graph, shell_arg_graph); 
 
3357
  igraph_destroy(&graph);
 
3358
  igraph_matrix_destroy(&W);
 
3359
 
 
3360
  return 0;
 
3361
}
 
3362
 
 
3363
/*-------------------------------------------/
 
3364
/ igraph_connect_neighborhood                /
 
3365
/-------------------------------------------*/
 
3366
void shell_igraph_connect_neighborhood_usage(char **argv) {
 
3367
  printf("%s --graph=<graph> --graph-out=<graph-out> --order=<order> --mode=<mode>\n", basename(argv[0]));
 
3368
  exit(1);
 
3369
}
 
3370
 
 
3371
int shell_igraph_connect_neighborhood(int argc, char **argv) {
 
3372
 
 
3373
  igraph_t graph;
 
3374
  igraph_integer_t order=2;
 
3375
  igraph_neimode_t mode=IGRAPH_ALL;
 
3376
  char* shell_arg_graph=0;
 
3377
  int shell_result;
 
3378
 
 
3379
 
 
3380
  int shell_seen[4];
 
3381
  int shell_index=-1;
 
3382
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3383
                                   { "graph-out",required_argument,0,1 },
 
3384
                                   { "order",required_argument,0,2 },
 
3385
                                   { "mode",required_argument,0,3 },
 
3386
                                   { "help",no_argument,0,4 },
 
3387
                                   { 0,0,0,0 }
 
3388
                                 };
 
3389
 
 
3390
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3391
  memset(shell_seen, 0, 4*sizeof(int));
 
3392
  shell_seen[2]=2;
 
3393
  shell_seen[3]=2;
 
3394
  
 
3395
  /* Parse arguments and read input */
 
3396
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3397
 
 
3398
    if (shell_index==-1) {
 
3399
      exit(1);
 
3400
    }
 
3401
 
 
3402
    if (shell_seen[shell_index]==1) {
 
3403
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3404
              shell_options[shell_index].name);
 
3405
      exit(1);
 
3406
    }
 
3407
    shell_seen[shell_index]=1;  
 
3408
 
 
3409
    switch (shell_index) {
 
3410
    case 0: /* graph */
 
3411
      shell_read_graph(&graph, optarg);
 
3412
      break;
 
3413
    case 1: /* graph-out */
 
3414
      shell_arg_graph=strdup(optarg);
 
3415
      break;
 
3416
    case 2: /* order */
 
3417
      shell_read_integer(&order, optarg);
 
3418
      break;
 
3419
    case 3: /* mode */
 
3420
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
3421
      break;
 
3422
    case 4:
 
3423
      shell_igraph_connect_neighborhood_usage(argv);
 
3424
      break;
 
3425
    default:
 
3426
      break;
 
3427
    }
 
3428
 
 
3429
    shell_index=-1;
 
3430
  }
 
3431
 
 
3432
  /* Check that we have all arguments */
 
3433
  for (shell_index=0; shell_index<4; shell_index++) {
 
3434
    if (!shell_seen[shell_index]) {
 
3435
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3436
              shell_options[shell_index].name);
 
3437
      exit(1);
 
3438
    }
 
3439
  }
 
3440
 
 
3441
  /* Do the operation */
 
3442
  shell_result=igraph_connect_neighborhood(&graph, order, mode);
 
3443
 
 
3444
  /* Write the result */
 
3445
  igraph_destroy(&graph);
 
3446
  shell_write_graph(&graph, shell_arg_graph); 
 
3447
  igraph_destroy(&graph);
 
3448
 
 
3449
  return 0;
 
3450
}
 
3451
 
 
3452
/*-------------------------------------------/
 
3453
/ igraph_linegraph                           /
 
3454
/-------------------------------------------*/
 
3455
void shell_igraph_linegraph_usage(char **argv) {
 
3456
  printf("%s --graph=<graph> --linegraph=<linegraph>\n", basename(argv[0]));
 
3457
  exit(1);
 
3458
}
 
3459
 
 
3460
int shell_igraph_linegraph(int argc, char **argv) {
 
3461
 
 
3462
  igraph_t graph;
 
3463
  igraph_t linegraph;
 
3464
  char* shell_arg_linegraph=0;
 
3465
  int shell_result;
 
3466
 
 
3467
 
 
3468
  int shell_seen[2];
 
3469
  int shell_index=-1;
 
3470
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3471
                                   { "linegraph",required_argument,0,1 },
 
3472
                                   { "help",no_argument,0,2 },
 
3473
                                   { 0,0,0,0 }
 
3474
                                 };
 
3475
 
 
3476
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3477
  memset(shell_seen, 0, 2*sizeof(int));
 
3478
 
 
3479
  
 
3480
  /* Parse arguments and read input */
 
3481
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3482
 
 
3483
    if (shell_index==-1) {
 
3484
      exit(1);
 
3485
    }
 
3486
 
 
3487
    if (shell_seen[shell_index]==1) {
 
3488
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3489
              shell_options[shell_index].name);
 
3490
      exit(1);
 
3491
    }
 
3492
    shell_seen[shell_index]=1;  
 
3493
 
 
3494
    switch (shell_index) {
 
3495
    case 0: /* graph */
 
3496
      shell_read_graph(&graph, optarg);
 
3497
      break;
 
3498
    case 1: /* linegraph */
 
3499
      shell_arg_linegraph=strdup(optarg);
 
3500
      break;
 
3501
    case 2:
 
3502
      shell_igraph_linegraph_usage(argv);
 
3503
      break;
 
3504
    default:
 
3505
      break;
 
3506
    }
 
3507
 
 
3508
    shell_index=-1;
 
3509
  }
 
3510
 
 
3511
  /* Check that we have all arguments */
 
3512
  for (shell_index=0; shell_index<2; shell_index++) {
 
3513
    if (!shell_seen[shell_index]) {
 
3514
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3515
              shell_options[shell_index].name);
 
3516
      exit(1);
 
3517
    }
 
3518
  }
 
3519
 
 
3520
  /* Do the operation */
 
3521
  shell_result=igraph_linegraph(&graph, &linegraph);
 
3522
 
 
3523
  /* Write the result */
 
3524
  igraph_destroy(&graph);
 
3525
  shell_write_graph(&linegraph, shell_arg_linegraph); 
 
3526
  igraph_destroy(&linegraph);
 
3527
 
 
3528
  return 0;
 
3529
}
 
3530
 
 
3531
/*-------------------------------------------/
 
3532
/ igraph_de_bruijn                           /
 
3533
/-------------------------------------------*/
 
3534
void shell_igraph_de_bruijn_usage(char **argv) {
 
3535
  printf("%s --graph=<graph> --m=<m> --n=<n>\n", basename(argv[0]));
 
3536
  exit(1);
 
3537
}
 
3538
 
 
3539
int shell_igraph_de_bruijn(int argc, char **argv) {
 
3540
 
 
3541
  igraph_t graph;
 
3542
  igraph_integer_t m;
 
3543
  igraph_integer_t n;
 
3544
  char* shell_arg_graph=0;
 
3545
  int shell_result;
 
3546
 
 
3547
 
 
3548
  int shell_seen[3];
 
3549
  int shell_index=-1;
 
3550
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3551
                                   { "m",required_argument,0,1 },
 
3552
                                   { "n",required_argument,0,2 },
 
3553
                                   { "help",no_argument,0,3 },
 
3554
                                   { 0,0,0,0 }
 
3555
                                 };
 
3556
 
 
3557
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3558
  memset(shell_seen, 0, 3*sizeof(int));
 
3559
 
 
3560
  
 
3561
  /* Parse arguments and read input */
 
3562
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3563
 
 
3564
    if (shell_index==-1) {
 
3565
      exit(1);
 
3566
    }
 
3567
 
 
3568
    if (shell_seen[shell_index]==1) {
 
3569
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3570
              shell_options[shell_index].name);
 
3571
      exit(1);
 
3572
    }
 
3573
    shell_seen[shell_index]=1;  
 
3574
 
 
3575
    switch (shell_index) {
 
3576
    case 0: /* graph */
 
3577
      shell_arg_graph=strdup(optarg);
 
3578
      break;
 
3579
    case 1: /* m */
 
3580
      shell_read_integer(&m, optarg);
 
3581
      break;
 
3582
    case 2: /* n */
 
3583
      shell_read_integer(&n, optarg);
 
3584
      break;
 
3585
    case 3:
 
3586
      shell_igraph_de_bruijn_usage(argv);
 
3587
      break;
 
3588
    default:
 
3589
      break;
 
3590
    }
 
3591
 
 
3592
    shell_index=-1;
 
3593
  }
 
3594
 
 
3595
  /* Check that we have all arguments */
 
3596
  for (shell_index=0; shell_index<3; shell_index++) {
 
3597
    if (!shell_seen[shell_index]) {
 
3598
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3599
              shell_options[shell_index].name);
 
3600
      exit(1);
 
3601
    }
 
3602
  }
 
3603
 
 
3604
  /* Do the operation */
 
3605
  shell_result=igraph_de_bruijn(&graph, m, n);
 
3606
 
 
3607
  /* Write the result */
 
3608
  shell_write_graph(&graph, shell_arg_graph); 
 
3609
  igraph_destroy(&graph);
 
3610
 
 
3611
  return 0;
 
3612
}
 
3613
 
 
3614
/*-------------------------------------------/
 
3615
/ igraph_kautz                               /
 
3616
/-------------------------------------------*/
 
3617
void shell_igraph_kautz_usage(char **argv) {
 
3618
  printf("%s --graph=<graph> --m=<m> --n=<n>\n", basename(argv[0]));
 
3619
  exit(1);
 
3620
}
 
3621
 
 
3622
int shell_igraph_kautz(int argc, char **argv) {
 
3623
 
 
3624
  igraph_t graph;
 
3625
  igraph_integer_t m;
 
3626
  igraph_integer_t n;
 
3627
  char* shell_arg_graph=0;
 
3628
  int shell_result;
 
3629
 
 
3630
 
 
3631
  int shell_seen[3];
 
3632
  int shell_index=-1;
 
3633
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3634
                                   { "m",required_argument,0,1 },
 
3635
                                   { "n",required_argument,0,2 },
 
3636
                                   { "help",no_argument,0,3 },
 
3637
                                   { 0,0,0,0 }
 
3638
                                 };
 
3639
 
 
3640
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3641
  memset(shell_seen, 0, 3*sizeof(int));
 
3642
 
 
3643
  
 
3644
  /* Parse arguments and read input */
 
3645
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3646
 
 
3647
    if (shell_index==-1) {
 
3648
      exit(1);
 
3649
    }
 
3650
 
 
3651
    if (shell_seen[shell_index]==1) {
 
3652
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3653
              shell_options[shell_index].name);
 
3654
      exit(1);
 
3655
    }
 
3656
    shell_seen[shell_index]=1;  
 
3657
 
 
3658
    switch (shell_index) {
 
3659
    case 0: /* graph */
 
3660
      shell_arg_graph=strdup(optarg);
 
3661
      break;
 
3662
    case 1: /* m */
 
3663
      shell_read_integer(&m, optarg);
 
3664
      break;
 
3665
    case 2: /* n */
 
3666
      shell_read_integer(&n, optarg);
 
3667
      break;
 
3668
    case 3:
 
3669
      shell_igraph_kautz_usage(argv);
 
3670
      break;
 
3671
    default:
 
3672
      break;
 
3673
    }
 
3674
 
 
3675
    shell_index=-1;
 
3676
  }
 
3677
 
 
3678
  /* Check that we have all arguments */
 
3679
  for (shell_index=0; shell_index<3; shell_index++) {
 
3680
    if (!shell_seen[shell_index]) {
 
3681
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3682
              shell_options[shell_index].name);
 
3683
      exit(1);
 
3684
    }
 
3685
  }
 
3686
 
 
3687
  /* Do the operation */
 
3688
  shell_result=igraph_kautz(&graph, m, n);
 
3689
 
 
3690
  /* Write the result */
 
3691
  shell_write_graph(&graph, shell_arg_graph); 
 
3692
  igraph_destroy(&graph);
 
3693
 
 
3694
  return 0;
 
3695
}
 
3696
 
 
3697
/*-------------------------------------------/
 
3698
/ igraph_famous                              /
 
3699
/-------------------------------------------*/
 
3700
void shell_igraph_famous_usage(char **argv) {
 
3701
  printf("%s --graph=<graph> --name=<name>\n", basename(argv[0]));
 
3702
  exit(1);
 
3703
}
 
3704
 
 
3705
int shell_igraph_famous(int argc, char **argv) {
 
3706
 
 
3707
  igraph_t graph;
 
3708
  char * name="";
 
3709
  char* shell_arg_graph=0;
 
3710
  int shell_result;
 
3711
 
 
3712
 
 
3713
  int shell_seen[2];
 
3714
  int shell_index=-1;
 
3715
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3716
                                   { "name",required_argument,0,1 },
 
3717
                                   { "help",no_argument,0,2 },
 
3718
                                   { 0,0,0,0 }
 
3719
                                 };
 
3720
 
 
3721
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3722
  memset(shell_seen, 0, 2*sizeof(int));
 
3723
  shell_seen[1]=2;
 
3724
  
 
3725
  /* Parse arguments and read input */
 
3726
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3727
 
 
3728
    if (shell_index==-1) {
 
3729
      exit(1);
 
3730
    }
 
3731
 
 
3732
    if (shell_seen[shell_index]==1) {
 
3733
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3734
              shell_options[shell_index].name);
 
3735
      exit(1);
 
3736
    }
 
3737
    shell_seen[shell_index]=1;  
 
3738
 
 
3739
    switch (shell_index) {
 
3740
    case 0: /* graph */
 
3741
      shell_arg_graph=strdup(optarg);
 
3742
      break;
 
3743
    case 1: /* name */
 
3744
      name=strdup(optarg);
 
3745
      break;
 
3746
    case 2:
 
3747
      shell_igraph_famous_usage(argv);
 
3748
      break;
 
3749
    default:
 
3750
      break;
 
3751
    }
 
3752
 
 
3753
    shell_index=-1;
 
3754
  }
 
3755
 
 
3756
  /* Check that we have all arguments */
 
3757
  for (shell_index=0; shell_index<2; shell_index++) {
 
3758
    if (!shell_seen[shell_index]) {
 
3759
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3760
              shell_options[shell_index].name);
 
3761
      exit(1);
 
3762
    }
 
3763
  }
 
3764
 
 
3765
  /* Do the operation */
 
3766
  shell_result=igraph_famous(&graph, name);
 
3767
 
 
3768
  /* Write the result */
 
3769
  shell_write_graph(&graph, shell_arg_graph); 
 
3770
  igraph_destroy(&graph);
 
3771
  free(name);
 
3772
 
 
3773
  return 0;
 
3774
}
 
3775
 
 
3776
/*-------------------------------------------/
 
3777
/ igraph_lcf_vector                          /
 
3778
/-------------------------------------------*/
 
3779
void shell_igraph_lcf_vector_usage(char **argv) {
 
3780
  printf("%s --graph=<graph> --n=<n> --shifts=<shifts> --repeats=<repeats>\n", basename(argv[0]));
 
3781
  exit(1);
 
3782
}
 
3783
 
 
3784
int shell_igraph_lcf_vector(int argc, char **argv) {
 
3785
 
 
3786
  igraph_t graph;
 
3787
  igraph_integer_t n;
 
3788
  igraph_vector_t shifts;
 
3789
  igraph_integer_t repeats=1;
 
3790
  char* shell_arg_graph=0;
 
3791
  int shell_result;
 
3792
 
 
3793
 
 
3794
  int shell_seen[4];
 
3795
  int shell_index=-1;
 
3796
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3797
                                   { "n",required_argument,0,1 },
 
3798
                                   { "shifts",required_argument,0,2 },
 
3799
                                   { "repeats",required_argument,0,3 },
 
3800
                                   { "help",no_argument,0,4 },
 
3801
                                   { 0,0,0,0 }
 
3802
                                 };
 
3803
 
 
3804
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3805
  memset(shell_seen, 0, 4*sizeof(int));
 
3806
  shell_seen[3]=2;
 
3807
  
 
3808
  /* Parse arguments and read input */
 
3809
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3810
 
 
3811
    if (shell_index==-1) {
 
3812
      exit(1);
 
3813
    }
 
3814
 
 
3815
    if (shell_seen[shell_index]==1) {
 
3816
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3817
              shell_options[shell_index].name);
 
3818
      exit(1);
 
3819
    }
 
3820
    shell_seen[shell_index]=1;  
 
3821
 
 
3822
    switch (shell_index) {
 
3823
    case 0: /* graph */
 
3824
      shell_arg_graph=strdup(optarg);
 
3825
      break;
 
3826
    case 1: /* n */
 
3827
      shell_read_integer(&n, optarg);
 
3828
      break;
 
3829
    case 2: /* shifts */
 
3830
      shell_read_vector(&shifts, optarg);
 
3831
      break;
 
3832
    case 3: /* repeats */
 
3833
      shell_read_integer(&repeats, optarg);
 
3834
      break;
 
3835
    case 4:
 
3836
      shell_igraph_lcf_vector_usage(argv);
 
3837
      break;
 
3838
    default:
 
3839
      break;
 
3840
    }
 
3841
 
 
3842
    shell_index=-1;
 
3843
  }
 
3844
 
 
3845
  /* Check that we have all arguments */
 
3846
  for (shell_index=0; shell_index<4; shell_index++) {
 
3847
    if (!shell_seen[shell_index]) {
 
3848
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3849
              shell_options[shell_index].name);
 
3850
      exit(1);
 
3851
    }
 
3852
  }
 
3853
 
 
3854
  /* Do the operation */
 
3855
  shell_result=igraph_lcf_vector(&graph, n, &shifts, repeats);
 
3856
 
 
3857
  /* Write the result */
 
3858
  shell_write_graph(&graph, shell_arg_graph); 
 
3859
  igraph_destroy(&graph);
 
3860
  igraph_vector_destroy(&shifts);
 
3861
 
 
3862
  return 0;
 
3863
}
 
3864
 
 
3865
/*-------------------------------------------/
 
3866
/ igraph_adjlist                             /
 
3867
/-------------------------------------------*/
 
3868
void shell_igraph_adjlist_usage(char **argv) {
 
3869
  printf("%s --graph=<graph> --directed=<directed> --duplicate=<duplicate>\n", basename(argv[0]));
 
3870
  exit(1);
 
3871
}
 
3872
 
 
3873
int shell_igraph_adjlist(int argc, char **argv) {
 
3874
 
 
3875
  igraph_t graph;
 
3876
 
 
3877
  igraph_bool_t directed=1;
 
3878
  igraph_bool_t duplicate=1;
 
3879
  char* shell_arg_graph=0;
 
3880
  int shell_result;
 
3881
 
 
3882
 
 
3883
  int shell_seen[3];
 
3884
  int shell_index=-1;
 
3885
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3886
                                   { "directed",required_argument,0,1 },
 
3887
                                   { "duplicate",required_argument,0,2 },
 
3888
                                   { "help",no_argument,0,3 },
 
3889
                                   { 0,0,0,0 }
 
3890
                                 };
 
3891
 
 
3892
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3893
  memset(shell_seen, 0, 3*sizeof(int));
 
3894
  shell_seen[1]=2;
 
3895
  shell_seen[2]=2;
 
3896
  
 
3897
  /* Parse arguments and read input */
 
3898
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3899
 
 
3900
    if (shell_index==-1) {
 
3901
      exit(1);
 
3902
    }
 
3903
 
 
3904
    if (shell_seen[shell_index]==1) {
 
3905
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3906
              shell_options[shell_index].name);
 
3907
      exit(1);
 
3908
    }
 
3909
    shell_seen[shell_index]=1;  
 
3910
 
 
3911
    switch (shell_index) {
 
3912
    case 0: /* graph */
 
3913
      shell_arg_graph=strdup(optarg);
 
3914
      break;
 
3915
    case 1: /* directed */
 
3916
      shell_read_boolean(&directed, optarg);
 
3917
      break;
 
3918
    case 2: /* duplicate */
 
3919
      shell_read_boolean(&duplicate, optarg);
 
3920
      break;
 
3921
    case 3:
 
3922
      shell_igraph_adjlist_usage(argv);
 
3923
      break;
 
3924
    default:
 
3925
      break;
 
3926
    }
 
3927
 
 
3928
    shell_index=-1;
 
3929
  }
 
3930
 
 
3931
  /* Check that we have all arguments */
 
3932
  for (shell_index=0; shell_index<3; shell_index++) {
 
3933
    if (!shell_seen[shell_index]) {
 
3934
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
3935
              shell_options[shell_index].name);
 
3936
      exit(1);
 
3937
    }
 
3938
  }
 
3939
 
 
3940
  /* Do the operation */
 
3941
  shell_result=igraph_adjlist(&graph, adjlist, directed, duplicate);
 
3942
 
 
3943
  /* Write the result */
 
3944
  shell_write_graph(&graph, shell_arg_graph); 
 
3945
  igraph_destroy(&graph);
 
3946
 
 
3947
  return 0;
 
3948
}
 
3949
 
 
3950
/*-------------------------------------------/
 
3951
/ igraph_full_bipartite                      /
 
3952
/-------------------------------------------*/
 
3953
void shell_igraph_full_bipartite_usage(char **argv) {
 
3954
  printf("%s --graph=<graph> --n1=<n1> --n2=<n2> --directed=<directed> --mode=<mode>\n", basename(argv[0]));
 
3955
  exit(1);
 
3956
}
 
3957
 
 
3958
int shell_igraph_full_bipartite(int argc, char **argv) {
 
3959
 
 
3960
  igraph_t graph;
 
3961
 
 
3962
  igraph_integer_t n1;
 
3963
  igraph_integer_t n2;
 
3964
  igraph_bool_t directed=0;
 
3965
  igraph_neimode_t mode=IGRAPH_ALL;
 
3966
  char* shell_arg_graph=0;
 
3967
  char* shell_arg_types=0;
 
3968
  int shell_result;
 
3969
 
 
3970
 
 
3971
  int shell_seen[5];
 
3972
  int shell_index=-1;
 
3973
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
3974
                                   { "n1",required_argument,0,1 },
 
3975
                                   { "n2",required_argument,0,2 },
 
3976
                                   { "directed",required_argument,0,3 },
 
3977
                                   { "mode",required_argument,0,4 },
 
3978
                                   { "help",no_argument,0,5 },
 
3979
                                   { 0,0,0,0 }
 
3980
                                 };
 
3981
 
 
3982
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
3983
  memset(shell_seen, 0, 5*sizeof(int));
 
3984
  shell_seen[3]=2;
 
3985
  shell_seen[4]=2;
 
3986
  
 
3987
  /* Parse arguments and read input */
 
3988
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
3989
 
 
3990
    if (shell_index==-1) {
 
3991
      exit(1);
 
3992
    }
 
3993
 
 
3994
    if (shell_seen[shell_index]==1) {
 
3995
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
3996
              shell_options[shell_index].name);
 
3997
      exit(1);
 
3998
    }
 
3999
    shell_seen[shell_index]=1;  
 
4000
 
 
4001
    switch (shell_index) {
 
4002
    case 0: /* graph */
 
4003
      shell_arg_graph=strdup(optarg);
 
4004
      break;
 
4005
    case 1: /* n1 */
 
4006
      shell_read_integer(&n1, optarg);
 
4007
      break;
 
4008
    case 2: /* n2 */
 
4009
      shell_read_integer(&n2, optarg);
 
4010
      break;
 
4011
    case 3: /* directed */
 
4012
      shell_read_boolean(&directed, optarg);
 
4013
      break;
 
4014
    case 4: /* mode */
 
4015
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
4016
      break;
 
4017
    case 5:
 
4018
      shell_igraph_full_bipartite_usage(argv);
 
4019
      break;
 
4020
    default:
 
4021
      break;
 
4022
    }
 
4023
 
 
4024
    shell_index=-1;
 
4025
  }
 
4026
 
 
4027
  /* Check that we have all arguments */
 
4028
  for (shell_index=0; shell_index<5; shell_index++) {
 
4029
    if (!shell_seen[shell_index]) {
 
4030
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4031
              shell_options[shell_index].name);
 
4032
      exit(1);
 
4033
    }
 
4034
  }
 
4035
 
 
4036
  /* Do the operation */
 
4037
  shell_result=igraph_full_bipartite(&graph, types, n1, n2, directed, mode);
 
4038
 
 
4039
  /* Write the result */
 
4040
  shell_write_graph(&graph, shell_arg_graph); 
 
4041
  igraph_destroy(&graph);
 
4042
 
 
4043
  return 0;
 
4044
}
 
4045
 
 
4046
/*-------------------------------------------/
 
4047
/ igraph_barabasi_game                       /
 
4048
/-------------------------------------------*/
 
4049
void shell_igraph_barabasi_game_usage(char **argv) {
 
4050
  printf("%s --graph=<graph> --n=<n> --m=<m> --outseq=<outseq> --outpref=<outpref> --directed=<directed>\n", basename(argv[0]));
 
4051
  exit(1);
 
4052
}
 
4053
 
 
4054
int shell_igraph_barabasi_game(int argc, char **argv) {
 
4055
 
 
4056
  igraph_t graph;
 
4057
  igraph_integer_t n;
 
4058
  igraph_integer_t m=1;
 
4059
  igraph_vector_t v_outseq; igraph_vector_t *outseq=0;
 
4060
  igraph_bool_t outpref=0;
 
4061
  igraph_bool_t directed=1;
 
4062
  char* shell_arg_graph=0;
 
4063
  int shell_result;
 
4064
 
 
4065
 
 
4066
  int shell_seen[6];
 
4067
  int shell_index=-1;
 
4068
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4069
                                   { "n",required_argument,0,1 },
 
4070
                                   { "m",required_argument,0,2 },
 
4071
                                   { "outseq",required_argument,0,3 },
 
4072
                                   { "outpref",required_argument,0,4 },
 
4073
                                   { "directed",required_argument,0,5 },
 
4074
                                   { "help",no_argument,0,6 },
 
4075
                                   { 0,0,0,0 }
 
4076
                                 };
 
4077
 
 
4078
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4079
  memset(shell_seen, 0, 6*sizeof(int));
 
4080
  shell_seen[2]=2;
 
4081
  shell_seen[4]=2;
 
4082
  shell_seen[5]=2;
 
4083
  
 
4084
  /* Parse arguments and read input */
 
4085
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4086
 
 
4087
    if (shell_index==-1) {
 
4088
      exit(1);
 
4089
    }
 
4090
 
 
4091
    if (shell_seen[shell_index]==1) {
 
4092
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4093
              shell_options[shell_index].name);
 
4094
      exit(1);
 
4095
    }
 
4096
    shell_seen[shell_index]=1;  
 
4097
 
 
4098
    switch (shell_index) {
 
4099
    case 0: /* graph */
 
4100
      shell_arg_graph=strdup(optarg);
 
4101
      break;
 
4102
    case 1: /* n */
 
4103
      shell_read_integer(&n, optarg);
 
4104
      break;
 
4105
    case 2: /* m */
 
4106
      shell_read_integer(&m, optarg);
 
4107
      break;
 
4108
    case 3: /* outseq */
 
4109
      outseq=&v_outseq; shell_read_vector(outseq, optarg);
 
4110
      break;
 
4111
    case 4: /* outpref */
 
4112
      shell_read_boolean(&outpref, optarg);
 
4113
      break;
 
4114
    case 5: /* directed */
 
4115
      shell_read_boolean(&directed, optarg);
 
4116
      break;
 
4117
    case 6:
 
4118
      shell_igraph_barabasi_game_usage(argv);
 
4119
      break;
 
4120
    default:
 
4121
      break;
 
4122
    }
 
4123
 
 
4124
    shell_index=-1;
 
4125
  }
 
4126
 
 
4127
  /* Check that we have all arguments */
 
4128
  for (shell_index=0; shell_index<6; shell_index++) {
 
4129
    if (!shell_seen[shell_index]) {
 
4130
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4131
              shell_options[shell_index].name);
 
4132
      exit(1);
 
4133
    }
 
4134
  }
 
4135
 
 
4136
  /* Do the operation */
 
4137
  shell_result=igraph_barabasi_game(&graph, n, m, outseq, outpref, directed);
 
4138
 
 
4139
  /* Write the result */
 
4140
  shell_write_graph(&graph, shell_arg_graph); 
 
4141
  igraph_destroy(&graph);
 
4142
  if (outseq) { igraph_vector_destroy(outseq); }
 
4143
 
 
4144
  return 0;
 
4145
}
 
4146
 
 
4147
/*-------------------------------------------/
 
4148
/ igraph_nonlinear_barabasi_game             /
 
4149
/-------------------------------------------*/
 
4150
void shell_igraph_nonlinear_barabasi_game_usage(char **argv) {
 
4151
  printf("%s --graph=<graph> --n=<n> --power=<power> --m=<m> --outseq=<outseq> --outpref=<outpref> --zeroappeal=<zeroappeal> --directed=<directed>\n", basename(argv[0]));
 
4152
  exit(1);
 
4153
}
 
4154
 
 
4155
int shell_igraph_nonlinear_barabasi_game(int argc, char **argv) {
 
4156
 
 
4157
  igraph_t graph;
 
4158
  igraph_integer_t n;
 
4159
  igraph_real_t power=1.0;
 
4160
  igraph_integer_t m=1;
 
4161
  igraph_vector_t v_outseq; igraph_vector_t *outseq=0;
 
4162
  igraph_bool_t outpref=0;
 
4163
  igraph_real_t zeroappeal=1.0;
 
4164
  igraph_bool_t directed=1;
 
4165
  char* shell_arg_graph=0;
 
4166
  int shell_result;
 
4167
 
 
4168
 
 
4169
  int shell_seen[8];
 
4170
  int shell_index=-1;
 
4171
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4172
                                   { "n",required_argument,0,1 },
 
4173
                                   { "power",required_argument,0,2 },
 
4174
                                   { "m",required_argument,0,3 },
 
4175
                                   { "outseq",required_argument,0,4 },
 
4176
                                   { "outpref",required_argument,0,5 },
 
4177
                                   { "zeroappeal",required_argument,0,6 },
 
4178
                                   { "directed",required_argument,0,7 },
 
4179
                                   { "help",no_argument,0,8 },
 
4180
                                   { 0,0,0,0 }
 
4181
                                 };
 
4182
 
 
4183
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4184
  memset(shell_seen, 0, 8*sizeof(int));
 
4185
  shell_seen[2]=2;
 
4186
  shell_seen[3]=2;
 
4187
  shell_seen[5]=2;
 
4188
  shell_seen[6]=2;
 
4189
  shell_seen[7]=2;
 
4190
  
 
4191
  /* Parse arguments and read input */
 
4192
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4193
 
 
4194
    if (shell_index==-1) {
 
4195
      exit(1);
 
4196
    }
 
4197
 
 
4198
    if (shell_seen[shell_index]==1) {
 
4199
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4200
              shell_options[shell_index].name);
 
4201
      exit(1);
 
4202
    }
 
4203
    shell_seen[shell_index]=1;  
 
4204
 
 
4205
    switch (shell_index) {
 
4206
    case 0: /* graph */
 
4207
      shell_arg_graph=strdup(optarg);
 
4208
      break;
 
4209
    case 1: /* n */
 
4210
      shell_read_integer(&n, optarg);
 
4211
      break;
 
4212
    case 2: /* power */
 
4213
      shell_read_real(&power, optarg);
 
4214
      break;
 
4215
    case 3: /* m */
 
4216
      shell_read_integer(&m, optarg);
 
4217
      break;
 
4218
    case 4: /* outseq */
 
4219
      outseq=&v_outseq; shell_read_vector(outseq, optarg);
 
4220
      break;
 
4221
    case 5: /* outpref */
 
4222
      shell_read_boolean(&outpref, optarg);
 
4223
      break;
 
4224
    case 6: /* zeroappeal */
 
4225
      shell_read_real(&zeroappeal, optarg);
 
4226
      break;
 
4227
    case 7: /* directed */
 
4228
      shell_read_boolean(&directed, optarg);
 
4229
      break;
 
4230
    case 8:
 
4231
      shell_igraph_nonlinear_barabasi_game_usage(argv);
 
4232
      break;
 
4233
    default:
 
4234
      break;
 
4235
    }
 
4236
 
 
4237
    shell_index=-1;
 
4238
  }
 
4239
 
 
4240
  /* Check that we have all arguments */
 
4241
  for (shell_index=0; shell_index<8; shell_index++) {
 
4242
    if (!shell_seen[shell_index]) {
 
4243
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4244
              shell_options[shell_index].name);
 
4245
      exit(1);
 
4246
    }
 
4247
  }
 
4248
 
 
4249
  /* Do the operation */
 
4250
  shell_result=igraph_nonlinear_barabasi_game(&graph, n, power, m, outseq, outpref, zeroappeal, directed);
 
4251
 
 
4252
  /* Write the result */
 
4253
  shell_write_graph(&graph, shell_arg_graph); 
 
4254
  igraph_destroy(&graph);
 
4255
  if (outseq) { igraph_vector_destroy(outseq); }
 
4256
 
 
4257
  return 0;
 
4258
}
 
4259
 
 
4260
/*-------------------------------------------/
 
4261
/ igraph_erdos_renyi_game_gnp                /
 
4262
/-------------------------------------------*/
 
4263
void shell_igraph_erdos_renyi_game_gnp_usage(char **argv) {
 
4264
  printf("%s --graph=<graph> --n=<n> --p=<p> --directed=<directed> --loops=<loops>\n", basename(argv[0]));
 
4265
  exit(1);
 
4266
}
 
4267
 
 
4268
int shell_igraph_erdos_renyi_game_gnp(int argc, char **argv) {
 
4269
 
 
4270
  igraph_t graph;
 
4271
  igraph_integer_t n;
 
4272
  igraph_real_t p;
 
4273
  igraph_bool_t directed=0;
 
4274
  igraph_bool_t loops=0;
 
4275
  char* shell_arg_graph=0;
 
4276
  int shell_result;
 
4277
 
 
4278
 
 
4279
  int shell_seen[5];
 
4280
  int shell_index=-1;
 
4281
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4282
                                   { "n",required_argument,0,1 },
 
4283
                                   { "p",required_argument,0,2 },
 
4284
                                   { "directed",required_argument,0,3 },
 
4285
                                   { "loops",required_argument,0,4 },
 
4286
                                   { "help",no_argument,0,5 },
 
4287
                                   { 0,0,0,0 }
 
4288
                                 };
 
4289
 
 
4290
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4291
  memset(shell_seen, 0, 5*sizeof(int));
 
4292
  shell_seen[3]=2;
 
4293
  shell_seen[4]=2;
 
4294
  
 
4295
  /* Parse arguments and read input */
 
4296
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4297
 
 
4298
    if (shell_index==-1) {
 
4299
      exit(1);
 
4300
    }
 
4301
 
 
4302
    if (shell_seen[shell_index]==1) {
 
4303
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4304
              shell_options[shell_index].name);
 
4305
      exit(1);
 
4306
    }
 
4307
    shell_seen[shell_index]=1;  
 
4308
 
 
4309
    switch (shell_index) {
 
4310
    case 0: /* graph */
 
4311
      shell_arg_graph=strdup(optarg);
 
4312
      break;
 
4313
    case 1: /* n */
 
4314
      shell_read_integer(&n, optarg);
 
4315
      break;
 
4316
    case 2: /* p */
 
4317
      shell_read_real(&p, optarg);
 
4318
      break;
 
4319
    case 3: /* directed */
 
4320
      shell_read_boolean(&directed, optarg);
 
4321
      break;
 
4322
    case 4: /* loops */
 
4323
      shell_read_boolean(&loops, optarg);
 
4324
      break;
 
4325
    case 5:
 
4326
      shell_igraph_erdos_renyi_game_gnp_usage(argv);
 
4327
      break;
 
4328
    default:
 
4329
      break;
 
4330
    }
 
4331
 
 
4332
    shell_index=-1;
 
4333
  }
 
4334
 
 
4335
  /* Check that we have all arguments */
 
4336
  for (shell_index=0; shell_index<5; shell_index++) {
 
4337
    if (!shell_seen[shell_index]) {
 
4338
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4339
              shell_options[shell_index].name);
 
4340
      exit(1);
 
4341
    }
 
4342
  }
 
4343
 
 
4344
  /* Do the operation */
 
4345
  shell_result=igraph_erdos_renyi_game_gnp(&graph, n, p, directed, loops);
 
4346
 
 
4347
  /* Write the result */
 
4348
  shell_write_graph(&graph, shell_arg_graph); 
 
4349
  igraph_destroy(&graph);
 
4350
 
 
4351
  return 0;
 
4352
}
 
4353
 
 
4354
/*-------------------------------------------/
 
4355
/ igraph_erdos_renyi_game_gnm                /
 
4356
/-------------------------------------------*/
 
4357
void shell_igraph_erdos_renyi_game_gnm_usage(char **argv) {
 
4358
  printf("%s --graph=<graph> --n=<n> --m=<m> --directed=<directed> --loops=<loops>\n", basename(argv[0]));
 
4359
  exit(1);
 
4360
}
 
4361
 
 
4362
int shell_igraph_erdos_renyi_game_gnm(int argc, char **argv) {
 
4363
 
 
4364
  igraph_t graph;
 
4365
  igraph_integer_t n;
 
4366
  igraph_real_t m;
 
4367
  igraph_bool_t directed=0;
 
4368
  igraph_bool_t loops=0;
 
4369
  char* shell_arg_graph=0;
 
4370
  int shell_result;
 
4371
 
 
4372
 
 
4373
  int shell_seen[5];
 
4374
  int shell_index=-1;
 
4375
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4376
                                   { "n",required_argument,0,1 },
 
4377
                                   { "m",required_argument,0,2 },
 
4378
                                   { "directed",required_argument,0,3 },
 
4379
                                   { "loops",required_argument,0,4 },
 
4380
                                   { "help",no_argument,0,5 },
 
4381
                                   { 0,0,0,0 }
 
4382
                                 };
 
4383
 
 
4384
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4385
  memset(shell_seen, 0, 5*sizeof(int));
 
4386
  shell_seen[3]=2;
 
4387
  shell_seen[4]=2;
 
4388
  
 
4389
  /* Parse arguments and read input */
 
4390
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4391
 
 
4392
    if (shell_index==-1) {
 
4393
      exit(1);
 
4394
    }
 
4395
 
 
4396
    if (shell_seen[shell_index]==1) {
 
4397
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4398
              shell_options[shell_index].name);
 
4399
      exit(1);
 
4400
    }
 
4401
    shell_seen[shell_index]=1;  
 
4402
 
 
4403
    switch (shell_index) {
 
4404
    case 0: /* graph */
 
4405
      shell_arg_graph=strdup(optarg);
 
4406
      break;
 
4407
    case 1: /* n */
 
4408
      shell_read_integer(&n, optarg);
 
4409
      break;
 
4410
    case 2: /* m */
 
4411
      shell_read_real(&m, optarg);
 
4412
      break;
 
4413
    case 3: /* directed */
 
4414
      shell_read_boolean(&directed, optarg);
 
4415
      break;
 
4416
    case 4: /* loops */
 
4417
      shell_read_boolean(&loops, optarg);
 
4418
      break;
 
4419
    case 5:
 
4420
      shell_igraph_erdos_renyi_game_gnm_usage(argv);
 
4421
      break;
 
4422
    default:
 
4423
      break;
 
4424
    }
 
4425
 
 
4426
    shell_index=-1;
 
4427
  }
 
4428
 
 
4429
  /* Check that we have all arguments */
 
4430
  for (shell_index=0; shell_index<5; shell_index++) {
 
4431
    if (!shell_seen[shell_index]) {
 
4432
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4433
              shell_options[shell_index].name);
 
4434
      exit(1);
 
4435
    }
 
4436
  }
 
4437
 
 
4438
  /* Do the operation */
 
4439
  shell_result=igraph_erdos_renyi_game_gnm(&graph, n, m, directed, loops);
 
4440
 
 
4441
  /* Write the result */
 
4442
  shell_write_graph(&graph, shell_arg_graph); 
 
4443
  igraph_destroy(&graph);
 
4444
 
 
4445
  return 0;
 
4446
}
 
4447
 
 
4448
/*-------------------------------------------/
 
4449
/ igraph_degree_sequence_game                /
 
4450
/-------------------------------------------*/
 
4451
void shell_igraph_degree_sequence_game_usage(char **argv) {
 
4452
  printf("%s --graph=<graph> --out_deg=<out_deg> --in_deg=<in_deg> --method=<method>\n", basename(argv[0]));
 
4453
  exit(1);
 
4454
}
 
4455
 
 
4456
int shell_igraph_degree_sequence_game(int argc, char **argv) {
 
4457
 
 
4458
  igraph_t graph;
 
4459
  igraph_vector_t out_deg;
 
4460
  igraph_vector_t v_in_deg; igraph_vector_t *in_deg=0;
 
4461
  igraph_degseq_t method=IGRAPH_DEGSEQ_SIMPLE;
 
4462
  char* shell_arg_graph=0;
 
4463
  int shell_result;
 
4464
 
 
4465
 
 
4466
  int shell_seen[4];
 
4467
  int shell_index=-1;
 
4468
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4469
                                   { "out_deg",required_argument,0,1 },
 
4470
                                   { "in_deg",required_argument,0,2 },
 
4471
                                   { "method",required_argument,0,3 },
 
4472
                                   { "help",no_argument,0,4 },
 
4473
                                   { 0,0,0,0 }
 
4474
                                 };
 
4475
 
 
4476
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4477
  memset(shell_seen, 0, 4*sizeof(int));
 
4478
  shell_seen[3]=2;
 
4479
  
 
4480
  /* Parse arguments and read input */
 
4481
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4482
 
 
4483
    if (shell_index==-1) {
 
4484
      exit(1);
 
4485
    }
 
4486
 
 
4487
    if (shell_seen[shell_index]==1) {
 
4488
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4489
              shell_options[shell_index].name);
 
4490
      exit(1);
 
4491
    }
 
4492
    shell_seen[shell_index]=1;  
 
4493
 
 
4494
    switch (shell_index) {
 
4495
    case 0: /* graph */
 
4496
      shell_arg_graph=strdup(optarg);
 
4497
      break;
 
4498
    case 1: /* out_deg */
 
4499
      shell_read_vector(&out_deg, optarg);
 
4500
      break;
 
4501
    case 2: /* in_deg */
 
4502
      in_deg=&v_in_deg; shell_read_vector(in_deg, optarg);
 
4503
      break;
 
4504
    case 3: /* method */
 
4505
      shell_read_enum(&method, optarg, "simple", 0, 0);
 
4506
      break;
 
4507
    case 4:
 
4508
      shell_igraph_degree_sequence_game_usage(argv);
 
4509
      break;
 
4510
    default:
 
4511
      break;
 
4512
    }
 
4513
 
 
4514
    shell_index=-1;
 
4515
  }
 
4516
 
 
4517
  /* Check that we have all arguments */
 
4518
  for (shell_index=0; shell_index<4; shell_index++) {
 
4519
    if (!shell_seen[shell_index]) {
 
4520
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4521
              shell_options[shell_index].name);
 
4522
      exit(1);
 
4523
    }
 
4524
  }
 
4525
 
 
4526
  /* Do the operation */
 
4527
  shell_result=igraph_degree_sequence_game(&graph, &out_deg, in_deg, method);
 
4528
 
 
4529
  /* Write the result */
 
4530
  shell_write_graph(&graph, shell_arg_graph); 
 
4531
  igraph_destroy(&graph);
 
4532
  igraph_vector_destroy(&out_deg);
 
4533
  if (in_deg) { igraph_vector_destroy(in_deg); }
 
4534
 
 
4535
  return 0;
 
4536
}
 
4537
 
 
4538
/*-------------------------------------------/
 
4539
/ igraph_growing_random_game                 /
 
4540
/-------------------------------------------*/
 
4541
void shell_igraph_growing_random_game_usage(char **argv) {
 
4542
  printf("%s --graph=<graph> --n=<n> --m=<m> --directed=<directed> --citation=<citation>\n", basename(argv[0]));
 
4543
  exit(1);
 
4544
}
 
4545
 
 
4546
int shell_igraph_growing_random_game(int argc, char **argv) {
 
4547
 
 
4548
  igraph_t graph;
 
4549
  igraph_integer_t n;
 
4550
  igraph_integer_t m=1;
 
4551
  igraph_bool_t directed=0;
 
4552
  igraph_bool_t citation=0;
 
4553
  char* shell_arg_graph=0;
 
4554
  int shell_result;
 
4555
 
 
4556
 
 
4557
  int shell_seen[5];
 
4558
  int shell_index=-1;
 
4559
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4560
                                   { "n",required_argument,0,1 },
 
4561
                                   { "m",required_argument,0,2 },
 
4562
                                   { "directed",required_argument,0,3 },
 
4563
                                   { "citation",required_argument,0,4 },
 
4564
                                   { "help",no_argument,0,5 },
 
4565
                                   { 0,0,0,0 }
 
4566
                                 };
 
4567
 
 
4568
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4569
  memset(shell_seen, 0, 5*sizeof(int));
 
4570
  shell_seen[2]=2;
 
4571
  shell_seen[3]=2;
 
4572
  shell_seen[4]=2;
 
4573
  
 
4574
  /* Parse arguments and read input */
 
4575
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4576
 
 
4577
    if (shell_index==-1) {
 
4578
      exit(1);
 
4579
    }
 
4580
 
 
4581
    if (shell_seen[shell_index]==1) {
 
4582
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4583
              shell_options[shell_index].name);
 
4584
      exit(1);
 
4585
    }
 
4586
    shell_seen[shell_index]=1;  
 
4587
 
 
4588
    switch (shell_index) {
 
4589
    case 0: /* graph */
 
4590
      shell_arg_graph=strdup(optarg);
 
4591
      break;
 
4592
    case 1: /* n */
 
4593
      shell_read_integer(&n, optarg);
 
4594
      break;
 
4595
    case 2: /* m */
 
4596
      shell_read_integer(&m, optarg);
 
4597
      break;
 
4598
    case 3: /* directed */
 
4599
      shell_read_boolean(&directed, optarg);
 
4600
      break;
 
4601
    case 4: /* citation */
 
4602
      shell_read_boolean(&citation, optarg);
 
4603
      break;
 
4604
    case 5:
 
4605
      shell_igraph_growing_random_game_usage(argv);
 
4606
      break;
 
4607
    default:
 
4608
      break;
 
4609
    }
 
4610
 
 
4611
    shell_index=-1;
 
4612
  }
 
4613
 
 
4614
  /* Check that we have all arguments */
 
4615
  for (shell_index=0; shell_index<5; shell_index++) {
 
4616
    if (!shell_seen[shell_index]) {
 
4617
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4618
              shell_options[shell_index].name);
 
4619
      exit(1);
 
4620
    }
 
4621
  }
 
4622
 
 
4623
  /* Do the operation */
 
4624
  shell_result=igraph_growing_random_game(&graph, n, m, directed, citation);
 
4625
 
 
4626
  /* Write the result */
 
4627
  shell_write_graph(&graph, shell_arg_graph); 
 
4628
  igraph_destroy(&graph);
 
4629
 
 
4630
  return 0;
 
4631
}
 
4632
 
 
4633
/*-------------------------------------------/
 
4634
/ igraph_barabasi_aging_game                 /
 
4635
/-------------------------------------------*/
 
4636
void shell_igraph_barabasi_aging_game_usage(char **argv) {
 
4637
  printf("%s --graph=<graph> --nodes=<nodes> --m=<m> --outseq=<outseq> --outpref=<outpref> --pa_exp=<pa_exp> --aging_exp=<aging_exp> --aging_bin=<aging_bin> --zero_deg_appeal=<zero_deg_appeal> --zero_age_appeal=<zero_age_appeal> --deg_coef=<deg_coef> --age_coef=<age_coef> --directed=<directed>\n", basename(argv[0]));
 
4638
  exit(1);
 
4639
}
 
4640
 
 
4641
int shell_igraph_barabasi_aging_game(int argc, char **argv) {
 
4642
 
 
4643
  igraph_t graph;
 
4644
  igraph_integer_t nodes;
 
4645
  igraph_integer_t m=1;
 
4646
  igraph_vector_t v_outseq; igraph_vector_t *outseq=0;
 
4647
  igraph_bool_t outpref=0;
 
4648
  igraph_real_t pa_exp=1.0;
 
4649
  igraph_real_t aging_exp=0.0;
 
4650
  igraph_integer_t aging_bin=1;
 
4651
  igraph_real_t zero_deg_appeal=1.0;
 
4652
  igraph_real_t zero_age_appeal=0.0;
 
4653
  igraph_real_t deg_coef=1.0;
 
4654
  igraph_real_t age_coef=1.0;
 
4655
  igraph_bool_t directed=1;
 
4656
  char* shell_arg_graph=0;
 
4657
  int shell_result;
 
4658
 
 
4659
 
 
4660
  int shell_seen[13];
 
4661
  int shell_index=-1;
 
4662
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4663
                                   { "nodes",required_argument,0,1 },
 
4664
                                   { "m",required_argument,0,2 },
 
4665
                                   { "outseq",required_argument,0,3 },
 
4666
                                   { "outpref",required_argument,0,4 },
 
4667
                                   { "pa_exp",required_argument,0,5 },
 
4668
                                   { "aging_exp",required_argument,0,6 },
 
4669
                                   { "aging_bin",required_argument,0,7 },
 
4670
                                   { "zero_deg_appeal",required_argument,0,8 },
 
4671
                                   { "zero_age_appeal",required_argument,0,9 },
 
4672
                                   { "deg_coef",required_argument,0,10 },
 
4673
                                   { "age_coef",required_argument,0,11 },
 
4674
                                   { "directed",required_argument,0,12 },
 
4675
                                   { "help",no_argument,0,13 },
 
4676
                                   { 0,0,0,0 }
 
4677
                                 };
 
4678
 
 
4679
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4680
  memset(shell_seen, 0, 13*sizeof(int));
 
4681
  shell_seen[2]=2;
 
4682
  shell_seen[4]=2;
 
4683
  shell_seen[5]=2;
 
4684
  shell_seen[6]=2;
 
4685
  shell_seen[7]=2;
 
4686
  shell_seen[8]=2;
 
4687
  shell_seen[9]=2;
 
4688
  shell_seen[10]=2;
 
4689
  shell_seen[11]=2;
 
4690
  shell_seen[12]=2;
 
4691
  
 
4692
  /* Parse arguments and read input */
 
4693
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4694
 
 
4695
    if (shell_index==-1) {
 
4696
      exit(1);
 
4697
    }
 
4698
 
 
4699
    if (shell_seen[shell_index]==1) {
 
4700
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4701
              shell_options[shell_index].name);
 
4702
      exit(1);
 
4703
    }
 
4704
    shell_seen[shell_index]=1;  
 
4705
 
 
4706
    switch (shell_index) {
 
4707
    case 0: /* graph */
 
4708
      shell_arg_graph=strdup(optarg);
 
4709
      break;
 
4710
    case 1: /* nodes */
 
4711
      shell_read_integer(&nodes, optarg);
 
4712
      break;
 
4713
    case 2: /* m */
 
4714
      shell_read_integer(&m, optarg);
 
4715
      break;
 
4716
    case 3: /* outseq */
 
4717
      outseq=&v_outseq; shell_read_vector(outseq, optarg);
 
4718
      break;
 
4719
    case 4: /* outpref */
 
4720
      shell_read_boolean(&outpref, optarg);
 
4721
      break;
 
4722
    case 5: /* pa_exp */
 
4723
      shell_read_real(&pa_exp, optarg);
 
4724
      break;
 
4725
    case 6: /* aging_exp */
 
4726
      shell_read_real(&aging_exp, optarg);
 
4727
      break;
 
4728
    case 7: /* aging_bin */
 
4729
      shell_read_integer(&aging_bin, optarg);
 
4730
      break;
 
4731
    case 8: /* zero_deg_appeal */
 
4732
      shell_read_real(&zero_deg_appeal, optarg);
 
4733
      break;
 
4734
    case 9: /* zero_age_appeal */
 
4735
      shell_read_real(&zero_age_appeal, optarg);
 
4736
      break;
 
4737
    case 10: /* deg_coef */
 
4738
      shell_read_real(&deg_coef, optarg);
 
4739
      break;
 
4740
    case 11: /* age_coef */
 
4741
      shell_read_real(&age_coef, optarg);
 
4742
      break;
 
4743
    case 12: /* directed */
 
4744
      shell_read_boolean(&directed, optarg);
 
4745
      break;
 
4746
    case 13:
 
4747
      shell_igraph_barabasi_aging_game_usage(argv);
 
4748
      break;
 
4749
    default:
 
4750
      break;
 
4751
    }
 
4752
 
 
4753
    shell_index=-1;
 
4754
  }
 
4755
 
 
4756
  /* Check that we have all arguments */
 
4757
  for (shell_index=0; shell_index<13; shell_index++) {
 
4758
    if (!shell_seen[shell_index]) {
 
4759
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4760
              shell_options[shell_index].name);
 
4761
      exit(1);
 
4762
    }
 
4763
  }
 
4764
 
 
4765
  /* Do the operation */
 
4766
  shell_result=igraph_barabasi_aging_game(&graph, nodes, m, outseq, outpref, pa_exp, aging_exp, aging_bin, zero_deg_appeal, zero_age_appeal, deg_coef, age_coef, directed);
 
4767
 
 
4768
  /* Write the result */
 
4769
  shell_write_graph(&graph, shell_arg_graph); 
 
4770
  igraph_destroy(&graph);
 
4771
  if (outseq) { igraph_vector_destroy(outseq); }
 
4772
 
 
4773
  return 0;
 
4774
}
 
4775
 
 
4776
/*-------------------------------------------/
 
4777
/ igraph_recent_degree_game                  /
 
4778
/-------------------------------------------*/
 
4779
void shell_igraph_recent_degree_game_usage(char **argv) {
 
4780
  printf("%s --graph=<graph> --n=<n> --power=<power> --window=<window> --m=<m> --outseq=<outseq> --outpref=<outpref> --zero_appeal=<zero_appeal> --directed=<directed>\n", basename(argv[0]));
 
4781
  exit(1);
 
4782
}
 
4783
 
 
4784
int shell_igraph_recent_degree_game(int argc, char **argv) {
 
4785
 
 
4786
  igraph_t graph;
 
4787
  igraph_integer_t n;
 
4788
  igraph_real_t power=1.0;
 
4789
  igraph_integer_t window=1;
 
4790
  igraph_integer_t m=1;
 
4791
  igraph_vector_t v_outseq; igraph_vector_t *outseq=0;
 
4792
  igraph_bool_t outpref=0;
 
4793
  igraph_real_t zero_appeal=1.0;
 
4794
  igraph_bool_t directed=1;
 
4795
  char* shell_arg_graph=0;
 
4796
  int shell_result;
 
4797
 
 
4798
 
 
4799
  int shell_seen[9];
 
4800
  int shell_index=-1;
 
4801
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4802
                                   { "n",required_argument,0,1 },
 
4803
                                   { "power",required_argument,0,2 },
 
4804
                                   { "window",required_argument,0,3 },
 
4805
                                   { "m",required_argument,0,4 },
 
4806
                                   { "outseq",required_argument,0,5 },
 
4807
                                   { "outpref",required_argument,0,6 },
 
4808
                                   { "zero_appeal",required_argument,0,7 },
 
4809
                                   { "directed",required_argument,0,8 },
 
4810
                                   { "help",no_argument,0,9 },
 
4811
                                   { 0,0,0,0 }
 
4812
                                 };
 
4813
 
 
4814
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4815
  memset(shell_seen, 0, 9*sizeof(int));
 
4816
  shell_seen[2]=2;
 
4817
  shell_seen[3]=2;
 
4818
  shell_seen[4]=2;
 
4819
  shell_seen[6]=2;
 
4820
  shell_seen[7]=2;
 
4821
  shell_seen[8]=2;
 
4822
  
 
4823
  /* Parse arguments and read input */
 
4824
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4825
 
 
4826
    if (shell_index==-1) {
 
4827
      exit(1);
 
4828
    }
 
4829
 
 
4830
    if (shell_seen[shell_index]==1) {
 
4831
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4832
              shell_options[shell_index].name);
 
4833
      exit(1);
 
4834
    }
 
4835
    shell_seen[shell_index]=1;  
 
4836
 
 
4837
    switch (shell_index) {
 
4838
    case 0: /* graph */
 
4839
      shell_arg_graph=strdup(optarg);
 
4840
      break;
 
4841
    case 1: /* n */
 
4842
      shell_read_integer(&n, optarg);
 
4843
      break;
 
4844
    case 2: /* power */
 
4845
      shell_read_real(&power, optarg);
 
4846
      break;
 
4847
    case 3: /* window */
 
4848
      shell_read_integer(&window, optarg);
 
4849
      break;
 
4850
    case 4: /* m */
 
4851
      shell_read_integer(&m, optarg);
 
4852
      break;
 
4853
    case 5: /* outseq */
 
4854
      outseq=&v_outseq; shell_read_vector(outseq, optarg);
 
4855
      break;
 
4856
    case 6: /* outpref */
 
4857
      shell_read_boolean(&outpref, optarg);
 
4858
      break;
 
4859
    case 7: /* zero_appeal */
 
4860
      shell_read_real(&zero_appeal, optarg);
 
4861
      break;
 
4862
    case 8: /* directed */
 
4863
      shell_read_boolean(&directed, optarg);
 
4864
      break;
 
4865
    case 9:
 
4866
      shell_igraph_recent_degree_game_usage(argv);
 
4867
      break;
 
4868
    default:
 
4869
      break;
 
4870
    }
 
4871
 
 
4872
    shell_index=-1;
 
4873
  }
 
4874
 
 
4875
  /* Check that we have all arguments */
 
4876
  for (shell_index=0; shell_index<9; shell_index++) {
 
4877
    if (!shell_seen[shell_index]) {
 
4878
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
4879
              shell_options[shell_index].name);
 
4880
      exit(1);
 
4881
    }
 
4882
  }
 
4883
 
 
4884
  /* Do the operation */
 
4885
  shell_result=igraph_recent_degree_game(&graph, n, power, window, m, outseq, outpref, zero_appeal, directed);
 
4886
 
 
4887
  /* Write the result */
 
4888
  shell_write_graph(&graph, shell_arg_graph); 
 
4889
  igraph_destroy(&graph);
 
4890
  if (outseq) { igraph_vector_destroy(outseq); }
 
4891
 
 
4892
  return 0;
 
4893
}
 
4894
 
 
4895
/*-------------------------------------------/
 
4896
/ igraph_recent_degree_aging_game            /
 
4897
/-------------------------------------------*/
 
4898
void shell_igraph_recent_degree_aging_game_usage(char **argv) {
 
4899
  printf("%s --graph=<graph> --nodes=<nodes> --m=<m> --outseq=<outseq> --outpref=<outpref> --pa_exp=<pa_exp> --aging_exp=<aging_exp> --aging_bin=<aging_bin> --window=<window> --zero_appeal=<zero_appeal> --directed=<directed>\n", basename(argv[0]));
 
4900
  exit(1);
 
4901
}
 
4902
 
 
4903
int shell_igraph_recent_degree_aging_game(int argc, char **argv) {
 
4904
 
 
4905
  igraph_t graph;
 
4906
  igraph_integer_t nodes;
 
4907
  igraph_integer_t m=1;
 
4908
  igraph_vector_t v_outseq; igraph_vector_t *outseq=0;
 
4909
  igraph_bool_t outpref=0;
 
4910
  igraph_real_t pa_exp=1.0;
 
4911
  igraph_real_t aging_exp=0.0;
 
4912
  igraph_integer_t aging_bin=1;
 
4913
  igraph_integer_t window=1;
 
4914
  igraph_real_t zero_appeal=1.0;
 
4915
  igraph_bool_t directed=1;
 
4916
  char* shell_arg_graph=0;
 
4917
  int shell_result;
 
4918
 
 
4919
 
 
4920
  int shell_seen[11];
 
4921
  int shell_index=-1;
 
4922
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
4923
                                   { "nodes",required_argument,0,1 },
 
4924
                                   { "m",required_argument,0,2 },
 
4925
                                   { "outseq",required_argument,0,3 },
 
4926
                                   { "outpref",required_argument,0,4 },
 
4927
                                   { "pa_exp",required_argument,0,5 },
 
4928
                                   { "aging_exp",required_argument,0,6 },
 
4929
                                   { "aging_bin",required_argument,0,7 },
 
4930
                                   { "window",required_argument,0,8 },
 
4931
                                   { "zero_appeal",required_argument,0,9 },
 
4932
                                   { "directed",required_argument,0,10 },
 
4933
                                   { "help",no_argument,0,11 },
 
4934
                                   { 0,0,0,0 }
 
4935
                                 };
 
4936
 
 
4937
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
4938
  memset(shell_seen, 0, 11*sizeof(int));
 
4939
  shell_seen[2]=2;
 
4940
  shell_seen[4]=2;
 
4941
  shell_seen[5]=2;
 
4942
  shell_seen[6]=2;
 
4943
  shell_seen[7]=2;
 
4944
  shell_seen[8]=2;
 
4945
  shell_seen[9]=2;
 
4946
  shell_seen[10]=2;
 
4947
  
 
4948
  /* Parse arguments and read input */
 
4949
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
4950
 
 
4951
    if (shell_index==-1) {
 
4952
      exit(1);
 
4953
    }
 
4954
 
 
4955
    if (shell_seen[shell_index]==1) {
 
4956
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
4957
              shell_options[shell_index].name);
 
4958
      exit(1);
 
4959
    }
 
4960
    shell_seen[shell_index]=1;  
 
4961
 
 
4962
    switch (shell_index) {
 
4963
    case 0: /* graph */
 
4964
      shell_arg_graph=strdup(optarg);
 
4965
      break;
 
4966
    case 1: /* nodes */
 
4967
      shell_read_integer(&nodes, optarg);
 
4968
      break;
 
4969
    case 2: /* m */
 
4970
      shell_read_integer(&m, optarg);
 
4971
      break;
 
4972
    case 3: /* outseq */
 
4973
      outseq=&v_outseq; shell_read_vector(outseq, optarg);
 
4974
      break;
 
4975
    case 4: /* outpref */
 
4976
      shell_read_boolean(&outpref, optarg);
 
4977
      break;
 
4978
    case 5: /* pa_exp */
 
4979
      shell_read_real(&pa_exp, optarg);
 
4980
      break;
 
4981
    case 6: /* aging_exp */
 
4982
      shell_read_real(&aging_exp, optarg);
 
4983
      break;
 
4984
    case 7: /* aging_bin */
 
4985
      shell_read_integer(&aging_bin, optarg);
 
4986
      break;
 
4987
    case 8: /* window */
 
4988
      shell_read_integer(&window, optarg);
 
4989
      break;
 
4990
    case 9: /* zero_appeal */
 
4991
      shell_read_real(&zero_appeal, optarg);
 
4992
      break;
 
4993
    case 10: /* directed */
 
4994
      shell_read_boolean(&directed, optarg);
 
4995
      break;
 
4996
    case 11:
 
4997
      shell_igraph_recent_degree_aging_game_usage(argv);
 
4998
      break;
 
4999
    default:
 
5000
      break;
 
5001
    }
 
5002
 
 
5003
    shell_index=-1;
 
5004
  }
 
5005
 
 
5006
  /* Check that we have all arguments */
 
5007
  for (shell_index=0; shell_index<11; shell_index++) {
 
5008
    if (!shell_seen[shell_index]) {
 
5009
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5010
              shell_options[shell_index].name);
 
5011
      exit(1);
 
5012
    }
 
5013
  }
 
5014
 
 
5015
  /* Do the operation */
 
5016
  shell_result=igraph_recent_degree_aging_game(&graph, nodes, m, outseq, outpref, pa_exp, aging_exp, aging_bin, window, zero_appeal, directed);
 
5017
 
 
5018
  /* Write the result */
 
5019
  shell_write_graph(&graph, shell_arg_graph); 
 
5020
  igraph_destroy(&graph);
 
5021
  if (outseq) { igraph_vector_destroy(outseq); }
 
5022
 
 
5023
  return 0;
 
5024
}
 
5025
 
 
5026
/*-------------------------------------------/
 
5027
/ igraph_callaway_traits_game                /
 
5028
/-------------------------------------------*/
 
5029
void shell_igraph_callaway_traits_game_usage(char **argv) {
 
5030
  printf("%s --graph=<graph> --nodes=<nodes> --types=<types> --edges_per_step=<edges_per_step> --type_dist=<type_dist> --pref_matrix=<pref_matrix> --directed=<directed>\n", basename(argv[0]));
 
5031
  exit(1);
 
5032
}
 
5033
 
 
5034
int shell_igraph_callaway_traits_game(int argc, char **argv) {
 
5035
 
 
5036
  igraph_t graph;
 
5037
  igraph_integer_t nodes;
 
5038
  igraph_integer_t types;
 
5039
  igraph_integer_t edges_per_step=1;
 
5040
  igraph_vector_t type_dist;
 
5041
  igraph_matrix_t pref_matrix;
 
5042
  igraph_bool_t directed=0;
 
5043
  char* shell_arg_graph=0;
 
5044
  int shell_result;
 
5045
 
 
5046
 
 
5047
  int shell_seen[7];
 
5048
  int shell_index=-1;
 
5049
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5050
                                   { "nodes",required_argument,0,1 },
 
5051
                                   { "types",required_argument,0,2 },
 
5052
                                   { "edges_per_step",required_argument,0,3 },
 
5053
                                   { "type_dist",required_argument,0,4 },
 
5054
                                   { "pref_matrix",required_argument,0,5 },
 
5055
                                   { "directed",required_argument,0,6 },
 
5056
                                   { "help",no_argument,0,7 },
 
5057
                                   { 0,0,0,0 }
 
5058
                                 };
 
5059
 
 
5060
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5061
  memset(shell_seen, 0, 7*sizeof(int));
 
5062
  shell_seen[3]=2;
 
5063
  shell_seen[6]=2;
 
5064
  
 
5065
  /* Parse arguments and read input */
 
5066
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5067
 
 
5068
    if (shell_index==-1) {
 
5069
      exit(1);
 
5070
    }
 
5071
 
 
5072
    if (shell_seen[shell_index]==1) {
 
5073
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5074
              shell_options[shell_index].name);
 
5075
      exit(1);
 
5076
    }
 
5077
    shell_seen[shell_index]=1;  
 
5078
 
 
5079
    switch (shell_index) {
 
5080
    case 0: /* graph */
 
5081
      shell_arg_graph=strdup(optarg);
 
5082
      break;
 
5083
    case 1: /* nodes */
 
5084
      shell_read_integer(&nodes, optarg);
 
5085
      break;
 
5086
    case 2: /* types */
 
5087
      shell_read_integer(&types, optarg);
 
5088
      break;
 
5089
    case 3: /* edges_per_step */
 
5090
      shell_read_integer(&edges_per_step, optarg);
 
5091
      break;
 
5092
    case 4: /* type_dist */
 
5093
      shell_read_vector(&type_dist, optarg);
 
5094
      break;
 
5095
    case 5: /* pref_matrix */
 
5096
      shell_read_matrix(&pref_matrix, optarg);
 
5097
      break;
 
5098
    case 6: /* directed */
 
5099
      shell_read_boolean(&directed, optarg);
 
5100
      break;
 
5101
    case 7:
 
5102
      shell_igraph_callaway_traits_game_usage(argv);
 
5103
      break;
 
5104
    default:
 
5105
      break;
 
5106
    }
 
5107
 
 
5108
    shell_index=-1;
 
5109
  }
 
5110
 
 
5111
  /* Check that we have all arguments */
 
5112
  for (shell_index=0; shell_index<7; shell_index++) {
 
5113
    if (!shell_seen[shell_index]) {
 
5114
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5115
              shell_options[shell_index].name);
 
5116
      exit(1);
 
5117
    }
 
5118
  }
 
5119
 
 
5120
  /* Do the operation */
 
5121
  shell_result=igraph_callaway_traits_game(&graph, nodes, types, edges_per_step, &type_dist, &pref_matrix, directed);
 
5122
 
 
5123
  /* Write the result */
 
5124
  shell_write_graph(&graph, shell_arg_graph); 
 
5125
  igraph_destroy(&graph);
 
5126
  igraph_vector_destroy(&type_dist);
 
5127
  igraph_matrix_destroy(&pref_matrix);
 
5128
 
 
5129
  return 0;
 
5130
}
 
5131
 
 
5132
/*-------------------------------------------/
 
5133
/ igraph_establishment_game                  /
 
5134
/-------------------------------------------*/
 
5135
void shell_igraph_establishment_game_usage(char **argv) {
 
5136
  printf("%s --graph=<graph> --nodes=<nodes> --types=<types> --k=<k> --type_dist=<type_dist> --pref_matrix=<pref_matrix> --directed=<directed>\n", basename(argv[0]));
 
5137
  exit(1);
 
5138
}
 
5139
 
 
5140
int shell_igraph_establishment_game(int argc, char **argv) {
 
5141
 
 
5142
  igraph_t graph;
 
5143
  igraph_integer_t nodes;
 
5144
  igraph_integer_t types;
 
5145
  igraph_integer_t k=1;
 
5146
  igraph_vector_t type_dist;
 
5147
  igraph_matrix_t pref_matrix;
 
5148
  igraph_bool_t directed=1;
 
5149
  char* shell_arg_graph=0;
 
5150
  int shell_result;
 
5151
 
 
5152
 
 
5153
  int shell_seen[7];
 
5154
  int shell_index=-1;
 
5155
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5156
                                   { "nodes",required_argument,0,1 },
 
5157
                                   { "types",required_argument,0,2 },
 
5158
                                   { "k",required_argument,0,3 },
 
5159
                                   { "type_dist",required_argument,0,4 },
 
5160
                                   { "pref_matrix",required_argument,0,5 },
 
5161
                                   { "directed",required_argument,0,6 },
 
5162
                                   { "help",no_argument,0,7 },
 
5163
                                   { 0,0,0,0 }
 
5164
                                 };
 
5165
 
 
5166
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5167
  memset(shell_seen, 0, 7*sizeof(int));
 
5168
  shell_seen[3]=2;
 
5169
  shell_seen[6]=2;
 
5170
  
 
5171
  /* Parse arguments and read input */
 
5172
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5173
 
 
5174
    if (shell_index==-1) {
 
5175
      exit(1);
 
5176
    }
 
5177
 
 
5178
    if (shell_seen[shell_index]==1) {
 
5179
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5180
              shell_options[shell_index].name);
 
5181
      exit(1);
 
5182
    }
 
5183
    shell_seen[shell_index]=1;  
 
5184
 
 
5185
    switch (shell_index) {
 
5186
    case 0: /* graph */
 
5187
      shell_arg_graph=strdup(optarg);
 
5188
      break;
 
5189
    case 1: /* nodes */
 
5190
      shell_read_integer(&nodes, optarg);
 
5191
      break;
 
5192
    case 2: /* types */
 
5193
      shell_read_integer(&types, optarg);
 
5194
      break;
 
5195
    case 3: /* k */
 
5196
      shell_read_integer(&k, optarg);
 
5197
      break;
 
5198
    case 4: /* type_dist */
 
5199
      shell_read_vector(&type_dist, optarg);
 
5200
      break;
 
5201
    case 5: /* pref_matrix */
 
5202
      shell_read_matrix(&pref_matrix, optarg);
 
5203
      break;
 
5204
    case 6: /* directed */
 
5205
      shell_read_boolean(&directed, optarg);
 
5206
      break;
 
5207
    case 7:
 
5208
      shell_igraph_establishment_game_usage(argv);
 
5209
      break;
 
5210
    default:
 
5211
      break;
 
5212
    }
 
5213
 
 
5214
    shell_index=-1;
 
5215
  }
 
5216
 
 
5217
  /* Check that we have all arguments */
 
5218
  for (shell_index=0; shell_index<7; shell_index++) {
 
5219
    if (!shell_seen[shell_index]) {
 
5220
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5221
              shell_options[shell_index].name);
 
5222
      exit(1);
 
5223
    }
 
5224
  }
 
5225
 
 
5226
  /* Do the operation */
 
5227
  shell_result=igraph_establishment_game(&graph, nodes, types, k, &type_dist, &pref_matrix, directed);
 
5228
 
 
5229
  /* Write the result */
 
5230
  shell_write_graph(&graph, shell_arg_graph); 
 
5231
  igraph_destroy(&graph);
 
5232
  igraph_vector_destroy(&type_dist);
 
5233
  igraph_matrix_destroy(&pref_matrix);
 
5234
 
 
5235
  return 0;
 
5236
}
 
5237
 
 
5238
/*-------------------------------------------/
 
5239
/ igraph_grg_game                            /
 
5240
/-------------------------------------------*/
 
5241
void shell_igraph_grg_game_usage(char **argv) {
 
5242
  printf("%s --graph=<graph> --nodes=<nodes> --radius=<radius> --torus=<torus> --x=<x> --y=<y>\n", basename(argv[0]));
 
5243
  exit(1);
 
5244
}
 
5245
 
 
5246
int shell_igraph_grg_game(int argc, char **argv) {
 
5247
 
 
5248
  igraph_t graph;
 
5249
  igraph_integer_t nodes;
 
5250
  igraph_real_t radius;
 
5251
  igraph_bool_t torus=0;
 
5252
  igraph_vector_t v_x; igraph_vector_t *x=0;
 
5253
  igraph_vector_t v_y; igraph_vector_t *y=0;
 
5254
  char* shell_arg_graph=0;
 
5255
  int shell_result;
 
5256
 
 
5257
 
 
5258
  int shell_seen[6];
 
5259
  int shell_index=-1;
 
5260
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5261
                                   { "nodes",required_argument,0,1 },
 
5262
                                   { "radius",required_argument,0,2 },
 
5263
                                   { "torus",required_argument,0,3 },
 
5264
                                   { "x",required_argument,0,4 },
 
5265
                                   { "y",required_argument,0,5 },
 
5266
                                   { "help",no_argument,0,6 },
 
5267
                                   { 0,0,0,0 }
 
5268
                                 };
 
5269
 
 
5270
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5271
  memset(shell_seen, 0, 6*sizeof(int));
 
5272
  shell_seen[3]=2;
 
5273
  
 
5274
  /* Parse arguments and read input */
 
5275
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5276
 
 
5277
    if (shell_index==-1) {
 
5278
      exit(1);
 
5279
    }
 
5280
 
 
5281
    if (shell_seen[shell_index]==1) {
 
5282
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5283
              shell_options[shell_index].name);
 
5284
      exit(1);
 
5285
    }
 
5286
    shell_seen[shell_index]=1;  
 
5287
 
 
5288
    switch (shell_index) {
 
5289
    case 0: /* graph */
 
5290
      shell_arg_graph=strdup(optarg);
 
5291
      break;
 
5292
    case 1: /* nodes */
 
5293
      shell_read_integer(&nodes, optarg);
 
5294
      break;
 
5295
    case 2: /* radius */
 
5296
      shell_read_real(&radius, optarg);
 
5297
      break;
 
5298
    case 3: /* torus */
 
5299
      shell_read_boolean(&torus, optarg);
 
5300
      break;
 
5301
    case 4: /* x */
 
5302
      x=&v_x; shell_read_vector(x, optarg);
 
5303
      break;
 
5304
    case 5: /* y */
 
5305
      y=&v_y; shell_read_vector(y, optarg);
 
5306
      break;
 
5307
    case 6:
 
5308
      shell_igraph_grg_game_usage(argv);
 
5309
      break;
 
5310
    default:
 
5311
      break;
 
5312
    }
 
5313
 
 
5314
    shell_index=-1;
 
5315
  }
 
5316
 
 
5317
  /* Check that we have all arguments */
 
5318
  for (shell_index=0; shell_index<6; shell_index++) {
 
5319
    if (!shell_seen[shell_index]) {
 
5320
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5321
              shell_options[shell_index].name);
 
5322
      exit(1);
 
5323
    }
 
5324
  }
 
5325
 
 
5326
  /* Do the operation */
 
5327
  shell_result=igraph_grg_game(&graph, nodes, radius, torus, x, y);
 
5328
 
 
5329
  /* Write the result */
 
5330
  shell_write_graph(&graph, shell_arg_graph); 
 
5331
  igraph_destroy(&graph);
 
5332
  if (x) { igraph_vector_destroy(x); }
 
5333
  if (y) { igraph_vector_destroy(y); }
 
5334
 
 
5335
  return 0;
 
5336
}
 
5337
 
 
5338
/*-------------------------------------------/
 
5339
/ igraph_preference_game                     /
 
5340
/-------------------------------------------*/
 
5341
void shell_igraph_preference_game_usage(char **argv) {
 
5342
  printf("%s --graph=<graph> --nodes=<nodes> --types=<types> --type_dist=<type_dist> --pref_matrix=<pref_matrix> --node_type_vec=<node_type_vec> --directed=<directed> --loops=<loops>\n", basename(argv[0]));
 
5343
  exit(1);
 
5344
}
 
5345
 
 
5346
int shell_igraph_preference_game(int argc, char **argv) {
 
5347
 
 
5348
  igraph_t graph;
 
5349
  igraph_integer_t nodes;
 
5350
  igraph_integer_t types;
 
5351
  igraph_vector_t type_dist;
 
5352
  igraph_matrix_t pref_matrix;
 
5353
  igraph_vector_t node_type_vec;
 
5354
  igraph_bool_t directed=0;
 
5355
  igraph_bool_t loops=0;
 
5356
  char* shell_arg_graph=0;
 
5357
  char* shell_arg_node_type_vec=0;
 
5358
  int shell_result;
 
5359
 
 
5360
 
 
5361
  int shell_seen[8];
 
5362
  int shell_index=-1;
 
5363
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5364
                                   { "nodes",required_argument,0,1 },
 
5365
                                   { "types",required_argument,0,2 },
 
5366
                                   { "type_dist",required_argument,0,3 },
 
5367
                                   { "pref_matrix",required_argument,0,4 },
 
5368
                                   { "node_type_vec",required_argument,0,5 },
 
5369
                                   { "directed",required_argument,0,6 },
 
5370
                                   { "loops",required_argument,0,7 },
 
5371
                                   { "help",no_argument,0,8 },
 
5372
                                   { 0,0,0,0 }
 
5373
                                 };
 
5374
 
 
5375
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5376
  memset(shell_seen, 0, 8*sizeof(int));
 
5377
  shell_seen[6]=2;
 
5378
  shell_seen[7]=2;
 
5379
  
 
5380
  /* Parse arguments and read input */
 
5381
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5382
 
 
5383
    if (shell_index==-1) {
 
5384
      exit(1);
 
5385
    }
 
5386
 
 
5387
    if (shell_seen[shell_index]==1) {
 
5388
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5389
              shell_options[shell_index].name);
 
5390
      exit(1);
 
5391
    }
 
5392
    shell_seen[shell_index]=1;  
 
5393
 
 
5394
    switch (shell_index) {
 
5395
    case 0: /* graph */
 
5396
      shell_arg_graph=strdup(optarg);
 
5397
      break;
 
5398
    case 1: /* nodes */
 
5399
      shell_read_integer(&nodes, optarg);
 
5400
      break;
 
5401
    case 2: /* types */
 
5402
      shell_read_integer(&types, optarg);
 
5403
      break;
 
5404
    case 3: /* type_dist */
 
5405
      shell_read_vector(&type_dist, optarg);
 
5406
      break;
 
5407
    case 4: /* pref_matrix */
 
5408
      shell_read_matrix(&pref_matrix, optarg);
 
5409
      break;
 
5410
    case 5: /* node_type_vec */
 
5411
      shell_arg_node_type_vec=strdup(optarg); 
 
5412
  igraph_vector_init(&node_type_vec, 0);
 
5413
      break;
 
5414
    case 6: /* directed */
 
5415
      shell_read_boolean(&directed, optarg);
 
5416
      break;
 
5417
    case 7: /* loops */
 
5418
      shell_read_boolean(&loops, optarg);
 
5419
      break;
 
5420
    case 8:
 
5421
      shell_igraph_preference_game_usage(argv);
 
5422
      break;
 
5423
    default:
 
5424
      break;
 
5425
    }
 
5426
 
 
5427
    shell_index=-1;
 
5428
  }
 
5429
 
 
5430
  /* Check that we have all arguments */
 
5431
  for (shell_index=0; shell_index<8; shell_index++) {
 
5432
    if (!shell_seen[shell_index]) {
 
5433
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5434
              shell_options[shell_index].name);
 
5435
      exit(1);
 
5436
    }
 
5437
  }
 
5438
 
 
5439
  /* Do the operation */
 
5440
  shell_result=igraph_preference_game(&graph, nodes, types, &type_dist, &pref_matrix, &node_type_vec, directed, loops);
 
5441
 
 
5442
  /* Write the result */
 
5443
  shell_write_graph(&graph, shell_arg_graph); 
 
5444
  igraph_destroy(&graph);
 
5445
  igraph_vector_destroy(&type_dist);
 
5446
  igraph_matrix_destroy(&pref_matrix);
 
5447
  shell_write_vector(&node_type_vec, shell_arg_node_type_vec); 
 
5448
  igraph_vector_destroy(&node_type_vec);
 
5449
 
 
5450
  return 0;
 
5451
}
 
5452
 
 
5453
/*-------------------------------------------/
 
5454
/ igraph_asymmetric_preference_game          /
 
5455
/-------------------------------------------*/
 
5456
void shell_igraph_asymmetric_preference_game_usage(char **argv) {
 
5457
  printf("%s --graph=<graph> --nodes=<nodes> --types=<types> --type_dist_matrix=<type_dist_matrix> --pref_matrix=<pref_matrix> --node_type_in_vec=<node_type_in_vec> --node_type_out_vec=<node_type_out_vec> --loops=<loops>\n", basename(argv[0]));
 
5458
  exit(1);
 
5459
}
 
5460
 
 
5461
int shell_igraph_asymmetric_preference_game(int argc, char **argv) {
 
5462
 
 
5463
  igraph_t graph;
 
5464
  igraph_integer_t nodes;
 
5465
  igraph_integer_t types;
 
5466
  igraph_matrix_t type_dist_matrix;
 
5467
  igraph_matrix_t pref_matrix;
 
5468
  igraph_vector_t node_type_in_vec;
 
5469
  igraph_vector_t node_type_out_vec;
 
5470
  igraph_bool_t loops=0;
 
5471
  char* shell_arg_graph=0;
 
5472
  char* shell_arg_node_type_in_vec=0;
 
5473
  char* shell_arg_node_type_out_vec=0;
 
5474
  int shell_result;
 
5475
 
 
5476
 
 
5477
  int shell_seen[8];
 
5478
  int shell_index=-1;
 
5479
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5480
                                   { "nodes",required_argument,0,1 },
 
5481
                                   { "types",required_argument,0,2 },
 
5482
                                   { "type_dist_matrix",required_argument,0,3 },
 
5483
                                   { "pref_matrix",required_argument,0,4 },
 
5484
                                   { "node_type_in_vec",required_argument,0,5 },
 
5485
                                   { "node_type_out_vec",required_argument,0,6 },
 
5486
                                   { "loops",required_argument,0,7 },
 
5487
                                   { "help",no_argument,0,8 },
 
5488
                                   { 0,0,0,0 }
 
5489
                                 };
 
5490
 
 
5491
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5492
  memset(shell_seen, 0, 8*sizeof(int));
 
5493
  shell_seen[7]=2;
 
5494
  
 
5495
  /* Parse arguments and read input */
 
5496
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5497
 
 
5498
    if (shell_index==-1) {
 
5499
      exit(1);
 
5500
    }
 
5501
 
 
5502
    if (shell_seen[shell_index]==1) {
 
5503
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5504
              shell_options[shell_index].name);
 
5505
      exit(1);
 
5506
    }
 
5507
    shell_seen[shell_index]=1;  
 
5508
 
 
5509
    switch (shell_index) {
 
5510
    case 0: /* graph */
 
5511
      shell_arg_graph=strdup(optarg);
 
5512
      break;
 
5513
    case 1: /* nodes */
 
5514
      shell_read_integer(&nodes, optarg);
 
5515
      break;
 
5516
    case 2: /* types */
 
5517
      shell_read_integer(&types, optarg);
 
5518
      break;
 
5519
    case 3: /* type_dist_matrix */
 
5520
      shell_read_matrix(&type_dist_matrix, optarg);
 
5521
      break;
 
5522
    case 4: /* pref_matrix */
 
5523
      shell_read_matrix(&pref_matrix, optarg);
 
5524
      break;
 
5525
    case 5: /* node_type_in_vec */
 
5526
      shell_arg_node_type_in_vec=strdup(optarg); 
 
5527
  igraph_vector_init(&node_type_in_vec, 0);
 
5528
      break;
 
5529
    case 6: /* node_type_out_vec */
 
5530
      shell_arg_node_type_out_vec=strdup(optarg); 
 
5531
  igraph_vector_init(&node_type_out_vec, 0);
 
5532
      break;
 
5533
    case 7: /* loops */
 
5534
      shell_read_boolean(&loops, optarg);
 
5535
      break;
 
5536
    case 8:
 
5537
      shell_igraph_asymmetric_preference_game_usage(argv);
 
5538
      break;
 
5539
    default:
 
5540
      break;
 
5541
    }
 
5542
 
 
5543
    shell_index=-1;
 
5544
  }
 
5545
 
 
5546
  /* Check that we have all arguments */
 
5547
  for (shell_index=0; shell_index<8; shell_index++) {
 
5548
    if (!shell_seen[shell_index]) {
 
5549
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5550
              shell_options[shell_index].name);
 
5551
      exit(1);
 
5552
    }
 
5553
  }
 
5554
 
 
5555
  /* Do the operation */
 
5556
  shell_result=igraph_asymmetric_preference_game(&graph, nodes, types, &type_dist_matrix, &pref_matrix, &node_type_in_vec, &node_type_out_vec, loops);
 
5557
 
 
5558
  /* Write the result */
 
5559
  shell_write_graph(&graph, shell_arg_graph); 
 
5560
  igraph_destroy(&graph);
 
5561
  igraph_matrix_destroy(&type_dist_matrix);
 
5562
  igraph_matrix_destroy(&pref_matrix);
 
5563
  shell_write_vector(&node_type_in_vec, shell_arg_node_type_in_vec); 
 
5564
  igraph_vector_destroy(&node_type_in_vec);
 
5565
  shell_write_vector(&node_type_out_vec, shell_arg_node_type_out_vec); 
 
5566
  igraph_vector_destroy(&node_type_out_vec);
 
5567
 
 
5568
  return 0;
 
5569
}
 
5570
 
 
5571
/*-------------------------------------------/
 
5572
/ igraph_rewire_edges                        /
 
5573
/-------------------------------------------*/
 
5574
void shell_igraph_rewire_edges_usage(char **argv) {
 
5575
  printf("%s --graph=<graph> --graph-out=<graph-out> --prob=<prob>\n", basename(argv[0]));
 
5576
  exit(1);
 
5577
}
 
5578
 
 
5579
int shell_igraph_rewire_edges(int argc, char **argv) {
 
5580
 
 
5581
  igraph_t graph;
 
5582
  igraph_real_t prob;
 
5583
  char* shell_arg_graph=0;
 
5584
  int shell_result;
 
5585
 
 
5586
 
 
5587
  int shell_seen[3];
 
5588
  int shell_index=-1;
 
5589
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5590
                                   { "graph-out",required_argument,0,1 },
 
5591
                                   { "prob",required_argument,0,2 },
 
5592
                                   { "help",no_argument,0,3 },
 
5593
                                   { 0,0,0,0 }
 
5594
                                 };
 
5595
 
 
5596
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5597
  memset(shell_seen, 0, 3*sizeof(int));
 
5598
 
 
5599
  
 
5600
  /* Parse arguments and read input */
 
5601
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5602
 
 
5603
    if (shell_index==-1) {
 
5604
      exit(1);
 
5605
    }
 
5606
 
 
5607
    if (shell_seen[shell_index]==1) {
 
5608
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5609
              shell_options[shell_index].name);
 
5610
      exit(1);
 
5611
    }
 
5612
    shell_seen[shell_index]=1;  
 
5613
 
 
5614
    switch (shell_index) {
 
5615
    case 0: /* graph */
 
5616
      shell_read_graph(&graph, optarg);
 
5617
      break;
 
5618
    case 1: /* graph-out */
 
5619
      shell_arg_graph=strdup(optarg);
 
5620
      break;
 
5621
    case 2: /* prob */
 
5622
      shell_read_real(&prob, optarg);
 
5623
      break;
 
5624
    case 3:
 
5625
      shell_igraph_rewire_edges_usage(argv);
 
5626
      break;
 
5627
    default:
 
5628
      break;
 
5629
    }
 
5630
 
 
5631
    shell_index=-1;
 
5632
  }
 
5633
 
 
5634
  /* Check that we have all arguments */
 
5635
  for (shell_index=0; shell_index<3; shell_index++) {
 
5636
    if (!shell_seen[shell_index]) {
 
5637
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5638
              shell_options[shell_index].name);
 
5639
      exit(1);
 
5640
    }
 
5641
  }
 
5642
 
 
5643
  /* Do the operation */
 
5644
  shell_result=igraph_rewire_edges(&graph, prob);
 
5645
 
 
5646
  /* Write the result */
 
5647
  igraph_destroy(&graph);
 
5648
  shell_write_graph(&graph, shell_arg_graph); 
 
5649
  igraph_destroy(&graph);
 
5650
 
 
5651
  return 0;
 
5652
}
 
5653
 
 
5654
/*-------------------------------------------/
 
5655
/ igraph_watts_strogatz_game                 /
 
5656
/-------------------------------------------*/
 
5657
void shell_igraph_watts_strogatz_game_usage(char **argv) {
 
5658
  printf("%s --graph=<graph> --dim=<dim> --size=<size> --nei=<nei> --p=<p>\n", basename(argv[0]));
 
5659
  exit(1);
 
5660
}
 
5661
 
 
5662
int shell_igraph_watts_strogatz_game(int argc, char **argv) {
 
5663
 
 
5664
  igraph_t graph;
 
5665
  igraph_integer_t dim;
 
5666
  igraph_integer_t size;
 
5667
  igraph_integer_t nei;
 
5668
  igraph_real_t p;
 
5669
  char* shell_arg_graph=0;
 
5670
  int shell_result;
 
5671
 
 
5672
 
 
5673
  int shell_seen[5];
 
5674
  int shell_index=-1;
 
5675
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5676
                                   { "dim",required_argument,0,1 },
 
5677
                                   { "size",required_argument,0,2 },
 
5678
                                   { "nei",required_argument,0,3 },
 
5679
                                   { "p",required_argument,0,4 },
 
5680
                                   { "help",no_argument,0,5 },
 
5681
                                   { 0,0,0,0 }
 
5682
                                 };
 
5683
 
 
5684
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5685
  memset(shell_seen, 0, 5*sizeof(int));
 
5686
 
 
5687
  
 
5688
  /* Parse arguments and read input */
 
5689
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5690
 
 
5691
    if (shell_index==-1) {
 
5692
      exit(1);
 
5693
    }
 
5694
 
 
5695
    if (shell_seen[shell_index]==1) {
 
5696
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5697
              shell_options[shell_index].name);
 
5698
      exit(1);
 
5699
    }
 
5700
    shell_seen[shell_index]=1;  
 
5701
 
 
5702
    switch (shell_index) {
 
5703
    case 0: /* graph */
 
5704
      shell_arg_graph=strdup(optarg);
 
5705
      break;
 
5706
    case 1: /* dim */
 
5707
      shell_read_integer(&dim, optarg);
 
5708
      break;
 
5709
    case 2: /* size */
 
5710
      shell_read_integer(&size, optarg);
 
5711
      break;
 
5712
    case 3: /* nei */
 
5713
      shell_read_integer(&nei, optarg);
 
5714
      break;
 
5715
    case 4: /* p */
 
5716
      shell_read_real(&p, optarg);
 
5717
      break;
 
5718
    case 5:
 
5719
      shell_igraph_watts_strogatz_game_usage(argv);
 
5720
      break;
 
5721
    default:
 
5722
      break;
 
5723
    }
 
5724
 
 
5725
    shell_index=-1;
 
5726
  }
 
5727
 
 
5728
  /* Check that we have all arguments */
 
5729
  for (shell_index=0; shell_index<5; shell_index++) {
 
5730
    if (!shell_seen[shell_index]) {
 
5731
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5732
              shell_options[shell_index].name);
 
5733
      exit(1);
 
5734
    }
 
5735
  }
 
5736
 
 
5737
  /* Do the operation */
 
5738
  shell_result=igraph_watts_strogatz_game(&graph, dim, size, nei, p);
 
5739
 
 
5740
  /* Write the result */
 
5741
  shell_write_graph(&graph, shell_arg_graph); 
 
5742
  igraph_destroy(&graph);
 
5743
 
 
5744
  return 0;
 
5745
}
 
5746
 
 
5747
/*-------------------------------------------/
 
5748
/ igraph_lastcit_game                        /
 
5749
/-------------------------------------------*/
 
5750
void shell_igraph_lastcit_game_usage(char **argv) {
 
5751
  printf("%s --graph=<graph> --nodes=<nodes> --edges_per_node=<edges_per_node> --agebins=<agebins> --preference=<preference> --directed=<directed>\n", basename(argv[0]));
 
5752
  exit(1);
 
5753
}
 
5754
 
 
5755
int shell_igraph_lastcit_game(int argc, char **argv) {
 
5756
 
 
5757
  igraph_t graph;
 
5758
  igraph_integer_t nodes;
 
5759
  igraph_integer_t edges_per_node=1;
 
5760
  igraph_integer_t agebins=1;
 
5761
  igraph_vector_t preference;
 
5762
  igraph_bool_t directed=1;
 
5763
  char* shell_arg_graph=0;
 
5764
  int shell_result;
 
5765
 
 
5766
 
 
5767
  int shell_seen[6];
 
5768
  int shell_index=-1;
 
5769
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5770
                                   { "nodes",required_argument,0,1 },
 
5771
                                   { "edges_per_node",required_argument,0,2 },
 
5772
                                   { "agebins",required_argument,0,3 },
 
5773
                                   { "preference",required_argument,0,4 },
 
5774
                                   { "directed",required_argument,0,5 },
 
5775
                                   { "help",no_argument,0,6 },
 
5776
                                   { 0,0,0,0 }
 
5777
                                 };
 
5778
 
 
5779
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5780
  memset(shell_seen, 0, 6*sizeof(int));
 
5781
  shell_seen[2]=2;
 
5782
  shell_seen[3]=2;
 
5783
  shell_seen[5]=2;
 
5784
  
 
5785
  /* Parse arguments and read input */
 
5786
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5787
 
 
5788
    if (shell_index==-1) {
 
5789
      exit(1);
 
5790
    }
 
5791
 
 
5792
    if (shell_seen[shell_index]==1) {
 
5793
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5794
              shell_options[shell_index].name);
 
5795
      exit(1);
 
5796
    }
 
5797
    shell_seen[shell_index]=1;  
 
5798
 
 
5799
    switch (shell_index) {
 
5800
    case 0: /* graph */
 
5801
      shell_arg_graph=strdup(optarg);
 
5802
      break;
 
5803
    case 1: /* nodes */
 
5804
      shell_read_integer(&nodes, optarg);
 
5805
      break;
 
5806
    case 2: /* edges_per_node */
 
5807
      shell_read_integer(&edges_per_node, optarg);
 
5808
      break;
 
5809
    case 3: /* agebins */
 
5810
      shell_read_integer(&agebins, optarg);
 
5811
      break;
 
5812
    case 4: /* preference */
 
5813
      shell_read_vector(&preference, optarg);
 
5814
      break;
 
5815
    case 5: /* directed */
 
5816
      shell_read_boolean(&directed, optarg);
 
5817
      break;
 
5818
    case 6:
 
5819
      shell_igraph_lastcit_game_usage(argv);
 
5820
      break;
 
5821
    default:
 
5822
      break;
 
5823
    }
 
5824
 
 
5825
    shell_index=-1;
 
5826
  }
 
5827
 
 
5828
  /* Check that we have all arguments */
 
5829
  for (shell_index=0; shell_index<6; shell_index++) {
 
5830
    if (!shell_seen[shell_index]) {
 
5831
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5832
              shell_options[shell_index].name);
 
5833
      exit(1);
 
5834
    }
 
5835
  }
 
5836
 
 
5837
  /* Do the operation */
 
5838
  shell_result=igraph_lastcit_game(&graph, nodes, edges_per_node, agebins, &preference, directed);
 
5839
 
 
5840
  /* Write the result */
 
5841
  shell_write_graph(&graph, shell_arg_graph); 
 
5842
  igraph_destroy(&graph);
 
5843
  igraph_vector_destroy(&preference);
 
5844
 
 
5845
  return 0;
 
5846
}
 
5847
 
 
5848
/*-------------------------------------------/
 
5849
/ igraph_cited_type_game                     /
 
5850
/-------------------------------------------*/
 
5851
void shell_igraph_cited_type_game_usage(char **argv) {
 
5852
  printf("%s --graph=<graph> --nodes=<nodes> --types=<types> --pref=<pref> --edges_per_step=<edges_per_step> --directed=<directed>\n", basename(argv[0]));
 
5853
  exit(1);
 
5854
}
 
5855
 
 
5856
int shell_igraph_cited_type_game(int argc, char **argv) {
 
5857
 
 
5858
  igraph_t graph;
 
5859
  igraph_integer_t nodes;
 
5860
  igraph_vector_t types;
 
5861
  igraph_vector_t pref;
 
5862
  igraph_integer_t edges_per_step=1;
 
5863
  igraph_bool_t directed=1;
 
5864
  char* shell_arg_graph=0;
 
5865
  int shell_result;
 
5866
 
 
5867
 
 
5868
  int shell_seen[6];
 
5869
  int shell_index=-1;
 
5870
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5871
                                   { "nodes",required_argument,0,1 },
 
5872
                                   { "types",required_argument,0,2 },
 
5873
                                   { "pref",required_argument,0,3 },
 
5874
                                   { "edges_per_step",required_argument,0,4 },
 
5875
                                   { "directed",required_argument,0,5 },
 
5876
                                   { "help",no_argument,0,6 },
 
5877
                                   { 0,0,0,0 }
 
5878
                                 };
 
5879
 
 
5880
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5881
  memset(shell_seen, 0, 6*sizeof(int));
 
5882
  shell_seen[4]=2;
 
5883
  shell_seen[5]=2;
 
5884
  
 
5885
  /* Parse arguments and read input */
 
5886
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5887
 
 
5888
    if (shell_index==-1) {
 
5889
      exit(1);
 
5890
    }
 
5891
 
 
5892
    if (shell_seen[shell_index]==1) {
 
5893
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5894
              shell_options[shell_index].name);
 
5895
      exit(1);
 
5896
    }
 
5897
    shell_seen[shell_index]=1;  
 
5898
 
 
5899
    switch (shell_index) {
 
5900
    case 0: /* graph */
 
5901
      shell_arg_graph=strdup(optarg);
 
5902
      break;
 
5903
    case 1: /* nodes */
 
5904
      shell_read_integer(&nodes, optarg);
 
5905
      break;
 
5906
    case 2: /* types */
 
5907
      shell_read_vector(&types, optarg);
 
5908
      break;
 
5909
    case 3: /* pref */
 
5910
      shell_read_vector(&pref, optarg);
 
5911
      break;
 
5912
    case 4: /* edges_per_step */
 
5913
      shell_read_integer(&edges_per_step, optarg);
 
5914
      break;
 
5915
    case 5: /* directed */
 
5916
      shell_read_boolean(&directed, optarg);
 
5917
      break;
 
5918
    case 6:
 
5919
      shell_igraph_cited_type_game_usage(argv);
 
5920
      break;
 
5921
    default:
 
5922
      break;
 
5923
    }
 
5924
 
 
5925
    shell_index=-1;
 
5926
  }
 
5927
 
 
5928
  /* Check that we have all arguments */
 
5929
  for (shell_index=0; shell_index<6; shell_index++) {
 
5930
    if (!shell_seen[shell_index]) {
 
5931
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
5932
              shell_options[shell_index].name);
 
5933
      exit(1);
 
5934
    }
 
5935
  }
 
5936
 
 
5937
  /* Do the operation */
 
5938
  shell_result=igraph_cited_type_game(&graph, nodes, &types, &pref, edges_per_step, directed);
 
5939
 
 
5940
  /* Write the result */
 
5941
  shell_write_graph(&graph, shell_arg_graph); 
 
5942
  igraph_destroy(&graph);
 
5943
  igraph_vector_destroy(&types);
 
5944
  igraph_vector_destroy(&pref);
 
5945
 
 
5946
  return 0;
 
5947
}
 
5948
 
 
5949
/*-------------------------------------------/
 
5950
/ igraph_citing_cited_type_game              /
 
5951
/-------------------------------------------*/
 
5952
void shell_igraph_citing_cited_type_game_usage(char **argv) {
 
5953
  printf("%s --graph=<graph> --nodes=<nodes> --types=<types> --pref=<pref> --edges_per_step=<edges_per_step> --directed=<directed>\n", basename(argv[0]));
 
5954
  exit(1);
 
5955
}
 
5956
 
 
5957
int shell_igraph_citing_cited_type_game(int argc, char **argv) {
 
5958
 
 
5959
  igraph_t graph;
 
5960
  igraph_integer_t nodes;
 
5961
  igraph_vector_t types;
 
5962
  igraph_matrix_t pref;
 
5963
  igraph_integer_t edges_per_step=1;
 
5964
  igraph_bool_t directed=1;
 
5965
  char* shell_arg_graph=0;
 
5966
  int shell_result;
 
5967
 
 
5968
 
 
5969
  int shell_seen[6];
 
5970
  int shell_index=-1;
 
5971
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
5972
                                   { "nodes",required_argument,0,1 },
 
5973
                                   { "types",required_argument,0,2 },
 
5974
                                   { "pref",required_argument,0,3 },
 
5975
                                   { "edges_per_step",required_argument,0,4 },
 
5976
                                   { "directed",required_argument,0,5 },
 
5977
                                   { "help",no_argument,0,6 },
 
5978
                                   { 0,0,0,0 }
 
5979
                                 };
 
5980
 
 
5981
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
5982
  memset(shell_seen, 0, 6*sizeof(int));
 
5983
  shell_seen[4]=2;
 
5984
  shell_seen[5]=2;
 
5985
  
 
5986
  /* Parse arguments and read input */
 
5987
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
5988
 
 
5989
    if (shell_index==-1) {
 
5990
      exit(1);
 
5991
    }
 
5992
 
 
5993
    if (shell_seen[shell_index]==1) {
 
5994
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
5995
              shell_options[shell_index].name);
 
5996
      exit(1);
 
5997
    }
 
5998
    shell_seen[shell_index]=1;  
 
5999
 
 
6000
    switch (shell_index) {
 
6001
    case 0: /* graph */
 
6002
      shell_arg_graph=strdup(optarg);
 
6003
      break;
 
6004
    case 1: /* nodes */
 
6005
      shell_read_integer(&nodes, optarg);
 
6006
      break;
 
6007
    case 2: /* types */
 
6008
      shell_read_vector(&types, optarg);
 
6009
      break;
 
6010
    case 3: /* pref */
 
6011
      shell_read_matrix(&pref, optarg);
 
6012
      break;
 
6013
    case 4: /* edges_per_step */
 
6014
      shell_read_integer(&edges_per_step, optarg);
 
6015
      break;
 
6016
    case 5: /* directed */
 
6017
      shell_read_boolean(&directed, optarg);
 
6018
      break;
 
6019
    case 6:
 
6020
      shell_igraph_citing_cited_type_game_usage(argv);
 
6021
      break;
 
6022
    default:
 
6023
      break;
 
6024
    }
 
6025
 
 
6026
    shell_index=-1;
 
6027
  }
 
6028
 
 
6029
  /* Check that we have all arguments */
 
6030
  for (shell_index=0; shell_index<6; shell_index++) {
 
6031
    if (!shell_seen[shell_index]) {
 
6032
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6033
              shell_options[shell_index].name);
 
6034
      exit(1);
 
6035
    }
 
6036
  }
 
6037
 
 
6038
  /* Do the operation */
 
6039
  shell_result=igraph_citing_cited_type_game(&graph, nodes, &types, &pref, edges_per_step, directed);
 
6040
 
 
6041
  /* Write the result */
 
6042
  shell_write_graph(&graph, shell_arg_graph); 
 
6043
  igraph_destroy(&graph);
 
6044
  igraph_vector_destroy(&types);
 
6045
  igraph_matrix_destroy(&pref);
 
6046
 
 
6047
  return 0;
 
6048
}
 
6049
 
 
6050
/*-------------------------------------------/
 
6051
/ igraph_forest_fire_game                    /
 
6052
/-------------------------------------------*/
 
6053
void shell_igraph_forest_fire_game_usage(char **argv) {
 
6054
  printf("%s --graph=<graph> --nodes=<nodes> --fw_prob=<fw_prob> --bw_factor=<bw_factor> --ambs=<ambs> --directed=<directed>\n", basename(argv[0]));
 
6055
  exit(1);
 
6056
}
 
6057
 
 
6058
int shell_igraph_forest_fire_game(int argc, char **argv) {
 
6059
 
 
6060
  igraph_t graph;
 
6061
  igraph_integer_t nodes;
 
6062
  igraph_real_t fw_prob;
 
6063
  igraph_real_t bw_factor=1;
 
6064
  igraph_integer_t ambs=1;
 
6065
  igraph_bool_t directed=1;
 
6066
  char* shell_arg_graph=0;
 
6067
  int shell_result;
 
6068
 
 
6069
 
 
6070
  int shell_seen[6];
 
6071
  int shell_index=-1;
 
6072
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6073
                                   { "nodes",required_argument,0,1 },
 
6074
                                   { "fw_prob",required_argument,0,2 },
 
6075
                                   { "bw_factor",required_argument,0,3 },
 
6076
                                   { "ambs",required_argument,0,4 },
 
6077
                                   { "directed",required_argument,0,5 },
 
6078
                                   { "help",no_argument,0,6 },
 
6079
                                   { 0,0,0,0 }
 
6080
                                 };
 
6081
 
 
6082
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6083
  memset(shell_seen, 0, 6*sizeof(int));
 
6084
  shell_seen[3]=2;
 
6085
  shell_seen[4]=2;
 
6086
  shell_seen[5]=2;
 
6087
  
 
6088
  /* Parse arguments and read input */
 
6089
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6090
 
 
6091
    if (shell_index==-1) {
 
6092
      exit(1);
 
6093
    }
 
6094
 
 
6095
    if (shell_seen[shell_index]==1) {
 
6096
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6097
              shell_options[shell_index].name);
 
6098
      exit(1);
 
6099
    }
 
6100
    shell_seen[shell_index]=1;  
 
6101
 
 
6102
    switch (shell_index) {
 
6103
    case 0: /* graph */
 
6104
      shell_arg_graph=strdup(optarg);
 
6105
      break;
 
6106
    case 1: /* nodes */
 
6107
      shell_read_integer(&nodes, optarg);
 
6108
      break;
 
6109
    case 2: /* fw_prob */
 
6110
      shell_read_real(&fw_prob, optarg);
 
6111
      break;
 
6112
    case 3: /* bw_factor */
 
6113
      shell_read_real(&bw_factor, optarg);
 
6114
      break;
 
6115
    case 4: /* ambs */
 
6116
      shell_read_integer(&ambs, optarg);
 
6117
      break;
 
6118
    case 5: /* directed */
 
6119
      shell_read_boolean(&directed, optarg);
 
6120
      break;
 
6121
    case 6:
 
6122
      shell_igraph_forest_fire_game_usage(argv);
 
6123
      break;
 
6124
    default:
 
6125
      break;
 
6126
    }
 
6127
 
 
6128
    shell_index=-1;
 
6129
  }
 
6130
 
 
6131
  /* Check that we have all arguments */
 
6132
  for (shell_index=0; shell_index<6; shell_index++) {
 
6133
    if (!shell_seen[shell_index]) {
 
6134
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6135
              shell_options[shell_index].name);
 
6136
      exit(1);
 
6137
    }
 
6138
  }
 
6139
 
 
6140
  /* Do the operation */
 
6141
  shell_result=igraph_forest_fire_game(&graph, nodes, fw_prob, bw_factor, ambs, directed);
 
6142
 
 
6143
  /* Write the result */
 
6144
  shell_write_graph(&graph, shell_arg_graph); 
 
6145
  igraph_destroy(&graph);
 
6146
 
 
6147
  return 0;
 
6148
}
 
6149
 
 
6150
/*-------------------------------------------/
 
6151
/ igraph_are_connected                       /
 
6152
/-------------------------------------------*/
 
6153
void shell_igraph_are_connected_usage(char **argv) {
 
6154
  printf("%s --graph=<graph> --v1=<v1> --v2=<v2> --res=<res>\n", basename(argv[0]));
 
6155
  exit(1);
 
6156
}
 
6157
 
 
6158
int shell_igraph_are_connected(int argc, char **argv) {
 
6159
 
 
6160
  igraph_t graph;
 
6161
  igraph_integer_t v1;
 
6162
  igraph_integer_t v2;
 
6163
  igraph_bool_t res;
 
6164
  char* shell_arg_res=0;
 
6165
  int shell_result;
 
6166
 
 
6167
 
 
6168
  int shell_seen[4];
 
6169
  int shell_index=-1;
 
6170
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6171
                                   { "v1",required_argument,0,1 },
 
6172
                                   { "v2",required_argument,0,2 },
 
6173
                                   { "res",required_argument,0,3 },
 
6174
                                   { "help",no_argument,0,4 },
 
6175
                                   { 0,0,0,0 }
 
6176
                                 };
 
6177
 
 
6178
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6179
  memset(shell_seen, 0, 4*sizeof(int));
 
6180
 
 
6181
  
 
6182
  /* Parse arguments and read input */
 
6183
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6184
 
 
6185
    if (shell_index==-1) {
 
6186
      exit(1);
 
6187
    }
 
6188
 
 
6189
    if (shell_seen[shell_index]==1) {
 
6190
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6191
              shell_options[shell_index].name);
 
6192
      exit(1);
 
6193
    }
 
6194
    shell_seen[shell_index]=1;  
 
6195
 
 
6196
    switch (shell_index) {
 
6197
    case 0: /* graph */
 
6198
      shell_read_graph(&graph, optarg);
 
6199
      break;
 
6200
    case 1: /* v1 */
 
6201
      shell_read_integer(&v1, optarg);
 
6202
      break;
 
6203
    case 2: /* v2 */
 
6204
      shell_read_integer(&v2, optarg);
 
6205
      break;
 
6206
    case 3: /* res */
 
6207
      
 
6208
      break;
 
6209
    case 4:
 
6210
      shell_igraph_are_connected_usage(argv);
 
6211
      break;
 
6212
    default:
 
6213
      break;
 
6214
    }
 
6215
 
 
6216
    shell_index=-1;
 
6217
  }
 
6218
 
 
6219
  /* Check that we have all arguments */
 
6220
  for (shell_index=0; shell_index<4; shell_index++) {
 
6221
    if (!shell_seen[shell_index]) {
 
6222
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6223
              shell_options[shell_index].name);
 
6224
      exit(1);
 
6225
    }
 
6226
  }
 
6227
 
 
6228
  /* Do the operation */
 
6229
  shell_result=igraph_are_connected(&graph, v1, v2, &res);
 
6230
 
 
6231
  /* Write the result */
 
6232
  igraph_destroy(&graph);
 
6233
  shell_write_boolean(res, shell_arg_res);
 
6234
 
 
6235
  return 0;
 
6236
}
 
6237
 
 
6238
/*-------------------------------------------/
 
6239
/ igraph_diameter                            /
 
6240
/-------------------------------------------*/
 
6241
void shell_igraph_diameter_usage(char **argv) {
 
6242
  printf("%s --graph=<graph> --res=<res> --from=<from> --to=<to> --path=<path> --directed=<directed> --unconnected=<unconnected>\n", basename(argv[0]));
 
6243
  exit(1);
 
6244
}
 
6245
 
 
6246
int shell_igraph_diameter(int argc, char **argv) {
 
6247
 
 
6248
  igraph_t graph;
 
6249
  igraph_integer_t res;
 
6250
  igraph_integer_t from;
 
6251
  igraph_integer_t to;
 
6252
  igraph_vector_t v_path; igraph_vector_t *path=0;
 
6253
  igraph_bool_t directed=1;
 
6254
  igraph_bool_t unconnected=1;
 
6255
  char* shell_arg_res=0;
 
6256
  char* shell_arg_from=0;
 
6257
  char* shell_arg_to=0;
 
6258
  char* shell_arg_path=0;
 
6259
  int shell_result;
 
6260
 
 
6261
 
 
6262
  int shell_seen[7];
 
6263
  int shell_index=-1;
 
6264
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6265
                                   { "res",required_argument,0,1 },
 
6266
                                   { "from",required_argument,0,2 },
 
6267
                                   { "to",required_argument,0,3 },
 
6268
                                   { "path",required_argument,0,4 },
 
6269
                                   { "directed",required_argument,0,5 },
 
6270
                                   { "unconnected",required_argument,0,6 },
 
6271
                                   { "help",no_argument,0,7 },
 
6272
                                   { 0,0,0,0 }
 
6273
                                 };
 
6274
 
 
6275
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6276
  memset(shell_seen, 0, 7*sizeof(int));
 
6277
  shell_seen[5]=2;
 
6278
  shell_seen[6]=2;
 
6279
  
 
6280
  /* Parse arguments and read input */
 
6281
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6282
 
 
6283
    if (shell_index==-1) {
 
6284
      exit(1);
 
6285
    }
 
6286
 
 
6287
    if (shell_seen[shell_index]==1) {
 
6288
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6289
              shell_options[shell_index].name);
 
6290
      exit(1);
 
6291
    }
 
6292
    shell_seen[shell_index]=1;  
 
6293
 
 
6294
    switch (shell_index) {
 
6295
    case 0: /* graph */
 
6296
      shell_read_graph(&graph, optarg);
 
6297
      break;
 
6298
    case 1: /* res */
 
6299
      shell_arg_res=strdup(optarg);
 
6300
      break;
 
6301
    case 2: /* from */
 
6302
      shell_arg_from=strdup(optarg);
 
6303
      break;
 
6304
    case 3: /* to */
 
6305
      shell_arg_to=strdup(optarg);
 
6306
      break;
 
6307
    case 4: /* path */
 
6308
      path=&v_path; igraph_vector_init(path, 0); 
 
6309
  shell_arg_path=strdup(optarg);
 
6310
      break;
 
6311
    case 5: /* directed */
 
6312
      shell_read_boolean(&directed, optarg);
 
6313
      break;
 
6314
    case 6: /* unconnected */
 
6315
      shell_read_boolean(&unconnected, optarg);
 
6316
      break;
 
6317
    case 7:
 
6318
      shell_igraph_diameter_usage(argv);
 
6319
      break;
 
6320
    default:
 
6321
      break;
 
6322
    }
 
6323
 
 
6324
    shell_index=-1;
 
6325
  }
 
6326
 
 
6327
  /* Check that we have all arguments */
 
6328
  for (shell_index=0; shell_index<7; shell_index++) {
 
6329
    if (!shell_seen[shell_index]) {
 
6330
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6331
              shell_options[shell_index].name);
 
6332
      exit(1);
 
6333
    }
 
6334
  }
 
6335
 
 
6336
  /* Do the operation */
 
6337
  shell_result=igraph_diameter(&graph, &res, &from, &to, path, directed, unconnected);
 
6338
 
 
6339
  /* Write the result */
 
6340
  igraph_destroy(&graph);
 
6341
  shell_write_integer(res, shell_arg_res);
 
6342
  shell_write_integer(from, shell_arg_from);
 
6343
  shell_write_integer(to, shell_arg_to);
 
6344
  if (path) { shell_write_vector(path, shell_arg_path); 
 
6345
  igraph_vector_destroy(path); }
 
6346
 
 
6347
  return 0;
 
6348
}
 
6349
 
 
6350
/*-------------------------------------------/
 
6351
/ igraph_diameter_dijkstra                   /
 
6352
/-------------------------------------------*/
 
6353
void shell_igraph_diameter_dijkstra_usage(char **argv) {
 
6354
  printf("%s --graph=<graph> --res=<res> --from=<from> --to=<to> --path=<path> --directed=<directed> --unconnected=<unconnected>\n", basename(argv[0]));
 
6355
  exit(1);
 
6356
}
 
6357
 
 
6358
int shell_igraph_diameter_dijkstra(int argc, char **argv) {
 
6359
 
 
6360
  igraph_t graph;
 
6361
 
 
6362
  igraph_integer_t res;
 
6363
  igraph_integer_t from;
 
6364
  igraph_integer_t to;
 
6365
  igraph_vector_t v_path; igraph_vector_t *path=0;
 
6366
  igraph_bool_t directed=1;
 
6367
  igraph_bool_t unconnected=1;
 
6368
  char* shell_arg_res=0;
 
6369
  char* shell_arg_from=0;
 
6370
  char* shell_arg_to=0;
 
6371
  char* shell_arg_path=0;
 
6372
  int shell_result;
 
6373
 
 
6374
 
 
6375
  int shell_seen[7];
 
6376
  int shell_index=-1;
 
6377
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6378
                                   { "res",required_argument,0,1 },
 
6379
                                   { "from",required_argument,0,2 },
 
6380
                                   { "to",required_argument,0,3 },
 
6381
                                   { "path",required_argument,0,4 },
 
6382
                                   { "directed",required_argument,0,5 },
 
6383
                                   { "unconnected",required_argument,0,6 },
 
6384
                                   { "help",no_argument,0,7 },
 
6385
                                   { 0,0,0,0 }
 
6386
                                 };
 
6387
 
 
6388
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6389
  memset(shell_seen, 0, 7*sizeof(int));
 
6390
  shell_seen[5]=2;
 
6391
  shell_seen[6]=2;
 
6392
  
 
6393
  /* Parse arguments and read input */
 
6394
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6395
 
 
6396
    if (shell_index==-1) {
 
6397
      exit(1);
 
6398
    }
 
6399
 
 
6400
    if (shell_seen[shell_index]==1) {
 
6401
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6402
              shell_options[shell_index].name);
 
6403
      exit(1);
 
6404
    }
 
6405
    shell_seen[shell_index]=1;  
 
6406
 
 
6407
    switch (shell_index) {
 
6408
    case 0: /* graph */
 
6409
      shell_read_graph(&graph, optarg);
 
6410
      break;
 
6411
    case 1: /* res */
 
6412
      shell_arg_res=strdup(optarg);
 
6413
      break;
 
6414
    case 2: /* from */
 
6415
      shell_arg_from=strdup(optarg);
 
6416
      break;
 
6417
    case 3: /* to */
 
6418
      shell_arg_to=strdup(optarg);
 
6419
      break;
 
6420
    case 4: /* path */
 
6421
      path=&v_path; igraph_vector_init(path, 0); 
 
6422
  shell_arg_path=strdup(optarg);
 
6423
      break;
 
6424
    case 5: /* directed */
 
6425
      shell_read_boolean(&directed, optarg);
 
6426
      break;
 
6427
    case 6: /* unconnected */
 
6428
      shell_read_boolean(&unconnected, optarg);
 
6429
      break;
 
6430
    case 7:
 
6431
      shell_igraph_diameter_dijkstra_usage(argv);
 
6432
      break;
 
6433
    default:
 
6434
      break;
 
6435
    }
 
6436
 
 
6437
    shell_index=-1;
 
6438
  }
 
6439
 
 
6440
  /* Check that we have all arguments */
 
6441
  for (shell_index=0; shell_index<7; shell_index++) {
 
6442
    if (!shell_seen[shell_index]) {
 
6443
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6444
              shell_options[shell_index].name);
 
6445
      exit(1);
 
6446
    }
 
6447
  }
 
6448
 
 
6449
  /* Do the operation */
 
6450
  shell_result=igraph_diameter_dijkstra(&graph, 0, &res, &from, &to, path, directed, unconnected);
 
6451
 
 
6452
  /* Write the result */
 
6453
  igraph_destroy(&graph);
 
6454
  shell_write_integer(res, shell_arg_res);
 
6455
  shell_write_integer(from, shell_arg_from);
 
6456
  shell_write_integer(to, shell_arg_to);
 
6457
  if (path) { shell_write_vector(path, shell_arg_path); 
 
6458
  igraph_vector_destroy(path); }
 
6459
 
 
6460
  return 0;
 
6461
}
 
6462
 
 
6463
/*-------------------------------------------/
 
6464
/ igraph_minimum_spanning_tree_unweighted    /
 
6465
/-------------------------------------------*/
 
6466
void shell_igraph_minimum_spanning_tree_unweighted_usage(char **argv) {
 
6467
  printf("%s --graph=<graph> --mst=<mst>\n", basename(argv[0]));
 
6468
  exit(1);
 
6469
}
 
6470
 
 
6471
int shell_igraph_minimum_spanning_tree_unweighted(int argc, char **argv) {
 
6472
 
 
6473
  igraph_t graph;
 
6474
  igraph_t mst;
 
6475
  char* shell_arg_mst=0;
 
6476
  int shell_result;
 
6477
 
 
6478
 
 
6479
  int shell_seen[2];
 
6480
  int shell_index=-1;
 
6481
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6482
                                   { "mst",required_argument,0,1 },
 
6483
                                   { "help",no_argument,0,2 },
 
6484
                                   { 0,0,0,0 }
 
6485
                                 };
 
6486
 
 
6487
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6488
  memset(shell_seen, 0, 2*sizeof(int));
 
6489
 
 
6490
  
 
6491
  /* Parse arguments and read input */
 
6492
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6493
 
 
6494
    if (shell_index==-1) {
 
6495
      exit(1);
 
6496
    }
 
6497
 
 
6498
    if (shell_seen[shell_index]==1) {
 
6499
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6500
              shell_options[shell_index].name);
 
6501
      exit(1);
 
6502
    }
 
6503
    shell_seen[shell_index]=1;  
 
6504
 
 
6505
    switch (shell_index) {
 
6506
    case 0: /* graph */
 
6507
      shell_read_graph(&graph, optarg);
 
6508
      break;
 
6509
    case 1: /* mst */
 
6510
      shell_arg_mst=strdup(optarg);
 
6511
      break;
 
6512
    case 2:
 
6513
      shell_igraph_minimum_spanning_tree_unweighted_usage(argv);
 
6514
      break;
 
6515
    default:
 
6516
      break;
 
6517
    }
 
6518
 
 
6519
    shell_index=-1;
 
6520
  }
 
6521
 
 
6522
  /* Check that we have all arguments */
 
6523
  for (shell_index=0; shell_index<2; shell_index++) {
 
6524
    if (!shell_seen[shell_index]) {
 
6525
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6526
              shell_options[shell_index].name);
 
6527
      exit(1);
 
6528
    }
 
6529
  }
 
6530
 
 
6531
  /* Do the operation */
 
6532
  shell_result=igraph_minimum_spanning_tree_unweighted(&graph, &mst);
 
6533
 
 
6534
  /* Write the result */
 
6535
  igraph_destroy(&graph);
 
6536
  shell_write_graph(&mst, shell_arg_mst); 
 
6537
  igraph_destroy(&mst);
 
6538
 
 
6539
  return 0;
 
6540
}
 
6541
 
 
6542
/*-------------------------------------------/
 
6543
/ igraph_minimum_spanning_tree_prim          /
 
6544
/-------------------------------------------*/
 
6545
void shell_igraph_minimum_spanning_tree_prim_usage(char **argv) {
 
6546
  printf("%s --graph=<graph> --mst=<mst> --weights=<weights>\n", basename(argv[0]));
 
6547
  exit(1);
 
6548
}
 
6549
 
 
6550
int shell_igraph_minimum_spanning_tree_prim(int argc, char **argv) {
 
6551
 
 
6552
  igraph_t graph;
 
6553
  igraph_t mst;
 
6554
  igraph_vector_t weights;
 
6555
  char* shell_arg_mst=0;
 
6556
  int shell_result;
 
6557
 
 
6558
 
 
6559
  int shell_seen[3];
 
6560
  int shell_index=-1;
 
6561
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6562
                                   { "mst",required_argument,0,1 },
 
6563
                                   { "weights",required_argument,0,2 },
 
6564
                                   { "help",no_argument,0,3 },
 
6565
                                   { 0,0,0,0 }
 
6566
                                 };
 
6567
 
 
6568
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6569
  memset(shell_seen, 0, 3*sizeof(int));
 
6570
 
 
6571
  
 
6572
  /* Parse arguments and read input */
 
6573
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6574
 
 
6575
    if (shell_index==-1) {
 
6576
      exit(1);
 
6577
    }
 
6578
 
 
6579
    if (shell_seen[shell_index]==1) {
 
6580
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6581
              shell_options[shell_index].name);
 
6582
      exit(1);
 
6583
    }
 
6584
    shell_seen[shell_index]=1;  
 
6585
 
 
6586
    switch (shell_index) {
 
6587
    case 0: /* graph */
 
6588
      shell_read_graph(&graph, optarg);
 
6589
      break;
 
6590
    case 1: /* mst */
 
6591
      shell_arg_mst=strdup(optarg);
 
6592
      break;
 
6593
    case 2: /* weights */
 
6594
      shell_read_vector(&weights, optarg);
 
6595
      break;
 
6596
    case 3:
 
6597
      shell_igraph_minimum_spanning_tree_prim_usage(argv);
 
6598
      break;
 
6599
    default:
 
6600
      break;
 
6601
    }
 
6602
 
 
6603
    shell_index=-1;
 
6604
  }
 
6605
 
 
6606
  /* Check that we have all arguments */
 
6607
  for (shell_index=0; shell_index<3; shell_index++) {
 
6608
    if (!shell_seen[shell_index]) {
 
6609
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6610
              shell_options[shell_index].name);
 
6611
      exit(1);
 
6612
    }
 
6613
  }
 
6614
 
 
6615
  /* Do the operation */
 
6616
  shell_result=igraph_minimum_spanning_tree_prim(&graph, &mst, &weights);
 
6617
 
 
6618
  /* Write the result */
 
6619
  igraph_destroy(&graph);
 
6620
  shell_write_graph(&mst, shell_arg_mst); 
 
6621
  igraph_destroy(&mst);
 
6622
  igraph_vector_destroy(&weights);
 
6623
 
 
6624
  return 0;
 
6625
}
 
6626
 
 
6627
/*-------------------------------------------/
 
6628
/ igraph_closeness                           /
 
6629
/-------------------------------------------*/
 
6630
void shell_igraph_closeness_usage(char **argv) {
 
6631
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode>\n", basename(argv[0]));
 
6632
  exit(1);
 
6633
}
 
6634
 
 
6635
int shell_igraph_closeness(int argc, char **argv) {
 
6636
 
 
6637
  igraph_t graph;
 
6638
  igraph_vector_t res;
 
6639
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
6640
  igraph_neimode_t mode=IGRAPH_OUT;
 
6641
  char* shell_arg_res=0;
 
6642
  int shell_result;
 
6643
 
 
6644
 
 
6645
  int shell_seen[4];
 
6646
  int shell_index=-1;
 
6647
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6648
                                   { "res",required_argument,0,1 },
 
6649
                                   { "vids",required_argument,0,2 },
 
6650
                                   { "mode",required_argument,0,3 },
 
6651
                                   { "help",no_argument,0,4 },
 
6652
                                   { 0,0,0,0 }
 
6653
                                 };
 
6654
 
 
6655
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6656
  memset(shell_seen, 0, 4*sizeof(int));
 
6657
  shell_seen[2]=2;
 
6658
  shell_seen[3]=2;
 
6659
  
 
6660
  /* Parse arguments and read input */
 
6661
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6662
 
 
6663
    if (shell_index==-1) {
 
6664
      exit(1);
 
6665
    }
 
6666
 
 
6667
    if (shell_seen[shell_index]==1) {
 
6668
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6669
              shell_options[shell_index].name);
 
6670
      exit(1);
 
6671
    }
 
6672
    shell_seen[shell_index]=1;  
 
6673
 
 
6674
    switch (shell_index) {
 
6675
    case 0: /* graph */
 
6676
      shell_read_graph(&graph, optarg);
 
6677
      break;
 
6678
    case 1: /* res */
 
6679
      shell_arg_res=strdup(optarg); 
 
6680
  igraph_vector_init(&res, 0);
 
6681
      break;
 
6682
    case 2: /* vids */
 
6683
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
6684
      break;
 
6685
    case 3: /* mode */
 
6686
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
6687
      break;
 
6688
    case 4:
 
6689
      shell_igraph_closeness_usage(argv);
 
6690
      break;
 
6691
    default:
 
6692
      break;
 
6693
    }
 
6694
 
 
6695
    shell_index=-1;
 
6696
  }
 
6697
 
 
6698
  /* Check that we have all arguments */
 
6699
  for (shell_index=0; shell_index<4; shell_index++) {
 
6700
    if (!shell_seen[shell_index]) {
 
6701
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6702
              shell_options[shell_index].name);
 
6703
      exit(1);
 
6704
    }
 
6705
  }
 
6706
 
 
6707
  /* Do the operation */
 
6708
  shell_result=igraph_closeness(&graph, &res, vids, mode);
 
6709
 
 
6710
  /* Write the result */
 
6711
  igraph_destroy(&graph);
 
6712
  shell_write_vector(&res, shell_arg_res); 
 
6713
  igraph_vector_destroy(&res);
 
6714
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
6715
 
 
6716
  return 0;
 
6717
}
 
6718
 
 
6719
/*-------------------------------------------/
 
6720
/ igraph_closeness_estimate                  /
 
6721
/-------------------------------------------*/
 
6722
void shell_igraph_closeness_estimate_usage(char **argv) {
 
6723
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode> --cutoff=<cutoff>\n", basename(argv[0]));
 
6724
  exit(1);
 
6725
}
 
6726
 
 
6727
int shell_igraph_closeness_estimate(int argc, char **argv) {
 
6728
 
 
6729
  igraph_t graph;
 
6730
  igraph_vector_t res;
 
6731
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
6732
  igraph_neimode_t mode=IGRAPH_OUT;
 
6733
  igraph_integer_t cutoff;
 
6734
  char* shell_arg_res=0;
 
6735
  int shell_result;
 
6736
 
 
6737
 
 
6738
  int shell_seen[5];
 
6739
  int shell_index=-1;
 
6740
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6741
                                   { "res",required_argument,0,1 },
 
6742
                                   { "vids",required_argument,0,2 },
 
6743
                                   { "mode",required_argument,0,3 },
 
6744
                                   { "cutoff",required_argument,0,4 },
 
6745
                                   { "help",no_argument,0,5 },
 
6746
                                   { 0,0,0,0 }
 
6747
                                 };
 
6748
 
 
6749
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6750
  memset(shell_seen, 0, 5*sizeof(int));
 
6751
  shell_seen[2]=2;
 
6752
  shell_seen[3]=2;
 
6753
  
 
6754
  /* Parse arguments and read input */
 
6755
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6756
 
 
6757
    if (shell_index==-1) {
 
6758
      exit(1);
 
6759
    }
 
6760
 
 
6761
    if (shell_seen[shell_index]==1) {
 
6762
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6763
              shell_options[shell_index].name);
 
6764
      exit(1);
 
6765
    }
 
6766
    shell_seen[shell_index]=1;  
 
6767
 
 
6768
    switch (shell_index) {
 
6769
    case 0: /* graph */
 
6770
      shell_read_graph(&graph, optarg);
 
6771
      break;
 
6772
    case 1: /* res */
 
6773
      shell_arg_res=strdup(optarg); 
 
6774
  igraph_vector_init(&res, 0);
 
6775
      break;
 
6776
    case 2: /* vids */
 
6777
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
6778
      break;
 
6779
    case 3: /* mode */
 
6780
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
6781
      break;
 
6782
    case 4: /* cutoff */
 
6783
      shell_read_integer(&cutoff, optarg);
 
6784
      break;
 
6785
    case 5:
 
6786
      shell_igraph_closeness_estimate_usage(argv);
 
6787
      break;
 
6788
    default:
 
6789
      break;
 
6790
    }
 
6791
 
 
6792
    shell_index=-1;
 
6793
  }
 
6794
 
 
6795
  /* Check that we have all arguments */
 
6796
  for (shell_index=0; shell_index<5; shell_index++) {
 
6797
    if (!shell_seen[shell_index]) {
 
6798
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6799
              shell_options[shell_index].name);
 
6800
      exit(1);
 
6801
    }
 
6802
  }
 
6803
 
 
6804
  /* Do the operation */
 
6805
  shell_result=igraph_closeness_estimate(&graph, &res, vids, mode, cutoff);
 
6806
 
 
6807
  /* Write the result */
 
6808
  igraph_destroy(&graph);
 
6809
  shell_write_vector(&res, shell_arg_res); 
 
6810
  igraph_vector_destroy(&res);
 
6811
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
6812
 
 
6813
  return 0;
 
6814
}
 
6815
 
 
6816
/*-------------------------------------------/
 
6817
/ igraph_shortest_paths                      /
 
6818
/-------------------------------------------*/
 
6819
void shell_igraph_shortest_paths_usage(char **argv) {
 
6820
  printf("%s --graph=<graph> --res=<res> --from=<from> --mode=<mode>\n", basename(argv[0]));
 
6821
  exit(1);
 
6822
}
 
6823
 
 
6824
int shell_igraph_shortest_paths(int argc, char **argv) {
 
6825
 
 
6826
  igraph_t graph;
 
6827
  igraph_matrix_t res;
 
6828
  igraph_vector_t v_from; igraph_vs_t from=igraph_vss_all();
 
6829
  igraph_neimode_t mode=IGRAPH_OUT;
 
6830
  char* shell_arg_res=0;
 
6831
  int shell_result;
 
6832
 
 
6833
 
 
6834
  int shell_seen[4];
 
6835
  int shell_index=-1;
 
6836
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6837
                                   { "res",required_argument,0,1 },
 
6838
                                   { "from",required_argument,0,2 },
 
6839
                                   { "mode",required_argument,0,3 },
 
6840
                                   { "help",no_argument,0,4 },
 
6841
                                   { 0,0,0,0 }
 
6842
                                 };
 
6843
 
 
6844
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6845
  memset(shell_seen, 0, 4*sizeof(int));
 
6846
  shell_seen[2]=2;
 
6847
  shell_seen[3]=2;
 
6848
  
 
6849
  /* Parse arguments and read input */
 
6850
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6851
 
 
6852
    if (shell_index==-1) {
 
6853
      exit(1);
 
6854
    }
 
6855
 
 
6856
    if (shell_seen[shell_index]==1) {
 
6857
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6858
              shell_options[shell_index].name);
 
6859
      exit(1);
 
6860
    }
 
6861
    shell_seen[shell_index]=1;  
 
6862
 
 
6863
    switch (shell_index) {
 
6864
    case 0: /* graph */
 
6865
      shell_read_graph(&graph, optarg);
 
6866
      break;
 
6867
    case 1: /* res */
 
6868
      shell_arg_res=strdup(optarg); 
 
6869
  igraph_matrix_init(&res, 0, 0);
 
6870
      break;
 
6871
    case 2: /* from */
 
6872
      shell_read_vector(&v_from, optarg); igraph_vs_vector(&from, &v_from);
 
6873
      break;
 
6874
    case 3: /* mode */
 
6875
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
6876
      break;
 
6877
    case 4:
 
6878
      shell_igraph_shortest_paths_usage(argv);
 
6879
      break;
 
6880
    default:
 
6881
      break;
 
6882
    }
 
6883
 
 
6884
    shell_index=-1;
 
6885
  }
 
6886
 
 
6887
  /* Check that we have all arguments */
 
6888
  for (shell_index=0; shell_index<4; shell_index++) {
 
6889
    if (!shell_seen[shell_index]) {
 
6890
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6891
              shell_options[shell_index].name);
 
6892
      exit(1);
 
6893
    }
 
6894
  }
 
6895
 
 
6896
  /* Do the operation */
 
6897
  shell_result=igraph_shortest_paths(&graph, &res, from, mode);
 
6898
 
 
6899
  /* Write the result */
 
6900
  igraph_destroy(&graph);
 
6901
  shell_write_matrix(&res, shell_arg_res); 
 
6902
  igraph_matrix_destroy(&res);
 
6903
  if (!igraph_vs_is_all(&from)) { igraph_vector_destroy(&v_from); }
 
6904
 
 
6905
  return 0;
 
6906
}
 
6907
 
 
6908
/*-------------------------------------------/
 
6909
/ igraph_get_shortest_paths                  /
 
6910
/-------------------------------------------*/
 
6911
void shell_igraph_get_shortest_paths_usage(char **argv) {
 
6912
  printf("%s --graph=<graph> --res=<res> --from=<from> --to=<to> --mode=<mode>\n", basename(argv[0]));
 
6913
  exit(1);
 
6914
}
 
6915
 
 
6916
int shell_igraph_get_shortest_paths(int argc, char **argv) {
 
6917
 
 
6918
  igraph_t graph;
 
6919
  igraph_vector_ptr_t res;
 
6920
  igraph_integer_t from;
 
6921
  igraph_vector_t v_to; igraph_vs_t to=igraph_vss_all();
 
6922
  igraph_neimode_t mode=IGRAPH_OUT;
 
6923
  char* shell_arg_res=0;
 
6924
  int shell_result;
 
6925
 
 
6926
 
 
6927
  int shell_seen[5];
 
6928
  int shell_index=-1;
 
6929
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
6930
                                   { "res",required_argument,0,1 },
 
6931
                                   { "from",required_argument,0,2 },
 
6932
                                   { "to",required_argument,0,3 },
 
6933
                                   { "mode",required_argument,0,4 },
 
6934
                                   { "help",no_argument,0,5 },
 
6935
                                   { 0,0,0,0 }
 
6936
                                 };
 
6937
 
 
6938
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
6939
  memset(shell_seen, 0, 5*sizeof(int));
 
6940
  shell_seen[3]=2;
 
6941
  shell_seen[4]=2;
 
6942
  
 
6943
  /* Parse arguments and read input */
 
6944
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
6945
 
 
6946
    if (shell_index==-1) {
 
6947
      exit(1);
 
6948
    }
 
6949
 
 
6950
    if (shell_seen[shell_index]==1) {
 
6951
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
6952
              shell_options[shell_index].name);
 
6953
      exit(1);
 
6954
    }
 
6955
    shell_seen[shell_index]=1;  
 
6956
 
 
6957
    switch (shell_index) {
 
6958
    case 0: /* graph */
 
6959
      shell_read_graph(&graph, optarg);
 
6960
      break;
 
6961
    case 1: /* res */
 
6962
      igraph_vector_ptr_init(&res, 0);
 
6963
      break;
 
6964
    case 2: /* from */
 
6965
      shell_read_integer(&from, optarg);
 
6966
      break;
 
6967
    case 3: /* to */
 
6968
      shell_read_vector(&v_to, optarg); igraph_vs_vector(&to, &v_to);
 
6969
      break;
 
6970
    case 4: /* mode */
 
6971
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
6972
      break;
 
6973
    case 5:
 
6974
      shell_igraph_get_shortest_paths_usage(argv);
 
6975
      break;
 
6976
    default:
 
6977
      break;
 
6978
    }
 
6979
 
 
6980
    shell_index=-1;
 
6981
  }
 
6982
 
 
6983
  /* Check that we have all arguments */
 
6984
  for (shell_index=0; shell_index<5; shell_index++) {
 
6985
    if (!shell_seen[shell_index]) {
 
6986
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
6987
              shell_options[shell_index].name);
 
6988
      exit(1);
 
6989
    }
 
6990
  }
 
6991
 
 
6992
  /* Do the operation */
 
6993
  shell_result=igraph_get_shortest_paths(&graph, &res, from, to, mode);
 
6994
 
 
6995
  /* Write the result */
 
6996
  igraph_destroy(&graph);
 
6997
  shell_write_vectorlist(&res, shell_arg_res); 
 
6998
  shell_free_vectorlist(&res); 
 
6999
  igraph_vector_ptr_destroy(&res);
 
7000
  if (!igraph_vs_is_all(&to)) { igraph_vector_destroy(&v_to); }
 
7001
 
 
7002
  return 0;
 
7003
}
 
7004
 
 
7005
/*-------------------------------------------/
 
7006
/ igraph_get_all_shortest_paths              /
 
7007
/-------------------------------------------*/
 
7008
void shell_igraph_get_all_shortest_paths_usage(char **argv) {
 
7009
  printf("%s --graph=<graph> --res=<res> --nrgeo=<nrgeo> --from=<from> --to=<to> --mode=<mode>\n", basename(argv[0]));
 
7010
  exit(1);
 
7011
}
 
7012
 
 
7013
int shell_igraph_get_all_shortest_paths(int argc, char **argv) {
 
7014
 
 
7015
  igraph_t graph;
 
7016
  igraph_vector_ptr_t res;
 
7017
  igraph_vector_t nrgeo;
 
7018
  igraph_integer_t from;
 
7019
  igraph_vector_t v_to; igraph_vs_t to;
 
7020
  igraph_neimode_t mode=IGRAPH_OUT;
 
7021
  char* shell_arg_res=0;
 
7022
  char* shell_arg_nrgeo=0;
 
7023
  int shell_result;
 
7024
 
 
7025
 
 
7026
  int shell_seen[6];
 
7027
  int shell_index=-1;
 
7028
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7029
                                   { "res",required_argument,0,1 },
 
7030
                                   { "nrgeo",required_argument,0,2 },
 
7031
                                   { "from",required_argument,0,3 },
 
7032
                                   { "to",required_argument,0,4 },
 
7033
                                   { "mode",required_argument,0,5 },
 
7034
                                   { "help",no_argument,0,6 },
 
7035
                                   { 0,0,0,0 }
 
7036
                                 };
 
7037
 
 
7038
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7039
  memset(shell_seen, 0, 6*sizeof(int));
 
7040
  shell_seen[5]=2;
 
7041
  
 
7042
  /* Parse arguments and read input */
 
7043
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7044
 
 
7045
    if (shell_index==-1) {
 
7046
      exit(1);
 
7047
    }
 
7048
 
 
7049
    if (shell_seen[shell_index]==1) {
 
7050
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7051
              shell_options[shell_index].name);
 
7052
      exit(1);
 
7053
    }
 
7054
    shell_seen[shell_index]=1;  
 
7055
 
 
7056
    switch (shell_index) {
 
7057
    case 0: /* graph */
 
7058
      shell_read_graph(&graph, optarg);
 
7059
      break;
 
7060
    case 1: /* res */
 
7061
      igraph_vector_ptr_init(&res, 0);
 
7062
      break;
 
7063
    case 2: /* nrgeo */
 
7064
      shell_arg_nrgeo=strdup(optarg); 
 
7065
  igraph_vector_init(&nrgeo, 0);
 
7066
      break;
 
7067
    case 3: /* from */
 
7068
      shell_read_integer(&from, optarg);
 
7069
      break;
 
7070
    case 4: /* to */
 
7071
      shell_read_vector(&v_to, optarg); igraph_vs_vector(&to, &v_to);
 
7072
      break;
 
7073
    case 5: /* mode */
 
7074
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
7075
      break;
 
7076
    case 6:
 
7077
      shell_igraph_get_all_shortest_paths_usage(argv);
 
7078
      break;
 
7079
    default:
 
7080
      break;
 
7081
    }
 
7082
 
 
7083
    shell_index=-1;
 
7084
  }
 
7085
 
 
7086
  /* Check that we have all arguments */
 
7087
  for (shell_index=0; shell_index<6; shell_index++) {
 
7088
    if (!shell_seen[shell_index]) {
 
7089
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7090
              shell_options[shell_index].name);
 
7091
      exit(1);
 
7092
    }
 
7093
  }
 
7094
 
 
7095
  /* Do the operation */
 
7096
  shell_result=igraph_get_all_shortest_paths(&graph, &res, &nrgeo, from, to, mode);
 
7097
 
 
7098
  /* Write the result */
 
7099
  igraph_destroy(&graph);
 
7100
  shell_write_vectorlist(&res, shell_arg_res); 
 
7101
  shell_free_vectorlist(&res); 
 
7102
  igraph_vector_ptr_destroy(&res);
 
7103
  shell_write_vector(&nrgeo, shell_arg_nrgeo); 
 
7104
  igraph_vector_destroy(&nrgeo);
 
7105
  if (!igraph_vs_is_all(&to)) { igraph_vector_destroy(&v_to); }
 
7106
 
 
7107
  return 0;
 
7108
}
 
7109
 
 
7110
/*-------------------------------------------/
 
7111
/ igraph_shortest_paths_dijkstra             /
 
7112
/-------------------------------------------*/
 
7113
void shell_igraph_shortest_paths_dijkstra_usage(char **argv) {
 
7114
  printf("%s --graph=<graph> --res=<res> --from=<from> --mode=<mode>\n", basename(argv[0]));
 
7115
  exit(1);
 
7116
}
 
7117
 
 
7118
int shell_igraph_shortest_paths_dijkstra(int argc, char **argv) {
 
7119
 
 
7120
  igraph_t graph;
 
7121
  igraph_matrix_t res;
 
7122
  igraph_vector_t v_from; igraph_vs_t from=igraph_vss_all();
 
7123
 
 
7124
  igraph_neimode_t mode=IGRAPH_OUT;
 
7125
  char* shell_arg_res=0;
 
7126
  int shell_result;
 
7127
 
 
7128
 
 
7129
  int shell_seen[4];
 
7130
  int shell_index=-1;
 
7131
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7132
                                   { "res",required_argument,0,1 },
 
7133
                                   { "from",required_argument,0,2 },
 
7134
                                   { "mode",required_argument,0,3 },
 
7135
                                   { "help",no_argument,0,4 },
 
7136
                                   { 0,0,0,0 }
 
7137
                                 };
 
7138
 
 
7139
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7140
  memset(shell_seen, 0, 4*sizeof(int));
 
7141
  shell_seen[2]=2;
 
7142
  shell_seen[3]=2;
 
7143
  
 
7144
  /* Parse arguments and read input */
 
7145
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7146
 
 
7147
    if (shell_index==-1) {
 
7148
      exit(1);
 
7149
    }
 
7150
 
 
7151
    if (shell_seen[shell_index]==1) {
 
7152
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7153
              shell_options[shell_index].name);
 
7154
      exit(1);
 
7155
    }
 
7156
    shell_seen[shell_index]=1;  
 
7157
 
 
7158
    switch (shell_index) {
 
7159
    case 0: /* graph */
 
7160
      shell_read_graph(&graph, optarg);
 
7161
      break;
 
7162
    case 1: /* res */
 
7163
      shell_arg_res=strdup(optarg); 
 
7164
  igraph_matrix_init(&res, 0, 0);
 
7165
      break;
 
7166
    case 2: /* from */
 
7167
      shell_read_vector(&v_from, optarg); igraph_vs_vector(&from, &v_from);
 
7168
      break;
 
7169
    case 3: /* mode */
 
7170
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
7171
      break;
 
7172
    case 4:
 
7173
      shell_igraph_shortest_paths_dijkstra_usage(argv);
 
7174
      break;
 
7175
    default:
 
7176
      break;
 
7177
    }
 
7178
 
 
7179
    shell_index=-1;
 
7180
  }
 
7181
 
 
7182
  /* Check that we have all arguments */
 
7183
  for (shell_index=0; shell_index<4; shell_index++) {
 
7184
    if (!shell_seen[shell_index]) {
 
7185
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7186
              shell_options[shell_index].name);
 
7187
      exit(1);
 
7188
    }
 
7189
  }
 
7190
 
 
7191
  /* Do the operation */
 
7192
  shell_result=igraph_shortest_paths_dijkstra(&graph, &res, from, 0, mode);
 
7193
 
 
7194
  /* Write the result */
 
7195
  igraph_destroy(&graph);
 
7196
  shell_write_matrix(&res, shell_arg_res); 
 
7197
  igraph_matrix_destroy(&res);
 
7198
  if (!igraph_vs_is_all(&from)) { igraph_vector_destroy(&v_from); }
 
7199
 
 
7200
  return 0;
 
7201
}
 
7202
 
 
7203
/*-------------------------------------------/
 
7204
/ igraph_shortest_paths_bellman_ford         /
 
7205
/-------------------------------------------*/
 
7206
void shell_igraph_shortest_paths_bellman_ford_usage(char **argv) {
 
7207
  printf("%s --graph=<graph> --res=<res> --from=<from> --mode=<mode>\n", basename(argv[0]));
 
7208
  exit(1);
 
7209
}
 
7210
 
 
7211
int shell_igraph_shortest_paths_bellman_ford(int argc, char **argv) {
 
7212
 
 
7213
  igraph_t graph;
 
7214
  igraph_matrix_t res;
 
7215
  igraph_vector_t v_from; igraph_vs_t from=igraph_vss_all();
 
7216
 
 
7217
  igraph_neimode_t mode=IGRAPH_OUT;
 
7218
  char* shell_arg_res=0;
 
7219
  int shell_result;
 
7220
 
 
7221
 
 
7222
  int shell_seen[4];
 
7223
  int shell_index=-1;
 
7224
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7225
                                   { "res",required_argument,0,1 },
 
7226
                                   { "from",required_argument,0,2 },
 
7227
                                   { "mode",required_argument,0,3 },
 
7228
                                   { "help",no_argument,0,4 },
 
7229
                                   { 0,0,0,0 }
 
7230
                                 };
 
7231
 
 
7232
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7233
  memset(shell_seen, 0, 4*sizeof(int));
 
7234
  shell_seen[2]=2;
 
7235
  shell_seen[3]=2;
 
7236
  
 
7237
  /* Parse arguments and read input */
 
7238
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7239
 
 
7240
    if (shell_index==-1) {
 
7241
      exit(1);
 
7242
    }
 
7243
 
 
7244
    if (shell_seen[shell_index]==1) {
 
7245
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7246
              shell_options[shell_index].name);
 
7247
      exit(1);
 
7248
    }
 
7249
    shell_seen[shell_index]=1;  
 
7250
 
 
7251
    switch (shell_index) {
 
7252
    case 0: /* graph */
 
7253
      shell_read_graph(&graph, optarg);
 
7254
      break;
 
7255
    case 1: /* res */
 
7256
      shell_arg_res=strdup(optarg); 
 
7257
  igraph_matrix_init(&res, 0, 0);
 
7258
      break;
 
7259
    case 2: /* from */
 
7260
      shell_read_vector(&v_from, optarg); igraph_vs_vector(&from, &v_from);
 
7261
      break;
 
7262
    case 3: /* mode */
 
7263
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
7264
      break;
 
7265
    case 4:
 
7266
      shell_igraph_shortest_paths_bellman_ford_usage(argv);
 
7267
      break;
 
7268
    default:
 
7269
      break;
 
7270
    }
 
7271
 
 
7272
    shell_index=-1;
 
7273
  }
 
7274
 
 
7275
  /* Check that we have all arguments */
 
7276
  for (shell_index=0; shell_index<4; shell_index++) {
 
7277
    if (!shell_seen[shell_index]) {
 
7278
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7279
              shell_options[shell_index].name);
 
7280
      exit(1);
 
7281
    }
 
7282
  }
 
7283
 
 
7284
  /* Do the operation */
 
7285
  shell_result=igraph_shortest_paths_bellman_ford(&graph, &res, from, 0, mode);
 
7286
 
 
7287
  /* Write the result */
 
7288
  igraph_destroy(&graph);
 
7289
  shell_write_matrix(&res, shell_arg_res); 
 
7290
  igraph_matrix_destroy(&res);
 
7291
  if (!igraph_vs_is_all(&from)) { igraph_vector_destroy(&v_from); }
 
7292
 
 
7293
  return 0;
 
7294
}
 
7295
 
 
7296
/*-------------------------------------------/
 
7297
/ igraph_subcomponent                        /
 
7298
/-------------------------------------------*/
 
7299
void shell_igraph_subcomponent_usage(char **argv) {
 
7300
  printf("%s --graph=<graph> --res=<res> --vid=<vid> --mode=<mode>\n", basename(argv[0]));
 
7301
  exit(1);
 
7302
}
 
7303
 
 
7304
int shell_igraph_subcomponent(int argc, char **argv) {
 
7305
 
 
7306
  igraph_t graph;
 
7307
  igraph_vector_t res;
 
7308
  igraph_real_t vid;
 
7309
  igraph_neimode_t mode=IGRAPH_ALL;
 
7310
  char* shell_arg_res=0;
 
7311
  int shell_result;
 
7312
 
 
7313
 
 
7314
  int shell_seen[4];
 
7315
  int shell_index=-1;
 
7316
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7317
                                   { "res",required_argument,0,1 },
 
7318
                                   { "vid",required_argument,0,2 },
 
7319
                                   { "mode",required_argument,0,3 },
 
7320
                                   { "help",no_argument,0,4 },
 
7321
                                   { 0,0,0,0 }
 
7322
                                 };
 
7323
 
 
7324
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7325
  memset(shell_seen, 0, 4*sizeof(int));
 
7326
  shell_seen[3]=2;
 
7327
  
 
7328
  /* Parse arguments and read input */
 
7329
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7330
 
 
7331
    if (shell_index==-1) {
 
7332
      exit(1);
 
7333
    }
 
7334
 
 
7335
    if (shell_seen[shell_index]==1) {
 
7336
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7337
              shell_options[shell_index].name);
 
7338
      exit(1);
 
7339
    }
 
7340
    shell_seen[shell_index]=1;  
 
7341
 
 
7342
    switch (shell_index) {
 
7343
    case 0: /* graph */
 
7344
      shell_read_graph(&graph, optarg);
 
7345
      break;
 
7346
    case 1: /* res */
 
7347
      shell_arg_res=strdup(optarg); 
 
7348
  igraph_vector_init(&res, 0);
 
7349
      break;
 
7350
    case 2: /* vid */
 
7351
      shell_read_real(&vid, optarg);
 
7352
      break;
 
7353
    case 3: /* mode */
 
7354
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
7355
      break;
 
7356
    case 4:
 
7357
      shell_igraph_subcomponent_usage(argv);
 
7358
      break;
 
7359
    default:
 
7360
      break;
 
7361
    }
 
7362
 
 
7363
    shell_index=-1;
 
7364
  }
 
7365
 
 
7366
  /* Check that we have all arguments */
 
7367
  for (shell_index=0; shell_index<4; shell_index++) {
 
7368
    if (!shell_seen[shell_index]) {
 
7369
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7370
              shell_options[shell_index].name);
 
7371
      exit(1);
 
7372
    }
 
7373
  }
 
7374
 
 
7375
  /* Do the operation */
 
7376
  shell_result=igraph_subcomponent(&graph, &res, vid, mode);
 
7377
 
 
7378
  /* Write the result */
 
7379
  igraph_destroy(&graph);
 
7380
  shell_write_vector(&res, shell_arg_res); 
 
7381
  igraph_vector_destroy(&res);
 
7382
 
 
7383
  return 0;
 
7384
}
 
7385
 
 
7386
/*-------------------------------------------/
 
7387
/ igraph_betweenness                         /
 
7388
/-------------------------------------------*/
 
7389
void shell_igraph_betweenness_usage(char **argv) {
 
7390
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --directed=<directed>\n", basename(argv[0]));
 
7391
  exit(1);
 
7392
}
 
7393
 
 
7394
int shell_igraph_betweenness(int argc, char **argv) {
 
7395
 
 
7396
  igraph_t graph;
 
7397
  igraph_vector_t res;
 
7398
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
7399
  igraph_bool_t directed=1;
 
7400
  char* shell_arg_res=0;
 
7401
  int shell_result;
 
7402
 
 
7403
 
 
7404
  int shell_seen[4];
 
7405
  int shell_index=-1;
 
7406
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7407
                                   { "res",required_argument,0,1 },
 
7408
                                   { "vids",required_argument,0,2 },
 
7409
                                   { "directed",required_argument,0,3 },
 
7410
                                   { "help",no_argument,0,4 },
 
7411
                                   { 0,0,0,0 }
 
7412
                                 };
 
7413
 
 
7414
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7415
  memset(shell_seen, 0, 4*sizeof(int));
 
7416
  shell_seen[2]=2;
 
7417
  shell_seen[3]=2;
 
7418
  
 
7419
  /* Parse arguments and read input */
 
7420
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7421
 
 
7422
    if (shell_index==-1) {
 
7423
      exit(1);
 
7424
    }
 
7425
 
 
7426
    if (shell_seen[shell_index]==1) {
 
7427
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7428
              shell_options[shell_index].name);
 
7429
      exit(1);
 
7430
    }
 
7431
    shell_seen[shell_index]=1;  
 
7432
 
 
7433
    switch (shell_index) {
 
7434
    case 0: /* graph */
 
7435
      shell_read_graph(&graph, optarg);
 
7436
      break;
 
7437
    case 1: /* res */
 
7438
      shell_arg_res=strdup(optarg); 
 
7439
  igraph_vector_init(&res, 0);
 
7440
      break;
 
7441
    case 2: /* vids */
 
7442
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
7443
      break;
 
7444
    case 3: /* directed */
 
7445
      shell_read_boolean(&directed, optarg);
 
7446
      break;
 
7447
    case 4:
 
7448
      shell_igraph_betweenness_usage(argv);
 
7449
      break;
 
7450
    default:
 
7451
      break;
 
7452
    }
 
7453
 
 
7454
    shell_index=-1;
 
7455
  }
 
7456
 
 
7457
  /* Check that we have all arguments */
 
7458
  for (shell_index=0; shell_index<4; shell_index++) {
 
7459
    if (!shell_seen[shell_index]) {
 
7460
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7461
              shell_options[shell_index].name);
 
7462
      exit(1);
 
7463
    }
 
7464
  }
 
7465
 
 
7466
  /* Do the operation */
 
7467
  shell_result=igraph_betweenness(&graph, &res, vids, directed);
 
7468
 
 
7469
  /* Write the result */
 
7470
  igraph_destroy(&graph);
 
7471
  shell_write_vector(&res, shell_arg_res); 
 
7472
  igraph_vector_destroy(&res);
 
7473
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
7474
 
 
7475
  return 0;
 
7476
}
 
7477
 
 
7478
/*-------------------------------------------/
 
7479
/ igraph_betweenness_estimate                /
 
7480
/-------------------------------------------*/
 
7481
void shell_igraph_betweenness_estimate_usage(char **argv) {
 
7482
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --directed=<directed> --cutoff=<cutoff>\n", basename(argv[0]));
 
7483
  exit(1);
 
7484
}
 
7485
 
 
7486
int shell_igraph_betweenness_estimate(int argc, char **argv) {
 
7487
 
 
7488
  igraph_t graph;
 
7489
  igraph_vector_t res;
 
7490
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
7491
  igraph_bool_t directed=1;
 
7492
  igraph_integer_t cutoff;
 
7493
  char* shell_arg_res=0;
 
7494
  int shell_result;
 
7495
 
 
7496
 
 
7497
  int shell_seen[5];
 
7498
  int shell_index=-1;
 
7499
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7500
                                   { "res",required_argument,0,1 },
 
7501
                                   { "vids",required_argument,0,2 },
 
7502
                                   { "directed",required_argument,0,3 },
 
7503
                                   { "cutoff",required_argument,0,4 },
 
7504
                                   { "help",no_argument,0,5 },
 
7505
                                   { 0,0,0,0 }
 
7506
                                 };
 
7507
 
 
7508
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7509
  memset(shell_seen, 0, 5*sizeof(int));
 
7510
  shell_seen[2]=2;
 
7511
  shell_seen[3]=2;
 
7512
  
 
7513
  /* Parse arguments and read input */
 
7514
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7515
 
 
7516
    if (shell_index==-1) {
 
7517
      exit(1);
 
7518
    }
 
7519
 
 
7520
    if (shell_seen[shell_index]==1) {
 
7521
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7522
              shell_options[shell_index].name);
 
7523
      exit(1);
 
7524
    }
 
7525
    shell_seen[shell_index]=1;  
 
7526
 
 
7527
    switch (shell_index) {
 
7528
    case 0: /* graph */
 
7529
      shell_read_graph(&graph, optarg);
 
7530
      break;
 
7531
    case 1: /* res */
 
7532
      shell_arg_res=strdup(optarg); 
 
7533
  igraph_vector_init(&res, 0);
 
7534
      break;
 
7535
    case 2: /* vids */
 
7536
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
7537
      break;
 
7538
    case 3: /* directed */
 
7539
      shell_read_boolean(&directed, optarg);
 
7540
      break;
 
7541
    case 4: /* cutoff */
 
7542
      shell_read_integer(&cutoff, optarg);
 
7543
      break;
 
7544
    case 5:
 
7545
      shell_igraph_betweenness_estimate_usage(argv);
 
7546
      break;
 
7547
    default:
 
7548
      break;
 
7549
    }
 
7550
 
 
7551
    shell_index=-1;
 
7552
  }
 
7553
 
 
7554
  /* Check that we have all arguments */
 
7555
  for (shell_index=0; shell_index<5; shell_index++) {
 
7556
    if (!shell_seen[shell_index]) {
 
7557
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7558
              shell_options[shell_index].name);
 
7559
      exit(1);
 
7560
    }
 
7561
  }
 
7562
 
 
7563
  /* Do the operation */
 
7564
  shell_result=igraph_betweenness_estimate(&graph, &res, vids, directed, cutoff);
 
7565
 
 
7566
  /* Write the result */
 
7567
  igraph_destroy(&graph);
 
7568
  shell_write_vector(&res, shell_arg_res); 
 
7569
  igraph_vector_destroy(&res);
 
7570
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
7571
 
 
7572
  return 0;
 
7573
}
 
7574
 
 
7575
/*-------------------------------------------/
 
7576
/ igraph_edge_betweenness                    /
 
7577
/-------------------------------------------*/
 
7578
void shell_igraph_edge_betweenness_usage(char **argv) {
 
7579
  printf("%s --graph=<graph> --res=<res> --directed=<directed>\n", basename(argv[0]));
 
7580
  exit(1);
 
7581
}
 
7582
 
 
7583
int shell_igraph_edge_betweenness(int argc, char **argv) {
 
7584
 
 
7585
  igraph_t graph;
 
7586
  igraph_vector_t res;
 
7587
  igraph_bool_t directed=1;
 
7588
  char* shell_arg_res=0;
 
7589
  int shell_result;
 
7590
 
 
7591
 
 
7592
  int shell_seen[3];
 
7593
  int shell_index=-1;
 
7594
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7595
                                   { "res",required_argument,0,1 },
 
7596
                                   { "directed",required_argument,0,2 },
 
7597
                                   { "help",no_argument,0,3 },
 
7598
                                   { 0,0,0,0 }
 
7599
                                 };
 
7600
 
 
7601
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7602
  memset(shell_seen, 0, 3*sizeof(int));
 
7603
  shell_seen[2]=2;
 
7604
  
 
7605
  /* Parse arguments and read input */
 
7606
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7607
 
 
7608
    if (shell_index==-1) {
 
7609
      exit(1);
 
7610
    }
 
7611
 
 
7612
    if (shell_seen[shell_index]==1) {
 
7613
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7614
              shell_options[shell_index].name);
 
7615
      exit(1);
 
7616
    }
 
7617
    shell_seen[shell_index]=1;  
 
7618
 
 
7619
    switch (shell_index) {
 
7620
    case 0: /* graph */
 
7621
      shell_read_graph(&graph, optarg);
 
7622
      break;
 
7623
    case 1: /* res */
 
7624
      shell_arg_res=strdup(optarg); 
 
7625
  igraph_vector_init(&res, 0);
 
7626
      break;
 
7627
    case 2: /* directed */
 
7628
      shell_read_boolean(&directed, optarg);
 
7629
      break;
 
7630
    case 3:
 
7631
      shell_igraph_edge_betweenness_usage(argv);
 
7632
      break;
 
7633
    default:
 
7634
      break;
 
7635
    }
 
7636
 
 
7637
    shell_index=-1;
 
7638
  }
 
7639
 
 
7640
  /* Check that we have all arguments */
 
7641
  for (shell_index=0; shell_index<3; shell_index++) {
 
7642
    if (!shell_seen[shell_index]) {
 
7643
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7644
              shell_options[shell_index].name);
 
7645
      exit(1);
 
7646
    }
 
7647
  }
 
7648
 
 
7649
  /* Do the operation */
 
7650
  shell_result=igraph_edge_betweenness(&graph, &res, directed);
 
7651
 
 
7652
  /* Write the result */
 
7653
  igraph_destroy(&graph);
 
7654
  shell_write_vector(&res, shell_arg_res); 
 
7655
  igraph_vector_destroy(&res);
 
7656
 
 
7657
  return 0;
 
7658
}
 
7659
 
 
7660
/*-------------------------------------------/
 
7661
/ igraph_edge_betweenness_estimate           /
 
7662
/-------------------------------------------*/
 
7663
void shell_igraph_edge_betweenness_estimate_usage(char **argv) {
 
7664
  printf("%s --graph=<graph> --res=<res> --directed=<directed> --cutoff=<cutoff>\n", basename(argv[0]));
 
7665
  exit(1);
 
7666
}
 
7667
 
 
7668
int shell_igraph_edge_betweenness_estimate(int argc, char **argv) {
 
7669
 
 
7670
  igraph_t graph;
 
7671
  igraph_vector_t res;
 
7672
  igraph_bool_t directed=1;
 
7673
  igraph_integer_t cutoff;
 
7674
  char* shell_arg_res=0;
 
7675
  int shell_result;
 
7676
 
 
7677
 
 
7678
  int shell_seen[4];
 
7679
  int shell_index=-1;
 
7680
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7681
                                   { "res",required_argument,0,1 },
 
7682
                                   { "directed",required_argument,0,2 },
 
7683
                                   { "cutoff",required_argument,0,3 },
 
7684
                                   { "help",no_argument,0,4 },
 
7685
                                   { 0,0,0,0 }
 
7686
                                 };
 
7687
 
 
7688
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7689
  memset(shell_seen, 0, 4*sizeof(int));
 
7690
  shell_seen[2]=2;
 
7691
  
 
7692
  /* Parse arguments and read input */
 
7693
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7694
 
 
7695
    if (shell_index==-1) {
 
7696
      exit(1);
 
7697
    }
 
7698
 
 
7699
    if (shell_seen[shell_index]==1) {
 
7700
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7701
              shell_options[shell_index].name);
 
7702
      exit(1);
 
7703
    }
 
7704
    shell_seen[shell_index]=1;  
 
7705
 
 
7706
    switch (shell_index) {
 
7707
    case 0: /* graph */
 
7708
      shell_read_graph(&graph, optarg);
 
7709
      break;
 
7710
    case 1: /* res */
 
7711
      shell_arg_res=strdup(optarg); 
 
7712
  igraph_vector_init(&res, 0);
 
7713
      break;
 
7714
    case 2: /* directed */
 
7715
      shell_read_boolean(&directed, optarg);
 
7716
      break;
 
7717
    case 3: /* cutoff */
 
7718
      shell_read_integer(&cutoff, optarg);
 
7719
      break;
 
7720
    case 4:
 
7721
      shell_igraph_edge_betweenness_estimate_usage(argv);
 
7722
      break;
 
7723
    default:
 
7724
      break;
 
7725
    }
 
7726
 
 
7727
    shell_index=-1;
 
7728
  }
 
7729
 
 
7730
  /* Check that we have all arguments */
 
7731
  for (shell_index=0; shell_index<4; shell_index++) {
 
7732
    if (!shell_seen[shell_index]) {
 
7733
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7734
              shell_options[shell_index].name);
 
7735
      exit(1);
 
7736
    }
 
7737
  }
 
7738
 
 
7739
  /* Do the operation */
 
7740
  shell_result=igraph_edge_betweenness_estimate(&graph, &res, directed, cutoff);
 
7741
 
 
7742
  /* Write the result */
 
7743
  igraph_destroy(&graph);
 
7744
  shell_write_vector(&res, shell_arg_res); 
 
7745
  igraph_vector_destroy(&res);
 
7746
 
 
7747
  return 0;
 
7748
}
 
7749
 
 
7750
/*-------------------------------------------/
 
7751
/ igraph_pagerank_old                        /
 
7752
/-------------------------------------------*/
 
7753
void shell_igraph_pagerank_old_usage(char **argv) {
 
7754
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --directed=<directed> --niter=<niter> --eps=<eps> --damping=<damping> --old=<old>\n", basename(argv[0]));
 
7755
  exit(1);
 
7756
}
 
7757
 
 
7758
int shell_igraph_pagerank_old(int argc, char **argv) {
 
7759
 
 
7760
  igraph_t graph;
 
7761
  igraph_vector_t res;
 
7762
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
7763
  igraph_bool_t directed=1;
 
7764
  igraph_integer_t niter=1000;
 
7765
  igraph_real_t eps=0.001;
 
7766
  igraph_real_t damping=0.85;
 
7767
  igraph_bool_t old=0;
 
7768
  char* shell_arg_res=0;
 
7769
  int shell_result;
 
7770
 
 
7771
 
 
7772
  int shell_seen[8];
 
7773
  int shell_index=-1;
 
7774
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7775
                                   { "res",required_argument,0,1 },
 
7776
                                   { "vids",required_argument,0,2 },
 
7777
                                   { "directed",required_argument,0,3 },
 
7778
                                   { "niter",required_argument,0,4 },
 
7779
                                   { "eps",required_argument,0,5 },
 
7780
                                   { "damping",required_argument,0,6 },
 
7781
                                   { "old",required_argument,0,7 },
 
7782
                                   { "help",no_argument,0,8 },
 
7783
                                   { 0,0,0,0 }
 
7784
                                 };
 
7785
 
 
7786
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7787
  memset(shell_seen, 0, 8*sizeof(int));
 
7788
  shell_seen[2]=2;
 
7789
  shell_seen[3]=2;
 
7790
  shell_seen[4]=2;
 
7791
  shell_seen[5]=2;
 
7792
  shell_seen[6]=2;
 
7793
  shell_seen[7]=2;
 
7794
  
 
7795
  /* Parse arguments and read input */
 
7796
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7797
 
 
7798
    if (shell_index==-1) {
 
7799
      exit(1);
 
7800
    }
 
7801
 
 
7802
    if (shell_seen[shell_index]==1) {
 
7803
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7804
              shell_options[shell_index].name);
 
7805
      exit(1);
 
7806
    }
 
7807
    shell_seen[shell_index]=1;  
 
7808
 
 
7809
    switch (shell_index) {
 
7810
    case 0: /* graph */
 
7811
      shell_read_graph(&graph, optarg);
 
7812
      break;
 
7813
    case 1: /* res */
 
7814
      shell_arg_res=strdup(optarg); 
 
7815
  igraph_vector_init(&res, 0);
 
7816
      break;
 
7817
    case 2: /* vids */
 
7818
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
7819
      break;
 
7820
    case 3: /* directed */
 
7821
      shell_read_boolean(&directed, optarg);
 
7822
      break;
 
7823
    case 4: /* niter */
 
7824
      shell_read_integer(&niter, optarg);
 
7825
      break;
 
7826
    case 5: /* eps */
 
7827
      shell_read_real(&eps, optarg);
 
7828
      break;
 
7829
    case 6: /* damping */
 
7830
      shell_read_real(&damping, optarg);
 
7831
      break;
 
7832
    case 7: /* old */
 
7833
      shell_read_boolean(&old, optarg);
 
7834
      break;
 
7835
    case 8:
 
7836
      shell_igraph_pagerank_old_usage(argv);
 
7837
      break;
 
7838
    default:
 
7839
      break;
 
7840
    }
 
7841
 
 
7842
    shell_index=-1;
 
7843
  }
 
7844
 
 
7845
  /* Check that we have all arguments */
 
7846
  for (shell_index=0; shell_index<8; shell_index++) {
 
7847
    if (!shell_seen[shell_index]) {
 
7848
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7849
              shell_options[shell_index].name);
 
7850
      exit(1);
 
7851
    }
 
7852
  }
 
7853
 
 
7854
  /* Do the operation */
 
7855
  shell_result=igraph_pagerank_old(&graph, &res, vids, directed, niter, eps, damping, old);
 
7856
 
 
7857
  /* Write the result */
 
7858
  igraph_destroy(&graph);
 
7859
  shell_write_vector(&res, shell_arg_res); 
 
7860
  igraph_vector_destroy(&res);
 
7861
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
7862
 
 
7863
  return 0;
 
7864
}
 
7865
 
 
7866
/*-------------------------------------------/
 
7867
/ igraph_pagerank                            /
 
7868
/-------------------------------------------*/
 
7869
void shell_igraph_pagerank_usage(char **argv) {
 
7870
  printf("%s --graph=<graph> --vector=<vector> --value=<value> --vids=<vids> --directed=<directed> --damping=<damping>\n", basename(argv[0]));
 
7871
  exit(1);
 
7872
}
 
7873
 
 
7874
int shell_igraph_pagerank(int argc, char **argv) {
 
7875
 
 
7876
  igraph_t graph;
 
7877
  igraph_vector_t vector;
 
7878
  igraph_real_t value;
 
7879
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
7880
  igraph_bool_t directed=1;
 
7881
  igraph_real_t damping=0.85;
 
7882
 
 
7883
 
 
7884
  char* shell_arg_vector=0;
 
7885
  char* shell_arg_value=0;
 
7886
  char* shell_arg_options=0;
 
7887
  int shell_result;
 
7888
 
 
7889
 
 
7890
  int shell_seen[6];
 
7891
  int shell_index=-1;
 
7892
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
7893
                                   { "vector",required_argument,0,1 },
 
7894
                                   { "value",required_argument,0,2 },
 
7895
                                   { "vids",required_argument,0,3 },
 
7896
                                   { "directed",required_argument,0,4 },
 
7897
                                   { "damping",required_argument,0,5 },
 
7898
                                   { "help",no_argument,0,6 },
 
7899
                                   { 0,0,0,0 }
 
7900
                                 };
 
7901
 
 
7902
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
7903
  memset(shell_seen, 0, 6*sizeof(int));
 
7904
  shell_seen[3]=2;
 
7905
  shell_seen[4]=2;
 
7906
  shell_seen[5]=2;
 
7907
  
 
7908
  /* Parse arguments and read input */
 
7909
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
7910
 
 
7911
    if (shell_index==-1) {
 
7912
      exit(1);
 
7913
    }
 
7914
 
 
7915
    if (shell_seen[shell_index]==1) {
 
7916
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
7917
              shell_options[shell_index].name);
 
7918
      exit(1);
 
7919
    }
 
7920
    shell_seen[shell_index]=1;  
 
7921
 
 
7922
    switch (shell_index) {
 
7923
    case 0: /* graph */
 
7924
      shell_read_graph(&graph, optarg);
 
7925
      break;
 
7926
    case 1: /* vector */
 
7927
      shell_arg_vector=strdup(optarg); 
 
7928
  igraph_vector_init(&vector, 0);
 
7929
      break;
 
7930
    case 2: /* value */
 
7931
      shell_arg_value=strdup(optarg);
 
7932
      break;
 
7933
    case 3: /* vids */
 
7934
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
7935
      break;
 
7936
    case 4: /* directed */
 
7937
      shell_read_boolean(&directed, optarg);
 
7938
      break;
 
7939
    case 5: /* damping */
 
7940
      shell_read_real(&damping, optarg);
 
7941
      break;
 
7942
    case 6:
 
7943
      shell_igraph_pagerank_usage(argv);
 
7944
      break;
 
7945
    default:
 
7946
      break;
 
7947
    }
 
7948
 
 
7949
    shell_index=-1;
 
7950
  }
 
7951
 
 
7952
  /* Check that we have all arguments */
 
7953
  for (shell_index=0; shell_index<6; shell_index++) {
 
7954
    if (!shell_seen[shell_index]) {
 
7955
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
7956
              shell_options[shell_index].name);
 
7957
      exit(1);
 
7958
    }
 
7959
  }
 
7960
 
 
7961
  /* Do the operation */
 
7962
  shell_result=igraph_pagerank(&graph, &vector, &value, vids, directed, damping, 0, 0);
 
7963
 
 
7964
  /* Write the result */
 
7965
  igraph_destroy(&graph);
 
7966
  shell_write_vector(&vector, shell_arg_vector); 
 
7967
  igraph_vector_destroy(&vector);
 
7968
  shell_write_real(value, shell_arg_value);
 
7969
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
7970
 
 
7971
  return 0;
 
7972
}
 
7973
 
 
7974
/*-------------------------------------------/
 
7975
/ igraph_rewire                              /
 
7976
/-------------------------------------------*/
 
7977
void shell_igraph_rewire_usage(char **argv) {
 
7978
  printf("%s --rewire=<rewire> --rewire-out=<rewire-out> --n=<n> --mode=<mode>\n", basename(argv[0]));
 
7979
  exit(1);
 
7980
}
 
7981
 
 
7982
int shell_igraph_rewire(int argc, char **argv) {
 
7983
 
 
7984
  igraph_t rewire;
 
7985
  igraph_integer_t n;
 
7986
  igraph_rewiring_t mode=IGRAPH_REWIRING_SIMPLE;
 
7987
  char* shell_arg_rewire=0;
 
7988
  int shell_result;
 
7989
 
 
7990
 
 
7991
  int shell_seen[4];
 
7992
  int shell_index=-1;
 
7993
  struct option shell_options[]= { { "rewire",required_argument,0,0 },
 
7994
                                   { "rewire-out",required_argument,0,1 },
 
7995
                                   { "n",required_argument,0,2 },
 
7996
                                   { "mode",required_argument,0,3 },
 
7997
                                   { "help",no_argument,0,4 },
 
7998
                                   { 0,0,0,0 }
 
7999
                                 };
 
8000
 
 
8001
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8002
  memset(shell_seen, 0, 4*sizeof(int));
 
8003
  shell_seen[3]=2;
 
8004
  
 
8005
  /* Parse arguments and read input */
 
8006
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8007
 
 
8008
    if (shell_index==-1) {
 
8009
      exit(1);
 
8010
    }
 
8011
 
 
8012
    if (shell_seen[shell_index]==1) {
 
8013
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8014
              shell_options[shell_index].name);
 
8015
      exit(1);
 
8016
    }
 
8017
    shell_seen[shell_index]=1;  
 
8018
 
 
8019
    switch (shell_index) {
 
8020
    case 0: /* rewire */
 
8021
      shell_read_graph(&rewire, optarg);
 
8022
      break;
 
8023
    case 1: /* rewire-out */
 
8024
      shell_arg_rewire=strdup(optarg);
 
8025
      break;
 
8026
    case 2: /* n */
 
8027
      shell_read_integer(&n, optarg);
 
8028
      break;
 
8029
    case 3: /* mode */
 
8030
      shell_read_enum(&mode, optarg, "simple", 0, 0);
 
8031
      break;
 
8032
    case 4:
 
8033
      shell_igraph_rewire_usage(argv);
 
8034
      break;
 
8035
    default:
 
8036
      break;
 
8037
    }
 
8038
 
 
8039
    shell_index=-1;
 
8040
  }
 
8041
 
 
8042
  /* Check that we have all arguments */
 
8043
  for (shell_index=0; shell_index<4; shell_index++) {
 
8044
    if (!shell_seen[shell_index]) {
 
8045
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8046
              shell_options[shell_index].name);
 
8047
      exit(1);
 
8048
    }
 
8049
  }
 
8050
 
 
8051
  /* Do the operation */
 
8052
  shell_result=igraph_rewire(&rewire, n, mode);
 
8053
 
 
8054
  /* Write the result */
 
8055
  igraph_destroy(&rewire);
 
8056
  shell_write_graph(&rewire, shell_arg_rewire); 
 
8057
  igraph_destroy(&rewire);
 
8058
 
 
8059
  return 0;
 
8060
}
 
8061
 
 
8062
/*-------------------------------------------/
 
8063
/ igraph_subgraph                            /
 
8064
/-------------------------------------------*/
 
8065
void shell_igraph_subgraph_usage(char **argv) {
 
8066
  printf("%s --graph=<graph> --res=<res> --vids=<vids>\n", basename(argv[0]));
 
8067
  exit(1);
 
8068
}
 
8069
 
 
8070
int shell_igraph_subgraph(int argc, char **argv) {
 
8071
 
 
8072
  igraph_t graph;
 
8073
  igraph_t res;
 
8074
  igraph_vector_t v_vids; igraph_vs_t vids;
 
8075
  char* shell_arg_res=0;
 
8076
  int shell_result;
 
8077
 
 
8078
 
 
8079
  int shell_seen[3];
 
8080
  int shell_index=-1;
 
8081
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8082
                                   { "res",required_argument,0,1 },
 
8083
                                   { "vids",required_argument,0,2 },
 
8084
                                   { "help",no_argument,0,3 },
 
8085
                                   { 0,0,0,0 }
 
8086
                                 };
 
8087
 
 
8088
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8089
  memset(shell_seen, 0, 3*sizeof(int));
 
8090
 
 
8091
  
 
8092
  /* Parse arguments and read input */
 
8093
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8094
 
 
8095
    if (shell_index==-1) {
 
8096
      exit(1);
 
8097
    }
 
8098
 
 
8099
    if (shell_seen[shell_index]==1) {
 
8100
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8101
              shell_options[shell_index].name);
 
8102
      exit(1);
 
8103
    }
 
8104
    shell_seen[shell_index]=1;  
 
8105
 
 
8106
    switch (shell_index) {
 
8107
    case 0: /* graph */
 
8108
      shell_read_graph(&graph, optarg);
 
8109
      break;
 
8110
    case 1: /* res */
 
8111
      shell_arg_res=strdup(optarg);
 
8112
      break;
 
8113
    case 2: /* vids */
 
8114
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
8115
      break;
 
8116
    case 3:
 
8117
      shell_igraph_subgraph_usage(argv);
 
8118
      break;
 
8119
    default:
 
8120
      break;
 
8121
    }
 
8122
 
 
8123
    shell_index=-1;
 
8124
  }
 
8125
 
 
8126
  /* Check that we have all arguments */
 
8127
  for (shell_index=0; shell_index<3; shell_index++) {
 
8128
    if (!shell_seen[shell_index]) {
 
8129
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8130
              shell_options[shell_index].name);
 
8131
      exit(1);
 
8132
    }
 
8133
  }
 
8134
 
 
8135
  /* Do the operation */
 
8136
  shell_result=igraph_subgraph(&graph, &res, vids);
 
8137
 
 
8138
  /* Write the result */
 
8139
  igraph_destroy(&graph);
 
8140
  shell_write_graph(&res, shell_arg_res); 
 
8141
  igraph_destroy(&res);
 
8142
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
8143
 
 
8144
  return 0;
 
8145
}
 
8146
 
 
8147
/*-------------------------------------------/
 
8148
/ igraph_average_path_length                 /
 
8149
/-------------------------------------------*/
 
8150
void shell_igraph_average_path_length_usage(char **argv) {
 
8151
  printf("%s --graph=<graph> --res=<res> --directed=<directed> --unconn=<unconn>\n", basename(argv[0]));
 
8152
  exit(1);
 
8153
}
 
8154
 
 
8155
int shell_igraph_average_path_length(int argc, char **argv) {
 
8156
 
 
8157
  igraph_t graph;
 
8158
  igraph_real_t res;
 
8159
  igraph_bool_t directed=1;
 
8160
  igraph_bool_t unconn=1;
 
8161
  char* shell_arg_res=0;
 
8162
  int shell_result;
 
8163
 
 
8164
 
 
8165
  int shell_seen[4];
 
8166
  int shell_index=-1;
 
8167
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8168
                                   { "res",required_argument,0,1 },
 
8169
                                   { "directed",required_argument,0,2 },
 
8170
                                   { "unconn",required_argument,0,3 },
 
8171
                                   { "help",no_argument,0,4 },
 
8172
                                   { 0,0,0,0 }
 
8173
                                 };
 
8174
 
 
8175
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8176
  memset(shell_seen, 0, 4*sizeof(int));
 
8177
  shell_seen[2]=2;
 
8178
  shell_seen[3]=2;
 
8179
  
 
8180
  /* Parse arguments and read input */
 
8181
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8182
 
 
8183
    if (shell_index==-1) {
 
8184
      exit(1);
 
8185
    }
 
8186
 
 
8187
    if (shell_seen[shell_index]==1) {
 
8188
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8189
              shell_options[shell_index].name);
 
8190
      exit(1);
 
8191
    }
 
8192
    shell_seen[shell_index]=1;  
 
8193
 
 
8194
    switch (shell_index) {
 
8195
    case 0: /* graph */
 
8196
      shell_read_graph(&graph, optarg);
 
8197
      break;
 
8198
    case 1: /* res */
 
8199
      shell_arg_res=strdup(optarg);
 
8200
      break;
 
8201
    case 2: /* directed */
 
8202
      shell_read_boolean(&directed, optarg);
 
8203
      break;
 
8204
    case 3: /* unconn */
 
8205
      shell_read_boolean(&unconn, optarg);
 
8206
      break;
 
8207
    case 4:
 
8208
      shell_igraph_average_path_length_usage(argv);
 
8209
      break;
 
8210
    default:
 
8211
      break;
 
8212
    }
 
8213
 
 
8214
    shell_index=-1;
 
8215
  }
 
8216
 
 
8217
  /* Check that we have all arguments */
 
8218
  for (shell_index=0; shell_index<4; shell_index++) {
 
8219
    if (!shell_seen[shell_index]) {
 
8220
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8221
              shell_options[shell_index].name);
 
8222
      exit(1);
 
8223
    }
 
8224
  }
 
8225
 
 
8226
  /* Do the operation */
 
8227
  shell_result=igraph_average_path_length(&graph, &res, directed, unconn);
 
8228
 
 
8229
  /* Write the result */
 
8230
  igraph_destroy(&graph);
 
8231
  shell_write_real(res, shell_arg_res);
 
8232
 
 
8233
  return 0;
 
8234
}
 
8235
 
 
8236
/*-------------------------------------------/
 
8237
/ igraph_path_length_hist                    /
 
8238
/-------------------------------------------*/
 
8239
void shell_igraph_path_length_hist_usage(char **argv) {
 
8240
  printf("%s --graph=<graph> --res=<res> --unconnected=<unconnected> --directed=<directed>\n", basename(argv[0]));
 
8241
  exit(1);
 
8242
}
 
8243
 
 
8244
int shell_igraph_path_length_hist(int argc, char **argv) {
 
8245
 
 
8246
  igraph_t graph;
 
8247
  igraph_vector_t res;
 
8248
  igraph_real_t unconnected;
 
8249
  igraph_bool_t directed=1;
 
8250
  char* shell_arg_res=0;
 
8251
  char* shell_arg_unconnected=0;
 
8252
  int shell_result;
 
8253
 
 
8254
 
 
8255
  int shell_seen[4];
 
8256
  int shell_index=-1;
 
8257
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8258
                                   { "res",required_argument,0,1 },
 
8259
                                   { "unconnected",required_argument,0,2 },
 
8260
                                   { "directed",required_argument,0,3 },
 
8261
                                   { "help",no_argument,0,4 },
 
8262
                                   { 0,0,0,0 }
 
8263
                                 };
 
8264
 
 
8265
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8266
  memset(shell_seen, 0, 4*sizeof(int));
 
8267
  shell_seen[3]=2;
 
8268
  
 
8269
  /* Parse arguments and read input */
 
8270
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8271
 
 
8272
    if (shell_index==-1) {
 
8273
      exit(1);
 
8274
    }
 
8275
 
 
8276
    if (shell_seen[shell_index]==1) {
 
8277
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8278
              shell_options[shell_index].name);
 
8279
      exit(1);
 
8280
    }
 
8281
    shell_seen[shell_index]=1;  
 
8282
 
 
8283
    switch (shell_index) {
 
8284
    case 0: /* graph */
 
8285
      shell_read_graph(&graph, optarg);
 
8286
      break;
 
8287
    case 1: /* res */
 
8288
      shell_arg_res=strdup(optarg); 
 
8289
  igraph_vector_init(&res, 0);
 
8290
      break;
 
8291
    case 2: /* unconnected */
 
8292
      shell_arg_unconnected=strdup(optarg);
 
8293
      break;
 
8294
    case 3: /* directed */
 
8295
      shell_read_boolean(&directed, optarg);
 
8296
      break;
 
8297
    case 4:
 
8298
      shell_igraph_path_length_hist_usage(argv);
 
8299
      break;
 
8300
    default:
 
8301
      break;
 
8302
    }
 
8303
 
 
8304
    shell_index=-1;
 
8305
  }
 
8306
 
 
8307
  /* Check that we have all arguments */
 
8308
  for (shell_index=0; shell_index<4; shell_index++) {
 
8309
    if (!shell_seen[shell_index]) {
 
8310
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8311
              shell_options[shell_index].name);
 
8312
      exit(1);
 
8313
    }
 
8314
  }
 
8315
 
 
8316
  /* Do the operation */
 
8317
  shell_result=igraph_path_length_hist(&graph, &res, &unconnected, directed);
 
8318
 
 
8319
  /* Write the result */
 
8320
  igraph_destroy(&graph);
 
8321
  shell_write_vector(&res, shell_arg_res); 
 
8322
  igraph_vector_destroy(&res);
 
8323
  shell_write_real(unconnected, shell_arg_unconnected);
 
8324
 
 
8325
  return 0;
 
8326
}
 
8327
 
 
8328
/*-------------------------------------------/
 
8329
/ igraph_simplify                            /
 
8330
/-------------------------------------------*/
 
8331
void shell_igraph_simplify_usage(char **argv) {
 
8332
  printf("%s --graph=<graph> --graph-out=<graph-out> --multiple=<multiple> --loops=<loops>\n", basename(argv[0]));
 
8333
  exit(1);
 
8334
}
 
8335
 
 
8336
int shell_igraph_simplify(int argc, char **argv) {
 
8337
 
 
8338
  igraph_t graph;
 
8339
  igraph_bool_t multiple=1;
 
8340
  igraph_bool_t loops=1;
 
8341
  char* shell_arg_graph=0;
 
8342
  int shell_result;
 
8343
 
 
8344
 
 
8345
  int shell_seen[4];
 
8346
  int shell_index=-1;
 
8347
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8348
                                   { "graph-out",required_argument,0,1 },
 
8349
                                   { "multiple",required_argument,0,2 },
 
8350
                                   { "loops",required_argument,0,3 },
 
8351
                                   { "help",no_argument,0,4 },
 
8352
                                   { 0,0,0,0 }
 
8353
                                 };
 
8354
 
 
8355
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8356
  memset(shell_seen, 0, 4*sizeof(int));
 
8357
  shell_seen[2]=2;
 
8358
  shell_seen[3]=2;
 
8359
  
 
8360
  /* Parse arguments and read input */
 
8361
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8362
 
 
8363
    if (shell_index==-1) {
 
8364
      exit(1);
 
8365
    }
 
8366
 
 
8367
    if (shell_seen[shell_index]==1) {
 
8368
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8369
              shell_options[shell_index].name);
 
8370
      exit(1);
 
8371
    }
 
8372
    shell_seen[shell_index]=1;  
 
8373
 
 
8374
    switch (shell_index) {
 
8375
    case 0: /* graph */
 
8376
      shell_read_graph(&graph, optarg);
 
8377
      break;
 
8378
    case 1: /* graph-out */
 
8379
      shell_arg_graph=strdup(optarg);
 
8380
      break;
 
8381
    case 2: /* multiple */
 
8382
      shell_read_boolean(&multiple, optarg);
 
8383
      break;
 
8384
    case 3: /* loops */
 
8385
      shell_read_boolean(&loops, optarg);
 
8386
      break;
 
8387
    case 4:
 
8388
      shell_igraph_simplify_usage(argv);
 
8389
      break;
 
8390
    default:
 
8391
      break;
 
8392
    }
 
8393
 
 
8394
    shell_index=-1;
 
8395
  }
 
8396
 
 
8397
  /* Check that we have all arguments */
 
8398
  for (shell_index=0; shell_index<4; shell_index++) {
 
8399
    if (!shell_seen[shell_index]) {
 
8400
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8401
              shell_options[shell_index].name);
 
8402
      exit(1);
 
8403
    }
 
8404
  }
 
8405
 
 
8406
  /* Do the operation */
 
8407
  shell_result=igraph_simplify(&graph, multiple, loops);
 
8408
 
 
8409
  /* Write the result */
 
8410
  igraph_destroy(&graph);
 
8411
  shell_write_graph(&graph, shell_arg_graph); 
 
8412
  igraph_destroy(&graph);
 
8413
 
 
8414
  return 0;
 
8415
}
 
8416
 
 
8417
/*-------------------------------------------/
 
8418
/ igraph_transitivity_undirected             /
 
8419
/-------------------------------------------*/
 
8420
void shell_igraph_transitivity_undirected_usage(char **argv) {
 
8421
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
8422
  exit(1);
 
8423
}
 
8424
 
 
8425
int shell_igraph_transitivity_undirected(int argc, char **argv) {
 
8426
 
 
8427
  igraph_t graph;
 
8428
  igraph_real_t res;
 
8429
  char* shell_arg_res=0;
 
8430
  int shell_result;
 
8431
 
 
8432
 
 
8433
  int shell_seen[2];
 
8434
  int shell_index=-1;
 
8435
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8436
                                   { "res",required_argument,0,1 },
 
8437
                                   { "help",no_argument,0,2 },
 
8438
                                   { 0,0,0,0 }
 
8439
                                 };
 
8440
 
 
8441
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8442
  memset(shell_seen, 0, 2*sizeof(int));
 
8443
 
 
8444
  
 
8445
  /* Parse arguments and read input */
 
8446
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8447
 
 
8448
    if (shell_index==-1) {
 
8449
      exit(1);
 
8450
    }
 
8451
 
 
8452
    if (shell_seen[shell_index]==1) {
 
8453
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8454
              shell_options[shell_index].name);
 
8455
      exit(1);
 
8456
    }
 
8457
    shell_seen[shell_index]=1;  
 
8458
 
 
8459
    switch (shell_index) {
 
8460
    case 0: /* graph */
 
8461
      shell_read_graph(&graph, optarg);
 
8462
      break;
 
8463
    case 1: /* res */
 
8464
      shell_arg_res=strdup(optarg);
 
8465
      break;
 
8466
    case 2:
 
8467
      shell_igraph_transitivity_undirected_usage(argv);
 
8468
      break;
 
8469
    default:
 
8470
      break;
 
8471
    }
 
8472
 
 
8473
    shell_index=-1;
 
8474
  }
 
8475
 
 
8476
  /* Check that we have all arguments */
 
8477
  for (shell_index=0; shell_index<2; shell_index++) {
 
8478
    if (!shell_seen[shell_index]) {
 
8479
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8480
              shell_options[shell_index].name);
 
8481
      exit(1);
 
8482
    }
 
8483
  }
 
8484
 
 
8485
  /* Do the operation */
 
8486
  shell_result=igraph_transitivity_undirected(&graph, &res);
 
8487
 
 
8488
  /* Write the result */
 
8489
  igraph_destroy(&graph);
 
8490
  shell_write_real(res, shell_arg_res);
 
8491
 
 
8492
  return 0;
 
8493
}
 
8494
 
 
8495
/*-------------------------------------------/
 
8496
/ igraph_transitivity_local_undirected       /
 
8497
/-------------------------------------------*/
 
8498
void shell_igraph_transitivity_local_undirected_usage(char **argv) {
 
8499
  printf("%s --graph=<graph> --res=<res> --vids=<vids>\n", basename(argv[0]));
 
8500
  exit(1);
 
8501
}
 
8502
 
 
8503
int shell_igraph_transitivity_local_undirected(int argc, char **argv) {
 
8504
 
 
8505
  igraph_t graph;
 
8506
  igraph_vector_t res;
 
8507
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
8508
  char* shell_arg_res=0;
 
8509
  int shell_result;
 
8510
 
 
8511
 
 
8512
  int shell_seen[3];
 
8513
  int shell_index=-1;
 
8514
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8515
                                   { "res",required_argument,0,1 },
 
8516
                                   { "vids",required_argument,0,2 },
 
8517
                                   { "help",no_argument,0,3 },
 
8518
                                   { 0,0,0,0 }
 
8519
                                 };
 
8520
 
 
8521
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8522
  memset(shell_seen, 0, 3*sizeof(int));
 
8523
  shell_seen[2]=2;
 
8524
  
 
8525
  /* Parse arguments and read input */
 
8526
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8527
 
 
8528
    if (shell_index==-1) {
 
8529
      exit(1);
 
8530
    }
 
8531
 
 
8532
    if (shell_seen[shell_index]==1) {
 
8533
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8534
              shell_options[shell_index].name);
 
8535
      exit(1);
 
8536
    }
 
8537
    shell_seen[shell_index]=1;  
 
8538
 
 
8539
    switch (shell_index) {
 
8540
    case 0: /* graph */
 
8541
      shell_read_graph(&graph, optarg);
 
8542
      break;
 
8543
    case 1: /* res */
 
8544
      shell_arg_res=strdup(optarg); 
 
8545
  igraph_vector_init(&res, 0);
 
8546
      break;
 
8547
    case 2: /* vids */
 
8548
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
8549
      break;
 
8550
    case 3:
 
8551
      shell_igraph_transitivity_local_undirected_usage(argv);
 
8552
      break;
 
8553
    default:
 
8554
      break;
 
8555
    }
 
8556
 
 
8557
    shell_index=-1;
 
8558
  }
 
8559
 
 
8560
  /* Check that we have all arguments */
 
8561
  for (shell_index=0; shell_index<3; shell_index++) {
 
8562
    if (!shell_seen[shell_index]) {
 
8563
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8564
              shell_options[shell_index].name);
 
8565
      exit(1);
 
8566
    }
 
8567
  }
 
8568
 
 
8569
  /* Do the operation */
 
8570
  shell_result=igraph_transitivity_local_undirected(&graph, &res, vids);
 
8571
 
 
8572
  /* Write the result */
 
8573
  igraph_destroy(&graph);
 
8574
  shell_write_vector(&res, shell_arg_res); 
 
8575
  igraph_vector_destroy(&res);
 
8576
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
8577
 
 
8578
  return 0;
 
8579
}
 
8580
 
 
8581
/*-------------------------------------------/
 
8582
/ igraph_transitivity_avglocal_undirected    /
 
8583
/-------------------------------------------*/
 
8584
void shell_igraph_transitivity_avglocal_undirected_usage(char **argv) {
 
8585
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
8586
  exit(1);
 
8587
}
 
8588
 
 
8589
int shell_igraph_transitivity_avglocal_undirected(int argc, char **argv) {
 
8590
 
 
8591
  igraph_t graph;
 
8592
  igraph_real_t res;
 
8593
  char* shell_arg_res=0;
 
8594
  int shell_result;
 
8595
 
 
8596
 
 
8597
  int shell_seen[2];
 
8598
  int shell_index=-1;
 
8599
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8600
                                   { "res",required_argument,0,1 },
 
8601
                                   { "help",no_argument,0,2 },
 
8602
                                   { 0,0,0,0 }
 
8603
                                 };
 
8604
 
 
8605
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8606
  memset(shell_seen, 0, 2*sizeof(int));
 
8607
 
 
8608
  
 
8609
  /* Parse arguments and read input */
 
8610
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8611
 
 
8612
    if (shell_index==-1) {
 
8613
      exit(1);
 
8614
    }
 
8615
 
 
8616
    if (shell_seen[shell_index]==1) {
 
8617
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8618
              shell_options[shell_index].name);
 
8619
      exit(1);
 
8620
    }
 
8621
    shell_seen[shell_index]=1;  
 
8622
 
 
8623
    switch (shell_index) {
 
8624
    case 0: /* graph */
 
8625
      shell_read_graph(&graph, optarg);
 
8626
      break;
 
8627
    case 1: /* res */
 
8628
      shell_arg_res=strdup(optarg);
 
8629
      break;
 
8630
    case 2:
 
8631
      shell_igraph_transitivity_avglocal_undirected_usage(argv);
 
8632
      break;
 
8633
    default:
 
8634
      break;
 
8635
    }
 
8636
 
 
8637
    shell_index=-1;
 
8638
  }
 
8639
 
 
8640
  /* Check that we have all arguments */
 
8641
  for (shell_index=0; shell_index<2; shell_index++) {
 
8642
    if (!shell_seen[shell_index]) {
 
8643
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8644
              shell_options[shell_index].name);
 
8645
      exit(1);
 
8646
    }
 
8647
  }
 
8648
 
 
8649
  /* Do the operation */
 
8650
  shell_result=igraph_transitivity_avglocal_undirected(&graph, &res);
 
8651
 
 
8652
  /* Write the result */
 
8653
  igraph_destroy(&graph);
 
8654
  shell_write_real(res, shell_arg_res);
 
8655
 
 
8656
  return 0;
 
8657
}
 
8658
 
 
8659
/*-------------------------------------------/
 
8660
/ igraph_reciprocity                         /
 
8661
/-------------------------------------------*/
 
8662
void shell_igraph_reciprocity_usage(char **argv) {
 
8663
  printf("%s --graph=<graph> --res=<res> --ignore_loops=<ignore_loops>\n", basename(argv[0]));
 
8664
  exit(1);
 
8665
}
 
8666
 
 
8667
int shell_igraph_reciprocity(int argc, char **argv) {
 
8668
 
 
8669
  igraph_t graph;
 
8670
  igraph_real_t res;
 
8671
  igraph_bool_t ignore_loops=1;
 
8672
  char* shell_arg_res=0;
 
8673
  int shell_result;
 
8674
 
 
8675
 
 
8676
  int shell_seen[3];
 
8677
  int shell_index=-1;
 
8678
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8679
                                   { "res",required_argument,0,1 },
 
8680
                                   { "ignore_loops",required_argument,0,2 },
 
8681
                                   { "help",no_argument,0,3 },
 
8682
                                   { 0,0,0,0 }
 
8683
                                 };
 
8684
 
 
8685
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8686
  memset(shell_seen, 0, 3*sizeof(int));
 
8687
  shell_seen[2]=2;
 
8688
  
 
8689
  /* Parse arguments and read input */
 
8690
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8691
 
 
8692
    if (shell_index==-1) {
 
8693
      exit(1);
 
8694
    }
 
8695
 
 
8696
    if (shell_seen[shell_index]==1) {
 
8697
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8698
              shell_options[shell_index].name);
 
8699
      exit(1);
 
8700
    }
 
8701
    shell_seen[shell_index]=1;  
 
8702
 
 
8703
    switch (shell_index) {
 
8704
    case 0: /* graph */
 
8705
      shell_read_graph(&graph, optarg);
 
8706
      break;
 
8707
    case 1: /* res */
 
8708
      shell_arg_res=strdup(optarg);
 
8709
      break;
 
8710
    case 2: /* ignore_loops */
 
8711
      shell_read_boolean(&ignore_loops, optarg);
 
8712
      break;
 
8713
    case 3:
 
8714
      shell_igraph_reciprocity_usage(argv);
 
8715
      break;
 
8716
    default:
 
8717
      break;
 
8718
    }
 
8719
 
 
8720
    shell_index=-1;
 
8721
  }
 
8722
 
 
8723
  /* Check that we have all arguments */
 
8724
  for (shell_index=0; shell_index<3; shell_index++) {
 
8725
    if (!shell_seen[shell_index]) {
 
8726
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8727
              shell_options[shell_index].name);
 
8728
      exit(1);
 
8729
    }
 
8730
  }
 
8731
 
 
8732
  /* Do the operation */
 
8733
  shell_result=igraph_reciprocity(&graph, &res, ignore_loops);
 
8734
 
 
8735
  /* Write the result */
 
8736
  igraph_destroy(&graph);
 
8737
  shell_write_real(res, shell_arg_res);
 
8738
 
 
8739
  return 0;
 
8740
}
 
8741
 
 
8742
/*-------------------------------------------/
 
8743
/ igraph_constraint                          /
 
8744
/-------------------------------------------*/
 
8745
void shell_igraph_constraint_usage(char **argv) {
 
8746
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --weights=<weights>\n", basename(argv[0]));
 
8747
  exit(1);
 
8748
}
 
8749
 
 
8750
int shell_igraph_constraint(int argc, char **argv) {
 
8751
 
 
8752
  igraph_t graph;
 
8753
  igraph_vector_t res;
 
8754
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
8755
  igraph_vector_t v_weights; igraph_vector_t *weights=0;
 
8756
  char* shell_arg_res=0;
 
8757
  int shell_result;
 
8758
 
 
8759
 
 
8760
  int shell_seen[4];
 
8761
  int shell_index=-1;
 
8762
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8763
                                   { "res",required_argument,0,1 },
 
8764
                                   { "vids",required_argument,0,2 },
 
8765
                                   { "weights",required_argument,0,3 },
 
8766
                                   { "help",no_argument,0,4 },
 
8767
                                   { 0,0,0,0 }
 
8768
                                 };
 
8769
 
 
8770
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8771
  memset(shell_seen, 0, 4*sizeof(int));
 
8772
  shell_seen[2]=2;
 
8773
  
 
8774
  /* Parse arguments and read input */
 
8775
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8776
 
 
8777
    if (shell_index==-1) {
 
8778
      exit(1);
 
8779
    }
 
8780
 
 
8781
    if (shell_seen[shell_index]==1) {
 
8782
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8783
              shell_options[shell_index].name);
 
8784
      exit(1);
 
8785
    }
 
8786
    shell_seen[shell_index]=1;  
 
8787
 
 
8788
    switch (shell_index) {
 
8789
    case 0: /* graph */
 
8790
      shell_read_graph(&graph, optarg);
 
8791
      break;
 
8792
    case 1: /* res */
 
8793
      shell_arg_res=strdup(optarg); 
 
8794
  igraph_vector_init(&res, 0);
 
8795
      break;
 
8796
    case 2: /* vids */
 
8797
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
8798
      break;
 
8799
    case 3: /* weights */
 
8800
      weights=&v_weights; shell_read_vector(weights, optarg);
 
8801
      break;
 
8802
    case 4:
 
8803
      shell_igraph_constraint_usage(argv);
 
8804
      break;
 
8805
    default:
 
8806
      break;
 
8807
    }
 
8808
 
 
8809
    shell_index=-1;
 
8810
  }
 
8811
 
 
8812
  /* Check that we have all arguments */
 
8813
  for (shell_index=0; shell_index<4; shell_index++) {
 
8814
    if (!shell_seen[shell_index]) {
 
8815
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8816
              shell_options[shell_index].name);
 
8817
      exit(1);
 
8818
    }
 
8819
  }
 
8820
 
 
8821
  /* Do the operation */
 
8822
  shell_result=igraph_constraint(&graph, &res, vids, weights);
 
8823
 
 
8824
  /* Write the result */
 
8825
  igraph_destroy(&graph);
 
8826
  shell_write_vector(&res, shell_arg_res); 
 
8827
  igraph_vector_destroy(&res);
 
8828
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
8829
  if (weights) { igraph_vector_destroy(weights); }
 
8830
 
 
8831
  return 0;
 
8832
}
 
8833
 
 
8834
/*-------------------------------------------/
 
8835
/ igraph_maxdegree                           /
 
8836
/-------------------------------------------*/
 
8837
void shell_igraph_maxdegree_usage(char **argv) {
 
8838
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode> --loops=<loops>\n", basename(argv[0]));
 
8839
  exit(1);
 
8840
}
 
8841
 
 
8842
int shell_igraph_maxdegree(int argc, char **argv) {
 
8843
 
 
8844
  igraph_t graph;
 
8845
  igraph_integer_t res;
 
8846
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
8847
  igraph_neimode_t mode=IGRAPH_ALL;
 
8848
  igraph_bool_t loops=1;
 
8849
  char* shell_arg_res=0;
 
8850
  int shell_result;
 
8851
 
 
8852
 
 
8853
  int shell_seen[5];
 
8854
  int shell_index=-1;
 
8855
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8856
                                   { "res",required_argument,0,1 },
 
8857
                                   { "vids",required_argument,0,2 },
 
8858
                                   { "mode",required_argument,0,3 },
 
8859
                                   { "loops",required_argument,0,4 },
 
8860
                                   { "help",no_argument,0,5 },
 
8861
                                   { 0,0,0,0 }
 
8862
                                 };
 
8863
 
 
8864
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8865
  memset(shell_seen, 0, 5*sizeof(int));
 
8866
  shell_seen[2]=2;
 
8867
  shell_seen[3]=2;
 
8868
  shell_seen[4]=2;
 
8869
  
 
8870
  /* Parse arguments and read input */
 
8871
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8872
 
 
8873
    if (shell_index==-1) {
 
8874
      exit(1);
 
8875
    }
 
8876
 
 
8877
    if (shell_seen[shell_index]==1) {
 
8878
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8879
              shell_options[shell_index].name);
 
8880
      exit(1);
 
8881
    }
 
8882
    shell_seen[shell_index]=1;  
 
8883
 
 
8884
    switch (shell_index) {
 
8885
    case 0: /* graph */
 
8886
      shell_read_graph(&graph, optarg);
 
8887
      break;
 
8888
    case 1: /* res */
 
8889
      shell_arg_res=strdup(optarg);
 
8890
      break;
 
8891
    case 2: /* vids */
 
8892
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
8893
      break;
 
8894
    case 3: /* mode */
 
8895
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
8896
      break;
 
8897
    case 4: /* loops */
 
8898
      shell_read_boolean(&loops, optarg);
 
8899
      break;
 
8900
    case 5:
 
8901
      shell_igraph_maxdegree_usage(argv);
 
8902
      break;
 
8903
    default:
 
8904
      break;
 
8905
    }
 
8906
 
 
8907
    shell_index=-1;
 
8908
  }
 
8909
 
 
8910
  /* Check that we have all arguments */
 
8911
  for (shell_index=0; shell_index<5; shell_index++) {
 
8912
    if (!shell_seen[shell_index]) {
 
8913
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8914
              shell_options[shell_index].name);
 
8915
      exit(1);
 
8916
    }
 
8917
  }
 
8918
 
 
8919
  /* Do the operation */
 
8920
  shell_result=igraph_maxdegree(&graph, &res, vids, mode, loops);
 
8921
 
 
8922
  /* Write the result */
 
8923
  igraph_destroy(&graph);
 
8924
  shell_write_integer(res, shell_arg_res);
 
8925
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
8926
 
 
8927
  return 0;
 
8928
}
 
8929
 
 
8930
/*-------------------------------------------/
 
8931
/ igraph_density                             /
 
8932
/-------------------------------------------*/
 
8933
void shell_igraph_density_usage(char **argv) {
 
8934
  printf("%s --graph=<graph> --res=<res> --loops=<loops>\n", basename(argv[0]));
 
8935
  exit(1);
 
8936
}
 
8937
 
 
8938
int shell_igraph_density(int argc, char **argv) {
 
8939
 
 
8940
  igraph_t graph;
 
8941
  igraph_real_t res;
 
8942
  igraph_bool_t loops=0;
 
8943
  char* shell_arg_res=0;
 
8944
  int shell_result;
 
8945
 
 
8946
 
 
8947
  int shell_seen[3];
 
8948
  int shell_index=-1;
 
8949
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
8950
                                   { "res",required_argument,0,1 },
 
8951
                                   { "loops",required_argument,0,2 },
 
8952
                                   { "help",no_argument,0,3 },
 
8953
                                   { 0,0,0,0 }
 
8954
                                 };
 
8955
 
 
8956
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
8957
  memset(shell_seen, 0, 3*sizeof(int));
 
8958
  shell_seen[2]=2;
 
8959
  
 
8960
  /* Parse arguments and read input */
 
8961
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
8962
 
 
8963
    if (shell_index==-1) {
 
8964
      exit(1);
 
8965
    }
 
8966
 
 
8967
    if (shell_seen[shell_index]==1) {
 
8968
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
8969
              shell_options[shell_index].name);
 
8970
      exit(1);
 
8971
    }
 
8972
    shell_seen[shell_index]=1;  
 
8973
 
 
8974
    switch (shell_index) {
 
8975
    case 0: /* graph */
 
8976
      shell_read_graph(&graph, optarg);
 
8977
      break;
 
8978
    case 1: /* res */
 
8979
      shell_arg_res=strdup(optarg);
 
8980
      break;
 
8981
    case 2: /* loops */
 
8982
      shell_read_boolean(&loops, optarg);
 
8983
      break;
 
8984
    case 3:
 
8985
      shell_igraph_density_usage(argv);
 
8986
      break;
 
8987
    default:
 
8988
      break;
 
8989
    }
 
8990
 
 
8991
    shell_index=-1;
 
8992
  }
 
8993
 
 
8994
  /* Check that we have all arguments */
 
8995
  for (shell_index=0; shell_index<3; shell_index++) {
 
8996
    if (!shell_seen[shell_index]) {
 
8997
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
8998
              shell_options[shell_index].name);
 
8999
      exit(1);
 
9000
    }
 
9001
  }
 
9002
 
 
9003
  /* Do the operation */
 
9004
  shell_result=igraph_density(&graph, &res, loops);
 
9005
 
 
9006
  /* Write the result */
 
9007
  igraph_destroy(&graph);
 
9008
  shell_write_real(res, shell_arg_res);
 
9009
 
 
9010
  return 0;
 
9011
}
 
9012
 
 
9013
/*-------------------------------------------/
 
9014
/ igraph_neighborhood_size                   /
 
9015
/-------------------------------------------*/
 
9016
void shell_igraph_neighborhood_size_usage(char **argv) {
 
9017
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --order=<order> --mode=<mode>\n", basename(argv[0]));
 
9018
  exit(1);
 
9019
}
 
9020
 
 
9021
int shell_igraph_neighborhood_size(int argc, char **argv) {
 
9022
 
 
9023
  igraph_t graph;
 
9024
  igraph_vector_t res;
 
9025
  igraph_vector_t v_vids; igraph_vs_t vids;
 
9026
  igraph_integer_t order;
 
9027
  igraph_neimode_t mode=IGRAPH_ALL;
 
9028
  char* shell_arg_res=0;
 
9029
  int shell_result;
 
9030
 
 
9031
 
 
9032
  int shell_seen[5];
 
9033
  int shell_index=-1;
 
9034
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9035
                                   { "res",required_argument,0,1 },
 
9036
                                   { "vids",required_argument,0,2 },
 
9037
                                   { "order",required_argument,0,3 },
 
9038
                                   { "mode",required_argument,0,4 },
 
9039
                                   { "help",no_argument,0,5 },
 
9040
                                   { 0,0,0,0 }
 
9041
                                 };
 
9042
 
 
9043
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9044
  memset(shell_seen, 0, 5*sizeof(int));
 
9045
  shell_seen[4]=2;
 
9046
  
 
9047
  /* Parse arguments and read input */
 
9048
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9049
 
 
9050
    if (shell_index==-1) {
 
9051
      exit(1);
 
9052
    }
 
9053
 
 
9054
    if (shell_seen[shell_index]==1) {
 
9055
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9056
              shell_options[shell_index].name);
 
9057
      exit(1);
 
9058
    }
 
9059
    shell_seen[shell_index]=1;  
 
9060
 
 
9061
    switch (shell_index) {
 
9062
    case 0: /* graph */
 
9063
      shell_read_graph(&graph, optarg);
 
9064
      break;
 
9065
    case 1: /* res */
 
9066
      shell_arg_res=strdup(optarg); 
 
9067
  igraph_vector_init(&res, 0);
 
9068
      break;
 
9069
    case 2: /* vids */
 
9070
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
9071
      break;
 
9072
    case 3: /* order */
 
9073
      shell_read_integer(&order, optarg);
 
9074
      break;
 
9075
    case 4: /* mode */
 
9076
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
9077
      break;
 
9078
    case 5:
 
9079
      shell_igraph_neighborhood_size_usage(argv);
 
9080
      break;
 
9081
    default:
 
9082
      break;
 
9083
    }
 
9084
 
 
9085
    shell_index=-1;
 
9086
  }
 
9087
 
 
9088
  /* Check that we have all arguments */
 
9089
  for (shell_index=0; shell_index<5; shell_index++) {
 
9090
    if (!shell_seen[shell_index]) {
 
9091
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9092
              shell_options[shell_index].name);
 
9093
      exit(1);
 
9094
    }
 
9095
  }
 
9096
 
 
9097
  /* Do the operation */
 
9098
  shell_result=igraph_neighborhood_size(&graph, &res, vids, order, mode);
 
9099
 
 
9100
  /* Write the result */
 
9101
  igraph_destroy(&graph);
 
9102
  shell_write_vector(&res, shell_arg_res); 
 
9103
  igraph_vector_destroy(&res);
 
9104
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
9105
 
 
9106
  return 0;
 
9107
}
 
9108
 
 
9109
/*-------------------------------------------/
 
9110
/ igraph_neighborhood                        /
 
9111
/-------------------------------------------*/
 
9112
void shell_igraph_neighborhood_usage(char **argv) {
 
9113
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --order=<order> --mode=<mode>\n", basename(argv[0]));
 
9114
  exit(1);
 
9115
}
 
9116
 
 
9117
int shell_igraph_neighborhood(int argc, char **argv) {
 
9118
 
 
9119
  igraph_t graph;
 
9120
  igraph_vector_ptr_t res;
 
9121
  igraph_vector_t v_vids; igraph_vs_t vids;
 
9122
  igraph_integer_t order;
 
9123
  igraph_neimode_t mode=IGRAPH_ALL;
 
9124
  char* shell_arg_res=0;
 
9125
  int shell_result;
 
9126
 
 
9127
 
 
9128
  int shell_seen[5];
 
9129
  int shell_index=-1;
 
9130
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9131
                                   { "res",required_argument,0,1 },
 
9132
                                   { "vids",required_argument,0,2 },
 
9133
                                   { "order",required_argument,0,3 },
 
9134
                                   { "mode",required_argument,0,4 },
 
9135
                                   { "help",no_argument,0,5 },
 
9136
                                   { 0,0,0,0 }
 
9137
                                 };
 
9138
 
 
9139
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9140
  memset(shell_seen, 0, 5*sizeof(int));
 
9141
  shell_seen[4]=2;
 
9142
  
 
9143
  /* Parse arguments and read input */
 
9144
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9145
 
 
9146
    if (shell_index==-1) {
 
9147
      exit(1);
 
9148
    }
 
9149
 
 
9150
    if (shell_seen[shell_index]==1) {
 
9151
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9152
              shell_options[shell_index].name);
 
9153
      exit(1);
 
9154
    }
 
9155
    shell_seen[shell_index]=1;  
 
9156
 
 
9157
    switch (shell_index) {
 
9158
    case 0: /* graph */
 
9159
      shell_read_graph(&graph, optarg);
 
9160
      break;
 
9161
    case 1: /* res */
 
9162
      igraph_vector_ptr_init(&res, 0);
 
9163
      break;
 
9164
    case 2: /* vids */
 
9165
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
9166
      break;
 
9167
    case 3: /* order */
 
9168
      shell_read_integer(&order, optarg);
 
9169
      break;
 
9170
    case 4: /* mode */
 
9171
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
9172
      break;
 
9173
    case 5:
 
9174
      shell_igraph_neighborhood_usage(argv);
 
9175
      break;
 
9176
    default:
 
9177
      break;
 
9178
    }
 
9179
 
 
9180
    shell_index=-1;
 
9181
  }
 
9182
 
 
9183
  /* Check that we have all arguments */
 
9184
  for (shell_index=0; shell_index<5; shell_index++) {
 
9185
    if (!shell_seen[shell_index]) {
 
9186
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9187
              shell_options[shell_index].name);
 
9188
      exit(1);
 
9189
    }
 
9190
  }
 
9191
 
 
9192
  /* Do the operation */
 
9193
  shell_result=igraph_neighborhood(&graph, &res, vids, order, mode);
 
9194
 
 
9195
  /* Write the result */
 
9196
  igraph_destroy(&graph);
 
9197
  shell_write_vectorlist(&res, shell_arg_res); 
 
9198
  shell_free_vectorlist(&res); 
 
9199
  igraph_vector_ptr_destroy(&res);
 
9200
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
9201
 
 
9202
  return 0;
 
9203
}
 
9204
 
 
9205
/*-------------------------------------------/
 
9206
/ igraph_neighborhood_graphs                 /
 
9207
/-------------------------------------------*/
 
9208
void shell_igraph_neighborhood_graphs_usage(char **argv) {
 
9209
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --order=<order> --mode=<mode>\n", basename(argv[0]));
 
9210
  exit(1);
 
9211
}
 
9212
 
 
9213
int shell_igraph_neighborhood_graphs(int argc, char **argv) {
 
9214
 
 
9215
  igraph_t graph;
 
9216
  igraph_vector_ptr_t res;
 
9217
  igraph_vector_t v_vids; igraph_vs_t vids;
 
9218
  igraph_integer_t order;
 
9219
  igraph_neimode_t mode=IGRAPH_ALL;
 
9220
  char* shell_arg_res=0;
 
9221
  int shell_result;
 
9222
 
 
9223
 
 
9224
  int shell_seen[5];
 
9225
  int shell_index=-1;
 
9226
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9227
                                   { "res",required_argument,0,1 },
 
9228
                                   { "vids",required_argument,0,2 },
 
9229
                                   { "order",required_argument,0,3 },
 
9230
                                   { "mode",required_argument,0,4 },
 
9231
                                   { "help",no_argument,0,5 },
 
9232
                                   { 0,0,0,0 }
 
9233
                                 };
 
9234
 
 
9235
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9236
  memset(shell_seen, 0, 5*sizeof(int));
 
9237
  shell_seen[4]=2;
 
9238
  
 
9239
  /* Parse arguments and read input */
 
9240
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9241
 
 
9242
    if (shell_index==-1) {
 
9243
      exit(1);
 
9244
    }
 
9245
 
 
9246
    if (shell_seen[shell_index]==1) {
 
9247
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9248
              shell_options[shell_index].name);
 
9249
      exit(1);
 
9250
    }
 
9251
    shell_seen[shell_index]=1;  
 
9252
 
 
9253
    switch (shell_index) {
 
9254
    case 0: /* graph */
 
9255
      shell_read_graph(&graph, optarg);
 
9256
      break;
 
9257
    case 1: /* res */
 
9258
      igraph_vector_ptr_init(&res, 0);
 
9259
      break;
 
9260
    case 2: /* vids */
 
9261
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
9262
      break;
 
9263
    case 3: /* order */
 
9264
      shell_read_integer(&order, optarg);
 
9265
      break;
 
9266
    case 4: /* mode */
 
9267
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
9268
      break;
 
9269
    case 5:
 
9270
      shell_igraph_neighborhood_graphs_usage(argv);
 
9271
      break;
 
9272
    default:
 
9273
      break;
 
9274
    }
 
9275
 
 
9276
    shell_index=-1;
 
9277
  }
 
9278
 
 
9279
  /* Check that we have all arguments */
 
9280
  for (shell_index=0; shell_index<5; shell_index++) {
 
9281
    if (!shell_seen[shell_index]) {
 
9282
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9283
              shell_options[shell_index].name);
 
9284
      exit(1);
 
9285
    }
 
9286
  }
 
9287
 
 
9288
  /* Do the operation */
 
9289
  shell_result=igraph_neighborhood_graphs(&graph, &res, vids, order, mode);
 
9290
 
 
9291
  /* Write the result */
 
9292
  igraph_destroy(&graph);
 
9293
  shell_write_graphlist(&res, shell_arg_res); 
 
9294
  shell_free_graphlist(&res); 
 
9295
  igraph_vector_ptr_destroy(&res);
 
9296
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
9297
 
 
9298
  return 0;
 
9299
}
 
9300
 
 
9301
/*-------------------------------------------/
 
9302
/ igraph_topological_sorting                 /
 
9303
/-------------------------------------------*/
 
9304
void shell_igraph_topological_sorting_usage(char **argv) {
 
9305
  printf("%s --graph=<graph> --res=<res> --mode=<mode>\n", basename(argv[0]));
 
9306
  exit(1);
 
9307
}
 
9308
 
 
9309
int shell_igraph_topological_sorting(int argc, char **argv) {
 
9310
 
 
9311
  igraph_t graph;
 
9312
  igraph_vector_t res;
 
9313
  igraph_neimode_t mode=IGRAPH_OUT;
 
9314
  char* shell_arg_res=0;
 
9315
  int shell_result;
 
9316
 
 
9317
 
 
9318
  int shell_seen[3];
 
9319
  int shell_index=-1;
 
9320
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9321
                                   { "res",required_argument,0,1 },
 
9322
                                   { "mode",required_argument,0,2 },
 
9323
                                   { "help",no_argument,0,3 },
 
9324
                                   { 0,0,0,0 }
 
9325
                                 };
 
9326
 
 
9327
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9328
  memset(shell_seen, 0, 3*sizeof(int));
 
9329
  shell_seen[2]=2;
 
9330
  
 
9331
  /* Parse arguments and read input */
 
9332
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9333
 
 
9334
    if (shell_index==-1) {
 
9335
      exit(1);
 
9336
    }
 
9337
 
 
9338
    if (shell_seen[shell_index]==1) {
 
9339
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9340
              shell_options[shell_index].name);
 
9341
      exit(1);
 
9342
    }
 
9343
    shell_seen[shell_index]=1;  
 
9344
 
 
9345
    switch (shell_index) {
 
9346
    case 0: /* graph */
 
9347
      shell_read_graph(&graph, optarg);
 
9348
      break;
 
9349
    case 1: /* res */
 
9350
      shell_arg_res=strdup(optarg); 
 
9351
  igraph_vector_init(&res, 0);
 
9352
      break;
 
9353
    case 2: /* mode */
 
9354
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
9355
      break;
 
9356
    case 3:
 
9357
      shell_igraph_topological_sorting_usage(argv);
 
9358
      break;
 
9359
    default:
 
9360
      break;
 
9361
    }
 
9362
 
 
9363
    shell_index=-1;
 
9364
  }
 
9365
 
 
9366
  /* Check that we have all arguments */
 
9367
  for (shell_index=0; shell_index<3; shell_index++) {
 
9368
    if (!shell_seen[shell_index]) {
 
9369
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9370
              shell_options[shell_index].name);
 
9371
      exit(1);
 
9372
    }
 
9373
  }
 
9374
 
 
9375
  /* Do the operation */
 
9376
  shell_result=igraph_topological_sorting(&graph, &res, mode);
 
9377
 
 
9378
  /* Write the result */
 
9379
  igraph_destroy(&graph);
 
9380
  shell_write_vector(&res, shell_arg_res); 
 
9381
  igraph_vector_destroy(&res);
 
9382
 
 
9383
  return 0;
 
9384
}
 
9385
 
 
9386
/*-------------------------------------------/
 
9387
/ igraph_is_loop                             /
 
9388
/-------------------------------------------*/
 
9389
void shell_igraph_is_loop_usage(char **argv) {
 
9390
  printf("%s --graph=<graph> --res=<res> --es=<es>\n", basename(argv[0]));
 
9391
  exit(1);
 
9392
}
 
9393
 
 
9394
int shell_igraph_is_loop(int argc, char **argv) {
 
9395
 
 
9396
  igraph_t graph;
 
9397
  igraph_vector_bool_t res;
 
9398
  igraph_vector_t v_es; igraph_es_t es=igraph_ess_all(IGRAPH_EDGEORDER_ID);
 
9399
  char* shell_arg_res=0;
 
9400
  int shell_result;
 
9401
 
 
9402
 
 
9403
  int shell_seen[3];
 
9404
  int shell_index=-1;
 
9405
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9406
                                   { "res",required_argument,0,1 },
 
9407
                                   { "es",required_argument,0,2 },
 
9408
                                   { "help",no_argument,0,3 },
 
9409
                                   { 0,0,0,0 }
 
9410
                                 };
 
9411
 
 
9412
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9413
  memset(shell_seen, 0, 3*sizeof(int));
 
9414
  shell_seen[2]=2;
 
9415
  
 
9416
  /* Parse arguments and read input */
 
9417
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9418
 
 
9419
    if (shell_index==-1) {
 
9420
      exit(1);
 
9421
    }
 
9422
 
 
9423
    if (shell_seen[shell_index]==1) {
 
9424
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9425
              shell_options[shell_index].name);
 
9426
      exit(1);
 
9427
    }
 
9428
    shell_seen[shell_index]=1;  
 
9429
 
 
9430
    switch (shell_index) {
 
9431
    case 0: /* graph */
 
9432
      shell_read_graph(&graph, optarg);
 
9433
      break;
 
9434
    case 1: /* res */
 
9435
      igraph_vector_bool_init(&res, 0);
 
9436
      break;
 
9437
    case 2: /* es */
 
9438
      shell_read_vector(&v_es, optarg); igraph_es_vector(&es, &v_es);
 
9439
      break;
 
9440
    case 3:
 
9441
      shell_igraph_is_loop_usage(argv);
 
9442
      break;
 
9443
    default:
 
9444
      break;
 
9445
    }
 
9446
 
 
9447
    shell_index=-1;
 
9448
  }
 
9449
 
 
9450
  /* Check that we have all arguments */
 
9451
  for (shell_index=0; shell_index<3; shell_index++) {
 
9452
    if (!shell_seen[shell_index]) {
 
9453
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9454
              shell_options[shell_index].name);
 
9455
      exit(1);
 
9456
    }
 
9457
  }
 
9458
 
 
9459
  /* Do the operation */
 
9460
  shell_result=igraph_is_loop(&graph, &res, es);
 
9461
 
 
9462
  /* Write the result */
 
9463
  igraph_destroy(&graph);
 
9464
  shell_write_vector_bool(&res, shell_arg_res); 
 
9465
  igraph_vector_bool_destroy(&res);
 
9466
  if (!igraph_es_is_all(&es)) { igraph_es_destroy(&es); }
 
9467
 
 
9468
  return 0;
 
9469
}
 
9470
 
 
9471
/*-------------------------------------------/
 
9472
/ igraph_is_simple                           /
 
9473
/-------------------------------------------*/
 
9474
void shell_igraph_is_simple_usage(char **argv) {
 
9475
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
9476
  exit(1);
 
9477
}
 
9478
 
 
9479
int shell_igraph_is_simple(int argc, char **argv) {
 
9480
 
 
9481
  igraph_t graph;
 
9482
  igraph_bool_t res;
 
9483
  char* shell_arg_res=0;
 
9484
  int shell_result;
 
9485
 
 
9486
 
 
9487
  int shell_seen[2];
 
9488
  int shell_index=-1;
 
9489
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9490
                                   { "res",required_argument,0,1 },
 
9491
                                   { "help",no_argument,0,2 },
 
9492
                                   { 0,0,0,0 }
 
9493
                                 };
 
9494
 
 
9495
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9496
  memset(shell_seen, 0, 2*sizeof(int));
 
9497
 
 
9498
  
 
9499
  /* Parse arguments and read input */
 
9500
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9501
 
 
9502
    if (shell_index==-1) {
 
9503
      exit(1);
 
9504
    }
 
9505
 
 
9506
    if (shell_seen[shell_index]==1) {
 
9507
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9508
              shell_options[shell_index].name);
 
9509
      exit(1);
 
9510
    }
 
9511
    shell_seen[shell_index]=1;  
 
9512
 
 
9513
    switch (shell_index) {
 
9514
    case 0: /* graph */
 
9515
      shell_read_graph(&graph, optarg);
 
9516
      break;
 
9517
    case 1: /* res */
 
9518
      
 
9519
      break;
 
9520
    case 2:
 
9521
      shell_igraph_is_simple_usage(argv);
 
9522
      break;
 
9523
    default:
 
9524
      break;
 
9525
    }
 
9526
 
 
9527
    shell_index=-1;
 
9528
  }
 
9529
 
 
9530
  /* Check that we have all arguments */
 
9531
  for (shell_index=0; shell_index<2; shell_index++) {
 
9532
    if (!shell_seen[shell_index]) {
 
9533
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9534
              shell_options[shell_index].name);
 
9535
      exit(1);
 
9536
    }
 
9537
  }
 
9538
 
 
9539
  /* Do the operation */
 
9540
  shell_result=igraph_is_simple(&graph, &res);
 
9541
 
 
9542
  /* Write the result */
 
9543
  igraph_destroy(&graph);
 
9544
  shell_write_boolean(res, shell_arg_res);
 
9545
 
 
9546
  return 0;
 
9547
}
 
9548
 
 
9549
/*-------------------------------------------/
 
9550
/ igraph_is_multiple                         /
 
9551
/-------------------------------------------*/
 
9552
void shell_igraph_is_multiple_usage(char **argv) {
 
9553
  printf("%s --graph=<graph> --res=<res> --es=<es>\n", basename(argv[0]));
 
9554
  exit(1);
 
9555
}
 
9556
 
 
9557
int shell_igraph_is_multiple(int argc, char **argv) {
 
9558
 
 
9559
  igraph_t graph;
 
9560
  igraph_vector_bool_t res;
 
9561
  igraph_vector_t v_es; igraph_es_t es=igraph_ess_all(IGRAPH_EDGEORDER_ID);
 
9562
  char* shell_arg_res=0;
 
9563
  int shell_result;
 
9564
 
 
9565
 
 
9566
  int shell_seen[3];
 
9567
  int shell_index=-1;
 
9568
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9569
                                   { "res",required_argument,0,1 },
 
9570
                                   { "es",required_argument,0,2 },
 
9571
                                   { "help",no_argument,0,3 },
 
9572
                                   { 0,0,0,0 }
 
9573
                                 };
 
9574
 
 
9575
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9576
  memset(shell_seen, 0, 3*sizeof(int));
 
9577
  shell_seen[2]=2;
 
9578
  
 
9579
  /* Parse arguments and read input */
 
9580
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9581
 
 
9582
    if (shell_index==-1) {
 
9583
      exit(1);
 
9584
    }
 
9585
 
 
9586
    if (shell_seen[shell_index]==1) {
 
9587
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9588
              shell_options[shell_index].name);
 
9589
      exit(1);
 
9590
    }
 
9591
    shell_seen[shell_index]=1;  
 
9592
 
 
9593
    switch (shell_index) {
 
9594
    case 0: /* graph */
 
9595
      shell_read_graph(&graph, optarg);
 
9596
      break;
 
9597
    case 1: /* res */
 
9598
      igraph_vector_bool_init(&res, 0);
 
9599
      break;
 
9600
    case 2: /* es */
 
9601
      shell_read_vector(&v_es, optarg); igraph_es_vector(&es, &v_es);
 
9602
      break;
 
9603
    case 3:
 
9604
      shell_igraph_is_multiple_usage(argv);
 
9605
      break;
 
9606
    default:
 
9607
      break;
 
9608
    }
 
9609
 
 
9610
    shell_index=-1;
 
9611
  }
 
9612
 
 
9613
  /* Check that we have all arguments */
 
9614
  for (shell_index=0; shell_index<3; shell_index++) {
 
9615
    if (!shell_seen[shell_index]) {
 
9616
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9617
              shell_options[shell_index].name);
 
9618
      exit(1);
 
9619
    }
 
9620
  }
 
9621
 
 
9622
  /* Do the operation */
 
9623
  shell_result=igraph_is_multiple(&graph, &res, es);
 
9624
 
 
9625
  /* Write the result */
 
9626
  igraph_destroy(&graph);
 
9627
  shell_write_vector_bool(&res, shell_arg_res); 
 
9628
  igraph_vector_bool_destroy(&res);
 
9629
  if (!igraph_es_is_all(&es)) { igraph_es_destroy(&es); }
 
9630
 
 
9631
  return 0;
 
9632
}
 
9633
 
 
9634
/*-------------------------------------------/
 
9635
/ igraph_count_multiple                      /
 
9636
/-------------------------------------------*/
 
9637
void shell_igraph_count_multiple_usage(char **argv) {
 
9638
  printf("%s --graph=<graph> --res=<res> --es=<es>\n", basename(argv[0]));
 
9639
  exit(1);
 
9640
}
 
9641
 
 
9642
int shell_igraph_count_multiple(int argc, char **argv) {
 
9643
 
 
9644
  igraph_t graph;
 
9645
  igraph_vector_t res;
 
9646
  igraph_vector_t v_es; igraph_es_t es=igraph_ess_all(IGRAPH_EDGEORDER_ID);
 
9647
  char* shell_arg_res=0;
 
9648
  int shell_result;
 
9649
 
 
9650
 
 
9651
  int shell_seen[3];
 
9652
  int shell_index=-1;
 
9653
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9654
                                   { "res",required_argument,0,1 },
 
9655
                                   { "es",required_argument,0,2 },
 
9656
                                   { "help",no_argument,0,3 },
 
9657
                                   { 0,0,0,0 }
 
9658
                                 };
 
9659
 
 
9660
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9661
  memset(shell_seen, 0, 3*sizeof(int));
 
9662
  shell_seen[2]=2;
 
9663
  
 
9664
  /* Parse arguments and read input */
 
9665
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9666
 
 
9667
    if (shell_index==-1) {
 
9668
      exit(1);
 
9669
    }
 
9670
 
 
9671
    if (shell_seen[shell_index]==1) {
 
9672
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9673
              shell_options[shell_index].name);
 
9674
      exit(1);
 
9675
    }
 
9676
    shell_seen[shell_index]=1;  
 
9677
 
 
9678
    switch (shell_index) {
 
9679
    case 0: /* graph */
 
9680
      shell_read_graph(&graph, optarg);
 
9681
      break;
 
9682
    case 1: /* res */
 
9683
      shell_arg_res=strdup(optarg); 
 
9684
  igraph_vector_init(&res, 0);
 
9685
      break;
 
9686
    case 2: /* es */
 
9687
      shell_read_vector(&v_es, optarg); igraph_es_vector(&es, &v_es);
 
9688
      break;
 
9689
    case 3:
 
9690
      shell_igraph_count_multiple_usage(argv);
 
9691
      break;
 
9692
    default:
 
9693
      break;
 
9694
    }
 
9695
 
 
9696
    shell_index=-1;
 
9697
  }
 
9698
 
 
9699
  /* Check that we have all arguments */
 
9700
  for (shell_index=0; shell_index<3; shell_index++) {
 
9701
    if (!shell_seen[shell_index]) {
 
9702
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9703
              shell_options[shell_index].name);
 
9704
      exit(1);
 
9705
    }
 
9706
  }
 
9707
 
 
9708
  /* Do the operation */
 
9709
  shell_result=igraph_count_multiple(&graph, &res, es);
 
9710
 
 
9711
  /* Write the result */
 
9712
  igraph_destroy(&graph);
 
9713
  shell_write_vector(&res, shell_arg_res); 
 
9714
  igraph_vector_destroy(&res);
 
9715
  if (!igraph_es_is_all(&es)) { igraph_es_destroy(&es); }
 
9716
 
 
9717
  return 0;
 
9718
}
 
9719
 
 
9720
/*-------------------------------------------/
 
9721
/ igraph_girth                               /
 
9722
/-------------------------------------------*/
 
9723
void shell_igraph_girth_usage(char **argv) {
 
9724
  printf("%s --graph=<graph> --girth=<girth> --circle=<circle>\n", basename(argv[0]));
 
9725
  exit(1);
 
9726
}
 
9727
 
 
9728
int shell_igraph_girth(int argc, char **argv) {
 
9729
 
 
9730
  igraph_t graph;
 
9731
  igraph_integer_t girth;
 
9732
  igraph_vector_t circle;
 
9733
  char* shell_arg_girth=0;
 
9734
  char* shell_arg_circle=0;
 
9735
  int shell_result;
 
9736
 
 
9737
 
 
9738
  int shell_seen[3];
 
9739
  int shell_index=-1;
 
9740
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9741
                                   { "girth",required_argument,0,1 },
 
9742
                                   { "circle",required_argument,0,2 },
 
9743
                                   { "help",no_argument,0,3 },
 
9744
                                   { 0,0,0,0 }
 
9745
                                 };
 
9746
 
 
9747
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9748
  memset(shell_seen, 0, 3*sizeof(int));
 
9749
 
 
9750
  
 
9751
  /* Parse arguments and read input */
 
9752
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9753
 
 
9754
    if (shell_index==-1) {
 
9755
      exit(1);
 
9756
    }
 
9757
 
 
9758
    if (shell_seen[shell_index]==1) {
 
9759
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9760
              shell_options[shell_index].name);
 
9761
      exit(1);
 
9762
    }
 
9763
    shell_seen[shell_index]=1;  
 
9764
 
 
9765
    switch (shell_index) {
 
9766
    case 0: /* graph */
 
9767
      shell_read_graph(&graph, optarg);
 
9768
      break;
 
9769
    case 1: /* girth */
 
9770
      shell_arg_girth=strdup(optarg);
 
9771
      break;
 
9772
    case 2: /* circle */
 
9773
      shell_arg_circle=strdup(optarg); 
 
9774
  igraph_vector_init(&circle, 0);
 
9775
      break;
 
9776
    case 3:
 
9777
      shell_igraph_girth_usage(argv);
 
9778
      break;
 
9779
    default:
 
9780
      break;
 
9781
    }
 
9782
 
 
9783
    shell_index=-1;
 
9784
  }
 
9785
 
 
9786
  /* Check that we have all arguments */
 
9787
  for (shell_index=0; shell_index<3; shell_index++) {
 
9788
    if (!shell_seen[shell_index]) {
 
9789
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9790
              shell_options[shell_index].name);
 
9791
      exit(1);
 
9792
    }
 
9793
  }
 
9794
 
 
9795
  /* Do the operation */
 
9796
  shell_result=igraph_girth(&graph, &girth, &circle);
 
9797
 
 
9798
  /* Write the result */
 
9799
  igraph_destroy(&graph);
 
9800
  shell_write_integer(girth, shell_arg_girth);
 
9801
  shell_write_vector(&circle, shell_arg_circle); 
 
9802
  igraph_vector_destroy(&circle);
 
9803
 
 
9804
  return 0;
 
9805
}
 
9806
 
 
9807
/*-------------------------------------------/
 
9808
/ igraph_add_edge                            /
 
9809
/-------------------------------------------*/
 
9810
void shell_igraph_add_edge_usage(char **argv) {
 
9811
  printf("%s --graph=<graph> --graph-out=<graph-out> --from=<from> --to=<to>\n", basename(argv[0]));
 
9812
  exit(1);
 
9813
}
 
9814
 
 
9815
int shell_igraph_add_edge(int argc, char **argv) {
 
9816
 
 
9817
  igraph_t graph;
 
9818
  igraph_integer_t from;
 
9819
  igraph_integer_t to;
 
9820
  char* shell_arg_graph=0;
 
9821
  int shell_result;
 
9822
 
 
9823
 
 
9824
  int shell_seen[4];
 
9825
  int shell_index=-1;
 
9826
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9827
                                   { "graph-out",required_argument,0,1 },
 
9828
                                   { "from",required_argument,0,2 },
 
9829
                                   { "to",required_argument,0,3 },
 
9830
                                   { "help",no_argument,0,4 },
 
9831
                                   { 0,0,0,0 }
 
9832
                                 };
 
9833
 
 
9834
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9835
  memset(shell_seen, 0, 4*sizeof(int));
 
9836
 
 
9837
  
 
9838
  /* Parse arguments and read input */
 
9839
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9840
 
 
9841
    if (shell_index==-1) {
 
9842
      exit(1);
 
9843
    }
 
9844
 
 
9845
    if (shell_seen[shell_index]==1) {
 
9846
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9847
              shell_options[shell_index].name);
 
9848
      exit(1);
 
9849
    }
 
9850
    shell_seen[shell_index]=1;  
 
9851
 
 
9852
    switch (shell_index) {
 
9853
    case 0: /* graph */
 
9854
      shell_read_graph(&graph, optarg);
 
9855
      break;
 
9856
    case 1: /* graph-out */
 
9857
      shell_arg_graph=strdup(optarg);
 
9858
      break;
 
9859
    case 2: /* from */
 
9860
      shell_read_integer(&from, optarg);
 
9861
      break;
 
9862
    case 3: /* to */
 
9863
      shell_read_integer(&to, optarg);
 
9864
      break;
 
9865
    case 4:
 
9866
      shell_igraph_add_edge_usage(argv);
 
9867
      break;
 
9868
    default:
 
9869
      break;
 
9870
    }
 
9871
 
 
9872
    shell_index=-1;
 
9873
  }
 
9874
 
 
9875
  /* Check that we have all arguments */
 
9876
  for (shell_index=0; shell_index<4; shell_index++) {
 
9877
    if (!shell_seen[shell_index]) {
 
9878
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9879
              shell_options[shell_index].name);
 
9880
      exit(1);
 
9881
    }
 
9882
  }
 
9883
 
 
9884
  /* Do the operation */
 
9885
  shell_result=igraph_add_edge(&graph, from, to);
 
9886
 
 
9887
  /* Write the result */
 
9888
  igraph_destroy(&graph);
 
9889
  shell_write_graph(&graph, shell_arg_graph); 
 
9890
  igraph_destroy(&graph);
 
9891
 
 
9892
  return 0;
 
9893
}
 
9894
 
 
9895
/*-------------------------------------------/
 
9896
/ igraph_eigenvector_centrality              /
 
9897
/-------------------------------------------*/
 
9898
void shell_igraph_eigenvector_centrality_usage(char **argv) {
 
9899
  printf("%s --graph=<graph> --vector=<vector> --value=<value> --scale=<scale>\n", basename(argv[0]));
 
9900
  exit(1);
 
9901
}
 
9902
 
 
9903
int shell_igraph_eigenvector_centrality(int argc, char **argv) {
 
9904
 
 
9905
  igraph_t graph;
 
9906
  igraph_vector_t vector;
 
9907
  igraph_real_t value;
 
9908
  igraph_bool_t scale=1;
 
9909
 
 
9910
 
 
9911
  char* shell_arg_vector=0;
 
9912
  char* shell_arg_value=0;
 
9913
  char* shell_arg_options=0;
 
9914
  int shell_result;
 
9915
 
 
9916
 
 
9917
  int shell_seen[4];
 
9918
  int shell_index=-1;
 
9919
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
9920
                                   { "vector",required_argument,0,1 },
 
9921
                                   { "value",required_argument,0,2 },
 
9922
                                   { "scale",required_argument,0,3 },
 
9923
                                   { "help",no_argument,0,4 },
 
9924
                                   { 0,0,0,0 }
 
9925
                                 };
 
9926
 
 
9927
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
9928
  memset(shell_seen, 0, 4*sizeof(int));
 
9929
  shell_seen[3]=2;
 
9930
  
 
9931
  /* Parse arguments and read input */
 
9932
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
9933
 
 
9934
    if (shell_index==-1) {
 
9935
      exit(1);
 
9936
    }
 
9937
 
 
9938
    if (shell_seen[shell_index]==1) {
 
9939
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
9940
              shell_options[shell_index].name);
 
9941
      exit(1);
 
9942
    }
 
9943
    shell_seen[shell_index]=1;  
 
9944
 
 
9945
    switch (shell_index) {
 
9946
    case 0: /* graph */
 
9947
      shell_read_graph(&graph, optarg);
 
9948
      break;
 
9949
    case 1: /* vector */
 
9950
      shell_arg_vector=strdup(optarg); 
 
9951
  igraph_vector_init(&vector, 0);
 
9952
      break;
 
9953
    case 2: /* value */
 
9954
      shell_arg_value=strdup(optarg);
 
9955
      break;
 
9956
    case 3: /* scale */
 
9957
      shell_read_boolean(&scale, optarg);
 
9958
      break;
 
9959
    case 4:
 
9960
      shell_igraph_eigenvector_centrality_usage(argv);
 
9961
      break;
 
9962
    default:
 
9963
      break;
 
9964
    }
 
9965
 
 
9966
    shell_index=-1;
 
9967
  }
 
9968
 
 
9969
  /* Check that we have all arguments */
 
9970
  for (shell_index=0; shell_index<4; shell_index++) {
 
9971
    if (!shell_seen[shell_index]) {
 
9972
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
9973
              shell_options[shell_index].name);
 
9974
      exit(1);
 
9975
    }
 
9976
  }
 
9977
 
 
9978
  /* Do the operation */
 
9979
  shell_result=igraph_eigenvector_centrality(&graph, &vector, &value, scale, 0, 0);
 
9980
 
 
9981
  /* Write the result */
 
9982
  igraph_destroy(&graph);
 
9983
  shell_write_vector(&vector, shell_arg_vector); 
 
9984
  igraph_vector_destroy(&vector);
 
9985
  shell_write_real(value, shell_arg_value);
 
9986
 
 
9987
  return 0;
 
9988
}
 
9989
 
 
9990
/*-------------------------------------------/
 
9991
/ igraph_hub_score                           /
 
9992
/-------------------------------------------*/
 
9993
void shell_igraph_hub_score_usage(char **argv) {
 
9994
  printf("%s --graph=<graph> --vector=<vector> --value=<value> --scale=<scale>\n", basename(argv[0]));
 
9995
  exit(1);
 
9996
}
 
9997
 
 
9998
int shell_igraph_hub_score(int argc, char **argv) {
 
9999
 
 
10000
  igraph_t graph;
 
10001
  igraph_vector_t vector;
 
10002
  igraph_real_t value;
 
10003
  igraph_bool_t scale=1;
 
10004
 
 
10005
  char* shell_arg_vector=0;
 
10006
  char* shell_arg_value=0;
 
10007
  char* shell_arg_options=0;
 
10008
  int shell_result;
 
10009
 
 
10010
 
 
10011
  int shell_seen[4];
 
10012
  int shell_index=-1;
 
10013
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10014
                                   { "vector",required_argument,0,1 },
 
10015
                                   { "value",required_argument,0,2 },
 
10016
                                   { "scale",required_argument,0,3 },
 
10017
                                   { "help",no_argument,0,4 },
 
10018
                                   { 0,0,0,0 }
 
10019
                                 };
 
10020
 
 
10021
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10022
  memset(shell_seen, 0, 4*sizeof(int));
 
10023
  shell_seen[3]=2;
 
10024
  
 
10025
  /* Parse arguments and read input */
 
10026
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10027
 
 
10028
    if (shell_index==-1) {
 
10029
      exit(1);
 
10030
    }
 
10031
 
 
10032
    if (shell_seen[shell_index]==1) {
 
10033
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10034
              shell_options[shell_index].name);
 
10035
      exit(1);
 
10036
    }
 
10037
    shell_seen[shell_index]=1;  
 
10038
 
 
10039
    switch (shell_index) {
 
10040
    case 0: /* graph */
 
10041
      shell_read_graph(&graph, optarg);
 
10042
      break;
 
10043
    case 1: /* vector */
 
10044
      shell_arg_vector=strdup(optarg); 
 
10045
  igraph_vector_init(&vector, 0);
 
10046
      break;
 
10047
    case 2: /* value */
 
10048
      shell_arg_value=strdup(optarg);
 
10049
      break;
 
10050
    case 3: /* scale */
 
10051
      shell_read_boolean(&scale, optarg);
 
10052
      break;
 
10053
    case 4:
 
10054
      shell_igraph_hub_score_usage(argv);
 
10055
      break;
 
10056
    default:
 
10057
      break;
 
10058
    }
 
10059
 
 
10060
    shell_index=-1;
 
10061
  }
 
10062
 
 
10063
  /* Check that we have all arguments */
 
10064
  for (shell_index=0; shell_index<4; shell_index++) {
 
10065
    if (!shell_seen[shell_index]) {
 
10066
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10067
              shell_options[shell_index].name);
 
10068
      exit(1);
 
10069
    }
 
10070
  }
 
10071
 
 
10072
  /* Do the operation */
 
10073
  shell_result=igraph_hub_score(&graph, &vector, &value, scale, 0);
 
10074
 
 
10075
  /* Write the result */
 
10076
  igraph_destroy(&graph);
 
10077
  shell_write_vector(&vector, shell_arg_vector); 
 
10078
  igraph_vector_destroy(&vector);
 
10079
  shell_write_real(value, shell_arg_value);
 
10080
 
 
10081
  return 0;
 
10082
}
 
10083
 
 
10084
/*-------------------------------------------/
 
10085
/ igraph_authority_score                     /
 
10086
/-------------------------------------------*/
 
10087
void shell_igraph_authority_score_usage(char **argv) {
 
10088
  printf("%s --graph=<graph> --vector=<vector> --value=<value> --scale=<scale>\n", basename(argv[0]));
 
10089
  exit(1);
 
10090
}
 
10091
 
 
10092
int shell_igraph_authority_score(int argc, char **argv) {
 
10093
 
 
10094
  igraph_t graph;
 
10095
  igraph_vector_t vector;
 
10096
  igraph_real_t value;
 
10097
  igraph_bool_t scale=1;
 
10098
 
 
10099
  char* shell_arg_vector=0;
 
10100
  char* shell_arg_value=0;
 
10101
  char* shell_arg_options=0;
 
10102
  int shell_result;
 
10103
 
 
10104
 
 
10105
  int shell_seen[4];
 
10106
  int shell_index=-1;
 
10107
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10108
                                   { "vector",required_argument,0,1 },
 
10109
                                   { "value",required_argument,0,2 },
 
10110
                                   { "scale",required_argument,0,3 },
 
10111
                                   { "help",no_argument,0,4 },
 
10112
                                   { 0,0,0,0 }
 
10113
                                 };
 
10114
 
 
10115
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10116
  memset(shell_seen, 0, 4*sizeof(int));
 
10117
  shell_seen[3]=2;
 
10118
  
 
10119
  /* Parse arguments and read input */
 
10120
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10121
 
 
10122
    if (shell_index==-1) {
 
10123
      exit(1);
 
10124
    }
 
10125
 
 
10126
    if (shell_seen[shell_index]==1) {
 
10127
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10128
              shell_options[shell_index].name);
 
10129
      exit(1);
 
10130
    }
 
10131
    shell_seen[shell_index]=1;  
 
10132
 
 
10133
    switch (shell_index) {
 
10134
    case 0: /* graph */
 
10135
      shell_read_graph(&graph, optarg);
 
10136
      break;
 
10137
    case 1: /* vector */
 
10138
      shell_arg_vector=strdup(optarg); 
 
10139
  igraph_vector_init(&vector, 0);
 
10140
      break;
 
10141
    case 2: /* value */
 
10142
      shell_arg_value=strdup(optarg);
 
10143
      break;
 
10144
    case 3: /* scale */
 
10145
      shell_read_boolean(&scale, optarg);
 
10146
      break;
 
10147
    case 4:
 
10148
      shell_igraph_authority_score_usage(argv);
 
10149
      break;
 
10150
    default:
 
10151
      break;
 
10152
    }
 
10153
 
 
10154
    shell_index=-1;
 
10155
  }
 
10156
 
 
10157
  /* Check that we have all arguments */
 
10158
  for (shell_index=0; shell_index<4; shell_index++) {
 
10159
    if (!shell_seen[shell_index]) {
 
10160
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10161
              shell_options[shell_index].name);
 
10162
      exit(1);
 
10163
    }
 
10164
  }
 
10165
 
 
10166
  /* Do the operation */
 
10167
  shell_result=igraph_authority_score(&graph, &vector, &value, scale, 0);
 
10168
 
 
10169
  /* Write the result */
 
10170
  igraph_destroy(&graph);
 
10171
  shell_write_vector(&vector, shell_arg_vector); 
 
10172
  igraph_vector_destroy(&vector);
 
10173
  shell_write_real(value, shell_arg_value);
 
10174
 
 
10175
  return 0;
 
10176
}
 
10177
 
 
10178
/*-------------------------------------------/
 
10179
/ igraph_arpack_rssolve                      /
 
10180
/-------------------------------------------*/
 
10181
void shell_igraph_arpack_rssolve_usage(char **argv) {
 
10182
  printf("%s --values=<values>\n", basename(argv[0]));
 
10183
  exit(1);
 
10184
}
 
10185
 
 
10186
int shell_igraph_arpack_rssolve(int argc, char **argv) {
 
10187
 
 
10188
 
 
10189
 
 
10190
 
 
10191
 
 
10192
  igraph_vector_t v_values; igraph_vector_t *values=0;
 
10193
 
 
10194
  char* shell_arg_options=0;
 
10195
  char* shell_arg_values=0;
 
10196
  char* shell_arg_vectors=0;
 
10197
  int shell_result;
 
10198
 
 
10199
 
 
10200
  int shell_seen[1];
 
10201
  int shell_index=-1;
 
10202
  struct option shell_options[]= { { "values",required_argument,0,0 },
 
10203
                                   { "help",no_argument,0,1 },
 
10204
                                   { 0,0,0,0 }
 
10205
                                 };
 
10206
 
 
10207
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10208
  memset(shell_seen, 0, 1*sizeof(int));
 
10209
 
 
10210
  
 
10211
  /* Parse arguments and read input */
 
10212
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10213
 
 
10214
    if (shell_index==-1) {
 
10215
      exit(1);
 
10216
    }
 
10217
 
 
10218
    if (shell_seen[shell_index]==1) {
 
10219
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10220
              shell_options[shell_index].name);
 
10221
      exit(1);
 
10222
    }
 
10223
    shell_seen[shell_index]=1;  
 
10224
 
 
10225
    switch (shell_index) {
 
10226
    case 0: /* values */
 
10227
      values=&v_values; igraph_vector_init(values, 0); 
 
10228
  shell_arg_values=strdup(optarg);
 
10229
      break;
 
10230
    case 1:
 
10231
      shell_igraph_arpack_rssolve_usage(argv);
 
10232
      break;
 
10233
    default:
 
10234
      break;
 
10235
    }
 
10236
 
 
10237
    shell_index=-1;
 
10238
  }
 
10239
 
 
10240
  /* Check that we have all arguments */
 
10241
  for (shell_index=0; shell_index<1; shell_index++) {
 
10242
    if (!shell_seen[shell_index]) {
 
10243
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10244
              shell_options[shell_index].name);
 
10245
      exit(1);
 
10246
    }
 
10247
  }
 
10248
 
 
10249
  /* Do the operation */
 
10250
  shell_result=igraph_arpack_rssolve(0, 0, 0, 0, values, 0);
 
10251
 
 
10252
  /* Write the result */
 
10253
  if (values) { shell_write_vector(values, shell_arg_values); 
 
10254
  igraph_vector_destroy(values); }
 
10255
 
 
10256
  return 0;
 
10257
}
 
10258
 
 
10259
/*-------------------------------------------/
 
10260
/ igraph_arpack_rnsolve                      /
 
10261
/-------------------------------------------*/
 
10262
void shell_igraph_arpack_rnsolve_usage(char **argv) {
 
10263
  printf("%s --values=<values>\n", basename(argv[0]));
 
10264
  exit(1);
 
10265
}
 
10266
 
 
10267
int shell_igraph_arpack_rnsolve(int argc, char **argv) {
 
10268
 
 
10269
 
 
10270
 
 
10271
 
 
10272
 
 
10273
  igraph_vector_t v_values; igraph_vector_t *values=0;
 
10274
 
 
10275
  char* shell_arg_options=0;
 
10276
  char* shell_arg_values=0;
 
10277
  char* shell_arg_vectors=0;
 
10278
  int shell_result;
 
10279
 
 
10280
 
 
10281
  int shell_seen[1];
 
10282
  int shell_index=-1;
 
10283
  struct option shell_options[]= { { "values",required_argument,0,0 },
 
10284
                                   { "help",no_argument,0,1 },
 
10285
                                   { 0,0,0,0 }
 
10286
                                 };
 
10287
 
 
10288
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10289
  memset(shell_seen, 0, 1*sizeof(int));
 
10290
 
 
10291
  
 
10292
  /* Parse arguments and read input */
 
10293
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10294
 
 
10295
    if (shell_index==-1) {
 
10296
      exit(1);
 
10297
    }
 
10298
 
 
10299
    if (shell_seen[shell_index]==1) {
 
10300
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10301
              shell_options[shell_index].name);
 
10302
      exit(1);
 
10303
    }
 
10304
    shell_seen[shell_index]=1;  
 
10305
 
 
10306
    switch (shell_index) {
 
10307
    case 0: /* values */
 
10308
      values=&v_values; igraph_vector_init(values, 0); 
 
10309
  shell_arg_values=strdup(optarg);
 
10310
      break;
 
10311
    case 1:
 
10312
      shell_igraph_arpack_rnsolve_usage(argv);
 
10313
      break;
 
10314
    default:
 
10315
      break;
 
10316
    }
 
10317
 
 
10318
    shell_index=-1;
 
10319
  }
 
10320
 
 
10321
  /* Check that we have all arguments */
 
10322
  for (shell_index=0; shell_index<1; shell_index++) {
 
10323
    if (!shell_seen[shell_index]) {
 
10324
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10325
              shell_options[shell_index].name);
 
10326
      exit(1);
 
10327
    }
 
10328
  }
 
10329
 
 
10330
  /* Do the operation */
 
10331
  shell_result=igraph_arpack_rnsolve(0, 0, 0, 0, values, 0);
 
10332
 
 
10333
  /* Write the result */
 
10334
  if (values) { shell_write_vector(values, shell_arg_values); 
 
10335
  igraph_vector_destroy(values); }
 
10336
 
 
10337
  return 0;
 
10338
}
 
10339
 
 
10340
/*-------------------------------------------/
 
10341
/ igraph_arpack_unpack_complex               /
 
10342
/-------------------------------------------*/
 
10343
void shell_igraph_arpack_unpack_complex_usage(char **argv) {
 
10344
  printf("%s --vectors=<vectors> --vectors-out=<vectors-out> --values=<values> --values-out=<values-out> --nev=<nev>\n", basename(argv[0]));
 
10345
  exit(1);
 
10346
}
 
10347
 
 
10348
int shell_igraph_arpack_unpack_complex(int argc, char **argv) {
 
10349
 
 
10350
  igraph_matrix_t vectors;
 
10351
  igraph_matrix_t values;
 
10352
  igraph_real_t nev;
 
10353
  char* shell_arg_vectors=0;
 
10354
  char* shell_arg_values=0;
 
10355
  int shell_result;
 
10356
 
 
10357
 
 
10358
  int shell_seen[5];
 
10359
  int shell_index=-1;
 
10360
  struct option shell_options[]= { { "vectors",required_argument,0,0 },
 
10361
                                   { "vectors-out",required_argument,0,1 },
 
10362
                                   { "values",required_argument,0,2 },
 
10363
                                   { "values-out",required_argument,0,3 },
 
10364
                                   { "nev",required_argument,0,4 },
 
10365
                                   { "help",no_argument,0,5 },
 
10366
                                   { 0,0,0,0 }
 
10367
                                 };
 
10368
 
 
10369
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10370
  memset(shell_seen, 0, 5*sizeof(int));
 
10371
 
 
10372
  
 
10373
  /* Parse arguments and read input */
 
10374
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10375
 
 
10376
    if (shell_index==-1) {
 
10377
      exit(1);
 
10378
    }
 
10379
 
 
10380
    if (shell_seen[shell_index]==1) {
 
10381
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10382
              shell_options[shell_index].name);
 
10383
      exit(1);
 
10384
    }
 
10385
    shell_seen[shell_index]=1;  
 
10386
 
 
10387
    switch (shell_index) {
 
10388
    case 0: /* vectors */
 
10389
      shell_read_matrix(&vectors, optarg);
 
10390
      break;
 
10391
    case 1: /* vectors-out */
 
10392
      shell_arg_vectors=strdup(optarg); 
 
10393
  igraph_matrix_init(&vectors, 0, 0);
 
10394
      break;
 
10395
    case 2: /* values */
 
10396
      shell_read_matrix(&values, optarg);
 
10397
      break;
 
10398
    case 3: /* values-out */
 
10399
      shell_arg_values=strdup(optarg); 
 
10400
  igraph_matrix_init(&values, 0, 0);
 
10401
      break;
 
10402
    case 4: /* nev */
 
10403
      shell_read_real(&nev, optarg);
 
10404
      break;
 
10405
    case 5:
 
10406
      shell_igraph_arpack_unpack_complex_usage(argv);
 
10407
      break;
 
10408
    default:
 
10409
      break;
 
10410
    }
 
10411
 
 
10412
    shell_index=-1;
 
10413
  }
 
10414
 
 
10415
  /* Check that we have all arguments */
 
10416
  for (shell_index=0; shell_index<5; shell_index++) {
 
10417
    if (!shell_seen[shell_index]) {
 
10418
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10419
              shell_options[shell_index].name);
 
10420
      exit(1);
 
10421
    }
 
10422
  }
 
10423
 
 
10424
  /* Do the operation */
 
10425
  shell_result=igraph_arpack_unpack_complex(&vectors, &values, nev);
 
10426
 
 
10427
  /* Write the result */
 
10428
  igraph_matrix_destroy(&vectors);
 
10429
  shell_write_matrix(&vectors, shell_arg_vectors); 
 
10430
  igraph_matrix_destroy(&vectors);
 
10431
  igraph_matrix_destroy(&values);
 
10432
  shell_write_matrix(&values, shell_arg_values); 
 
10433
  igraph_matrix_destroy(&values);
 
10434
 
 
10435
  return 0;
 
10436
}
 
10437
 
 
10438
/*-------------------------------------------/
 
10439
/ igraph_unfold_tree                         /
 
10440
/-------------------------------------------*/
 
10441
void shell_igraph_unfold_tree_usage(char **argv) {
 
10442
  printf("%s --graph=<graph> --tree=<tree> --mode=<mode> --roots=<roots> --vertex_index=<vertex_index>\n", basename(argv[0]));
 
10443
  exit(1);
 
10444
}
 
10445
 
 
10446
int shell_igraph_unfold_tree(int argc, char **argv) {
 
10447
 
 
10448
  igraph_t graph;
 
10449
  igraph_t tree;
 
10450
  igraph_neimode_t mode=IGRAPH_ALL;
 
10451
  igraph_vector_t roots;
 
10452
  igraph_vector_t v_vertex_index; igraph_vector_t *vertex_index=0;
 
10453
  char* shell_arg_tree=0;
 
10454
  char* shell_arg_vertex_index=0;
 
10455
  int shell_result;
 
10456
 
 
10457
 
 
10458
  int shell_seen[5];
 
10459
  int shell_index=-1;
 
10460
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10461
                                   { "tree",required_argument,0,1 },
 
10462
                                   { "mode",required_argument,0,2 },
 
10463
                                   { "roots",required_argument,0,3 },
 
10464
                                   { "vertex_index",required_argument,0,4 },
 
10465
                                   { "help",no_argument,0,5 },
 
10466
                                   { 0,0,0,0 }
 
10467
                                 };
 
10468
 
 
10469
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10470
  memset(shell_seen, 0, 5*sizeof(int));
 
10471
  shell_seen[2]=2;
 
10472
  
 
10473
  /* Parse arguments and read input */
 
10474
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10475
 
 
10476
    if (shell_index==-1) {
 
10477
      exit(1);
 
10478
    }
 
10479
 
 
10480
    if (shell_seen[shell_index]==1) {
 
10481
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10482
              shell_options[shell_index].name);
 
10483
      exit(1);
 
10484
    }
 
10485
    shell_seen[shell_index]=1;  
 
10486
 
 
10487
    switch (shell_index) {
 
10488
    case 0: /* graph */
 
10489
      shell_read_graph(&graph, optarg);
 
10490
      break;
 
10491
    case 1: /* tree */
 
10492
      shell_arg_tree=strdup(optarg);
 
10493
      break;
 
10494
    case 2: /* mode */
 
10495
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
10496
      break;
 
10497
    case 3: /* roots */
 
10498
      shell_read_vector(&roots, optarg);
 
10499
      break;
 
10500
    case 4: /* vertex_index */
 
10501
      vertex_index=&v_vertex_index; igraph_vector_init(vertex_index, 0); 
 
10502
  shell_arg_vertex_index=strdup(optarg);
 
10503
      break;
 
10504
    case 5:
 
10505
      shell_igraph_unfold_tree_usage(argv);
 
10506
      break;
 
10507
    default:
 
10508
      break;
 
10509
    }
 
10510
 
 
10511
    shell_index=-1;
 
10512
  }
 
10513
 
 
10514
  /* Check that we have all arguments */
 
10515
  for (shell_index=0; shell_index<5; shell_index++) {
 
10516
    if (!shell_seen[shell_index]) {
 
10517
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10518
              shell_options[shell_index].name);
 
10519
      exit(1);
 
10520
    }
 
10521
  }
 
10522
 
 
10523
  /* Do the operation */
 
10524
  shell_result=igraph_unfold_tree(&graph, &tree, mode, &roots, vertex_index);
 
10525
 
 
10526
  /* Write the result */
 
10527
  igraph_destroy(&graph);
 
10528
  shell_write_graph(&tree, shell_arg_tree); 
 
10529
  igraph_destroy(&tree);
 
10530
  igraph_vector_destroy(&roots);
 
10531
  if (vertex_index) { shell_write_vector(vertex_index, shell_arg_vertex_index); 
 
10532
  igraph_vector_destroy(vertex_index); }
 
10533
 
 
10534
  return 0;
 
10535
}
 
10536
 
 
10537
/*-------------------------------------------/
 
10538
/ igraph_laplacian                           /
 
10539
/-------------------------------------------*/
 
10540
void shell_igraph_laplacian_usage(char **argv) {
 
10541
  printf("%s --graph=<graph> --res=<res> --normalized=<normalized>\n", basename(argv[0]));
 
10542
  exit(1);
 
10543
}
 
10544
 
 
10545
int shell_igraph_laplacian(int argc, char **argv) {
 
10546
 
 
10547
  igraph_t graph;
 
10548
  igraph_matrix_t res;
 
10549
  igraph_bool_t normalized=0;
 
10550
  char* shell_arg_res=0;
 
10551
  int shell_result;
 
10552
 
 
10553
 
 
10554
  int shell_seen[3];
 
10555
  int shell_index=-1;
 
10556
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10557
                                   { "res",required_argument,0,1 },
 
10558
                                   { "normalized",required_argument,0,2 },
 
10559
                                   { "help",no_argument,0,3 },
 
10560
                                   { 0,0,0,0 }
 
10561
                                 };
 
10562
 
 
10563
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10564
  memset(shell_seen, 0, 3*sizeof(int));
 
10565
  shell_seen[2]=2;
 
10566
  
 
10567
  /* Parse arguments and read input */
 
10568
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10569
 
 
10570
    if (shell_index==-1) {
 
10571
      exit(1);
 
10572
    }
 
10573
 
 
10574
    if (shell_seen[shell_index]==1) {
 
10575
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10576
              shell_options[shell_index].name);
 
10577
      exit(1);
 
10578
    }
 
10579
    shell_seen[shell_index]=1;  
 
10580
 
 
10581
    switch (shell_index) {
 
10582
    case 0: /* graph */
 
10583
      shell_read_graph(&graph, optarg);
 
10584
      break;
 
10585
    case 1: /* res */
 
10586
      shell_arg_res=strdup(optarg); 
 
10587
  igraph_matrix_init(&res, 0, 0);
 
10588
      break;
 
10589
    case 2: /* normalized */
 
10590
      shell_read_boolean(&normalized, optarg);
 
10591
      break;
 
10592
    case 3:
 
10593
      shell_igraph_laplacian_usage(argv);
 
10594
      break;
 
10595
    default:
 
10596
      break;
 
10597
    }
 
10598
 
 
10599
    shell_index=-1;
 
10600
  }
 
10601
 
 
10602
  /* Check that we have all arguments */
 
10603
  for (shell_index=0; shell_index<3; shell_index++) {
 
10604
    if (!shell_seen[shell_index]) {
 
10605
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10606
              shell_options[shell_index].name);
 
10607
      exit(1);
 
10608
    }
 
10609
  }
 
10610
 
 
10611
  /* Do the operation */
 
10612
  shell_result=igraph_laplacian(&graph, &res, normalized);
 
10613
 
 
10614
  /* Write the result */
 
10615
  igraph_destroy(&graph);
 
10616
  shell_write_matrix(&res, shell_arg_res); 
 
10617
  igraph_matrix_destroy(&res);
 
10618
 
 
10619
  return 0;
 
10620
}
 
10621
 
 
10622
/*-------------------------------------------/
 
10623
/ igraph_is_mutual                           /
 
10624
/-------------------------------------------*/
 
10625
void shell_igraph_is_mutual_usage(char **argv) {
 
10626
  printf("%s --graph=<graph> --res=<res> --es=<es>\n", basename(argv[0]));
 
10627
  exit(1);
 
10628
}
 
10629
 
 
10630
int shell_igraph_is_mutual(int argc, char **argv) {
 
10631
 
 
10632
  igraph_t graph;
 
10633
  igraph_vector_bool_t res;
 
10634
  igraph_vector_t v_es; igraph_es_t es=igraph_ess_all(IGRAPH_EDGEORDER_ID);
 
10635
  char* shell_arg_res=0;
 
10636
  int shell_result;
 
10637
 
 
10638
 
 
10639
  int shell_seen[3];
 
10640
  int shell_index=-1;
 
10641
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10642
                                   { "res",required_argument,0,1 },
 
10643
                                   { "es",required_argument,0,2 },
 
10644
                                   { "help",no_argument,0,3 },
 
10645
                                   { 0,0,0,0 }
 
10646
                                 };
 
10647
 
 
10648
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10649
  memset(shell_seen, 0, 3*sizeof(int));
 
10650
  shell_seen[2]=2;
 
10651
  
 
10652
  /* Parse arguments and read input */
 
10653
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10654
 
 
10655
    if (shell_index==-1) {
 
10656
      exit(1);
 
10657
    }
 
10658
 
 
10659
    if (shell_seen[shell_index]==1) {
 
10660
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10661
              shell_options[shell_index].name);
 
10662
      exit(1);
 
10663
    }
 
10664
    shell_seen[shell_index]=1;  
 
10665
 
 
10666
    switch (shell_index) {
 
10667
    case 0: /* graph */
 
10668
      shell_read_graph(&graph, optarg);
 
10669
      break;
 
10670
    case 1: /* res */
 
10671
      igraph_vector_bool_init(&res, 0);
 
10672
      break;
 
10673
    case 2: /* es */
 
10674
      shell_read_vector(&v_es, optarg); igraph_es_vector(&es, &v_es);
 
10675
      break;
 
10676
    case 3:
 
10677
      shell_igraph_is_mutual_usage(argv);
 
10678
      break;
 
10679
    default:
 
10680
      break;
 
10681
    }
 
10682
 
 
10683
    shell_index=-1;
 
10684
  }
 
10685
 
 
10686
  /* Check that we have all arguments */
 
10687
  for (shell_index=0; shell_index<3; shell_index++) {
 
10688
    if (!shell_seen[shell_index]) {
 
10689
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10690
              shell_options[shell_index].name);
 
10691
      exit(1);
 
10692
    }
 
10693
  }
 
10694
 
 
10695
  /* Do the operation */
 
10696
  shell_result=igraph_is_mutual(&graph, &res, es);
 
10697
 
 
10698
  /* Write the result */
 
10699
  igraph_destroy(&graph);
 
10700
  shell_write_vector_bool(&res, shell_arg_res); 
 
10701
  igraph_vector_bool_destroy(&res);
 
10702
  if (!igraph_es_is_all(&es)) { igraph_es_destroy(&es); }
 
10703
 
 
10704
  return 0;
 
10705
}
 
10706
 
 
10707
/*-------------------------------------------/
 
10708
/ igraph_avg_nearest_neighbor_degree         /
 
10709
/-------------------------------------------*/
 
10710
void shell_igraph_avg_nearest_neighbor_degree_usage(char **argv) {
 
10711
  printf("%s --graph=<graph> --vids=<vids> --knn=<knn> --knnk=<knnk>\n", basename(argv[0]));
 
10712
  exit(1);
 
10713
}
 
10714
 
 
10715
int shell_igraph_avg_nearest_neighbor_degree(int argc, char **argv) {
 
10716
 
 
10717
  igraph_t graph;
 
10718
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
10719
  igraph_vector_t v_knn; igraph_vector_t *knn=0;
 
10720
  igraph_vector_t v_knnk; igraph_vector_t *knnk=0;
 
10721
 
 
10722
  char* shell_arg_knn=0;
 
10723
  char* shell_arg_knnk=0;
 
10724
  int shell_result;
 
10725
 
 
10726
 
 
10727
  int shell_seen[4];
 
10728
  int shell_index=-1;
 
10729
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10730
                                   { "vids",required_argument,0,1 },
 
10731
                                   { "knn",required_argument,0,2 },
 
10732
                                   { "knnk",required_argument,0,3 },
 
10733
                                   { "help",no_argument,0,4 },
 
10734
                                   { 0,0,0,0 }
 
10735
                                 };
 
10736
 
 
10737
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10738
  memset(shell_seen, 0, 4*sizeof(int));
 
10739
  shell_seen[1]=2;
 
10740
  
 
10741
  /* Parse arguments and read input */
 
10742
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10743
 
 
10744
    if (shell_index==-1) {
 
10745
      exit(1);
 
10746
    }
 
10747
 
 
10748
    if (shell_seen[shell_index]==1) {
 
10749
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10750
              shell_options[shell_index].name);
 
10751
      exit(1);
 
10752
    }
 
10753
    shell_seen[shell_index]=1;  
 
10754
 
 
10755
    switch (shell_index) {
 
10756
    case 0: /* graph */
 
10757
      shell_read_graph(&graph, optarg);
 
10758
      break;
 
10759
    case 1: /* vids */
 
10760
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
10761
      break;
 
10762
    case 2: /* knn */
 
10763
      knn=&v_knn; igraph_vector_init(knn, 0); 
 
10764
  shell_arg_knn=strdup(optarg);
 
10765
      break;
 
10766
    case 3: /* knnk */
 
10767
      knnk=&v_knnk; igraph_vector_init(knnk, 0); 
 
10768
  shell_arg_knnk=strdup(optarg);
 
10769
      break;
 
10770
    case 4:
 
10771
      shell_igraph_avg_nearest_neighbor_degree_usage(argv);
 
10772
      break;
 
10773
    default:
 
10774
      break;
 
10775
    }
 
10776
 
 
10777
    shell_index=-1;
 
10778
  }
 
10779
 
 
10780
  /* Check that we have all arguments */
 
10781
  for (shell_index=0; shell_index<4; shell_index++) {
 
10782
    if (!shell_seen[shell_index]) {
 
10783
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10784
              shell_options[shell_index].name);
 
10785
      exit(1);
 
10786
    }
 
10787
  }
 
10788
 
 
10789
  /* Do the operation */
 
10790
  shell_result=igraph_avg_nearest_neighbor_degree(&graph, vids, knn, knnk, 0);
 
10791
 
 
10792
  /* Write the result */
 
10793
  igraph_destroy(&graph);
 
10794
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
10795
  if (knn) { shell_write_vector(knn, shell_arg_knn); 
 
10796
  igraph_vector_destroy(knn); }
 
10797
  if (knnk) { shell_write_vector(knnk, shell_arg_knnk); 
 
10798
  igraph_vector_destroy(knnk); }
 
10799
 
 
10800
  return 0;
 
10801
}
 
10802
 
 
10803
/*-------------------------------------------/
 
10804
/ igraph_strength                            /
 
10805
/-------------------------------------------*/
 
10806
void shell_igraph_strength_usage(char **argv) {
 
10807
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode> --loops=<loops>\n", basename(argv[0]));
 
10808
  exit(1);
 
10809
}
 
10810
 
 
10811
int shell_igraph_strength(int argc, char **argv) {
 
10812
 
 
10813
  igraph_t graph;
 
10814
  igraph_vector_t res;
 
10815
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
10816
  igraph_neimode_t mode=IGRAPH_ALL;
 
10817
  igraph_bool_t loops=1;
 
10818
 
 
10819
  char* shell_arg_res=0;
 
10820
  int shell_result;
 
10821
 
 
10822
 
 
10823
  int shell_seen[5];
 
10824
  int shell_index=-1;
 
10825
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10826
                                   { "res",required_argument,0,1 },
 
10827
                                   { "vids",required_argument,0,2 },
 
10828
                                   { "mode",required_argument,0,3 },
 
10829
                                   { "loops",required_argument,0,4 },
 
10830
                                   { "help",no_argument,0,5 },
 
10831
                                   { 0,0,0,0 }
 
10832
                                 };
 
10833
 
 
10834
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10835
  memset(shell_seen, 0, 5*sizeof(int));
 
10836
  shell_seen[2]=2;
 
10837
  shell_seen[3]=2;
 
10838
  shell_seen[4]=2;
 
10839
  
 
10840
  /* Parse arguments and read input */
 
10841
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10842
 
 
10843
    if (shell_index==-1) {
 
10844
      exit(1);
 
10845
    }
 
10846
 
 
10847
    if (shell_seen[shell_index]==1) {
 
10848
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10849
              shell_options[shell_index].name);
 
10850
      exit(1);
 
10851
    }
 
10852
    shell_seen[shell_index]=1;  
 
10853
 
 
10854
    switch (shell_index) {
 
10855
    case 0: /* graph */
 
10856
      shell_read_graph(&graph, optarg);
 
10857
      break;
 
10858
    case 1: /* res */
 
10859
      shell_arg_res=strdup(optarg); 
 
10860
  igraph_vector_init(&res, 0);
 
10861
      break;
 
10862
    case 2: /* vids */
 
10863
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
10864
      break;
 
10865
    case 3: /* mode */
 
10866
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
10867
      break;
 
10868
    case 4: /* loops */
 
10869
      shell_read_boolean(&loops, optarg);
 
10870
      break;
 
10871
    case 5:
 
10872
      shell_igraph_strength_usage(argv);
 
10873
      break;
 
10874
    default:
 
10875
      break;
 
10876
    }
 
10877
 
 
10878
    shell_index=-1;
 
10879
  }
 
10880
 
 
10881
  /* Check that we have all arguments */
 
10882
  for (shell_index=0; shell_index<5; shell_index++) {
 
10883
    if (!shell_seen[shell_index]) {
 
10884
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10885
              shell_options[shell_index].name);
 
10886
      exit(1);
 
10887
    }
 
10888
  }
 
10889
 
 
10890
  /* Do the operation */
 
10891
  shell_result=igraph_strength(&graph, &res, vids, mode, loops, 0);
 
10892
 
 
10893
  /* Write the result */
 
10894
  igraph_destroy(&graph);
 
10895
  shell_write_vector(&res, shell_arg_res); 
 
10896
  igraph_vector_destroy(&res);
 
10897
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
10898
 
 
10899
  return 0;
 
10900
}
 
10901
 
 
10902
/*-------------------------------------------/
 
10903
/ igraph_bipartite_projection_size           /
 
10904
/-------------------------------------------*/
 
10905
void shell_igraph_bipartite_projection_size_usage(char **argv) {
 
10906
  printf("%s --graph=<graph> --vcount1=<vcount1> --ecount1=<ecount1> --vcount2=<vcount2> --ecount2=<ecount2>\n", basename(argv[0]));
 
10907
  exit(1);
 
10908
}
 
10909
 
 
10910
int shell_igraph_bipartite_projection_size(int argc, char **argv) {
 
10911
 
 
10912
  igraph_t graph;
 
10913
 
 
10914
  igraph_integer_t vcount1;
 
10915
  igraph_integer_t ecount1;
 
10916
  igraph_integer_t vcount2;
 
10917
  igraph_integer_t ecount2;
 
10918
  char* shell_arg_vcount1=0;
 
10919
  char* shell_arg_ecount1=0;
 
10920
  char* shell_arg_vcount2=0;
 
10921
  char* shell_arg_ecount2=0;
 
10922
  int shell_result;
 
10923
 
 
10924
 
 
10925
  int shell_seen[5];
 
10926
  int shell_index=-1;
 
10927
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
10928
                                   { "vcount1",required_argument,0,1 },
 
10929
                                   { "ecount1",required_argument,0,2 },
 
10930
                                   { "vcount2",required_argument,0,3 },
 
10931
                                   { "ecount2",required_argument,0,4 },
 
10932
                                   { "help",no_argument,0,5 },
 
10933
                                   { 0,0,0,0 }
 
10934
                                 };
 
10935
 
 
10936
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
10937
  memset(shell_seen, 0, 5*sizeof(int));
 
10938
 
 
10939
  
 
10940
  /* Parse arguments and read input */
 
10941
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
10942
 
 
10943
    if (shell_index==-1) {
 
10944
      exit(1);
 
10945
    }
 
10946
 
 
10947
    if (shell_seen[shell_index]==1) {
 
10948
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
10949
              shell_options[shell_index].name);
 
10950
      exit(1);
 
10951
    }
 
10952
    shell_seen[shell_index]=1;  
 
10953
 
 
10954
    switch (shell_index) {
 
10955
    case 0: /* graph */
 
10956
      shell_read_graph(&graph, optarg);
 
10957
      break;
 
10958
    case 1: /* vcount1 */
 
10959
      shell_arg_vcount1=strdup(optarg);
 
10960
      break;
 
10961
    case 2: /* ecount1 */
 
10962
      shell_arg_ecount1=strdup(optarg);
 
10963
      break;
 
10964
    case 3: /* vcount2 */
 
10965
      shell_arg_vcount2=strdup(optarg);
 
10966
      break;
 
10967
    case 4: /* ecount2 */
 
10968
      shell_arg_ecount2=strdup(optarg);
 
10969
      break;
 
10970
    case 5:
 
10971
      shell_igraph_bipartite_projection_size_usage(argv);
 
10972
      break;
 
10973
    default:
 
10974
      break;
 
10975
    }
 
10976
 
 
10977
    shell_index=-1;
 
10978
  }
 
10979
 
 
10980
  /* Check that we have all arguments */
 
10981
  for (shell_index=0; shell_index<5; shell_index++) {
 
10982
    if (!shell_seen[shell_index]) {
 
10983
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
10984
              shell_options[shell_index].name);
 
10985
      exit(1);
 
10986
    }
 
10987
  }
 
10988
 
 
10989
  /* Do the operation */
 
10990
  shell_result=igraph_bipartite_projection_size(&graph, types, &vcount1, &ecount1, &vcount2, &ecount2);
 
10991
 
 
10992
  /* Write the result */
 
10993
  igraph_destroy(&graph);
 
10994
  shell_write_integer(vcount1, shell_arg_vcount1);
 
10995
  shell_write_integer(ecount1, shell_arg_ecount1);
 
10996
  shell_write_integer(vcount2, shell_arg_vcount2);
 
10997
  shell_write_integer(ecount2, shell_arg_ecount2);
 
10998
 
 
10999
  return 0;
 
11000
}
 
11001
 
 
11002
/*-------------------------------------------/
 
11003
/ igraph_bipartite_projection                /
 
11004
/-------------------------------------------*/
 
11005
void shell_igraph_bipartite_projection_usage(char **argv) {
 
11006
  printf("%s --graph=<graph> --proj1=<proj1> --proj2=<proj2> --probe1=<probe1>\n", basename(argv[0]));
 
11007
  exit(1);
 
11008
}
 
11009
 
 
11010
int shell_igraph_bipartite_projection(int argc, char **argv) {
 
11011
 
 
11012
  igraph_t graph;
 
11013
 
 
11014
  igraph_t proj1;
 
11015
  igraph_t proj2;
 
11016
  igraph_integer_t probe1=-1;
 
11017
  char* shell_arg_proj1=0;
 
11018
  char* shell_arg_proj2=0;
 
11019
  int shell_result;
 
11020
 
 
11021
 
 
11022
  int shell_seen[4];
 
11023
  int shell_index=-1;
 
11024
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11025
                                   { "proj1",required_argument,0,1 },
 
11026
                                   { "proj2",required_argument,0,2 },
 
11027
                                   { "probe1",required_argument,0,3 },
 
11028
                                   { "help",no_argument,0,4 },
 
11029
                                   { 0,0,0,0 }
 
11030
                                 };
 
11031
 
 
11032
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11033
  memset(shell_seen, 0, 4*sizeof(int));
 
11034
  shell_seen[3]=2;
 
11035
  
 
11036
  /* Parse arguments and read input */
 
11037
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11038
 
 
11039
    if (shell_index==-1) {
 
11040
      exit(1);
 
11041
    }
 
11042
 
 
11043
    if (shell_seen[shell_index]==1) {
 
11044
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11045
              shell_options[shell_index].name);
 
11046
      exit(1);
 
11047
    }
 
11048
    shell_seen[shell_index]=1;  
 
11049
 
 
11050
    switch (shell_index) {
 
11051
    case 0: /* graph */
 
11052
      shell_read_graph(&graph, optarg);
 
11053
      break;
 
11054
    case 1: /* proj1 */
 
11055
      shell_arg_proj1=strdup(optarg);
 
11056
      break;
 
11057
    case 2: /* proj2 */
 
11058
      shell_arg_proj2=strdup(optarg);
 
11059
      break;
 
11060
    case 3: /* probe1 */
 
11061
      shell_read_integer(&probe1, optarg);
 
11062
      break;
 
11063
    case 4:
 
11064
      shell_igraph_bipartite_projection_usage(argv);
 
11065
      break;
 
11066
    default:
 
11067
      break;
 
11068
    }
 
11069
 
 
11070
    shell_index=-1;
 
11071
  }
 
11072
 
 
11073
  /* Check that we have all arguments */
 
11074
  for (shell_index=0; shell_index<4; shell_index++) {
 
11075
    if (!shell_seen[shell_index]) {
 
11076
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11077
              shell_options[shell_index].name);
 
11078
      exit(1);
 
11079
    }
 
11080
  }
 
11081
 
 
11082
  /* Do the operation */
 
11083
  shell_result=igraph_bipartite_projection(&graph, types, &proj1, &proj2, probe1);
 
11084
 
 
11085
  /* Write the result */
 
11086
  igraph_destroy(&graph);
 
11087
  shell_write_graph(&proj1, shell_arg_proj1); 
 
11088
  igraph_destroy(&proj1);
 
11089
  shell_write_graph(&proj2, shell_arg_proj2); 
 
11090
  igraph_destroy(&proj2);
 
11091
 
 
11092
  return 0;
 
11093
}
 
11094
 
 
11095
/*-------------------------------------------/
 
11096
/ igraph_create_bipartite                    /
 
11097
/-------------------------------------------*/
 
11098
void shell_igraph_create_bipartite_usage(char **argv) {
 
11099
  printf("%s --graph=<graph> --types=<types> --edges=<edges> --directed=<directed>\n", basename(argv[0]));
 
11100
  exit(1);
 
11101
}
 
11102
 
 
11103
int shell_igraph_create_bipartite(int argc, char **argv) {
 
11104
 
 
11105
  igraph_t graph;
 
11106
  igraph_vector_bool_t types;
 
11107
  igraph_vector_t edges;
 
11108
  igraph_bool_t directed=0;
 
11109
  char* shell_arg_graph=0;
 
11110
  int shell_result;
 
11111
 
 
11112
 
 
11113
  int shell_seen[4];
 
11114
  int shell_index=-1;
 
11115
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11116
                                   { "types",required_argument,0,1 },
 
11117
                                   { "edges",required_argument,0,2 },
 
11118
                                   { "directed",required_argument,0,3 },
 
11119
                                   { "help",no_argument,0,4 },
 
11120
                                   { 0,0,0,0 }
 
11121
                                 };
 
11122
 
 
11123
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11124
  memset(shell_seen, 0, 4*sizeof(int));
 
11125
  shell_seen[3]=2;
 
11126
  
 
11127
  /* Parse arguments and read input */
 
11128
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11129
 
 
11130
    if (shell_index==-1) {
 
11131
      exit(1);
 
11132
    }
 
11133
 
 
11134
    if (shell_seen[shell_index]==1) {
 
11135
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11136
              shell_options[shell_index].name);
 
11137
      exit(1);
 
11138
    }
 
11139
    shell_seen[shell_index]=1;  
 
11140
 
 
11141
    switch (shell_index) {
 
11142
    case 0: /* graph */
 
11143
      shell_arg_graph=strdup(optarg);
 
11144
      break;
 
11145
    case 1: /* types */
 
11146
      
 
11147
      break;
 
11148
    case 2: /* edges */
 
11149
      shell_read_vector(&edges, optarg);
 
11150
      break;
 
11151
    case 3: /* directed */
 
11152
      shell_read_boolean(&directed, optarg);
 
11153
      break;
 
11154
    case 4:
 
11155
      shell_igraph_create_bipartite_usage(argv);
 
11156
      break;
 
11157
    default:
 
11158
      break;
 
11159
    }
 
11160
 
 
11161
    shell_index=-1;
 
11162
  }
 
11163
 
 
11164
  /* Check that we have all arguments */
 
11165
  for (shell_index=0; shell_index<4; shell_index++) {
 
11166
    if (!shell_seen[shell_index]) {
 
11167
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11168
              shell_options[shell_index].name);
 
11169
      exit(1);
 
11170
    }
 
11171
  }
 
11172
 
 
11173
  /* Do the operation */
 
11174
  shell_result=igraph_create_bipartite(&graph, &types, &edges, directed);
 
11175
 
 
11176
  /* Write the result */
 
11177
  shell_write_graph(&graph, shell_arg_graph); 
 
11178
  igraph_destroy(&graph);
 
11179
  igraph_vector_destroy(&edges);
 
11180
 
 
11181
  return 0;
 
11182
}
 
11183
 
 
11184
/*-------------------------------------------/
 
11185
/ igraph_incidence                           /
 
11186
/-------------------------------------------*/
 
11187
void shell_igraph_incidence_usage(char **argv) {
 
11188
  printf("%s --graph=<graph> --types=<types> --incidence=<incidence> --directed=<directed> --mode=<mode> --multiple=<multiple>\n", basename(argv[0]));
 
11189
  exit(1);
 
11190
}
 
11191
 
 
11192
int shell_igraph_incidence(int argc, char **argv) {
 
11193
 
 
11194
  igraph_t graph;
 
11195
  igraph_vector_bool_t types;
 
11196
  igraph_matrix_t incidence;
 
11197
  igraph_bool_t directed=0;
 
11198
  igraph_neimode_t mode=IGRAPH_ALL;
 
11199
  igraph_bool_t multiple=0;
 
11200
  char* shell_arg_graph=0;
 
11201
  char* shell_arg_types=0;
 
11202
  int shell_result;
 
11203
 
 
11204
 
 
11205
  int shell_seen[6];
 
11206
  int shell_index=-1;
 
11207
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11208
                                   { "types",required_argument,0,1 },
 
11209
                                   { "incidence",required_argument,0,2 },
 
11210
                                   { "directed",required_argument,0,3 },
 
11211
                                   { "mode",required_argument,0,4 },
 
11212
                                   { "multiple",required_argument,0,5 },
 
11213
                                   { "help",no_argument,0,6 },
 
11214
                                   { 0,0,0,0 }
 
11215
                                 };
 
11216
 
 
11217
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11218
  memset(shell_seen, 0, 6*sizeof(int));
 
11219
  shell_seen[3]=2;
 
11220
  shell_seen[4]=2;
 
11221
  shell_seen[5]=2;
 
11222
  
 
11223
  /* Parse arguments and read input */
 
11224
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11225
 
 
11226
    if (shell_index==-1) {
 
11227
      exit(1);
 
11228
    }
 
11229
 
 
11230
    if (shell_seen[shell_index]==1) {
 
11231
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11232
              shell_options[shell_index].name);
 
11233
      exit(1);
 
11234
    }
 
11235
    shell_seen[shell_index]=1;  
 
11236
 
 
11237
    switch (shell_index) {
 
11238
    case 0: /* graph */
 
11239
      shell_arg_graph=strdup(optarg);
 
11240
      break;
 
11241
    case 1: /* types */
 
11242
      igraph_vector_bool_init(&types, 0);
 
11243
      break;
 
11244
    case 2: /* incidence */
 
11245
      shell_read_matrix(&incidence, optarg);
 
11246
      break;
 
11247
    case 3: /* directed */
 
11248
      shell_read_boolean(&directed, optarg);
 
11249
      break;
 
11250
    case 4: /* mode */
 
11251
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
11252
      break;
 
11253
    case 5: /* multiple */
 
11254
      shell_read_boolean(&multiple, optarg);
 
11255
      break;
 
11256
    case 6:
 
11257
      shell_igraph_incidence_usage(argv);
 
11258
      break;
 
11259
    default:
 
11260
      break;
 
11261
    }
 
11262
 
 
11263
    shell_index=-1;
 
11264
  }
 
11265
 
 
11266
  /* Check that we have all arguments */
 
11267
  for (shell_index=0; shell_index<6; shell_index++) {
 
11268
    if (!shell_seen[shell_index]) {
 
11269
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11270
              shell_options[shell_index].name);
 
11271
      exit(1);
 
11272
    }
 
11273
  }
 
11274
 
 
11275
  /* Do the operation */
 
11276
  shell_result=igraph_incidence(&graph, &types, &incidence, directed, mode, multiple);
 
11277
 
 
11278
  /* Write the result */
 
11279
  shell_write_graph(&graph, shell_arg_graph); 
 
11280
  igraph_destroy(&graph);
 
11281
  shell_write_vector_bool(&types, shell_arg_types); 
 
11282
  igraph_vector_bool_destroy(&types);
 
11283
  igraph_matrix_destroy(&incidence);
 
11284
 
 
11285
  return 0;
 
11286
}
 
11287
 
 
11288
/*-------------------------------------------/
 
11289
/ igraph_get_incidence                       /
 
11290
/-------------------------------------------*/
 
11291
void shell_igraph_get_incidence_usage(char **argv) {
 
11292
  printf("%s --graph=<graph> --res=<res> --row_ids=<row_ids> --col_ids=<col_ids>\n", basename(argv[0]));
 
11293
  exit(1);
 
11294
}
 
11295
 
 
11296
int shell_igraph_get_incidence(int argc, char **argv) {
 
11297
 
 
11298
  igraph_t graph;
 
11299
 
 
11300
  igraph_matrix_t res;
 
11301
  igraph_vector_t v_row_ids; igraph_vector_t *row_ids=0;
 
11302
  igraph_vector_t v_col_ids; igraph_vector_t *col_ids=0;
 
11303
  char* shell_arg_res=0;
 
11304
  char* shell_arg_row_ids=0;
 
11305
  char* shell_arg_col_ids=0;
 
11306
  int shell_result;
 
11307
 
 
11308
 
 
11309
  int shell_seen[4];
 
11310
  int shell_index=-1;
 
11311
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11312
                                   { "res",required_argument,0,1 },
 
11313
                                   { "row_ids",required_argument,0,2 },
 
11314
                                   { "col_ids",required_argument,0,3 },
 
11315
                                   { "help",no_argument,0,4 },
 
11316
                                   { 0,0,0,0 }
 
11317
                                 };
 
11318
 
 
11319
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11320
  memset(shell_seen, 0, 4*sizeof(int));
 
11321
 
 
11322
  
 
11323
  /* Parse arguments and read input */
 
11324
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11325
 
 
11326
    if (shell_index==-1) {
 
11327
      exit(1);
 
11328
    }
 
11329
 
 
11330
    if (shell_seen[shell_index]==1) {
 
11331
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11332
              shell_options[shell_index].name);
 
11333
      exit(1);
 
11334
    }
 
11335
    shell_seen[shell_index]=1;  
 
11336
 
 
11337
    switch (shell_index) {
 
11338
    case 0: /* graph */
 
11339
      shell_read_graph(&graph, optarg);
 
11340
      break;
 
11341
    case 1: /* res */
 
11342
      shell_arg_res=strdup(optarg); 
 
11343
  igraph_matrix_init(&res, 0, 0);
 
11344
      break;
 
11345
    case 2: /* row_ids */
 
11346
      row_ids=&v_row_ids; igraph_vector_init(row_ids, 0); 
 
11347
  shell_arg_row_ids=strdup(optarg);
 
11348
      break;
 
11349
    case 3: /* col_ids */
 
11350
      col_ids=&v_col_ids; igraph_vector_init(col_ids, 0); 
 
11351
  shell_arg_col_ids=strdup(optarg);
 
11352
      break;
 
11353
    case 4:
 
11354
      shell_igraph_get_incidence_usage(argv);
 
11355
      break;
 
11356
    default:
 
11357
      break;
 
11358
    }
 
11359
 
 
11360
    shell_index=-1;
 
11361
  }
 
11362
 
 
11363
  /* Check that we have all arguments */
 
11364
  for (shell_index=0; shell_index<4; shell_index++) {
 
11365
    if (!shell_seen[shell_index]) {
 
11366
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11367
              shell_options[shell_index].name);
 
11368
      exit(1);
 
11369
    }
 
11370
  }
 
11371
 
 
11372
  /* Do the operation */
 
11373
  shell_result=igraph_get_incidence(&graph, types, &res, row_ids, col_ids);
 
11374
 
 
11375
  /* Write the result */
 
11376
  igraph_destroy(&graph);
 
11377
  shell_write_matrix(&res, shell_arg_res); 
 
11378
  igraph_matrix_destroy(&res);
 
11379
  if (row_ids) { shell_write_vector(row_ids, shell_arg_row_ids); 
 
11380
  igraph_vector_destroy(row_ids); }
 
11381
  if (col_ids) { shell_write_vector(col_ids, shell_arg_col_ids); 
 
11382
  igraph_vector_destroy(col_ids); }
 
11383
 
 
11384
  return 0;
 
11385
}
 
11386
 
 
11387
/*-------------------------------------------/
 
11388
/ igraph_is_bipartite                        /
 
11389
/-------------------------------------------*/
 
11390
void shell_igraph_is_bipartite_usage(char **argv) {
 
11391
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
11392
  exit(1);
 
11393
}
 
11394
 
 
11395
int shell_igraph_is_bipartite(int argc, char **argv) {
 
11396
 
 
11397
  igraph_t graph;
 
11398
  igraph_bool_t res;
 
11399
 
 
11400
  char* shell_arg_res=0;
 
11401
  char* shell_arg_type=0;
 
11402
  int shell_result;
 
11403
 
 
11404
 
 
11405
  int shell_seen[2];
 
11406
  int shell_index=-1;
 
11407
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11408
                                   { "res",required_argument,0,1 },
 
11409
                                   { "help",no_argument,0,2 },
 
11410
                                   { 0,0,0,0 }
 
11411
                                 };
 
11412
 
 
11413
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11414
  memset(shell_seen, 0, 2*sizeof(int));
 
11415
 
 
11416
  
 
11417
  /* Parse arguments and read input */
 
11418
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11419
 
 
11420
    if (shell_index==-1) {
 
11421
      exit(1);
 
11422
    }
 
11423
 
 
11424
    if (shell_seen[shell_index]==1) {
 
11425
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11426
              shell_options[shell_index].name);
 
11427
      exit(1);
 
11428
    }
 
11429
    shell_seen[shell_index]=1;  
 
11430
 
 
11431
    switch (shell_index) {
 
11432
    case 0: /* graph */
 
11433
      shell_read_graph(&graph, optarg);
 
11434
      break;
 
11435
    case 1: /* res */
 
11436
      
 
11437
      break;
 
11438
    case 2:
 
11439
      shell_igraph_is_bipartite_usage(argv);
 
11440
      break;
 
11441
    default:
 
11442
      break;
 
11443
    }
 
11444
 
 
11445
    shell_index=-1;
 
11446
  }
 
11447
 
 
11448
  /* Check that we have all arguments */
 
11449
  for (shell_index=0; shell_index<2; shell_index++) {
 
11450
    if (!shell_seen[shell_index]) {
 
11451
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11452
              shell_options[shell_index].name);
 
11453
      exit(1);
 
11454
    }
 
11455
  }
 
11456
 
 
11457
  /* Do the operation */
 
11458
  shell_result=igraph_is_bipartite(&graph, &res, type);
 
11459
 
 
11460
  /* Write the result */
 
11461
  igraph_destroy(&graph);
 
11462
  shell_write_boolean(res, shell_arg_res);
 
11463
 
 
11464
  return 0;
 
11465
}
 
11466
 
 
11467
/*-------------------------------------------/
 
11468
/ igraph_clusters                            /
 
11469
/-------------------------------------------*/
 
11470
void shell_igraph_clusters_usage(char **argv) {
 
11471
  printf("%s --graph=<graph> --membership=<membership> --csize=<csize> --no=<no> --mode=<mode>\n", basename(argv[0]));
 
11472
  exit(1);
 
11473
}
 
11474
 
 
11475
int shell_igraph_clusters(int argc, char **argv) {
 
11476
 
 
11477
  igraph_t graph;
 
11478
  igraph_vector_t membership;
 
11479
  igraph_vector_t csize;
 
11480
  igraph_integer_t no;
 
11481
  igraph_connectedness_t mode=IGRAPH_WEAK;
 
11482
  char* shell_arg_membership=0;
 
11483
  char* shell_arg_csize=0;
 
11484
  char* shell_arg_no=0;
 
11485
  int shell_result;
 
11486
 
 
11487
 
 
11488
  int shell_seen[5];
 
11489
  int shell_index=-1;
 
11490
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11491
                                   { "membership",required_argument,0,1 },
 
11492
                                   { "csize",required_argument,0,2 },
 
11493
                                   { "no",required_argument,0,3 },
 
11494
                                   { "mode",required_argument,0,4 },
 
11495
                                   { "help",no_argument,0,5 },
 
11496
                                   { 0,0,0,0 }
 
11497
                                 };
 
11498
 
 
11499
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11500
  memset(shell_seen, 0, 5*sizeof(int));
 
11501
  shell_seen[4]=2;
 
11502
  
 
11503
  /* Parse arguments and read input */
 
11504
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11505
 
 
11506
    if (shell_index==-1) {
 
11507
      exit(1);
 
11508
    }
 
11509
 
 
11510
    if (shell_seen[shell_index]==1) {
 
11511
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11512
              shell_options[shell_index].name);
 
11513
      exit(1);
 
11514
    }
 
11515
    shell_seen[shell_index]=1;  
 
11516
 
 
11517
    switch (shell_index) {
 
11518
    case 0: /* graph */
 
11519
      shell_read_graph(&graph, optarg);
 
11520
      break;
 
11521
    case 1: /* membership */
 
11522
      shell_arg_membership=strdup(optarg); 
 
11523
  igraph_vector_init(&membership, 0);
 
11524
      break;
 
11525
    case 2: /* csize */
 
11526
      shell_arg_csize=strdup(optarg); 
 
11527
  igraph_vector_init(&csize, 0);
 
11528
      break;
 
11529
    case 3: /* no */
 
11530
      shell_arg_no=strdup(optarg);
 
11531
      break;
 
11532
    case 4: /* mode */
 
11533
      shell_read_enum(&mode, optarg, "weak", 1, "strong", 2, 0);
 
11534
      break;
 
11535
    case 5:
 
11536
      shell_igraph_clusters_usage(argv);
 
11537
      break;
 
11538
    default:
 
11539
      break;
 
11540
    }
 
11541
 
 
11542
    shell_index=-1;
 
11543
  }
 
11544
 
 
11545
  /* Check that we have all arguments */
 
11546
  for (shell_index=0; shell_index<5; shell_index++) {
 
11547
    if (!shell_seen[shell_index]) {
 
11548
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11549
              shell_options[shell_index].name);
 
11550
      exit(1);
 
11551
    }
 
11552
  }
 
11553
 
 
11554
  /* Do the operation */
 
11555
  shell_result=igraph_clusters(&graph, &membership, &csize, &no, mode);
 
11556
 
 
11557
  /* Write the result */
 
11558
  igraph_destroy(&graph);
 
11559
  shell_write_vector(&membership, shell_arg_membership); 
 
11560
  igraph_vector_destroy(&membership);
 
11561
  shell_write_vector(&csize, shell_arg_csize); 
 
11562
  igraph_vector_destroy(&csize);
 
11563
  shell_write_integer(no, shell_arg_no);
 
11564
 
 
11565
  return 0;
 
11566
}
 
11567
 
 
11568
/*-------------------------------------------/
 
11569
/ igraph_is_connected                        /
 
11570
/-------------------------------------------*/
 
11571
void shell_igraph_is_connected_usage(char **argv) {
 
11572
  printf("%s --graph=<graph> --res=<res> --mode=<mode>\n", basename(argv[0]));
 
11573
  exit(1);
 
11574
}
 
11575
 
 
11576
int shell_igraph_is_connected(int argc, char **argv) {
 
11577
 
 
11578
  igraph_t graph;
 
11579
  igraph_bool_t res;
 
11580
  igraph_connectedness_t mode=IGRAPH_WEAK;
 
11581
  char* shell_arg_res=0;
 
11582
  int shell_result;
 
11583
 
 
11584
 
 
11585
  int shell_seen[3];
 
11586
  int shell_index=-1;
 
11587
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11588
                                   { "res",required_argument,0,1 },
 
11589
                                   { "mode",required_argument,0,2 },
 
11590
                                   { "help",no_argument,0,3 },
 
11591
                                   { 0,0,0,0 }
 
11592
                                 };
 
11593
 
 
11594
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11595
  memset(shell_seen, 0, 3*sizeof(int));
 
11596
  shell_seen[2]=2;
 
11597
  
 
11598
  /* Parse arguments and read input */
 
11599
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11600
 
 
11601
    if (shell_index==-1) {
 
11602
      exit(1);
 
11603
    }
 
11604
 
 
11605
    if (shell_seen[shell_index]==1) {
 
11606
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11607
              shell_options[shell_index].name);
 
11608
      exit(1);
 
11609
    }
 
11610
    shell_seen[shell_index]=1;  
 
11611
 
 
11612
    switch (shell_index) {
 
11613
    case 0: /* graph */
 
11614
      shell_read_graph(&graph, optarg);
 
11615
      break;
 
11616
    case 1: /* res */
 
11617
      
 
11618
      break;
 
11619
    case 2: /* mode */
 
11620
      shell_read_enum(&mode, optarg, "weak", 1, "strong", 2, 0);
 
11621
      break;
 
11622
    case 3:
 
11623
      shell_igraph_is_connected_usage(argv);
 
11624
      break;
 
11625
    default:
 
11626
      break;
 
11627
    }
 
11628
 
 
11629
    shell_index=-1;
 
11630
  }
 
11631
 
 
11632
  /* Check that we have all arguments */
 
11633
  for (shell_index=0; shell_index<3; shell_index++) {
 
11634
    if (!shell_seen[shell_index]) {
 
11635
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11636
              shell_options[shell_index].name);
 
11637
      exit(1);
 
11638
    }
 
11639
  }
 
11640
 
 
11641
  /* Do the operation */
 
11642
  shell_result=igraph_is_connected(&graph, &res, mode);
 
11643
 
 
11644
  /* Write the result */
 
11645
  igraph_destroy(&graph);
 
11646
  shell_write_boolean(res, shell_arg_res);
 
11647
 
 
11648
  return 0;
 
11649
}
 
11650
 
 
11651
/*-------------------------------------------/
 
11652
/ igraph_decompose                           /
 
11653
/-------------------------------------------*/
 
11654
void shell_igraph_decompose_usage(char **argv) {
 
11655
  printf("%s --graph=<graph> --components=<components> --mode=<mode> --maxcompno=<maxcompno> --minelements=<minelements>\n", basename(argv[0]));
 
11656
  exit(1);
 
11657
}
 
11658
 
 
11659
int shell_igraph_decompose(int argc, char **argv) {
 
11660
 
 
11661
  igraph_t graph;
 
11662
  igraph_vector_ptr_t components;
 
11663
  igraph_connectedness_t mode=IGRAPH_WEAK;
 
11664
  long int maxcompno=-1;
 
11665
  long int minelements=1;
 
11666
  char* shell_arg_components=0;
 
11667
  int shell_result;
 
11668
 
 
11669
 
 
11670
  int shell_seen[5];
 
11671
  int shell_index=-1;
 
11672
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11673
                                   { "components",required_argument,0,1 },
 
11674
                                   { "mode",required_argument,0,2 },
 
11675
                                   { "maxcompno",required_argument,0,3 },
 
11676
                                   { "minelements",required_argument,0,4 },
 
11677
                                   { "help",no_argument,0,5 },
 
11678
                                   { 0,0,0,0 }
 
11679
                                 };
 
11680
 
 
11681
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11682
  memset(shell_seen, 0, 5*sizeof(int));
 
11683
  shell_seen[2]=2;
 
11684
  shell_seen[3]=2;
 
11685
  shell_seen[4]=2;
 
11686
  
 
11687
  /* Parse arguments and read input */
 
11688
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11689
 
 
11690
    if (shell_index==-1) {
 
11691
      exit(1);
 
11692
    }
 
11693
 
 
11694
    if (shell_seen[shell_index]==1) {
 
11695
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11696
              shell_options[shell_index].name);
 
11697
      exit(1);
 
11698
    }
 
11699
    shell_seen[shell_index]=1;  
 
11700
 
 
11701
    switch (shell_index) {
 
11702
    case 0: /* graph */
 
11703
      shell_read_graph(&graph, optarg);
 
11704
      break;
 
11705
    case 1: /* components */
 
11706
      igraph_vector_ptr_init(&components, 0);
 
11707
      break;
 
11708
    case 2: /* mode */
 
11709
      shell_read_enum(&mode, optarg, "weak", 1, "strong", 2, 0);
 
11710
      break;
 
11711
    case 3: /* maxcompno */
 
11712
      shell_read_longint(&maxcompno, optarg);
 
11713
      break;
 
11714
    case 4: /* minelements */
 
11715
      shell_read_longint(&minelements, optarg);
 
11716
      break;
 
11717
    case 5:
 
11718
      shell_igraph_decompose_usage(argv);
 
11719
      break;
 
11720
    default:
 
11721
      break;
 
11722
    }
 
11723
 
 
11724
    shell_index=-1;
 
11725
  }
 
11726
 
 
11727
  /* Check that we have all arguments */
 
11728
  for (shell_index=0; shell_index<5; shell_index++) {
 
11729
    if (!shell_seen[shell_index]) {
 
11730
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11731
              shell_options[shell_index].name);
 
11732
      exit(1);
 
11733
    }
 
11734
  }
 
11735
 
 
11736
  /* Do the operation */
 
11737
  shell_result=igraph_decompose(&graph, &components, mode, maxcompno, minelements);
 
11738
 
 
11739
  /* Write the result */
 
11740
  igraph_destroy(&graph);
 
11741
  shell_write_graphlist(&components, shell_arg_components); 
 
11742
  shell_free_graphlist(&components); 
 
11743
  igraph_vector_ptr_destroy(&components);
 
11744
 
 
11745
  return 0;
 
11746
}
 
11747
 
 
11748
/*-------------------------------------------/
 
11749
/ igraph_articulation_points                 /
 
11750
/-------------------------------------------*/
 
11751
void shell_igraph_articulation_points_usage(char **argv) {
 
11752
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
11753
  exit(1);
 
11754
}
 
11755
 
 
11756
int shell_igraph_articulation_points(int argc, char **argv) {
 
11757
 
 
11758
  igraph_t graph;
 
11759
  igraph_vector_t res;
 
11760
  char* shell_arg_res=0;
 
11761
  int shell_result;
 
11762
 
 
11763
 
 
11764
  int shell_seen[2];
 
11765
  int shell_index=-1;
 
11766
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11767
                                   { "res",required_argument,0,1 },
 
11768
                                   { "help",no_argument,0,2 },
 
11769
                                   { 0,0,0,0 }
 
11770
                                 };
 
11771
 
 
11772
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11773
  memset(shell_seen, 0, 2*sizeof(int));
 
11774
 
 
11775
  
 
11776
  /* Parse arguments and read input */
 
11777
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11778
 
 
11779
    if (shell_index==-1) {
 
11780
      exit(1);
 
11781
    }
 
11782
 
 
11783
    if (shell_seen[shell_index]==1) {
 
11784
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11785
              shell_options[shell_index].name);
 
11786
      exit(1);
 
11787
    }
 
11788
    shell_seen[shell_index]=1;  
 
11789
 
 
11790
    switch (shell_index) {
 
11791
    case 0: /* graph */
 
11792
      shell_read_graph(&graph, optarg);
 
11793
      break;
 
11794
    case 1: /* res */
 
11795
      shell_arg_res=strdup(optarg); 
 
11796
  igraph_vector_init(&res, 0);
 
11797
      break;
 
11798
    case 2:
 
11799
      shell_igraph_articulation_points_usage(argv);
 
11800
      break;
 
11801
    default:
 
11802
      break;
 
11803
    }
 
11804
 
 
11805
    shell_index=-1;
 
11806
  }
 
11807
 
 
11808
  /* Check that we have all arguments */
 
11809
  for (shell_index=0; shell_index<2; shell_index++) {
 
11810
    if (!shell_seen[shell_index]) {
 
11811
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11812
              shell_options[shell_index].name);
 
11813
      exit(1);
 
11814
    }
 
11815
  }
 
11816
 
 
11817
  /* Do the operation */
 
11818
  shell_result=igraph_articulation_points(&graph, &res);
 
11819
 
 
11820
  /* Write the result */
 
11821
  igraph_destroy(&graph);
 
11822
  shell_write_vector(&res, shell_arg_res); 
 
11823
  igraph_vector_destroy(&res);
 
11824
 
 
11825
  return 0;
 
11826
}
 
11827
 
 
11828
/*-------------------------------------------/
 
11829
/ igraph_biconnected_components              /
 
11830
/-------------------------------------------*/
 
11831
void shell_igraph_biconnected_components_usage(char **argv) {
 
11832
  printf("%s --graph=<graph> --no=<no> --components=<components> --articulation_points=<articulation_points>\n", basename(argv[0]));
 
11833
  exit(1);
 
11834
}
 
11835
 
 
11836
int shell_igraph_biconnected_components(int argc, char **argv) {
 
11837
 
 
11838
  igraph_t graph;
 
11839
  igraph_integer_t no;
 
11840
  igraph_vector_ptr_t components;
 
11841
  igraph_vector_t articulation_points;
 
11842
  char* shell_arg_no=0;
 
11843
  char* shell_arg_components=0;
 
11844
  char* shell_arg_articulation_points=0;
 
11845
  int shell_result;
 
11846
 
 
11847
 
 
11848
  int shell_seen[4];
 
11849
  int shell_index=-1;
 
11850
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11851
                                   { "no",required_argument,0,1 },
 
11852
                                   { "components",required_argument,0,2 },
 
11853
                                   { "articulation_points",required_argument,0,3 },
 
11854
                                   { "help",no_argument,0,4 },
 
11855
                                   { 0,0,0,0 }
 
11856
                                 };
 
11857
 
 
11858
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11859
  memset(shell_seen, 0, 4*sizeof(int));
 
11860
 
 
11861
  
 
11862
  /* Parse arguments and read input */
 
11863
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11864
 
 
11865
    if (shell_index==-1) {
 
11866
      exit(1);
 
11867
    }
 
11868
 
 
11869
    if (shell_seen[shell_index]==1) {
 
11870
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11871
              shell_options[shell_index].name);
 
11872
      exit(1);
 
11873
    }
 
11874
    shell_seen[shell_index]=1;  
 
11875
 
 
11876
    switch (shell_index) {
 
11877
    case 0: /* graph */
 
11878
      shell_read_graph(&graph, optarg);
 
11879
      break;
 
11880
    case 1: /* no */
 
11881
      shell_arg_no=strdup(optarg);
 
11882
      break;
 
11883
    case 2: /* components */
 
11884
      igraph_vector_ptr_init(&components, 0);
 
11885
      break;
 
11886
    case 3: /* articulation_points */
 
11887
      shell_arg_articulation_points=strdup(optarg); 
 
11888
  igraph_vector_init(&articulation_points, 0);
 
11889
      break;
 
11890
    case 4:
 
11891
      shell_igraph_biconnected_components_usage(argv);
 
11892
      break;
 
11893
    default:
 
11894
      break;
 
11895
    }
 
11896
 
 
11897
    shell_index=-1;
 
11898
  }
 
11899
 
 
11900
  /* Check that we have all arguments */
 
11901
  for (shell_index=0; shell_index<4; shell_index++) {
 
11902
    if (!shell_seen[shell_index]) {
 
11903
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11904
              shell_options[shell_index].name);
 
11905
      exit(1);
 
11906
    }
 
11907
  }
 
11908
 
 
11909
  /* Do the operation */
 
11910
  shell_result=igraph_biconnected_components(&graph, &no, &components, &articulation_points);
 
11911
 
 
11912
  /* Write the result */
 
11913
  igraph_destroy(&graph);
 
11914
  shell_write_integer(no, shell_arg_no);
 
11915
  shell_write_vectorlist(&components, shell_arg_components); 
 
11916
  shell_free_vectorlist(&components); 
 
11917
  igraph_vector_ptr_destroy(&components);
 
11918
  shell_write_vector(&articulation_points, shell_arg_articulation_points); 
 
11919
  igraph_vector_destroy(&articulation_points);
 
11920
 
 
11921
  return 0;
 
11922
}
 
11923
 
 
11924
/*-------------------------------------------/
 
11925
/ igraph_cliques                             /
 
11926
/-------------------------------------------*/
 
11927
void shell_igraph_cliques_usage(char **argv) {
 
11928
  printf("%s --graph=<graph> --res=<res> --min_size=<min_size> --max_size=<max_size>\n", basename(argv[0]));
 
11929
  exit(1);
 
11930
}
 
11931
 
 
11932
int shell_igraph_cliques(int argc, char **argv) {
 
11933
 
 
11934
  igraph_t graph;
 
11935
  igraph_vector_ptr_t res;
 
11936
  igraph_integer_t min_size=0;
 
11937
  igraph_integer_t max_size=0;
 
11938
  char* shell_arg_res=0;
 
11939
  int shell_result;
 
11940
 
 
11941
 
 
11942
  int shell_seen[4];
 
11943
  int shell_index=-1;
 
11944
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
11945
                                   { "res",required_argument,0,1 },
 
11946
                                   { "min_size",required_argument,0,2 },
 
11947
                                   { "max_size",required_argument,0,3 },
 
11948
                                   { "help",no_argument,0,4 },
 
11949
                                   { 0,0,0,0 }
 
11950
                                 };
 
11951
 
 
11952
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
11953
  memset(shell_seen, 0, 4*sizeof(int));
 
11954
  shell_seen[2]=2;
 
11955
  shell_seen[3]=2;
 
11956
  
 
11957
  /* Parse arguments and read input */
 
11958
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
11959
 
 
11960
    if (shell_index==-1) {
 
11961
      exit(1);
 
11962
    }
 
11963
 
 
11964
    if (shell_seen[shell_index]==1) {
 
11965
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
11966
              shell_options[shell_index].name);
 
11967
      exit(1);
 
11968
    }
 
11969
    shell_seen[shell_index]=1;  
 
11970
 
 
11971
    switch (shell_index) {
 
11972
    case 0: /* graph */
 
11973
      shell_read_graph(&graph, optarg);
 
11974
      break;
 
11975
    case 1: /* res */
 
11976
      igraph_vector_ptr_init(&res, 0);
 
11977
      break;
 
11978
    case 2: /* min_size */
 
11979
      shell_read_integer(&min_size, optarg);
 
11980
      break;
 
11981
    case 3: /* max_size */
 
11982
      shell_read_integer(&max_size, optarg);
 
11983
      break;
 
11984
    case 4:
 
11985
      shell_igraph_cliques_usage(argv);
 
11986
      break;
 
11987
    default:
 
11988
      break;
 
11989
    }
 
11990
 
 
11991
    shell_index=-1;
 
11992
  }
 
11993
 
 
11994
  /* Check that we have all arguments */
 
11995
  for (shell_index=0; shell_index<4; shell_index++) {
 
11996
    if (!shell_seen[shell_index]) {
 
11997
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
11998
              shell_options[shell_index].name);
 
11999
      exit(1);
 
12000
    }
 
12001
  }
 
12002
 
 
12003
  /* Do the operation */
 
12004
  shell_result=igraph_cliques(&graph, &res, min_size, max_size);
 
12005
 
 
12006
  /* Write the result */
 
12007
  igraph_destroy(&graph);
 
12008
  shell_write_vectorlist(&res, shell_arg_res); 
 
12009
  shell_free_vectorlist(&res); 
 
12010
  igraph_vector_ptr_destroy(&res);
 
12011
 
 
12012
  return 0;
 
12013
}
 
12014
 
 
12015
/*-------------------------------------------/
 
12016
/ igraph_largest_cliques                     /
 
12017
/-------------------------------------------*/
 
12018
void shell_igraph_largest_cliques_usage(char **argv) {
 
12019
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
12020
  exit(1);
 
12021
}
 
12022
 
 
12023
int shell_igraph_largest_cliques(int argc, char **argv) {
 
12024
 
 
12025
  igraph_t graph;
 
12026
  igraph_vector_ptr_t res;
 
12027
  char* shell_arg_res=0;
 
12028
  int shell_result;
 
12029
 
 
12030
 
 
12031
  int shell_seen[2];
 
12032
  int shell_index=-1;
 
12033
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12034
                                   { "res",required_argument,0,1 },
 
12035
                                   { "help",no_argument,0,2 },
 
12036
                                   { 0,0,0,0 }
 
12037
                                 };
 
12038
 
 
12039
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12040
  memset(shell_seen, 0, 2*sizeof(int));
 
12041
 
 
12042
  
 
12043
  /* Parse arguments and read input */
 
12044
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12045
 
 
12046
    if (shell_index==-1) {
 
12047
      exit(1);
 
12048
    }
 
12049
 
 
12050
    if (shell_seen[shell_index]==1) {
 
12051
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12052
              shell_options[shell_index].name);
 
12053
      exit(1);
 
12054
    }
 
12055
    shell_seen[shell_index]=1;  
 
12056
 
 
12057
    switch (shell_index) {
 
12058
    case 0: /* graph */
 
12059
      shell_read_graph(&graph, optarg);
 
12060
      break;
 
12061
    case 1: /* res */
 
12062
      igraph_vector_ptr_init(&res, 0);
 
12063
      break;
 
12064
    case 2:
 
12065
      shell_igraph_largest_cliques_usage(argv);
 
12066
      break;
 
12067
    default:
 
12068
      break;
 
12069
    }
 
12070
 
 
12071
    shell_index=-1;
 
12072
  }
 
12073
 
 
12074
  /* Check that we have all arguments */
 
12075
  for (shell_index=0; shell_index<2; shell_index++) {
 
12076
    if (!shell_seen[shell_index]) {
 
12077
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12078
              shell_options[shell_index].name);
 
12079
      exit(1);
 
12080
    }
 
12081
  }
 
12082
 
 
12083
  /* Do the operation */
 
12084
  shell_result=igraph_largest_cliques(&graph, &res);
 
12085
 
 
12086
  /* Write the result */
 
12087
  igraph_destroy(&graph);
 
12088
  shell_write_vectorlist(&res, shell_arg_res); 
 
12089
  shell_free_vectorlist(&res); 
 
12090
  igraph_vector_ptr_destroy(&res);
 
12091
 
 
12092
  return 0;
 
12093
}
 
12094
 
 
12095
/*-------------------------------------------/
 
12096
/ igraph_maximal_cliques                     /
 
12097
/-------------------------------------------*/
 
12098
void shell_igraph_maximal_cliques_usage(char **argv) {
 
12099
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
12100
  exit(1);
 
12101
}
 
12102
 
 
12103
int shell_igraph_maximal_cliques(int argc, char **argv) {
 
12104
 
 
12105
  igraph_t graph;
 
12106
  igraph_vector_ptr_t res;
 
12107
  char* shell_arg_res=0;
 
12108
  int shell_result;
 
12109
 
 
12110
 
 
12111
  int shell_seen[2];
 
12112
  int shell_index=-1;
 
12113
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12114
                                   { "res",required_argument,0,1 },
 
12115
                                   { "help",no_argument,0,2 },
 
12116
                                   { 0,0,0,0 }
 
12117
                                 };
 
12118
 
 
12119
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12120
  memset(shell_seen, 0, 2*sizeof(int));
 
12121
 
 
12122
  
 
12123
  /* Parse arguments and read input */
 
12124
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12125
 
 
12126
    if (shell_index==-1) {
 
12127
      exit(1);
 
12128
    }
 
12129
 
 
12130
    if (shell_seen[shell_index]==1) {
 
12131
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12132
              shell_options[shell_index].name);
 
12133
      exit(1);
 
12134
    }
 
12135
    shell_seen[shell_index]=1;  
 
12136
 
 
12137
    switch (shell_index) {
 
12138
    case 0: /* graph */
 
12139
      shell_read_graph(&graph, optarg);
 
12140
      break;
 
12141
    case 1: /* res */
 
12142
      igraph_vector_ptr_init(&res, 0);
 
12143
      break;
 
12144
    case 2:
 
12145
      shell_igraph_maximal_cliques_usage(argv);
 
12146
      break;
 
12147
    default:
 
12148
      break;
 
12149
    }
 
12150
 
 
12151
    shell_index=-1;
 
12152
  }
 
12153
 
 
12154
  /* Check that we have all arguments */
 
12155
  for (shell_index=0; shell_index<2; shell_index++) {
 
12156
    if (!shell_seen[shell_index]) {
 
12157
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12158
              shell_options[shell_index].name);
 
12159
      exit(1);
 
12160
    }
 
12161
  }
 
12162
 
 
12163
  /* Do the operation */
 
12164
  shell_result=igraph_maximal_cliques(&graph, &res);
 
12165
 
 
12166
  /* Write the result */
 
12167
  igraph_destroy(&graph);
 
12168
  shell_write_vectorlist(&res, shell_arg_res); 
 
12169
  shell_free_vectorlist(&res); 
 
12170
  igraph_vector_ptr_destroy(&res);
 
12171
 
 
12172
  return 0;
 
12173
}
 
12174
 
 
12175
/*-------------------------------------------/
 
12176
/ igraph_clique_number                       /
 
12177
/-------------------------------------------*/
 
12178
void shell_igraph_clique_number_usage(char **argv) {
 
12179
  printf("%s --graph=<graph> --no=<no>\n", basename(argv[0]));
 
12180
  exit(1);
 
12181
}
 
12182
 
 
12183
int shell_igraph_clique_number(int argc, char **argv) {
 
12184
 
 
12185
  igraph_t graph;
 
12186
  igraph_integer_t no;
 
12187
  char* shell_arg_no=0;
 
12188
  int shell_result;
 
12189
 
 
12190
 
 
12191
  int shell_seen[2];
 
12192
  int shell_index=-1;
 
12193
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12194
                                   { "no",required_argument,0,1 },
 
12195
                                   { "help",no_argument,0,2 },
 
12196
                                   { 0,0,0,0 }
 
12197
                                 };
 
12198
 
 
12199
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12200
  memset(shell_seen, 0, 2*sizeof(int));
 
12201
 
 
12202
  
 
12203
  /* Parse arguments and read input */
 
12204
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12205
 
 
12206
    if (shell_index==-1) {
 
12207
      exit(1);
 
12208
    }
 
12209
 
 
12210
    if (shell_seen[shell_index]==1) {
 
12211
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12212
              shell_options[shell_index].name);
 
12213
      exit(1);
 
12214
    }
 
12215
    shell_seen[shell_index]=1;  
 
12216
 
 
12217
    switch (shell_index) {
 
12218
    case 0: /* graph */
 
12219
      shell_read_graph(&graph, optarg);
 
12220
      break;
 
12221
    case 1: /* no */
 
12222
      shell_arg_no=strdup(optarg);
 
12223
      break;
 
12224
    case 2:
 
12225
      shell_igraph_clique_number_usage(argv);
 
12226
      break;
 
12227
    default:
 
12228
      break;
 
12229
    }
 
12230
 
 
12231
    shell_index=-1;
 
12232
  }
 
12233
 
 
12234
  /* Check that we have all arguments */
 
12235
  for (shell_index=0; shell_index<2; shell_index++) {
 
12236
    if (!shell_seen[shell_index]) {
 
12237
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12238
              shell_options[shell_index].name);
 
12239
      exit(1);
 
12240
    }
 
12241
  }
 
12242
 
 
12243
  /* Do the operation */
 
12244
  shell_result=igraph_clique_number(&graph, &no);
 
12245
 
 
12246
  /* Write the result */
 
12247
  igraph_destroy(&graph);
 
12248
  shell_write_integer(no, shell_arg_no);
 
12249
 
 
12250
  return 0;
 
12251
}
 
12252
 
 
12253
/*-------------------------------------------/
 
12254
/ igraph_independent_vertex_sets             /
 
12255
/-------------------------------------------*/
 
12256
void shell_igraph_independent_vertex_sets_usage(char **argv) {
 
12257
  printf("%s --graph=<graph> --res=<res> --min_size=<min_size> --max_size=<max_size>\n", basename(argv[0]));
 
12258
  exit(1);
 
12259
}
 
12260
 
 
12261
int shell_igraph_independent_vertex_sets(int argc, char **argv) {
 
12262
 
 
12263
  igraph_t graph;
 
12264
  igraph_vector_ptr_t res;
 
12265
  igraph_integer_t min_size=0;
 
12266
  igraph_integer_t max_size=0;
 
12267
  char* shell_arg_res=0;
 
12268
  int shell_result;
 
12269
 
 
12270
 
 
12271
  int shell_seen[4];
 
12272
  int shell_index=-1;
 
12273
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12274
                                   { "res",required_argument,0,1 },
 
12275
                                   { "min_size",required_argument,0,2 },
 
12276
                                   { "max_size",required_argument,0,3 },
 
12277
                                   { "help",no_argument,0,4 },
 
12278
                                   { 0,0,0,0 }
 
12279
                                 };
 
12280
 
 
12281
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12282
  memset(shell_seen, 0, 4*sizeof(int));
 
12283
  shell_seen[2]=2;
 
12284
  shell_seen[3]=2;
 
12285
  
 
12286
  /* Parse arguments and read input */
 
12287
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12288
 
 
12289
    if (shell_index==-1) {
 
12290
      exit(1);
 
12291
    }
 
12292
 
 
12293
    if (shell_seen[shell_index]==1) {
 
12294
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12295
              shell_options[shell_index].name);
 
12296
      exit(1);
 
12297
    }
 
12298
    shell_seen[shell_index]=1;  
 
12299
 
 
12300
    switch (shell_index) {
 
12301
    case 0: /* graph */
 
12302
      shell_read_graph(&graph, optarg);
 
12303
      break;
 
12304
    case 1: /* res */
 
12305
      igraph_vector_ptr_init(&res, 0);
 
12306
      break;
 
12307
    case 2: /* min_size */
 
12308
      shell_read_integer(&min_size, optarg);
 
12309
      break;
 
12310
    case 3: /* max_size */
 
12311
      shell_read_integer(&max_size, optarg);
 
12312
      break;
 
12313
    case 4:
 
12314
      shell_igraph_independent_vertex_sets_usage(argv);
 
12315
      break;
 
12316
    default:
 
12317
      break;
 
12318
    }
 
12319
 
 
12320
    shell_index=-1;
 
12321
  }
 
12322
 
 
12323
  /* Check that we have all arguments */
 
12324
  for (shell_index=0; shell_index<4; shell_index++) {
 
12325
    if (!shell_seen[shell_index]) {
 
12326
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12327
              shell_options[shell_index].name);
 
12328
      exit(1);
 
12329
    }
 
12330
  }
 
12331
 
 
12332
  /* Do the operation */
 
12333
  shell_result=igraph_independent_vertex_sets(&graph, &res, min_size, max_size);
 
12334
 
 
12335
  /* Write the result */
 
12336
  igraph_destroy(&graph);
 
12337
  shell_write_vectorlist(&res, shell_arg_res); 
 
12338
  shell_free_vectorlist(&res); 
 
12339
  igraph_vector_ptr_destroy(&res);
 
12340
 
 
12341
  return 0;
 
12342
}
 
12343
 
 
12344
/*-------------------------------------------/
 
12345
/ igraph_largest_independent_vertex_sets     /
 
12346
/-------------------------------------------*/
 
12347
void shell_igraph_largest_independent_vertex_sets_usage(char **argv) {
 
12348
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
12349
  exit(1);
 
12350
}
 
12351
 
 
12352
int shell_igraph_largest_independent_vertex_sets(int argc, char **argv) {
 
12353
 
 
12354
  igraph_t graph;
 
12355
  igraph_vector_ptr_t res;
 
12356
  char* shell_arg_res=0;
 
12357
  int shell_result;
 
12358
 
 
12359
 
 
12360
  int shell_seen[2];
 
12361
  int shell_index=-1;
 
12362
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12363
                                   { "res",required_argument,0,1 },
 
12364
                                   { "help",no_argument,0,2 },
 
12365
                                   { 0,0,0,0 }
 
12366
                                 };
 
12367
 
 
12368
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12369
  memset(shell_seen, 0, 2*sizeof(int));
 
12370
 
 
12371
  
 
12372
  /* Parse arguments and read input */
 
12373
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12374
 
 
12375
    if (shell_index==-1) {
 
12376
      exit(1);
 
12377
    }
 
12378
 
 
12379
    if (shell_seen[shell_index]==1) {
 
12380
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12381
              shell_options[shell_index].name);
 
12382
      exit(1);
 
12383
    }
 
12384
    shell_seen[shell_index]=1;  
 
12385
 
 
12386
    switch (shell_index) {
 
12387
    case 0: /* graph */
 
12388
      shell_read_graph(&graph, optarg);
 
12389
      break;
 
12390
    case 1: /* res */
 
12391
      igraph_vector_ptr_init(&res, 0);
 
12392
      break;
 
12393
    case 2:
 
12394
      shell_igraph_largest_independent_vertex_sets_usage(argv);
 
12395
      break;
 
12396
    default:
 
12397
      break;
 
12398
    }
 
12399
 
 
12400
    shell_index=-1;
 
12401
  }
 
12402
 
 
12403
  /* Check that we have all arguments */
 
12404
  for (shell_index=0; shell_index<2; shell_index++) {
 
12405
    if (!shell_seen[shell_index]) {
 
12406
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12407
              shell_options[shell_index].name);
 
12408
      exit(1);
 
12409
    }
 
12410
  }
 
12411
 
 
12412
  /* Do the operation */
 
12413
  shell_result=igraph_largest_independent_vertex_sets(&graph, &res);
 
12414
 
 
12415
  /* Write the result */
 
12416
  igraph_destroy(&graph);
 
12417
  shell_write_vectorlist(&res, shell_arg_res); 
 
12418
  shell_free_vectorlist(&res); 
 
12419
  igraph_vector_ptr_destroy(&res);
 
12420
 
 
12421
  return 0;
 
12422
}
 
12423
 
 
12424
/*-------------------------------------------/
 
12425
/ igraph_maximal_independent_vertex_sets     /
 
12426
/-------------------------------------------*/
 
12427
void shell_igraph_maximal_independent_vertex_sets_usage(char **argv) {
 
12428
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
12429
  exit(1);
 
12430
}
 
12431
 
 
12432
int shell_igraph_maximal_independent_vertex_sets(int argc, char **argv) {
 
12433
 
 
12434
  igraph_t graph;
 
12435
  igraph_vector_ptr_t res;
 
12436
  char* shell_arg_res=0;
 
12437
  int shell_result;
 
12438
 
 
12439
 
 
12440
  int shell_seen[2];
 
12441
  int shell_index=-1;
 
12442
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12443
                                   { "res",required_argument,0,1 },
 
12444
                                   { "help",no_argument,0,2 },
 
12445
                                   { 0,0,0,0 }
 
12446
                                 };
 
12447
 
 
12448
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12449
  memset(shell_seen, 0, 2*sizeof(int));
 
12450
 
 
12451
  
 
12452
  /* Parse arguments and read input */
 
12453
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12454
 
 
12455
    if (shell_index==-1) {
 
12456
      exit(1);
 
12457
    }
 
12458
 
 
12459
    if (shell_seen[shell_index]==1) {
 
12460
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12461
              shell_options[shell_index].name);
 
12462
      exit(1);
 
12463
    }
 
12464
    shell_seen[shell_index]=1;  
 
12465
 
 
12466
    switch (shell_index) {
 
12467
    case 0: /* graph */
 
12468
      shell_read_graph(&graph, optarg);
 
12469
      break;
 
12470
    case 1: /* res */
 
12471
      igraph_vector_ptr_init(&res, 0);
 
12472
      break;
 
12473
    case 2:
 
12474
      shell_igraph_maximal_independent_vertex_sets_usage(argv);
 
12475
      break;
 
12476
    default:
 
12477
      break;
 
12478
    }
 
12479
 
 
12480
    shell_index=-1;
 
12481
  }
 
12482
 
 
12483
  /* Check that we have all arguments */
 
12484
  for (shell_index=0; shell_index<2; shell_index++) {
 
12485
    if (!shell_seen[shell_index]) {
 
12486
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12487
              shell_options[shell_index].name);
 
12488
      exit(1);
 
12489
    }
 
12490
  }
 
12491
 
 
12492
  /* Do the operation */
 
12493
  shell_result=igraph_maximal_independent_vertex_sets(&graph, &res);
 
12494
 
 
12495
  /* Write the result */
 
12496
  igraph_destroy(&graph);
 
12497
  shell_write_vectorlist(&res, shell_arg_res); 
 
12498
  shell_free_vectorlist(&res); 
 
12499
  igraph_vector_ptr_destroy(&res);
 
12500
 
 
12501
  return 0;
 
12502
}
 
12503
 
 
12504
/*-------------------------------------------/
 
12505
/ igraph_independence_number                 /
 
12506
/-------------------------------------------*/
 
12507
void shell_igraph_independence_number_usage(char **argv) {
 
12508
  printf("%s --graph=<graph> --no=<no>\n", basename(argv[0]));
 
12509
  exit(1);
 
12510
}
 
12511
 
 
12512
int shell_igraph_independence_number(int argc, char **argv) {
 
12513
 
 
12514
  igraph_t graph;
 
12515
  igraph_integer_t no;
 
12516
  char* shell_arg_no=0;
 
12517
  int shell_result;
 
12518
 
 
12519
 
 
12520
  int shell_seen[2];
 
12521
  int shell_index=-1;
 
12522
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12523
                                   { "no",required_argument,0,1 },
 
12524
                                   { "help",no_argument,0,2 },
 
12525
                                   { 0,0,0,0 }
 
12526
                                 };
 
12527
 
 
12528
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12529
  memset(shell_seen, 0, 2*sizeof(int));
 
12530
 
 
12531
  
 
12532
  /* Parse arguments and read input */
 
12533
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12534
 
 
12535
    if (shell_index==-1) {
 
12536
      exit(1);
 
12537
    }
 
12538
 
 
12539
    if (shell_seen[shell_index]==1) {
 
12540
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12541
              shell_options[shell_index].name);
 
12542
      exit(1);
 
12543
    }
 
12544
    shell_seen[shell_index]=1;  
 
12545
 
 
12546
    switch (shell_index) {
 
12547
    case 0: /* graph */
 
12548
      shell_read_graph(&graph, optarg);
 
12549
      break;
 
12550
    case 1: /* no */
 
12551
      shell_arg_no=strdup(optarg);
 
12552
      break;
 
12553
    case 2:
 
12554
      shell_igraph_independence_number_usage(argv);
 
12555
      break;
 
12556
    default:
 
12557
      break;
 
12558
    }
 
12559
 
 
12560
    shell_index=-1;
 
12561
  }
 
12562
 
 
12563
  /* Check that we have all arguments */
 
12564
  for (shell_index=0; shell_index<2; shell_index++) {
 
12565
    if (!shell_seen[shell_index]) {
 
12566
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12567
              shell_options[shell_index].name);
 
12568
      exit(1);
 
12569
    }
 
12570
  }
 
12571
 
 
12572
  /* Do the operation */
 
12573
  shell_result=igraph_independence_number(&graph, &no);
 
12574
 
 
12575
  /* Write the result */
 
12576
  igraph_destroy(&graph);
 
12577
  shell_write_integer(no, shell_arg_no);
 
12578
 
 
12579
  return 0;
 
12580
}
 
12581
 
 
12582
/*-------------------------------------------/
 
12583
/ igraph_layout_random                       /
 
12584
/-------------------------------------------*/
 
12585
void shell_igraph_layout_random_usage(char **argv) {
 
12586
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
12587
  exit(1);
 
12588
}
 
12589
 
 
12590
int shell_igraph_layout_random(int argc, char **argv) {
 
12591
 
 
12592
  igraph_t graph;
 
12593
  igraph_matrix_t res;
 
12594
  char* shell_arg_res=0;
 
12595
  int shell_result;
 
12596
 
 
12597
 
 
12598
  int shell_seen[2];
 
12599
  int shell_index=-1;
 
12600
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12601
                                   { "res",required_argument,0,1 },
 
12602
                                   { "help",no_argument,0,2 },
 
12603
                                   { 0,0,0,0 }
 
12604
                                 };
 
12605
 
 
12606
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12607
  memset(shell_seen, 0, 2*sizeof(int));
 
12608
 
 
12609
  
 
12610
  /* Parse arguments and read input */
 
12611
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12612
 
 
12613
    if (shell_index==-1) {
 
12614
      exit(1);
 
12615
    }
 
12616
 
 
12617
    if (shell_seen[shell_index]==1) {
 
12618
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12619
              shell_options[shell_index].name);
 
12620
      exit(1);
 
12621
    }
 
12622
    shell_seen[shell_index]=1;  
 
12623
 
 
12624
    switch (shell_index) {
 
12625
    case 0: /* graph */
 
12626
      shell_read_graph(&graph, optarg);
 
12627
      break;
 
12628
    case 1: /* res */
 
12629
      shell_arg_res=strdup(optarg); 
 
12630
  igraph_matrix_init(&res, 0, 0);
 
12631
      break;
 
12632
    case 2:
 
12633
      shell_igraph_layout_random_usage(argv);
 
12634
      break;
 
12635
    default:
 
12636
      break;
 
12637
    }
 
12638
 
 
12639
    shell_index=-1;
 
12640
  }
 
12641
 
 
12642
  /* Check that we have all arguments */
 
12643
  for (shell_index=0; shell_index<2; shell_index++) {
 
12644
    if (!shell_seen[shell_index]) {
 
12645
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12646
              shell_options[shell_index].name);
 
12647
      exit(1);
 
12648
    }
 
12649
  }
 
12650
 
 
12651
  /* Do the operation */
 
12652
  shell_result=igraph_layout_random(&graph, &res);
 
12653
 
 
12654
  /* Write the result */
 
12655
  igraph_destroy(&graph);
 
12656
  shell_write_matrix(&res, shell_arg_res); 
 
12657
  igraph_matrix_destroy(&res);
 
12658
 
 
12659
  return 0;
 
12660
}
 
12661
 
 
12662
/*-------------------------------------------/
 
12663
/ igraph_layout_circle                       /
 
12664
/-------------------------------------------*/
 
12665
void shell_igraph_layout_circle_usage(char **argv) {
 
12666
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
12667
  exit(1);
 
12668
}
 
12669
 
 
12670
int shell_igraph_layout_circle(int argc, char **argv) {
 
12671
 
 
12672
  igraph_t graph;
 
12673
  igraph_matrix_t res;
 
12674
  char* shell_arg_res=0;
 
12675
  int shell_result;
 
12676
 
 
12677
 
 
12678
  int shell_seen[2];
 
12679
  int shell_index=-1;
 
12680
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12681
                                   { "res",required_argument,0,1 },
 
12682
                                   { "help",no_argument,0,2 },
 
12683
                                   { 0,0,0,0 }
 
12684
                                 };
 
12685
 
 
12686
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12687
  memset(shell_seen, 0, 2*sizeof(int));
 
12688
 
 
12689
  
 
12690
  /* Parse arguments and read input */
 
12691
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12692
 
 
12693
    if (shell_index==-1) {
 
12694
      exit(1);
 
12695
    }
 
12696
 
 
12697
    if (shell_seen[shell_index]==1) {
 
12698
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12699
              shell_options[shell_index].name);
 
12700
      exit(1);
 
12701
    }
 
12702
    shell_seen[shell_index]=1;  
 
12703
 
 
12704
    switch (shell_index) {
 
12705
    case 0: /* graph */
 
12706
      shell_read_graph(&graph, optarg);
 
12707
      break;
 
12708
    case 1: /* res */
 
12709
      shell_arg_res=strdup(optarg); 
 
12710
  igraph_matrix_init(&res, 0, 0);
 
12711
      break;
 
12712
    case 2:
 
12713
      shell_igraph_layout_circle_usage(argv);
 
12714
      break;
 
12715
    default:
 
12716
      break;
 
12717
    }
 
12718
 
 
12719
    shell_index=-1;
 
12720
  }
 
12721
 
 
12722
  /* Check that we have all arguments */
 
12723
  for (shell_index=0; shell_index<2; shell_index++) {
 
12724
    if (!shell_seen[shell_index]) {
 
12725
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12726
              shell_options[shell_index].name);
 
12727
      exit(1);
 
12728
    }
 
12729
  }
 
12730
 
 
12731
  /* Do the operation */
 
12732
  shell_result=igraph_layout_circle(&graph, &res);
 
12733
 
 
12734
  /* Write the result */
 
12735
  igraph_destroy(&graph);
 
12736
  shell_write_matrix(&res, shell_arg_res); 
 
12737
  igraph_matrix_destroy(&res);
 
12738
 
 
12739
  return 0;
 
12740
}
 
12741
 
 
12742
/*-------------------------------------------/
 
12743
/ igraph_layout_fruchterman_reingold         /
 
12744
/-------------------------------------------*/
 
12745
void shell_igraph_layout_fruchterman_reingold_usage(char **argv) {
 
12746
  printf("%s --graph=<graph> --res=<res> --niter=<niter> --maxdelta=<maxdelta> --area=<area> --coolexp=<coolexp> --repulserad=<repulserad> --weight=<weight>\n", basename(argv[0]));
 
12747
  exit(1);
 
12748
}
 
12749
 
 
12750
int shell_igraph_layout_fruchterman_reingold(int argc, char **argv) {
 
12751
 
 
12752
  igraph_t graph;
 
12753
  igraph_matrix_t res;
 
12754
  igraph_integer_t niter=500;
 
12755
  igraph_real_t maxdelta=100;
 
12756
  igraph_real_t area=1000;
 
12757
  igraph_real_t coolexp=1.5;
 
12758
  igraph_real_t repulserad=10000;
 
12759
 
 
12760
  igraph_vector_t v_weight; igraph_vector_t *weight=0;
 
12761
  char* shell_arg_res=0;
 
12762
  int shell_result;
 
12763
 
 
12764
 
 
12765
  int shell_seen[8];
 
12766
  int shell_index=-1;
 
12767
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12768
                                   { "res",required_argument,0,1 },
 
12769
                                   { "niter",required_argument,0,2 },
 
12770
                                   { "maxdelta",required_argument,0,3 },
 
12771
                                   { "area",required_argument,0,4 },
 
12772
                                   { "coolexp",required_argument,0,5 },
 
12773
                                   { "repulserad",required_argument,0,6 },
 
12774
                                   { "weight",required_argument,0,7 },
 
12775
                                   { "help",no_argument,0,8 },
 
12776
                                   { 0,0,0,0 }
 
12777
                                 };
 
12778
 
 
12779
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12780
  memset(shell_seen, 0, 8*sizeof(int));
 
12781
  shell_seen[2]=2;
 
12782
  shell_seen[3]=2;
 
12783
  shell_seen[4]=2;
 
12784
  shell_seen[5]=2;
 
12785
  shell_seen[6]=2;
 
12786
  
 
12787
  /* Parse arguments and read input */
 
12788
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12789
 
 
12790
    if (shell_index==-1) {
 
12791
      exit(1);
 
12792
    }
 
12793
 
 
12794
    if (shell_seen[shell_index]==1) {
 
12795
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12796
              shell_options[shell_index].name);
 
12797
      exit(1);
 
12798
    }
 
12799
    shell_seen[shell_index]=1;  
 
12800
 
 
12801
    switch (shell_index) {
 
12802
    case 0: /* graph */
 
12803
      shell_read_graph(&graph, optarg);
 
12804
      break;
 
12805
    case 1: /* res */
 
12806
      shell_arg_res=strdup(optarg); 
 
12807
  igraph_matrix_init(&res, 0, 0);
 
12808
      break;
 
12809
    case 2: /* niter */
 
12810
      shell_read_integer(&niter, optarg);
 
12811
      break;
 
12812
    case 3: /* maxdelta */
 
12813
      shell_read_real(&maxdelta, optarg);
 
12814
      break;
 
12815
    case 4: /* area */
 
12816
      shell_read_real(&area, optarg);
 
12817
      break;
 
12818
    case 5: /* coolexp */
 
12819
      shell_read_real(&coolexp, optarg);
 
12820
      break;
 
12821
    case 6: /* repulserad */
 
12822
      shell_read_real(&repulserad, optarg);
 
12823
      break;
 
12824
    case 7: /* weight */
 
12825
      weight=&v_weight; shell_read_vector(weight, optarg);
 
12826
      break;
 
12827
    case 8:
 
12828
      shell_igraph_layout_fruchterman_reingold_usage(argv);
 
12829
      break;
 
12830
    default:
 
12831
      break;
 
12832
    }
 
12833
 
 
12834
    shell_index=-1;
 
12835
  }
 
12836
 
 
12837
  /* Check that we have all arguments */
 
12838
  for (shell_index=0; shell_index<8; shell_index++) {
 
12839
    if (!shell_seen[shell_index]) {
 
12840
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12841
              shell_options[shell_index].name);
 
12842
      exit(1);
 
12843
    }
 
12844
  }
 
12845
 
 
12846
  /* Do the operation */
 
12847
  shell_result=igraph_layout_fruchterman_reingold(&graph, &res, niter, maxdelta, area, coolexp, repulserad, 0, weight);
 
12848
 
 
12849
  /* Write the result */
 
12850
  igraph_destroy(&graph);
 
12851
  shell_write_matrix(&res, shell_arg_res); 
 
12852
  igraph_matrix_destroy(&res);
 
12853
  if (weight) { igraph_vector_destroy(weight); }
 
12854
 
 
12855
  return 0;
 
12856
}
 
12857
 
 
12858
/*-------------------------------------------/
 
12859
/ igraph_layout_grid_fruchterman_reingold    /
 
12860
/-------------------------------------------*/
 
12861
void shell_igraph_layout_grid_fruchterman_reingold_usage(char **argv) {
 
12862
  printf("%s --graph=<graph> --res=<res> --niter=<niter> --maxdelta=<maxdelta> --area=<area> --coolexp=<coolexp> --repulserad=<repulserad> --cellsize=<cellsize>\n", basename(argv[0]));
 
12863
  exit(1);
 
12864
}
 
12865
 
 
12866
int shell_igraph_layout_grid_fruchterman_reingold(int argc, char **argv) {
 
12867
 
 
12868
  igraph_t graph;
 
12869
  igraph_matrix_t res;
 
12870
  igraph_integer_t niter=500;
 
12871
  igraph_real_t maxdelta=100;
 
12872
  igraph_real_t area=1000;
 
12873
  igraph_real_t coolexp=1.5;
 
12874
  igraph_real_t repulserad=10000;
 
12875
  igraph_real_t cellsize=100;
 
12876
 
 
12877
  char* shell_arg_res=0;
 
12878
  int shell_result;
 
12879
 
 
12880
 
 
12881
  int shell_seen[8];
 
12882
  int shell_index=-1;
 
12883
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12884
                                   { "res",required_argument,0,1 },
 
12885
                                   { "niter",required_argument,0,2 },
 
12886
                                   { "maxdelta",required_argument,0,3 },
 
12887
                                   { "area",required_argument,0,4 },
 
12888
                                   { "coolexp",required_argument,0,5 },
 
12889
                                   { "repulserad",required_argument,0,6 },
 
12890
                                   { "cellsize",required_argument,0,7 },
 
12891
                                   { "help",no_argument,0,8 },
 
12892
                                   { 0,0,0,0 }
 
12893
                                 };
 
12894
 
 
12895
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
12896
  memset(shell_seen, 0, 8*sizeof(int));
 
12897
  shell_seen[2]=2;
 
12898
  shell_seen[3]=2;
 
12899
  shell_seen[4]=2;
 
12900
  shell_seen[5]=2;
 
12901
  shell_seen[6]=2;
 
12902
  shell_seen[7]=2;
 
12903
  
 
12904
  /* Parse arguments and read input */
 
12905
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
12906
 
 
12907
    if (shell_index==-1) {
 
12908
      exit(1);
 
12909
    }
 
12910
 
 
12911
    if (shell_seen[shell_index]==1) {
 
12912
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
12913
              shell_options[shell_index].name);
 
12914
      exit(1);
 
12915
    }
 
12916
    shell_seen[shell_index]=1;  
 
12917
 
 
12918
    switch (shell_index) {
 
12919
    case 0: /* graph */
 
12920
      shell_read_graph(&graph, optarg);
 
12921
      break;
 
12922
    case 1: /* res */
 
12923
      shell_arg_res=strdup(optarg); 
 
12924
  igraph_matrix_init(&res, 0, 0);
 
12925
      break;
 
12926
    case 2: /* niter */
 
12927
      shell_read_integer(&niter, optarg);
 
12928
      break;
 
12929
    case 3: /* maxdelta */
 
12930
      shell_read_real(&maxdelta, optarg);
 
12931
      break;
 
12932
    case 4: /* area */
 
12933
      shell_read_real(&area, optarg);
 
12934
      break;
 
12935
    case 5: /* coolexp */
 
12936
      shell_read_real(&coolexp, optarg);
 
12937
      break;
 
12938
    case 6: /* repulserad */
 
12939
      shell_read_real(&repulserad, optarg);
 
12940
      break;
 
12941
    case 7: /* cellsize */
 
12942
      shell_read_real(&cellsize, optarg);
 
12943
      break;
 
12944
    case 8:
 
12945
      shell_igraph_layout_grid_fruchterman_reingold_usage(argv);
 
12946
      break;
 
12947
    default:
 
12948
      break;
 
12949
    }
 
12950
 
 
12951
    shell_index=-1;
 
12952
  }
 
12953
 
 
12954
  /* Check that we have all arguments */
 
12955
  for (shell_index=0; shell_index<8; shell_index++) {
 
12956
    if (!shell_seen[shell_index]) {
 
12957
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
12958
              shell_options[shell_index].name);
 
12959
      exit(1);
 
12960
    }
 
12961
  }
 
12962
 
 
12963
  /* Do the operation */
 
12964
  shell_result=igraph_layout_grid_fruchterman_reingold(&graph, &res, niter, maxdelta, area, coolexp, repulserad, cellsize, 0);
 
12965
 
 
12966
  /* Write the result */
 
12967
  igraph_destroy(&graph);
 
12968
  shell_write_matrix(&res, shell_arg_res); 
 
12969
  igraph_matrix_destroy(&res);
 
12970
 
 
12971
  return 0;
 
12972
}
 
12973
 
 
12974
/*-------------------------------------------/
 
12975
/ igraph_layout_kamada_kawai                 /
 
12976
/-------------------------------------------*/
 
12977
void shell_igraph_layout_kamada_kawai_usage(char **argv) {
 
12978
  printf("%s --graph=<graph> --res=<res> --niter=<niter> --sigma=<sigma> --initemp=<initemp> --coolexp=<coolexp> --kkconst=<kkconst>\n", basename(argv[0]));
 
12979
  exit(1);
 
12980
}
 
12981
 
 
12982
int shell_igraph_layout_kamada_kawai(int argc, char **argv) {
 
12983
 
 
12984
  igraph_t graph;
 
12985
  igraph_matrix_t res;
 
12986
  igraph_integer_t niter=1000;
 
12987
  igraph_real_t sigma=10;
 
12988
  igraph_real_t initemp=10;
 
12989
  igraph_real_t coolexp=0.99;
 
12990
  igraph_real_t kkconst=1000;
 
12991
  char* shell_arg_res=0;
 
12992
  int shell_result;
 
12993
 
 
12994
 
 
12995
  int shell_seen[7];
 
12996
  int shell_index=-1;
 
12997
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
12998
                                   { "res",required_argument,0,1 },
 
12999
                                   { "niter",required_argument,0,2 },
 
13000
                                   { "sigma",required_argument,0,3 },
 
13001
                                   { "initemp",required_argument,0,4 },
 
13002
                                   { "coolexp",required_argument,0,5 },
 
13003
                                   { "kkconst",required_argument,0,6 },
 
13004
                                   { "help",no_argument,0,7 },
 
13005
                                   { 0,0,0,0 }
 
13006
                                 };
 
13007
 
 
13008
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13009
  memset(shell_seen, 0, 7*sizeof(int));
 
13010
  shell_seen[2]=2;
 
13011
  shell_seen[3]=2;
 
13012
  shell_seen[4]=2;
 
13013
  shell_seen[5]=2;
 
13014
  shell_seen[6]=2;
 
13015
  
 
13016
  /* Parse arguments and read input */
 
13017
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13018
 
 
13019
    if (shell_index==-1) {
 
13020
      exit(1);
 
13021
    }
 
13022
 
 
13023
    if (shell_seen[shell_index]==1) {
 
13024
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13025
              shell_options[shell_index].name);
 
13026
      exit(1);
 
13027
    }
 
13028
    shell_seen[shell_index]=1;  
 
13029
 
 
13030
    switch (shell_index) {
 
13031
    case 0: /* graph */
 
13032
      shell_read_graph(&graph, optarg);
 
13033
      break;
 
13034
    case 1: /* res */
 
13035
      shell_arg_res=strdup(optarg); 
 
13036
  igraph_matrix_init(&res, 0, 0);
 
13037
      break;
 
13038
    case 2: /* niter */
 
13039
      shell_read_integer(&niter, optarg);
 
13040
      break;
 
13041
    case 3: /* sigma */
 
13042
      shell_read_real(&sigma, optarg);
 
13043
      break;
 
13044
    case 4: /* initemp */
 
13045
      shell_read_real(&initemp, optarg);
 
13046
      break;
 
13047
    case 5: /* coolexp */
 
13048
      shell_read_real(&coolexp, optarg);
 
13049
      break;
 
13050
    case 6: /* kkconst */
 
13051
      shell_read_real(&kkconst, optarg);
 
13052
      break;
 
13053
    case 7:
 
13054
      shell_igraph_layout_kamada_kawai_usage(argv);
 
13055
      break;
 
13056
    default:
 
13057
      break;
 
13058
    }
 
13059
 
 
13060
    shell_index=-1;
 
13061
  }
 
13062
 
 
13063
  /* Check that we have all arguments */
 
13064
  for (shell_index=0; shell_index<7; shell_index++) {
 
13065
    if (!shell_seen[shell_index]) {
 
13066
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13067
              shell_options[shell_index].name);
 
13068
      exit(1);
 
13069
    }
 
13070
  }
 
13071
 
 
13072
  /* Do the operation */
 
13073
  shell_result=igraph_layout_kamada_kawai(&graph, &res, niter, sigma, initemp, coolexp, kkconst);
 
13074
 
 
13075
  /* Write the result */
 
13076
  igraph_destroy(&graph);
 
13077
  shell_write_matrix(&res, shell_arg_res); 
 
13078
  igraph_matrix_destroy(&res);
 
13079
 
 
13080
  return 0;
 
13081
}
 
13082
 
 
13083
/*-------------------------------------------/
 
13084
/ igraph_layout_lgl                          /
 
13085
/-------------------------------------------*/
 
13086
void shell_igraph_layout_lgl_usage(char **argv) {
 
13087
  printf("%s --graph=<graph> --res=<res> --maxiter=<maxiter> --maxdelta=<maxdelta> --area=<area> --coolexp=<coolexp> --repulserad=<repulserad> --cellsize=<cellsize> --root=<root>\n", basename(argv[0]));
 
13088
  exit(1);
 
13089
}
 
13090
 
 
13091
int shell_igraph_layout_lgl(int argc, char **argv) {
 
13092
 
 
13093
  igraph_t graph;
 
13094
  igraph_matrix_t res;
 
13095
  igraph_integer_t maxiter=150;
 
13096
  igraph_real_t maxdelta=100;
 
13097
  igraph_real_t area=1000;
 
13098
  igraph_real_t coolexp=1.5;
 
13099
  igraph_real_t repulserad=10000;
 
13100
  igraph_real_t cellsize=100;
 
13101
  igraph_integer_t root=-1;
 
13102
  char* shell_arg_res=0;
 
13103
  int shell_result;
 
13104
 
 
13105
 
 
13106
  int shell_seen[9];
 
13107
  int shell_index=-1;
 
13108
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13109
                                   { "res",required_argument,0,1 },
 
13110
                                   { "maxiter",required_argument,0,2 },
 
13111
                                   { "maxdelta",required_argument,0,3 },
 
13112
                                   { "area",required_argument,0,4 },
 
13113
                                   { "coolexp",required_argument,0,5 },
 
13114
                                   { "repulserad",required_argument,0,6 },
 
13115
                                   { "cellsize",required_argument,0,7 },
 
13116
                                   { "root",required_argument,0,8 },
 
13117
                                   { "help",no_argument,0,9 },
 
13118
                                   { 0,0,0,0 }
 
13119
                                 };
 
13120
 
 
13121
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13122
  memset(shell_seen, 0, 9*sizeof(int));
 
13123
  shell_seen[2]=2;
 
13124
  shell_seen[3]=2;
 
13125
  shell_seen[4]=2;
 
13126
  shell_seen[5]=2;
 
13127
  shell_seen[6]=2;
 
13128
  shell_seen[7]=2;
 
13129
  shell_seen[8]=2;
 
13130
  
 
13131
  /* Parse arguments and read input */
 
13132
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13133
 
 
13134
    if (shell_index==-1) {
 
13135
      exit(1);
 
13136
    }
 
13137
 
 
13138
    if (shell_seen[shell_index]==1) {
 
13139
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13140
              shell_options[shell_index].name);
 
13141
      exit(1);
 
13142
    }
 
13143
    shell_seen[shell_index]=1;  
 
13144
 
 
13145
    switch (shell_index) {
 
13146
    case 0: /* graph */
 
13147
      shell_read_graph(&graph, optarg);
 
13148
      break;
 
13149
    case 1: /* res */
 
13150
      shell_arg_res=strdup(optarg); 
 
13151
  igraph_matrix_init(&res, 0, 0);
 
13152
      break;
 
13153
    case 2: /* maxiter */
 
13154
      shell_read_integer(&maxiter, optarg);
 
13155
      break;
 
13156
    case 3: /* maxdelta */
 
13157
      shell_read_real(&maxdelta, optarg);
 
13158
      break;
 
13159
    case 4: /* area */
 
13160
      shell_read_real(&area, optarg);
 
13161
      break;
 
13162
    case 5: /* coolexp */
 
13163
      shell_read_real(&coolexp, optarg);
 
13164
      break;
 
13165
    case 6: /* repulserad */
 
13166
      shell_read_real(&repulserad, optarg);
 
13167
      break;
 
13168
    case 7: /* cellsize */
 
13169
      shell_read_real(&cellsize, optarg);
 
13170
      break;
 
13171
    case 8: /* root */
 
13172
      shell_read_integer(&root, optarg);
 
13173
      break;
 
13174
    case 9:
 
13175
      shell_igraph_layout_lgl_usage(argv);
 
13176
      break;
 
13177
    default:
 
13178
      break;
 
13179
    }
 
13180
 
 
13181
    shell_index=-1;
 
13182
  }
 
13183
 
 
13184
  /* Check that we have all arguments */
 
13185
  for (shell_index=0; shell_index<9; shell_index++) {
 
13186
    if (!shell_seen[shell_index]) {
 
13187
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13188
              shell_options[shell_index].name);
 
13189
      exit(1);
 
13190
    }
 
13191
  }
 
13192
 
 
13193
  /* Do the operation */
 
13194
  shell_result=igraph_layout_lgl(&graph, &res, maxiter, maxdelta, area, coolexp, repulserad, cellsize, root);
 
13195
 
 
13196
  /* Write the result */
 
13197
  igraph_destroy(&graph);
 
13198
  shell_write_matrix(&res, shell_arg_res); 
 
13199
  igraph_matrix_destroy(&res);
 
13200
 
 
13201
  return 0;
 
13202
}
 
13203
 
 
13204
/*-------------------------------------------/
 
13205
/ igraph_layout_reingold_tilford             /
 
13206
/-------------------------------------------*/
 
13207
void shell_igraph_layout_reingold_tilford_usage(char **argv) {
 
13208
  printf("%s --graph=<graph> --res=<res> --root=<root>\n", basename(argv[0]));
 
13209
  exit(1);
 
13210
}
 
13211
 
 
13212
int shell_igraph_layout_reingold_tilford(int argc, char **argv) {
 
13213
 
 
13214
  igraph_t graph;
 
13215
  igraph_matrix_t res;
 
13216
  long int root=0;
 
13217
  char* shell_arg_res=0;
 
13218
  int shell_result;
 
13219
 
 
13220
 
 
13221
  int shell_seen[3];
 
13222
  int shell_index=-1;
 
13223
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13224
                                   { "res",required_argument,0,1 },
 
13225
                                   { "root",required_argument,0,2 },
 
13226
                                   { "help",no_argument,0,3 },
 
13227
                                   { 0,0,0,0 }
 
13228
                                 };
 
13229
 
 
13230
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13231
  memset(shell_seen, 0, 3*sizeof(int));
 
13232
  shell_seen[2]=2;
 
13233
  
 
13234
  /* Parse arguments and read input */
 
13235
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13236
 
 
13237
    if (shell_index==-1) {
 
13238
      exit(1);
 
13239
    }
 
13240
 
 
13241
    if (shell_seen[shell_index]==1) {
 
13242
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13243
              shell_options[shell_index].name);
 
13244
      exit(1);
 
13245
    }
 
13246
    shell_seen[shell_index]=1;  
 
13247
 
 
13248
    switch (shell_index) {
 
13249
    case 0: /* graph */
 
13250
      shell_read_graph(&graph, optarg);
 
13251
      break;
 
13252
    case 1: /* res */
 
13253
      shell_arg_res=strdup(optarg); 
 
13254
  igraph_matrix_init(&res, 0, 0);
 
13255
      break;
 
13256
    case 2: /* root */
 
13257
      shell_read_longint(&root, optarg);
 
13258
      break;
 
13259
    case 3:
 
13260
      shell_igraph_layout_reingold_tilford_usage(argv);
 
13261
      break;
 
13262
    default:
 
13263
      break;
 
13264
    }
 
13265
 
 
13266
    shell_index=-1;
 
13267
  }
 
13268
 
 
13269
  /* Check that we have all arguments */
 
13270
  for (shell_index=0; shell_index<3; shell_index++) {
 
13271
    if (!shell_seen[shell_index]) {
 
13272
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13273
              shell_options[shell_index].name);
 
13274
      exit(1);
 
13275
    }
 
13276
  }
 
13277
 
 
13278
  /* Do the operation */
 
13279
  shell_result=igraph_layout_reingold_tilford(&graph, &res, root);
 
13280
 
 
13281
  /* Write the result */
 
13282
  igraph_destroy(&graph);
 
13283
  shell_write_matrix(&res, shell_arg_res); 
 
13284
  igraph_matrix_destroy(&res);
 
13285
 
 
13286
  return 0;
 
13287
}
 
13288
 
 
13289
/*-------------------------------------------/
 
13290
/ igraph_layout_reingold_tilford_circular    /
 
13291
/-------------------------------------------*/
 
13292
void shell_igraph_layout_reingold_tilford_circular_usage(char **argv) {
 
13293
  printf("%s --graph=<graph> --res=<res> --root=<root>\n", basename(argv[0]));
 
13294
  exit(1);
 
13295
}
 
13296
 
 
13297
int shell_igraph_layout_reingold_tilford_circular(int argc, char **argv) {
 
13298
 
 
13299
  igraph_t graph;
 
13300
  igraph_matrix_t res;
 
13301
  long int root=0;
 
13302
  char* shell_arg_res=0;
 
13303
  int shell_result;
 
13304
 
 
13305
 
 
13306
  int shell_seen[3];
 
13307
  int shell_index=-1;
 
13308
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13309
                                   { "res",required_argument,0,1 },
 
13310
                                   { "root",required_argument,0,2 },
 
13311
                                   { "help",no_argument,0,3 },
 
13312
                                   { 0,0,0,0 }
 
13313
                                 };
 
13314
 
 
13315
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13316
  memset(shell_seen, 0, 3*sizeof(int));
 
13317
  shell_seen[2]=2;
 
13318
  
 
13319
  /* Parse arguments and read input */
 
13320
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13321
 
 
13322
    if (shell_index==-1) {
 
13323
      exit(1);
 
13324
    }
 
13325
 
 
13326
    if (shell_seen[shell_index]==1) {
 
13327
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13328
              shell_options[shell_index].name);
 
13329
      exit(1);
 
13330
    }
 
13331
    shell_seen[shell_index]=1;  
 
13332
 
 
13333
    switch (shell_index) {
 
13334
    case 0: /* graph */
 
13335
      shell_read_graph(&graph, optarg);
 
13336
      break;
 
13337
    case 1: /* res */
 
13338
      shell_arg_res=strdup(optarg); 
 
13339
  igraph_matrix_init(&res, 0, 0);
 
13340
      break;
 
13341
    case 2: /* root */
 
13342
      shell_read_longint(&root, optarg);
 
13343
      break;
 
13344
    case 3:
 
13345
      shell_igraph_layout_reingold_tilford_circular_usage(argv);
 
13346
      break;
 
13347
    default:
 
13348
      break;
 
13349
    }
 
13350
 
 
13351
    shell_index=-1;
 
13352
  }
 
13353
 
 
13354
  /* Check that we have all arguments */
 
13355
  for (shell_index=0; shell_index<3; shell_index++) {
 
13356
    if (!shell_seen[shell_index]) {
 
13357
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13358
              shell_options[shell_index].name);
 
13359
      exit(1);
 
13360
    }
 
13361
  }
 
13362
 
 
13363
  /* Do the operation */
 
13364
  shell_result=igraph_layout_reingold_tilford_circular(&graph, &res, root);
 
13365
 
 
13366
  /* Write the result */
 
13367
  igraph_destroy(&graph);
 
13368
  shell_write_matrix(&res, shell_arg_res); 
 
13369
  igraph_matrix_destroy(&res);
 
13370
 
 
13371
  return 0;
 
13372
}
 
13373
 
 
13374
/*-------------------------------------------/
 
13375
/ igraph_layout_random_3d                    /
 
13376
/-------------------------------------------*/
 
13377
void shell_igraph_layout_random_3d_usage(char **argv) {
 
13378
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
13379
  exit(1);
 
13380
}
 
13381
 
 
13382
int shell_igraph_layout_random_3d(int argc, char **argv) {
 
13383
 
 
13384
  igraph_t graph;
 
13385
  igraph_matrix_t res;
 
13386
  char* shell_arg_res=0;
 
13387
  int shell_result;
 
13388
 
 
13389
 
 
13390
  int shell_seen[2];
 
13391
  int shell_index=-1;
 
13392
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13393
                                   { "res",required_argument,0,1 },
 
13394
                                   { "help",no_argument,0,2 },
 
13395
                                   { 0,0,0,0 }
 
13396
                                 };
 
13397
 
 
13398
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13399
  memset(shell_seen, 0, 2*sizeof(int));
 
13400
 
 
13401
  
 
13402
  /* Parse arguments and read input */
 
13403
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13404
 
 
13405
    if (shell_index==-1) {
 
13406
      exit(1);
 
13407
    }
 
13408
 
 
13409
    if (shell_seen[shell_index]==1) {
 
13410
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13411
              shell_options[shell_index].name);
 
13412
      exit(1);
 
13413
    }
 
13414
    shell_seen[shell_index]=1;  
 
13415
 
 
13416
    switch (shell_index) {
 
13417
    case 0: /* graph */
 
13418
      shell_read_graph(&graph, optarg);
 
13419
      break;
 
13420
    case 1: /* res */
 
13421
      shell_arg_res=strdup(optarg); 
 
13422
  igraph_matrix_init(&res, 0, 0);
 
13423
      break;
 
13424
    case 2:
 
13425
      shell_igraph_layout_random_3d_usage(argv);
 
13426
      break;
 
13427
    default:
 
13428
      break;
 
13429
    }
 
13430
 
 
13431
    shell_index=-1;
 
13432
  }
 
13433
 
 
13434
  /* Check that we have all arguments */
 
13435
  for (shell_index=0; shell_index<2; shell_index++) {
 
13436
    if (!shell_seen[shell_index]) {
 
13437
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13438
              shell_options[shell_index].name);
 
13439
      exit(1);
 
13440
    }
 
13441
  }
 
13442
 
 
13443
  /* Do the operation */
 
13444
  shell_result=igraph_layout_random_3d(&graph, &res);
 
13445
 
 
13446
  /* Write the result */
 
13447
  igraph_destroy(&graph);
 
13448
  shell_write_matrix(&res, shell_arg_res); 
 
13449
  igraph_matrix_destroy(&res);
 
13450
 
 
13451
  return 0;
 
13452
}
 
13453
 
 
13454
/*-------------------------------------------/
 
13455
/ igraph_layout_sphere                       /
 
13456
/-------------------------------------------*/
 
13457
void shell_igraph_layout_sphere_usage(char **argv) {
 
13458
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
13459
  exit(1);
 
13460
}
 
13461
 
 
13462
int shell_igraph_layout_sphere(int argc, char **argv) {
 
13463
 
 
13464
  igraph_t graph;
 
13465
  igraph_matrix_t res;
 
13466
  char* shell_arg_res=0;
 
13467
  int shell_result;
 
13468
 
 
13469
 
 
13470
  int shell_seen[2];
 
13471
  int shell_index=-1;
 
13472
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13473
                                   { "res",required_argument,0,1 },
 
13474
                                   { "help",no_argument,0,2 },
 
13475
                                   { 0,0,0,0 }
 
13476
                                 };
 
13477
 
 
13478
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13479
  memset(shell_seen, 0, 2*sizeof(int));
 
13480
 
 
13481
  
 
13482
  /* Parse arguments and read input */
 
13483
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13484
 
 
13485
    if (shell_index==-1) {
 
13486
      exit(1);
 
13487
    }
 
13488
 
 
13489
    if (shell_seen[shell_index]==1) {
 
13490
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13491
              shell_options[shell_index].name);
 
13492
      exit(1);
 
13493
    }
 
13494
    shell_seen[shell_index]=1;  
 
13495
 
 
13496
    switch (shell_index) {
 
13497
    case 0: /* graph */
 
13498
      shell_read_graph(&graph, optarg);
 
13499
      break;
 
13500
    case 1: /* res */
 
13501
      shell_arg_res=strdup(optarg); 
 
13502
  igraph_matrix_init(&res, 0, 0);
 
13503
      break;
 
13504
    case 2:
 
13505
      shell_igraph_layout_sphere_usage(argv);
 
13506
      break;
 
13507
    default:
 
13508
      break;
 
13509
    }
 
13510
 
 
13511
    shell_index=-1;
 
13512
  }
 
13513
 
 
13514
  /* Check that we have all arguments */
 
13515
  for (shell_index=0; shell_index<2; shell_index++) {
 
13516
    if (!shell_seen[shell_index]) {
 
13517
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13518
              shell_options[shell_index].name);
 
13519
      exit(1);
 
13520
    }
 
13521
  }
 
13522
 
 
13523
  /* Do the operation */
 
13524
  shell_result=igraph_layout_sphere(&graph, &res);
 
13525
 
 
13526
  /* Write the result */
 
13527
  igraph_destroy(&graph);
 
13528
  shell_write_matrix(&res, shell_arg_res); 
 
13529
  igraph_matrix_destroy(&res);
 
13530
 
 
13531
  return 0;
 
13532
}
 
13533
 
 
13534
/*-------------------------------------------/
 
13535
/ igraph_layout_fruchterman_reingold_3d      /
 
13536
/-------------------------------------------*/
 
13537
void shell_igraph_layout_fruchterman_reingold_3d_usage(char **argv) {
 
13538
  printf("%s --graph=<graph> --res=<res> --niter=<niter> --maxdelta=<maxdelta> --volume=<volume> --coolexp=<coolexp> --repulserad=<repulserad> --weight=<weight>\n", basename(argv[0]));
 
13539
  exit(1);
 
13540
}
 
13541
 
 
13542
int shell_igraph_layout_fruchterman_reingold_3d(int argc, char **argv) {
 
13543
 
 
13544
  igraph_t graph;
 
13545
  igraph_matrix_t res;
 
13546
  igraph_integer_t niter=500;
 
13547
  igraph_real_t maxdelta=100;
 
13548
  igraph_real_t volume=1000;
 
13549
  igraph_real_t coolexp=1.5;
 
13550
  igraph_real_t repulserad=10000;
 
13551
 
 
13552
  igraph_vector_t v_weight; igraph_vector_t *weight=0;
 
13553
  char* shell_arg_res=0;
 
13554
  int shell_result;
 
13555
 
 
13556
 
 
13557
  int shell_seen[8];
 
13558
  int shell_index=-1;
 
13559
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13560
                                   { "res",required_argument,0,1 },
 
13561
                                   { "niter",required_argument,0,2 },
 
13562
                                   { "maxdelta",required_argument,0,3 },
 
13563
                                   { "volume",required_argument,0,4 },
 
13564
                                   { "coolexp",required_argument,0,5 },
 
13565
                                   { "repulserad",required_argument,0,6 },
 
13566
                                   { "weight",required_argument,0,7 },
 
13567
                                   { "help",no_argument,0,8 },
 
13568
                                   { 0,0,0,0 }
 
13569
                                 };
 
13570
 
 
13571
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13572
  memset(shell_seen, 0, 8*sizeof(int));
 
13573
  shell_seen[2]=2;
 
13574
  shell_seen[3]=2;
 
13575
  shell_seen[4]=2;
 
13576
  shell_seen[5]=2;
 
13577
  shell_seen[6]=2;
 
13578
  
 
13579
  /* Parse arguments and read input */
 
13580
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13581
 
 
13582
    if (shell_index==-1) {
 
13583
      exit(1);
 
13584
    }
 
13585
 
 
13586
    if (shell_seen[shell_index]==1) {
 
13587
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13588
              shell_options[shell_index].name);
 
13589
      exit(1);
 
13590
    }
 
13591
    shell_seen[shell_index]=1;  
 
13592
 
 
13593
    switch (shell_index) {
 
13594
    case 0: /* graph */
 
13595
      shell_read_graph(&graph, optarg);
 
13596
      break;
 
13597
    case 1: /* res */
 
13598
      shell_arg_res=strdup(optarg); 
 
13599
  igraph_matrix_init(&res, 0, 0);
 
13600
      break;
 
13601
    case 2: /* niter */
 
13602
      shell_read_integer(&niter, optarg);
 
13603
      break;
 
13604
    case 3: /* maxdelta */
 
13605
      shell_read_real(&maxdelta, optarg);
 
13606
      break;
 
13607
    case 4: /* volume */
 
13608
      shell_read_real(&volume, optarg);
 
13609
      break;
 
13610
    case 5: /* coolexp */
 
13611
      shell_read_real(&coolexp, optarg);
 
13612
      break;
 
13613
    case 6: /* repulserad */
 
13614
      shell_read_real(&repulserad, optarg);
 
13615
      break;
 
13616
    case 7: /* weight */
 
13617
      weight=&v_weight; shell_read_vector(weight, optarg);
 
13618
      break;
 
13619
    case 8:
 
13620
      shell_igraph_layout_fruchterman_reingold_3d_usage(argv);
 
13621
      break;
 
13622
    default:
 
13623
      break;
 
13624
    }
 
13625
 
 
13626
    shell_index=-1;
 
13627
  }
 
13628
 
 
13629
  /* Check that we have all arguments */
 
13630
  for (shell_index=0; shell_index<8; shell_index++) {
 
13631
    if (!shell_seen[shell_index]) {
 
13632
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13633
              shell_options[shell_index].name);
 
13634
      exit(1);
 
13635
    }
 
13636
  }
 
13637
 
 
13638
  /* Do the operation */
 
13639
  shell_result=igraph_layout_fruchterman_reingold_3d(&graph, &res, niter, maxdelta, volume, coolexp, repulserad, 0, weight);
 
13640
 
 
13641
  /* Write the result */
 
13642
  igraph_destroy(&graph);
 
13643
  shell_write_matrix(&res, shell_arg_res); 
 
13644
  igraph_matrix_destroy(&res);
 
13645
  if (weight) { igraph_vector_destroy(weight); }
 
13646
 
 
13647
  return 0;
 
13648
}
 
13649
 
 
13650
/*-------------------------------------------/
 
13651
/ igraph_layout_kamada_kawai_3d              /
 
13652
/-------------------------------------------*/
 
13653
void shell_igraph_layout_kamada_kawai_3d_usage(char **argv) {
 
13654
  printf("%s --graph=<graph> --res=<res> --niter=<niter> --sigma=<sigma> --initemp=<initemp> --coolexp=<coolexp> --kkconst=<kkconst>\n", basename(argv[0]));
 
13655
  exit(1);
 
13656
}
 
13657
 
 
13658
int shell_igraph_layout_kamada_kawai_3d(int argc, char **argv) {
 
13659
 
 
13660
  igraph_t graph;
 
13661
  igraph_matrix_t res;
 
13662
  igraph_integer_t niter=1000;
 
13663
  igraph_real_t sigma=10;
 
13664
  igraph_real_t initemp=10;
 
13665
  igraph_real_t coolexp=0.99;
 
13666
  igraph_real_t kkconst=1000;
 
13667
  char* shell_arg_res=0;
 
13668
  int shell_result;
 
13669
 
 
13670
 
 
13671
  int shell_seen[7];
 
13672
  int shell_index=-1;
 
13673
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13674
                                   { "res",required_argument,0,1 },
 
13675
                                   { "niter",required_argument,0,2 },
 
13676
                                   { "sigma",required_argument,0,3 },
 
13677
                                   { "initemp",required_argument,0,4 },
 
13678
                                   { "coolexp",required_argument,0,5 },
 
13679
                                   { "kkconst",required_argument,0,6 },
 
13680
                                   { "help",no_argument,0,7 },
 
13681
                                   { 0,0,0,0 }
 
13682
                                 };
 
13683
 
 
13684
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13685
  memset(shell_seen, 0, 7*sizeof(int));
 
13686
  shell_seen[2]=2;
 
13687
  shell_seen[3]=2;
 
13688
  shell_seen[4]=2;
 
13689
  shell_seen[5]=2;
 
13690
  shell_seen[6]=2;
 
13691
  
 
13692
  /* Parse arguments and read input */
 
13693
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13694
 
 
13695
    if (shell_index==-1) {
 
13696
      exit(1);
 
13697
    }
 
13698
 
 
13699
    if (shell_seen[shell_index]==1) {
 
13700
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13701
              shell_options[shell_index].name);
 
13702
      exit(1);
 
13703
    }
 
13704
    shell_seen[shell_index]=1;  
 
13705
 
 
13706
    switch (shell_index) {
 
13707
    case 0: /* graph */
 
13708
      shell_read_graph(&graph, optarg);
 
13709
      break;
 
13710
    case 1: /* res */
 
13711
      shell_arg_res=strdup(optarg); 
 
13712
  igraph_matrix_init(&res, 0, 0);
 
13713
      break;
 
13714
    case 2: /* niter */
 
13715
      shell_read_integer(&niter, optarg);
 
13716
      break;
 
13717
    case 3: /* sigma */
 
13718
      shell_read_real(&sigma, optarg);
 
13719
      break;
 
13720
    case 4: /* initemp */
 
13721
      shell_read_real(&initemp, optarg);
 
13722
      break;
 
13723
    case 5: /* coolexp */
 
13724
      shell_read_real(&coolexp, optarg);
 
13725
      break;
 
13726
    case 6: /* kkconst */
 
13727
      shell_read_real(&kkconst, optarg);
 
13728
      break;
 
13729
    case 7:
 
13730
      shell_igraph_layout_kamada_kawai_3d_usage(argv);
 
13731
      break;
 
13732
    default:
 
13733
      break;
 
13734
    }
 
13735
 
 
13736
    shell_index=-1;
 
13737
  }
 
13738
 
 
13739
  /* Check that we have all arguments */
 
13740
  for (shell_index=0; shell_index<7; shell_index++) {
 
13741
    if (!shell_seen[shell_index]) {
 
13742
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13743
              shell_options[shell_index].name);
 
13744
      exit(1);
 
13745
    }
 
13746
  }
 
13747
 
 
13748
  /* Do the operation */
 
13749
  shell_result=igraph_layout_kamada_kawai_3d(&graph, &res, niter, sigma, initemp, coolexp, kkconst);
 
13750
 
 
13751
  /* Write the result */
 
13752
  igraph_destroy(&graph);
 
13753
  shell_write_matrix(&res, shell_arg_res); 
 
13754
  igraph_matrix_destroy(&res);
 
13755
 
 
13756
  return 0;
 
13757
}
 
13758
 
 
13759
/*-------------------------------------------/
 
13760
/ igraph_layout_graphopt                     /
 
13761
/-------------------------------------------*/
 
13762
void shell_igraph_layout_graphopt_usage(char **argv) {
 
13763
  printf("%s --graph=<graph> --res=<res> --niter=<niter> --node_charge=<node_charge> --node_mass=<node_mass> --spring_length=<spring_length> --spring_constant=<spring_constant> --max_sa_movement=<max_sa_movement>\n", basename(argv[0]));
 
13764
  exit(1);
 
13765
}
 
13766
 
 
13767
int shell_igraph_layout_graphopt(int argc, char **argv) {
 
13768
 
 
13769
  igraph_t graph;
 
13770
  igraph_matrix_t res;
 
13771
  igraph_integer_t niter=500;
 
13772
  igraph_real_t node_charge=0.001;
 
13773
  igraph_real_t node_mass=30;
 
13774
  igraph_integer_t spring_length=0;
 
13775
  igraph_real_t spring_constant=1;
 
13776
  igraph_real_t max_sa_movement=5;
 
13777
 
 
13778
  char* shell_arg_res=0;
 
13779
  int shell_result;
 
13780
 
 
13781
 
 
13782
  int shell_seen[8];
 
13783
  int shell_index=-1;
 
13784
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13785
                                   { "res",required_argument,0,1 },
 
13786
                                   { "niter",required_argument,0,2 },
 
13787
                                   { "node_charge",required_argument,0,3 },
 
13788
                                   { "node_mass",required_argument,0,4 },
 
13789
                                   { "spring_length",required_argument,0,5 },
 
13790
                                   { "spring_constant",required_argument,0,6 },
 
13791
                                   { "max_sa_movement",required_argument,0,7 },
 
13792
                                   { "help",no_argument,0,8 },
 
13793
                                   { 0,0,0,0 }
 
13794
                                 };
 
13795
 
 
13796
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13797
  memset(shell_seen, 0, 8*sizeof(int));
 
13798
  shell_seen[2]=2;
 
13799
  shell_seen[3]=2;
 
13800
  shell_seen[4]=2;
 
13801
  shell_seen[5]=2;
 
13802
  shell_seen[6]=2;
 
13803
  shell_seen[7]=2;
 
13804
  
 
13805
  /* Parse arguments and read input */
 
13806
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13807
 
 
13808
    if (shell_index==-1) {
 
13809
      exit(1);
 
13810
    }
 
13811
 
 
13812
    if (shell_seen[shell_index]==1) {
 
13813
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13814
              shell_options[shell_index].name);
 
13815
      exit(1);
 
13816
    }
 
13817
    shell_seen[shell_index]=1;  
 
13818
 
 
13819
    switch (shell_index) {
 
13820
    case 0: /* graph */
 
13821
      shell_read_graph(&graph, optarg);
 
13822
      break;
 
13823
    case 1: /* res */
 
13824
      shell_arg_res=strdup(optarg); 
 
13825
  igraph_matrix_init(&res, 0, 0);
 
13826
      break;
 
13827
    case 2: /* niter */
 
13828
      shell_read_integer(&niter, optarg);
 
13829
      break;
 
13830
    case 3: /* node_charge */
 
13831
      shell_read_real(&node_charge, optarg);
 
13832
      break;
 
13833
    case 4: /* node_mass */
 
13834
      shell_read_real(&node_mass, optarg);
 
13835
      break;
 
13836
    case 5: /* spring_length */
 
13837
      shell_read_integer(&spring_length, optarg);
 
13838
      break;
 
13839
    case 6: /* spring_constant */
 
13840
      shell_read_real(&spring_constant, optarg);
 
13841
      break;
 
13842
    case 7: /* max_sa_movement */
 
13843
      shell_read_real(&max_sa_movement, optarg);
 
13844
      break;
 
13845
    case 8:
 
13846
      shell_igraph_layout_graphopt_usage(argv);
 
13847
      break;
 
13848
    default:
 
13849
      break;
 
13850
    }
 
13851
 
 
13852
    shell_index=-1;
 
13853
  }
 
13854
 
 
13855
  /* Check that we have all arguments */
 
13856
  for (shell_index=0; shell_index<8; shell_index++) {
 
13857
    if (!shell_seen[shell_index]) {
 
13858
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13859
              shell_options[shell_index].name);
 
13860
      exit(1);
 
13861
    }
 
13862
  }
 
13863
 
 
13864
  /* Do the operation */
 
13865
  shell_result=igraph_layout_graphopt(&graph, &res, niter, node_charge, node_mass, spring_length, spring_constant, max_sa_movement, 0);
 
13866
 
 
13867
  /* Write the result */
 
13868
  igraph_destroy(&graph);
 
13869
  shell_write_matrix(&res, shell_arg_res); 
 
13870
  igraph_matrix_destroy(&res);
 
13871
 
 
13872
  return 0;
 
13873
}
 
13874
 
 
13875
/*-------------------------------------------/
 
13876
/ igraph_layout_drl                          /
 
13877
/-------------------------------------------*/
 
13878
void shell_igraph_layout_drl_usage(char **argv) {
 
13879
  printf("%s --graph=<graph> --res=<res> --res-out=<res-out> --use_seed=<use_seed> --weights=<weights>\n", basename(argv[0]));
 
13880
  exit(1);
 
13881
}
 
13882
 
 
13883
int shell_igraph_layout_drl(int argc, char **argv) {
 
13884
 
 
13885
  igraph_t graph;
 
13886
  igraph_matrix_t res;
 
13887
  igraph_bool_t use_seed=0;
 
13888
 
 
13889
  igraph_vector_t v_weights; igraph_vector_t *weights=0=NULL;
 
13890
 
 
13891
  char* shell_arg_res=0;
 
13892
  int shell_result;
 
13893
 
 
13894
 
 
13895
  int shell_seen[5];
 
13896
  int shell_index=-1;
 
13897
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13898
                                   { "res",required_argument,0,1 },
 
13899
                                   { "res-out",required_argument,0,2 },
 
13900
                                   { "use_seed",required_argument,0,3 },
 
13901
                                   { "weights",required_argument,0,4 },
 
13902
                                   { "help",no_argument,0,5 },
 
13903
                                   { 0,0,0,0 }
 
13904
                                 };
 
13905
 
 
13906
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
13907
  memset(shell_seen, 0, 5*sizeof(int));
 
13908
  shell_seen[3]=2;
 
13909
  shell_seen[4]=2;
 
13910
  
 
13911
  /* Parse arguments and read input */
 
13912
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
13913
 
 
13914
    if (shell_index==-1) {
 
13915
      exit(1);
 
13916
    }
 
13917
 
 
13918
    if (shell_seen[shell_index]==1) {
 
13919
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
13920
              shell_options[shell_index].name);
 
13921
      exit(1);
 
13922
    }
 
13923
    shell_seen[shell_index]=1;  
 
13924
 
 
13925
    switch (shell_index) {
 
13926
    case 0: /* graph */
 
13927
      shell_read_graph(&graph, optarg);
 
13928
      break;
 
13929
    case 1: /* res */
 
13930
      shell_read_matrix(&res, optarg);
 
13931
      break;
 
13932
    case 2: /* res-out */
 
13933
      shell_arg_res=strdup(optarg); 
 
13934
  igraph_matrix_init(&res, 0, 0);
 
13935
      break;
 
13936
    case 3: /* use_seed */
 
13937
      shell_read_boolean(&use_seed, optarg);
 
13938
      break;
 
13939
    case 4: /* weights */
 
13940
      weights=&v_weights; shell_read_vector(weights, optarg);
 
13941
      break;
 
13942
    case 5:
 
13943
      shell_igraph_layout_drl_usage(argv);
 
13944
      break;
 
13945
    default:
 
13946
      break;
 
13947
    }
 
13948
 
 
13949
    shell_index=-1;
 
13950
  }
 
13951
 
 
13952
  /* Check that we have all arguments */
 
13953
  for (shell_index=0; shell_index<5; shell_index++) {
 
13954
    if (!shell_seen[shell_index]) {
 
13955
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
13956
              shell_options[shell_index].name);
 
13957
      exit(1);
 
13958
    }
 
13959
  }
 
13960
 
 
13961
  /* Do the operation */
 
13962
  shell_result=igraph_layout_drl(&graph, &res, use_seed, options, weights, fixed);
 
13963
 
 
13964
  /* Write the result */
 
13965
  igraph_destroy(&graph);
 
13966
  igraph_matrix_destroy(&res);
 
13967
  shell_write_matrix(&res, shell_arg_res); 
 
13968
  igraph_matrix_destroy(&res);
 
13969
  if (weights) { igraph_vector_destroy(weights); }
 
13970
 
 
13971
  return 0;
 
13972
}
 
13973
 
 
13974
/*-------------------------------------------/
 
13975
/ igraph_layout_drl_3d                       /
 
13976
/-------------------------------------------*/
 
13977
void shell_igraph_layout_drl_3d_usage(char **argv) {
 
13978
  printf("%s --graph=<graph> --res=<res> --res-out=<res-out> --use_seed=<use_seed> --weights=<weights>\n", basename(argv[0]));
 
13979
  exit(1);
 
13980
}
 
13981
 
 
13982
int shell_igraph_layout_drl_3d(int argc, char **argv) {
 
13983
 
 
13984
  igraph_t graph;
 
13985
  igraph_matrix_t res;
 
13986
  igraph_bool_t use_seed=0;
 
13987
 
 
13988
  igraph_vector_t v_weights; igraph_vector_t *weights=0=NULL;
 
13989
 
 
13990
  char* shell_arg_res=0;
 
13991
  int shell_result;
 
13992
 
 
13993
 
 
13994
  int shell_seen[5];
 
13995
  int shell_index=-1;
 
13996
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
13997
                                   { "res",required_argument,0,1 },
 
13998
                                   { "res-out",required_argument,0,2 },
 
13999
                                   { "use_seed",required_argument,0,3 },
 
14000
                                   { "weights",required_argument,0,4 },
 
14001
                                   { "help",no_argument,0,5 },
 
14002
                                   { 0,0,0,0 }
 
14003
                                 };
 
14004
 
 
14005
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14006
  memset(shell_seen, 0, 5*sizeof(int));
 
14007
  shell_seen[3]=2;
 
14008
  shell_seen[4]=2;
 
14009
  
 
14010
  /* Parse arguments and read input */
 
14011
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14012
 
 
14013
    if (shell_index==-1) {
 
14014
      exit(1);
 
14015
    }
 
14016
 
 
14017
    if (shell_seen[shell_index]==1) {
 
14018
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14019
              shell_options[shell_index].name);
 
14020
      exit(1);
 
14021
    }
 
14022
    shell_seen[shell_index]=1;  
 
14023
 
 
14024
    switch (shell_index) {
 
14025
    case 0: /* graph */
 
14026
      shell_read_graph(&graph, optarg);
 
14027
      break;
 
14028
    case 1: /* res */
 
14029
      shell_read_matrix(&res, optarg);
 
14030
      break;
 
14031
    case 2: /* res-out */
 
14032
      shell_arg_res=strdup(optarg); 
 
14033
  igraph_matrix_init(&res, 0, 0);
 
14034
      break;
 
14035
    case 3: /* use_seed */
 
14036
      shell_read_boolean(&use_seed, optarg);
 
14037
      break;
 
14038
    case 4: /* weights */
 
14039
      weights=&v_weights; shell_read_vector(weights, optarg);
 
14040
      break;
 
14041
    case 5:
 
14042
      shell_igraph_layout_drl_3d_usage(argv);
 
14043
      break;
 
14044
    default:
 
14045
      break;
 
14046
    }
 
14047
 
 
14048
    shell_index=-1;
 
14049
  }
 
14050
 
 
14051
  /* Check that we have all arguments */
 
14052
  for (shell_index=0; shell_index<5; shell_index++) {
 
14053
    if (!shell_seen[shell_index]) {
 
14054
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14055
              shell_options[shell_index].name);
 
14056
      exit(1);
 
14057
    }
 
14058
  }
 
14059
 
 
14060
  /* Do the operation */
 
14061
  shell_result=igraph_layout_drl_3d(&graph, &res, use_seed, options, weights, fixed);
 
14062
 
 
14063
  /* Write the result */
 
14064
  igraph_destroy(&graph);
 
14065
  igraph_matrix_destroy(&res);
 
14066
  shell_write_matrix(&res, shell_arg_res); 
 
14067
  igraph_matrix_destroy(&res);
 
14068
  if (weights) { igraph_vector_destroy(weights); }
 
14069
 
 
14070
  return 0;
 
14071
}
 
14072
 
 
14073
/*-------------------------------------------/
 
14074
/ igraph_layout_merge_dla                    /
 
14075
/-------------------------------------------*/
 
14076
void shell_igraph_layout_merge_dla_usage(char **argv) {
 
14077
  printf("%s --graphs=<graphs> --coords=<coords> --res=<res>\n", basename(argv[0]));
 
14078
  exit(1);
 
14079
}
 
14080
 
 
14081
int shell_igraph_layout_merge_dla(int argc, char **argv) {
 
14082
 
 
14083
  igraph_vector_ptr_t graphs;
 
14084
  igraph_vector_ptr_t coords;
 
14085
  igraph_matrix_t res;
 
14086
  char* shell_arg_res=0;
 
14087
  int shell_result;
 
14088
 
 
14089
 
 
14090
  int shell_seen[3];
 
14091
  int shell_index=-1;
 
14092
  struct option shell_options[]= { { "graphs",required_argument,0,0 },
 
14093
                                   { "coords",required_argument,0,1 },
 
14094
                                   { "res",required_argument,0,2 },
 
14095
                                   { "help",no_argument,0,3 },
 
14096
                                   { 0,0,0,0 }
 
14097
                                 };
 
14098
 
 
14099
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14100
  memset(shell_seen, 0, 3*sizeof(int));
 
14101
 
 
14102
  
 
14103
  /* Parse arguments and read input */
 
14104
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14105
 
 
14106
    if (shell_index==-1) {
 
14107
      exit(1);
 
14108
    }
 
14109
 
 
14110
    if (shell_seen[shell_index]==1) {
 
14111
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14112
              shell_options[shell_index].name);
 
14113
      exit(1);
 
14114
    }
 
14115
    shell_seen[shell_index]=1;  
 
14116
 
 
14117
    switch (shell_index) {
 
14118
    case 0: /* graphs */
 
14119
      shell_read_graphlist(&graphs, optarg);
 
14120
      break;
 
14121
    case 1: /* coords */
 
14122
      shell_read_matrixlist(&coords, optarg);
 
14123
      break;
 
14124
    case 2: /* res */
 
14125
      shell_arg_res=strdup(optarg); 
 
14126
  igraph_matrix_init(&res, 0, 0);
 
14127
      break;
 
14128
    case 3:
 
14129
      shell_igraph_layout_merge_dla_usage(argv);
 
14130
      break;
 
14131
    default:
 
14132
      break;
 
14133
    }
 
14134
 
 
14135
    shell_index=-1;
 
14136
  }
 
14137
 
 
14138
  /* Check that we have all arguments */
 
14139
  for (shell_index=0; shell_index<3; shell_index++) {
 
14140
    if (!shell_seen[shell_index]) {
 
14141
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14142
              shell_options[shell_index].name);
 
14143
      exit(1);
 
14144
    }
 
14145
  }
 
14146
 
 
14147
  /* Do the operation */
 
14148
  shell_result=igraph_layout_merge_dla(&graphs, &coords, &res);
 
14149
 
 
14150
  /* Write the result */
 
14151
  shell_free_graphlist(&graphs); 
 
14152
  igraph_vector_ptr_destroy(&graphs);
 
14153
  shell_free_matrixlist(&coords); 
 
14154
  igraph_vector_ptr_destroy(&coords);
 
14155
  shell_write_matrix(&res, shell_arg_res); 
 
14156
  igraph_matrix_destroy(&res);
 
14157
 
 
14158
  return 0;
 
14159
}
 
14160
 
 
14161
/*-------------------------------------------/
 
14162
/ igraph_cocitation                          /
 
14163
/-------------------------------------------*/
 
14164
void shell_igraph_cocitation_usage(char **argv) {
 
14165
  printf("%s --graph=<graph> --res=<res> --vids=<vids>\n", basename(argv[0]));
 
14166
  exit(1);
 
14167
}
 
14168
 
 
14169
int shell_igraph_cocitation(int argc, char **argv) {
 
14170
 
 
14171
  igraph_t graph;
 
14172
  igraph_matrix_t res;
 
14173
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
14174
  char* shell_arg_res=0;
 
14175
  int shell_result;
 
14176
 
 
14177
 
 
14178
  int shell_seen[3];
 
14179
  int shell_index=-1;
 
14180
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14181
                                   { "res",required_argument,0,1 },
 
14182
                                   { "vids",required_argument,0,2 },
 
14183
                                   { "help",no_argument,0,3 },
 
14184
                                   { 0,0,0,0 }
 
14185
                                 };
 
14186
 
 
14187
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14188
  memset(shell_seen, 0, 3*sizeof(int));
 
14189
  shell_seen[2]=2;
 
14190
  
 
14191
  /* Parse arguments and read input */
 
14192
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14193
 
 
14194
    if (shell_index==-1) {
 
14195
      exit(1);
 
14196
    }
 
14197
 
 
14198
    if (shell_seen[shell_index]==1) {
 
14199
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14200
              shell_options[shell_index].name);
 
14201
      exit(1);
 
14202
    }
 
14203
    shell_seen[shell_index]=1;  
 
14204
 
 
14205
    switch (shell_index) {
 
14206
    case 0: /* graph */
 
14207
      shell_read_graph(&graph, optarg);
 
14208
      break;
 
14209
    case 1: /* res */
 
14210
      shell_arg_res=strdup(optarg); 
 
14211
  igraph_matrix_init(&res, 0, 0);
 
14212
      break;
 
14213
    case 2: /* vids */
 
14214
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
14215
      break;
 
14216
    case 3:
 
14217
      shell_igraph_cocitation_usage(argv);
 
14218
      break;
 
14219
    default:
 
14220
      break;
 
14221
    }
 
14222
 
 
14223
    shell_index=-1;
 
14224
  }
 
14225
 
 
14226
  /* Check that we have all arguments */
 
14227
  for (shell_index=0; shell_index<3; shell_index++) {
 
14228
    if (!shell_seen[shell_index]) {
 
14229
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14230
              shell_options[shell_index].name);
 
14231
      exit(1);
 
14232
    }
 
14233
  }
 
14234
 
 
14235
  /* Do the operation */
 
14236
  shell_result=igraph_cocitation(&graph, &res, vids);
 
14237
 
 
14238
  /* Write the result */
 
14239
  igraph_destroy(&graph);
 
14240
  shell_write_matrix(&res, shell_arg_res); 
 
14241
  igraph_matrix_destroy(&res);
 
14242
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
14243
 
 
14244
  return 0;
 
14245
}
 
14246
 
 
14247
/*-------------------------------------------/
 
14248
/ igraph_bibcoupling                         /
 
14249
/-------------------------------------------*/
 
14250
void shell_igraph_bibcoupling_usage(char **argv) {
 
14251
  printf("%s --graph=<graph> --res=<res> --vids=<vids>\n", basename(argv[0]));
 
14252
  exit(1);
 
14253
}
 
14254
 
 
14255
int shell_igraph_bibcoupling(int argc, char **argv) {
 
14256
 
 
14257
  igraph_t graph;
 
14258
  igraph_matrix_t res;
 
14259
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
14260
  char* shell_arg_res=0;
 
14261
  int shell_result;
 
14262
 
 
14263
 
 
14264
  int shell_seen[3];
 
14265
  int shell_index=-1;
 
14266
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14267
                                   { "res",required_argument,0,1 },
 
14268
                                   { "vids",required_argument,0,2 },
 
14269
                                   { "help",no_argument,0,3 },
 
14270
                                   { 0,0,0,0 }
 
14271
                                 };
 
14272
 
 
14273
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14274
  memset(shell_seen, 0, 3*sizeof(int));
 
14275
  shell_seen[2]=2;
 
14276
  
 
14277
  /* Parse arguments and read input */
 
14278
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14279
 
 
14280
    if (shell_index==-1) {
 
14281
      exit(1);
 
14282
    }
 
14283
 
 
14284
    if (shell_seen[shell_index]==1) {
 
14285
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14286
              shell_options[shell_index].name);
 
14287
      exit(1);
 
14288
    }
 
14289
    shell_seen[shell_index]=1;  
 
14290
 
 
14291
    switch (shell_index) {
 
14292
    case 0: /* graph */
 
14293
      shell_read_graph(&graph, optarg);
 
14294
      break;
 
14295
    case 1: /* res */
 
14296
      shell_arg_res=strdup(optarg); 
 
14297
  igraph_matrix_init(&res, 0, 0);
 
14298
      break;
 
14299
    case 2: /* vids */
 
14300
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
14301
      break;
 
14302
    case 3:
 
14303
      shell_igraph_bibcoupling_usage(argv);
 
14304
      break;
 
14305
    default:
 
14306
      break;
 
14307
    }
 
14308
 
 
14309
    shell_index=-1;
 
14310
  }
 
14311
 
 
14312
  /* Check that we have all arguments */
 
14313
  for (shell_index=0; shell_index<3; shell_index++) {
 
14314
    if (!shell_seen[shell_index]) {
 
14315
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14316
              shell_options[shell_index].name);
 
14317
      exit(1);
 
14318
    }
 
14319
  }
 
14320
 
 
14321
  /* Do the operation */
 
14322
  shell_result=igraph_bibcoupling(&graph, &res, vids);
 
14323
 
 
14324
  /* Write the result */
 
14325
  igraph_destroy(&graph);
 
14326
  shell_write_matrix(&res, shell_arg_res); 
 
14327
  igraph_matrix_destroy(&res);
 
14328
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
14329
 
 
14330
  return 0;
 
14331
}
 
14332
 
 
14333
/*-------------------------------------------/
 
14334
/ igraph_similarity_jaccard                  /
 
14335
/-------------------------------------------*/
 
14336
void shell_igraph_similarity_jaccard_usage(char **argv) {
 
14337
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode> --loops=<loops>\n", basename(argv[0]));
 
14338
  exit(1);
 
14339
}
 
14340
 
 
14341
int shell_igraph_similarity_jaccard(int argc, char **argv) {
 
14342
 
 
14343
  igraph_t graph;
 
14344
  igraph_matrix_t res;
 
14345
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
14346
  igraph_neimode_t mode=IGRAPH_ALL;
 
14347
  igraph_bool_t loops=0;
 
14348
  char* shell_arg_res=0;
 
14349
  int shell_result;
 
14350
 
 
14351
 
 
14352
  int shell_seen[5];
 
14353
  int shell_index=-1;
 
14354
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14355
                                   { "res",required_argument,0,1 },
 
14356
                                   { "vids",required_argument,0,2 },
 
14357
                                   { "mode",required_argument,0,3 },
 
14358
                                   { "loops",required_argument,0,4 },
 
14359
                                   { "help",no_argument,0,5 },
 
14360
                                   { 0,0,0,0 }
 
14361
                                 };
 
14362
 
 
14363
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14364
  memset(shell_seen, 0, 5*sizeof(int));
 
14365
  shell_seen[2]=2;
 
14366
  shell_seen[3]=2;
 
14367
  shell_seen[4]=2;
 
14368
  
 
14369
  /* Parse arguments and read input */
 
14370
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14371
 
 
14372
    if (shell_index==-1) {
 
14373
      exit(1);
 
14374
    }
 
14375
 
 
14376
    if (shell_seen[shell_index]==1) {
 
14377
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14378
              shell_options[shell_index].name);
 
14379
      exit(1);
 
14380
    }
 
14381
    shell_seen[shell_index]=1;  
 
14382
 
 
14383
    switch (shell_index) {
 
14384
    case 0: /* graph */
 
14385
      shell_read_graph(&graph, optarg);
 
14386
      break;
 
14387
    case 1: /* res */
 
14388
      shell_arg_res=strdup(optarg); 
 
14389
  igraph_matrix_init(&res, 0, 0);
 
14390
      break;
 
14391
    case 2: /* vids */
 
14392
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
14393
      break;
 
14394
    case 3: /* mode */
 
14395
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
14396
      break;
 
14397
    case 4: /* loops */
 
14398
      shell_read_boolean(&loops, optarg);
 
14399
      break;
 
14400
    case 5:
 
14401
      shell_igraph_similarity_jaccard_usage(argv);
 
14402
      break;
 
14403
    default:
 
14404
      break;
 
14405
    }
 
14406
 
 
14407
    shell_index=-1;
 
14408
  }
 
14409
 
 
14410
  /* Check that we have all arguments */
 
14411
  for (shell_index=0; shell_index<5; shell_index++) {
 
14412
    if (!shell_seen[shell_index]) {
 
14413
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14414
              shell_options[shell_index].name);
 
14415
      exit(1);
 
14416
    }
 
14417
  }
 
14418
 
 
14419
  /* Do the operation */
 
14420
  shell_result=igraph_similarity_jaccard(&graph, &res, vids, mode, loops);
 
14421
 
 
14422
  /* Write the result */
 
14423
  igraph_destroy(&graph);
 
14424
  shell_write_matrix(&res, shell_arg_res); 
 
14425
  igraph_matrix_destroy(&res);
 
14426
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
14427
 
 
14428
  return 0;
 
14429
}
 
14430
 
 
14431
/*-------------------------------------------/
 
14432
/ igraph_similarity_dice                     /
 
14433
/-------------------------------------------*/
 
14434
void shell_igraph_similarity_dice_usage(char **argv) {
 
14435
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode> --loops=<loops>\n", basename(argv[0]));
 
14436
  exit(1);
 
14437
}
 
14438
 
 
14439
int shell_igraph_similarity_dice(int argc, char **argv) {
 
14440
 
 
14441
  igraph_t graph;
 
14442
  igraph_matrix_t res;
 
14443
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
14444
  igraph_neimode_t mode=IGRAPH_ALL;
 
14445
  igraph_bool_t loops=0;
 
14446
  char* shell_arg_res=0;
 
14447
  int shell_result;
 
14448
 
 
14449
 
 
14450
  int shell_seen[5];
 
14451
  int shell_index=-1;
 
14452
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14453
                                   { "res",required_argument,0,1 },
 
14454
                                   { "vids",required_argument,0,2 },
 
14455
                                   { "mode",required_argument,0,3 },
 
14456
                                   { "loops",required_argument,0,4 },
 
14457
                                   { "help",no_argument,0,5 },
 
14458
                                   { 0,0,0,0 }
 
14459
                                 };
 
14460
 
 
14461
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14462
  memset(shell_seen, 0, 5*sizeof(int));
 
14463
  shell_seen[2]=2;
 
14464
  shell_seen[3]=2;
 
14465
  shell_seen[4]=2;
 
14466
  
 
14467
  /* Parse arguments and read input */
 
14468
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14469
 
 
14470
    if (shell_index==-1) {
 
14471
      exit(1);
 
14472
    }
 
14473
 
 
14474
    if (shell_seen[shell_index]==1) {
 
14475
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14476
              shell_options[shell_index].name);
 
14477
      exit(1);
 
14478
    }
 
14479
    shell_seen[shell_index]=1;  
 
14480
 
 
14481
    switch (shell_index) {
 
14482
    case 0: /* graph */
 
14483
      shell_read_graph(&graph, optarg);
 
14484
      break;
 
14485
    case 1: /* res */
 
14486
      shell_arg_res=strdup(optarg); 
 
14487
  igraph_matrix_init(&res, 0, 0);
 
14488
      break;
 
14489
    case 2: /* vids */
 
14490
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
14491
      break;
 
14492
    case 3: /* mode */
 
14493
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
14494
      break;
 
14495
    case 4: /* loops */
 
14496
      shell_read_boolean(&loops, optarg);
 
14497
      break;
 
14498
    case 5:
 
14499
      shell_igraph_similarity_dice_usage(argv);
 
14500
      break;
 
14501
    default:
 
14502
      break;
 
14503
    }
 
14504
 
 
14505
    shell_index=-1;
 
14506
  }
 
14507
 
 
14508
  /* Check that we have all arguments */
 
14509
  for (shell_index=0; shell_index<5; shell_index++) {
 
14510
    if (!shell_seen[shell_index]) {
 
14511
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14512
              shell_options[shell_index].name);
 
14513
      exit(1);
 
14514
    }
 
14515
  }
 
14516
 
 
14517
  /* Do the operation */
 
14518
  shell_result=igraph_similarity_dice(&graph, &res, vids, mode, loops);
 
14519
 
 
14520
  /* Write the result */
 
14521
  igraph_destroy(&graph);
 
14522
  shell_write_matrix(&res, shell_arg_res); 
 
14523
  igraph_matrix_destroy(&res);
 
14524
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
14525
 
 
14526
  return 0;
 
14527
}
 
14528
 
 
14529
/*-------------------------------------------/
 
14530
/ igraph_similarity_inverse_log_weighted     /
 
14531
/-------------------------------------------*/
 
14532
void shell_igraph_similarity_inverse_log_weighted_usage(char **argv) {
 
14533
  printf("%s --graph=<graph> --res=<res> --vids=<vids> --mode=<mode>\n", basename(argv[0]));
 
14534
  exit(1);
 
14535
}
 
14536
 
 
14537
int shell_igraph_similarity_inverse_log_weighted(int argc, char **argv) {
 
14538
 
 
14539
  igraph_t graph;
 
14540
  igraph_matrix_t res;
 
14541
  igraph_vector_t v_vids; igraph_vs_t vids=igraph_vss_all();
 
14542
  igraph_neimode_t mode=IGRAPH_ALL;
 
14543
  char* shell_arg_res=0;
 
14544
  int shell_result;
 
14545
 
 
14546
 
 
14547
  int shell_seen[4];
 
14548
  int shell_index=-1;
 
14549
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14550
                                   { "res",required_argument,0,1 },
 
14551
                                   { "vids",required_argument,0,2 },
 
14552
                                   { "mode",required_argument,0,3 },
 
14553
                                   { "help",no_argument,0,4 },
 
14554
                                   { 0,0,0,0 }
 
14555
                                 };
 
14556
 
 
14557
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14558
  memset(shell_seen, 0, 4*sizeof(int));
 
14559
  shell_seen[2]=2;
 
14560
  shell_seen[3]=2;
 
14561
  
 
14562
  /* Parse arguments and read input */
 
14563
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14564
 
 
14565
    if (shell_index==-1) {
 
14566
      exit(1);
 
14567
    }
 
14568
 
 
14569
    if (shell_seen[shell_index]==1) {
 
14570
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14571
              shell_options[shell_index].name);
 
14572
      exit(1);
 
14573
    }
 
14574
    shell_seen[shell_index]=1;  
 
14575
 
 
14576
    switch (shell_index) {
 
14577
    case 0: /* graph */
 
14578
      shell_read_graph(&graph, optarg);
 
14579
      break;
 
14580
    case 1: /* res */
 
14581
      shell_arg_res=strdup(optarg); 
 
14582
  igraph_matrix_init(&res, 0, 0);
 
14583
      break;
 
14584
    case 2: /* vids */
 
14585
      shell_read_vector(&v_vids, optarg); igraph_vs_vector(&vids, &v_vids);
 
14586
      break;
 
14587
    case 3: /* mode */
 
14588
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
14589
      break;
 
14590
    case 4:
 
14591
      shell_igraph_similarity_inverse_log_weighted_usage(argv);
 
14592
      break;
 
14593
    default:
 
14594
      break;
 
14595
    }
 
14596
 
 
14597
    shell_index=-1;
 
14598
  }
 
14599
 
 
14600
  /* Check that we have all arguments */
 
14601
  for (shell_index=0; shell_index<4; shell_index++) {
 
14602
    if (!shell_seen[shell_index]) {
 
14603
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14604
              shell_options[shell_index].name);
 
14605
      exit(1);
 
14606
    }
 
14607
  }
 
14608
 
 
14609
  /* Do the operation */
 
14610
  shell_result=igraph_similarity_inverse_log_weighted(&graph, &res, vids, mode);
 
14611
 
 
14612
  /* Write the result */
 
14613
  igraph_destroy(&graph);
 
14614
  shell_write_matrix(&res, shell_arg_res); 
 
14615
  igraph_matrix_destroy(&res);
 
14616
  if (!igraph_vs_is_all(&vids)) { igraph_vector_destroy(&v_vids); }
 
14617
 
 
14618
  return 0;
 
14619
}
 
14620
 
 
14621
/*-------------------------------------------/
 
14622
/ igraph_community_spinglass                 /
 
14623
/-------------------------------------------*/
 
14624
void shell_igraph_community_spinglass_usage(char **argv) {
 
14625
  printf("%s --graph=<graph> --weights=<weights> --modularity=<modularity> --temperature=<temperature> --membership=<membership> --csize=<csize> --spins=<spins> --parupdate=<parupdate> --starttemp=<starttemp> --stoptemp=<stoptemp> --coolfact=<coolfact> --update_rule=<update_rule> --gamma=<gamma>\n", basename(argv[0]));
 
14626
  exit(1);
 
14627
}
 
14628
 
 
14629
int shell_igraph_community_spinglass(int argc, char **argv) {
 
14630
 
 
14631
  igraph_t graph;
 
14632
  igraph_vector_t v_weights; igraph_vector_t *weights=0;
 
14633
  igraph_real_t modularity;
 
14634
  igraph_real_t temperature;
 
14635
  igraph_vector_t membership;
 
14636
  igraph_vector_t csize;
 
14637
  igraph_integer_t spins=25;
 
14638
  igraph_bool_t parupdate=0;
 
14639
  igraph_real_t starttemp=1;
 
14640
  igraph_real_t stoptemp=0.01;
 
14641
  igraph_real_t coolfact=0.99;
 
14642
  igraph_spincomm_update_t update_rule=IGRAPH_SPINCOMM_UPDATE_CONFIG;
 
14643
  igraph_real_t gamma=1.0;
 
14644
  char* shell_arg_modularity=0;
 
14645
  char* shell_arg_temperature=0;
 
14646
  char* shell_arg_membership=0;
 
14647
  char* shell_arg_csize=0;
 
14648
  int shell_result;
 
14649
 
 
14650
 
 
14651
  int shell_seen[13];
 
14652
  int shell_index=-1;
 
14653
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14654
                                   { "weights",required_argument,0,1 },
 
14655
                                   { "modularity",required_argument,0,2 },
 
14656
                                   { "temperature",required_argument,0,3 },
 
14657
                                   { "membership",required_argument,0,4 },
 
14658
                                   { "csize",required_argument,0,5 },
 
14659
                                   { "spins",required_argument,0,6 },
 
14660
                                   { "parupdate",required_argument,0,7 },
 
14661
                                   { "starttemp",required_argument,0,8 },
 
14662
                                   { "stoptemp",required_argument,0,9 },
 
14663
                                   { "coolfact",required_argument,0,10 },
 
14664
                                   { "update_rule",required_argument,0,11 },
 
14665
                                   { "gamma",required_argument,0,12 },
 
14666
                                   { "help",no_argument,0,13 },
 
14667
                                   { 0,0,0,0 }
 
14668
                                 };
 
14669
 
 
14670
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14671
  memset(shell_seen, 0, 13*sizeof(int));
 
14672
  shell_seen[6]=2;
 
14673
  shell_seen[7]=2;
 
14674
  shell_seen[8]=2;
 
14675
  shell_seen[9]=2;
 
14676
  shell_seen[10]=2;
 
14677
  shell_seen[11]=2;
 
14678
  shell_seen[12]=2;
 
14679
  
 
14680
  /* Parse arguments and read input */
 
14681
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14682
 
 
14683
    if (shell_index==-1) {
 
14684
      exit(1);
 
14685
    }
 
14686
 
 
14687
    if (shell_seen[shell_index]==1) {
 
14688
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14689
              shell_options[shell_index].name);
 
14690
      exit(1);
 
14691
    }
 
14692
    shell_seen[shell_index]=1;  
 
14693
 
 
14694
    switch (shell_index) {
 
14695
    case 0: /* graph */
 
14696
      shell_read_graph(&graph, optarg);
 
14697
      break;
 
14698
    case 1: /* weights */
 
14699
      weights=&v_weights; shell_read_vector(weights, optarg);
 
14700
      break;
 
14701
    case 2: /* modularity */
 
14702
      shell_arg_modularity=strdup(optarg);
 
14703
      break;
 
14704
    case 3: /* temperature */
 
14705
      shell_arg_temperature=strdup(optarg);
 
14706
      break;
 
14707
    case 4: /* membership */
 
14708
      shell_arg_membership=strdup(optarg); 
 
14709
  igraph_vector_init(&membership, 0);
 
14710
      break;
 
14711
    case 5: /* csize */
 
14712
      shell_arg_csize=strdup(optarg); 
 
14713
  igraph_vector_init(&csize, 0);
 
14714
      break;
 
14715
    case 6: /* spins */
 
14716
      shell_read_integer(&spins, optarg);
 
14717
      break;
 
14718
    case 7: /* parupdate */
 
14719
      shell_read_boolean(&parupdate, optarg);
 
14720
      break;
 
14721
    case 8: /* starttemp */
 
14722
      shell_read_real(&starttemp, optarg);
 
14723
      break;
 
14724
    case 9: /* stoptemp */
 
14725
      shell_read_real(&stoptemp, optarg);
 
14726
      break;
 
14727
    case 10: /* coolfact */
 
14728
      shell_read_real(&coolfact, optarg);
 
14729
      break;
 
14730
    case 11: /* update_rule */
 
14731
      shell_read_enum(&update_rule, optarg, "simple", 0, "config", 1, 0);
 
14732
      break;
 
14733
    case 12: /* gamma */
 
14734
      shell_read_real(&gamma, optarg);
 
14735
      break;
 
14736
    case 13:
 
14737
      shell_igraph_community_spinglass_usage(argv);
 
14738
      break;
 
14739
    default:
 
14740
      break;
 
14741
    }
 
14742
 
 
14743
    shell_index=-1;
 
14744
  }
 
14745
 
 
14746
  /* Check that we have all arguments */
 
14747
  for (shell_index=0; shell_index<13; shell_index++) {
 
14748
    if (!shell_seen[shell_index]) {
 
14749
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14750
              shell_options[shell_index].name);
 
14751
      exit(1);
 
14752
    }
 
14753
  }
 
14754
 
 
14755
  /* Do the operation */
 
14756
  shell_result=igraph_community_spinglass(&graph, weights, &modularity, &temperature, &membership, &csize, spins, parupdate, starttemp, stoptemp, coolfact, update_rule, gamma);
 
14757
 
 
14758
  /* Write the result */
 
14759
  igraph_destroy(&graph);
 
14760
  if (weights) { igraph_vector_destroy(weights); }
 
14761
  shell_write_real(modularity, shell_arg_modularity);
 
14762
  shell_write_real(temperature, shell_arg_temperature);
 
14763
  shell_write_vector(&membership, shell_arg_membership); 
 
14764
  igraph_vector_destroy(&membership);
 
14765
  shell_write_vector(&csize, shell_arg_csize); 
 
14766
  igraph_vector_destroy(&csize);
 
14767
 
 
14768
  return 0;
 
14769
}
 
14770
 
 
14771
/*-------------------------------------------/
 
14772
/ igraph_community_spinglass_single          /
 
14773
/-------------------------------------------*/
 
14774
void shell_igraph_community_spinglass_single_usage(char **argv) {
 
14775
  printf("%s --graph=<graph> --weights=<weights> --vertex=<vertex> --community=<community> --cohesion=<cohesion> --adhesion=<adhesion> --inner_links=<inner_links> --outer_links=<outer_links> --spins=<spins> --update_rule=<update_rule> --gamma=<gamma>\n", basename(argv[0]));
 
14776
  exit(1);
 
14777
}
 
14778
 
 
14779
int shell_igraph_community_spinglass_single(int argc, char **argv) {
 
14780
 
 
14781
  igraph_t graph;
 
14782
  igraph_vector_t v_weights; igraph_vector_t *weights=0;
 
14783
  igraph_integer_t vertex;
 
14784
  igraph_vector_t community;
 
14785
  igraph_real_t cohesion;
 
14786
  igraph_real_t adhesion;
 
14787
  igraph_integer_t inner_links;
 
14788
  igraph_integer_t outer_links;
 
14789
  igraph_integer_t spins=25;
 
14790
  igraph_spincomm_update_t update_rule=IGRAPH_SPINCOMM_UPDATE_CONFIG;
 
14791
  igraph_real_t gamma=1.0;
 
14792
  char* shell_arg_community=0;
 
14793
  char* shell_arg_cohesion=0;
 
14794
  char* shell_arg_adhesion=0;
 
14795
  char* shell_arg_inner_links=0;
 
14796
  char* shell_arg_outer_links=0;
 
14797
  int shell_result;
 
14798
 
 
14799
 
 
14800
  int shell_seen[11];
 
14801
  int shell_index=-1;
 
14802
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14803
                                   { "weights",required_argument,0,1 },
 
14804
                                   { "vertex",required_argument,0,2 },
 
14805
                                   { "community",required_argument,0,3 },
 
14806
                                   { "cohesion",required_argument,0,4 },
 
14807
                                   { "adhesion",required_argument,0,5 },
 
14808
                                   { "inner_links",required_argument,0,6 },
 
14809
                                   { "outer_links",required_argument,0,7 },
 
14810
                                   { "spins",required_argument,0,8 },
 
14811
                                   { "update_rule",required_argument,0,9 },
 
14812
                                   { "gamma",required_argument,0,10 },
 
14813
                                   { "help",no_argument,0,11 },
 
14814
                                   { 0,0,0,0 }
 
14815
                                 };
 
14816
 
 
14817
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14818
  memset(shell_seen, 0, 11*sizeof(int));
 
14819
  shell_seen[8]=2;
 
14820
  shell_seen[9]=2;
 
14821
  shell_seen[10]=2;
 
14822
  
 
14823
  /* Parse arguments and read input */
 
14824
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14825
 
 
14826
    if (shell_index==-1) {
 
14827
      exit(1);
 
14828
    }
 
14829
 
 
14830
    if (shell_seen[shell_index]==1) {
 
14831
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14832
              shell_options[shell_index].name);
 
14833
      exit(1);
 
14834
    }
 
14835
    shell_seen[shell_index]=1;  
 
14836
 
 
14837
    switch (shell_index) {
 
14838
    case 0: /* graph */
 
14839
      shell_read_graph(&graph, optarg);
 
14840
      break;
 
14841
    case 1: /* weights */
 
14842
      weights=&v_weights; shell_read_vector(weights, optarg);
 
14843
      break;
 
14844
    case 2: /* vertex */
 
14845
      shell_read_integer(&vertex, optarg);
 
14846
      break;
 
14847
    case 3: /* community */
 
14848
      shell_arg_community=strdup(optarg); 
 
14849
  igraph_vector_init(&community, 0);
 
14850
      break;
 
14851
    case 4: /* cohesion */
 
14852
      shell_arg_cohesion=strdup(optarg);
 
14853
      break;
 
14854
    case 5: /* adhesion */
 
14855
      shell_arg_adhesion=strdup(optarg);
 
14856
      break;
 
14857
    case 6: /* inner_links */
 
14858
      shell_arg_inner_links=strdup(optarg);
 
14859
      break;
 
14860
    case 7: /* outer_links */
 
14861
      shell_arg_outer_links=strdup(optarg);
 
14862
      break;
 
14863
    case 8: /* spins */
 
14864
      shell_read_integer(&spins, optarg);
 
14865
      break;
 
14866
    case 9: /* update_rule */
 
14867
      shell_read_enum(&update_rule, optarg, "simple", 0, "config", 1, 0);
 
14868
      break;
 
14869
    case 10: /* gamma */
 
14870
      shell_read_real(&gamma, optarg);
 
14871
      break;
 
14872
    case 11:
 
14873
      shell_igraph_community_spinglass_single_usage(argv);
 
14874
      break;
 
14875
    default:
 
14876
      break;
 
14877
    }
 
14878
 
 
14879
    shell_index=-1;
 
14880
  }
 
14881
 
 
14882
  /* Check that we have all arguments */
 
14883
  for (shell_index=0; shell_index<11; shell_index++) {
 
14884
    if (!shell_seen[shell_index]) {
 
14885
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14886
              shell_options[shell_index].name);
 
14887
      exit(1);
 
14888
    }
 
14889
  }
 
14890
 
 
14891
  /* Do the operation */
 
14892
  shell_result=igraph_community_spinglass_single(&graph, weights, vertex, &community, &cohesion, &adhesion, &inner_links, &outer_links, spins, update_rule, gamma);
 
14893
 
 
14894
  /* Write the result */
 
14895
  igraph_destroy(&graph);
 
14896
  if (weights) { igraph_vector_destroy(weights); }
 
14897
  shell_write_vector(&community, shell_arg_community); 
 
14898
  igraph_vector_destroy(&community);
 
14899
  shell_write_real(cohesion, shell_arg_cohesion);
 
14900
  shell_write_real(adhesion, shell_arg_adhesion);
 
14901
  shell_write_integer(inner_links, shell_arg_inner_links);
 
14902
  shell_write_integer(outer_links, shell_arg_outer_links);
 
14903
 
 
14904
  return 0;
 
14905
}
 
14906
 
 
14907
/*-------------------------------------------/
 
14908
/ igraph_community_walktrap                  /
 
14909
/-------------------------------------------*/
 
14910
void shell_igraph_community_walktrap_usage(char **argv) {
 
14911
  printf("%s --graph=<graph> --weights=<weights> --steps=<steps> --merges=<merges> --modularity=<modularity>\n", basename(argv[0]));
 
14912
  exit(1);
 
14913
}
 
14914
 
 
14915
int shell_igraph_community_walktrap(int argc, char **argv) {
 
14916
 
 
14917
  igraph_t graph;
 
14918
  igraph_vector_t weights;
 
14919
  int steps=4;
 
14920
  igraph_matrix_t merges;
 
14921
  igraph_vector_t modularity;
 
14922
  char* shell_arg_merges=0;
 
14923
  char* shell_arg_modularity=0;
 
14924
  int shell_result;
 
14925
 
 
14926
 
 
14927
  int shell_seen[5];
 
14928
  int shell_index=-1;
 
14929
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
14930
                                   { "weights",required_argument,0,1 },
 
14931
                                   { "steps",required_argument,0,2 },
 
14932
                                   { "merges",required_argument,0,3 },
 
14933
                                   { "modularity",required_argument,0,4 },
 
14934
                                   { "help",no_argument,0,5 },
 
14935
                                   { 0,0,0,0 }
 
14936
                                 };
 
14937
 
 
14938
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
14939
  memset(shell_seen, 0, 5*sizeof(int));
 
14940
  shell_seen[2]=2;
 
14941
  
 
14942
  /* Parse arguments and read input */
 
14943
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
14944
 
 
14945
    if (shell_index==-1) {
 
14946
      exit(1);
 
14947
    }
 
14948
 
 
14949
    if (shell_seen[shell_index]==1) {
 
14950
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
14951
              shell_options[shell_index].name);
 
14952
      exit(1);
 
14953
    }
 
14954
    shell_seen[shell_index]=1;  
 
14955
 
 
14956
    switch (shell_index) {
 
14957
    case 0: /* graph */
 
14958
      shell_read_graph(&graph, optarg);
 
14959
      break;
 
14960
    case 1: /* weights */
 
14961
      shell_read_vector(&weights, optarg);
 
14962
      break;
 
14963
    case 2: /* steps */
 
14964
      shell_read_int(&steps, optarg);
 
14965
      break;
 
14966
    case 3: /* merges */
 
14967
      shell_arg_merges=strdup(optarg); 
 
14968
  igraph_matrix_init(&merges, 0, 0);
 
14969
      break;
 
14970
    case 4: /* modularity */
 
14971
      shell_arg_modularity=strdup(optarg); 
 
14972
  igraph_vector_init(&modularity, 0);
 
14973
      break;
 
14974
    case 5:
 
14975
      shell_igraph_community_walktrap_usage(argv);
 
14976
      break;
 
14977
    default:
 
14978
      break;
 
14979
    }
 
14980
 
 
14981
    shell_index=-1;
 
14982
  }
 
14983
 
 
14984
  /* Check that we have all arguments */
 
14985
  for (shell_index=0; shell_index<5; shell_index++) {
 
14986
    if (!shell_seen[shell_index]) {
 
14987
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
14988
              shell_options[shell_index].name);
 
14989
      exit(1);
 
14990
    }
 
14991
  }
 
14992
 
 
14993
  /* Do the operation */
 
14994
  shell_result=igraph_community_walktrap(&graph, &weights, steps, &merges, &modularity);
 
14995
 
 
14996
  /* Write the result */
 
14997
  igraph_destroy(&graph);
 
14998
  igraph_vector_destroy(&weights);
 
14999
  shell_write_matrix(&merges, shell_arg_merges); 
 
15000
  igraph_matrix_destroy(&merges);
 
15001
  shell_write_vector(&modularity, shell_arg_modularity); 
 
15002
  igraph_vector_destroy(&modularity);
 
15003
 
 
15004
  return 0;
 
15005
}
 
15006
 
 
15007
/*-------------------------------------------/
 
15008
/ igraph_community_edge_betweenness          /
 
15009
/-------------------------------------------*/
 
15010
void shell_igraph_community_edge_betweenness_usage(char **argv) {
 
15011
  printf("%s --graph=<graph> --result=<result> --edge_betweenness=<edge_betweenness> --merges=<merges> --bridges=<bridges> --directed=<directed>\n", basename(argv[0]));
 
15012
  exit(1);
 
15013
}
 
15014
 
 
15015
int shell_igraph_community_edge_betweenness(int argc, char **argv) {
 
15016
 
 
15017
  igraph_t graph;
 
15018
  igraph_vector_t result;
 
15019
  igraph_vector_t edge_betweenness;
 
15020
  igraph_matrix_t merges;
 
15021
  igraph_vector_t bridges;
 
15022
  igraph_bool_t directed=1;
 
15023
  char* shell_arg_result=0;
 
15024
  char* shell_arg_edge_betweenness=0;
 
15025
  char* shell_arg_merges=0;
 
15026
  char* shell_arg_bridges=0;
 
15027
  int shell_result;
 
15028
 
 
15029
 
 
15030
  int shell_seen[6];
 
15031
  int shell_index=-1;
 
15032
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15033
                                   { "result",required_argument,0,1 },
 
15034
                                   { "edge_betweenness",required_argument,0,2 },
 
15035
                                   { "merges",required_argument,0,3 },
 
15036
                                   { "bridges",required_argument,0,4 },
 
15037
                                   { "directed",required_argument,0,5 },
 
15038
                                   { "help",no_argument,0,6 },
 
15039
                                   { 0,0,0,0 }
 
15040
                                 };
 
15041
 
 
15042
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15043
  memset(shell_seen, 0, 6*sizeof(int));
 
15044
  shell_seen[5]=2;
 
15045
  
 
15046
  /* Parse arguments and read input */
 
15047
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15048
 
 
15049
    if (shell_index==-1) {
 
15050
      exit(1);
 
15051
    }
 
15052
 
 
15053
    if (shell_seen[shell_index]==1) {
 
15054
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15055
              shell_options[shell_index].name);
 
15056
      exit(1);
 
15057
    }
 
15058
    shell_seen[shell_index]=1;  
 
15059
 
 
15060
    switch (shell_index) {
 
15061
    case 0: /* graph */
 
15062
      shell_read_graph(&graph, optarg);
 
15063
      break;
 
15064
    case 1: /* result */
 
15065
      shell_arg_result=strdup(optarg); 
 
15066
  igraph_vector_init(&result, 0);
 
15067
      break;
 
15068
    case 2: /* edge_betweenness */
 
15069
      shell_arg_edge_betweenness=strdup(optarg); 
 
15070
  igraph_vector_init(&edge_betweenness, 0);
 
15071
      break;
 
15072
    case 3: /* merges */
 
15073
      shell_arg_merges=strdup(optarg); 
 
15074
  igraph_matrix_init(&merges, 0, 0);
 
15075
      break;
 
15076
    case 4: /* bridges */
 
15077
      shell_arg_bridges=strdup(optarg); 
 
15078
  igraph_vector_init(&bridges, 0);
 
15079
      break;
 
15080
    case 5: /* directed */
 
15081
      shell_read_boolean(&directed, optarg);
 
15082
      break;
 
15083
    case 6:
 
15084
      shell_igraph_community_edge_betweenness_usage(argv);
 
15085
      break;
 
15086
    default:
 
15087
      break;
 
15088
    }
 
15089
 
 
15090
    shell_index=-1;
 
15091
  }
 
15092
 
 
15093
  /* Check that we have all arguments */
 
15094
  for (shell_index=0; shell_index<6; shell_index++) {
 
15095
    if (!shell_seen[shell_index]) {
 
15096
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15097
              shell_options[shell_index].name);
 
15098
      exit(1);
 
15099
    }
 
15100
  }
 
15101
 
 
15102
  /* Do the operation */
 
15103
  shell_result=igraph_community_edge_betweenness(&graph, &result, &edge_betweenness, &merges, &bridges, directed);
 
15104
 
 
15105
  /* Write the result */
 
15106
  igraph_destroy(&graph);
 
15107
  shell_write_vector(&result, shell_arg_result); 
 
15108
  igraph_vector_destroy(&result);
 
15109
  shell_write_vector(&edge_betweenness, shell_arg_edge_betweenness); 
 
15110
  igraph_vector_destroy(&edge_betweenness);
 
15111
  shell_write_matrix(&merges, shell_arg_merges); 
 
15112
  igraph_matrix_destroy(&merges);
 
15113
  shell_write_vector(&bridges, shell_arg_bridges); 
 
15114
  igraph_vector_destroy(&bridges);
 
15115
 
 
15116
  return 0;
 
15117
}
 
15118
 
 
15119
/*-------------------------------------------/
 
15120
/ igraph_community_eb_get_merges             /
 
15121
/-------------------------------------------*/
 
15122
void shell_igraph_community_eb_get_merges_usage(char **argv) {
 
15123
  printf("%s --graph=<graph> --edges=<edges> --merges=<merges> --bridges=<bridges>\n", basename(argv[0]));
 
15124
  exit(1);
 
15125
}
 
15126
 
 
15127
int shell_igraph_community_eb_get_merges(int argc, char **argv) {
 
15128
 
 
15129
  igraph_t graph;
 
15130
  igraph_vector_t edges;
 
15131
  igraph_matrix_t merges;
 
15132
  igraph_vector_t bridges;
 
15133
  char* shell_arg_merges=0;
 
15134
  char* shell_arg_bridges=0;
 
15135
  int shell_result;
 
15136
 
 
15137
 
 
15138
  int shell_seen[4];
 
15139
  int shell_index=-1;
 
15140
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15141
                                   { "edges",required_argument,0,1 },
 
15142
                                   { "merges",required_argument,0,2 },
 
15143
                                   { "bridges",required_argument,0,3 },
 
15144
                                   { "help",no_argument,0,4 },
 
15145
                                   { 0,0,0,0 }
 
15146
                                 };
 
15147
 
 
15148
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15149
  memset(shell_seen, 0, 4*sizeof(int));
 
15150
 
 
15151
  
 
15152
  /* Parse arguments and read input */
 
15153
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15154
 
 
15155
    if (shell_index==-1) {
 
15156
      exit(1);
 
15157
    }
 
15158
 
 
15159
    if (shell_seen[shell_index]==1) {
 
15160
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15161
              shell_options[shell_index].name);
 
15162
      exit(1);
 
15163
    }
 
15164
    shell_seen[shell_index]=1;  
 
15165
 
 
15166
    switch (shell_index) {
 
15167
    case 0: /* graph */
 
15168
      shell_read_graph(&graph, optarg);
 
15169
      break;
 
15170
    case 1: /* edges */
 
15171
      shell_read_vector(&edges, optarg);
 
15172
      break;
 
15173
    case 2: /* merges */
 
15174
      shell_arg_merges=strdup(optarg); 
 
15175
  igraph_matrix_init(&merges, 0, 0);
 
15176
      break;
 
15177
    case 3: /* bridges */
 
15178
      shell_arg_bridges=strdup(optarg); 
 
15179
  igraph_vector_init(&bridges, 0);
 
15180
      break;
 
15181
    case 4:
 
15182
      shell_igraph_community_eb_get_merges_usage(argv);
 
15183
      break;
 
15184
    default:
 
15185
      break;
 
15186
    }
 
15187
 
 
15188
    shell_index=-1;
 
15189
  }
 
15190
 
 
15191
  /* Check that we have all arguments */
 
15192
  for (shell_index=0; shell_index<4; shell_index++) {
 
15193
    if (!shell_seen[shell_index]) {
 
15194
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15195
              shell_options[shell_index].name);
 
15196
      exit(1);
 
15197
    }
 
15198
  }
 
15199
 
 
15200
  /* Do the operation */
 
15201
  shell_result=igraph_community_eb_get_merges(&graph, &edges, &merges, &bridges);
 
15202
 
 
15203
  /* Write the result */
 
15204
  igraph_destroy(&graph);
 
15205
  igraph_vector_destroy(&edges);
 
15206
  shell_write_matrix(&merges, shell_arg_merges); 
 
15207
  igraph_matrix_destroy(&merges);
 
15208
  shell_write_vector(&bridges, shell_arg_bridges); 
 
15209
  igraph_vector_destroy(&bridges);
 
15210
 
 
15211
  return 0;
 
15212
}
 
15213
 
 
15214
/*-------------------------------------------/
 
15215
/ igraph_community_fastgreedy                /
 
15216
/-------------------------------------------*/
 
15217
void shell_igraph_community_fastgreedy_usage(char **argv) {
 
15218
  printf("%s --graph=<graph> --weights=<weights> --merges=<merges> --modularity=<modularity>\n", basename(argv[0]));
 
15219
  exit(1);
 
15220
}
 
15221
 
 
15222
int shell_igraph_community_fastgreedy(int argc, char **argv) {
 
15223
 
 
15224
  igraph_t graph;
 
15225
  igraph_vector_t v_weights; igraph_vector_t *weights=0;
 
15226
  igraph_matrix_t merges;
 
15227
  igraph_vector_t modularity;
 
15228
  char* shell_arg_merges=0;
 
15229
  char* shell_arg_modularity=0;
 
15230
  int shell_result;
 
15231
 
 
15232
 
 
15233
  int shell_seen[4];
 
15234
  int shell_index=-1;
 
15235
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15236
                                   { "weights",required_argument,0,1 },
 
15237
                                   { "merges",required_argument,0,2 },
 
15238
                                   { "modularity",required_argument,0,3 },
 
15239
                                   { "help",no_argument,0,4 },
 
15240
                                   { 0,0,0,0 }
 
15241
                                 };
 
15242
 
 
15243
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15244
  memset(shell_seen, 0, 4*sizeof(int));
 
15245
 
 
15246
  
 
15247
  /* Parse arguments and read input */
 
15248
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15249
 
 
15250
    if (shell_index==-1) {
 
15251
      exit(1);
 
15252
    }
 
15253
 
 
15254
    if (shell_seen[shell_index]==1) {
 
15255
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15256
              shell_options[shell_index].name);
 
15257
      exit(1);
 
15258
    }
 
15259
    shell_seen[shell_index]=1;  
 
15260
 
 
15261
    switch (shell_index) {
 
15262
    case 0: /* graph */
 
15263
      shell_read_graph(&graph, optarg);
 
15264
      break;
 
15265
    case 1: /* weights */
 
15266
      weights=&v_weights; shell_read_vector(weights, optarg);
 
15267
      break;
 
15268
    case 2: /* merges */
 
15269
      shell_arg_merges=strdup(optarg); 
 
15270
  igraph_matrix_init(&merges, 0, 0);
 
15271
      break;
 
15272
    case 3: /* modularity */
 
15273
      shell_arg_modularity=strdup(optarg); 
 
15274
  igraph_vector_init(&modularity, 0);
 
15275
      break;
 
15276
    case 4:
 
15277
      shell_igraph_community_fastgreedy_usage(argv);
 
15278
      break;
 
15279
    default:
 
15280
      break;
 
15281
    }
 
15282
 
 
15283
    shell_index=-1;
 
15284
  }
 
15285
 
 
15286
  /* Check that we have all arguments */
 
15287
  for (shell_index=0; shell_index<4; shell_index++) {
 
15288
    if (!shell_seen[shell_index]) {
 
15289
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15290
              shell_options[shell_index].name);
 
15291
      exit(1);
 
15292
    }
 
15293
  }
 
15294
 
 
15295
  /* Do the operation */
 
15296
  shell_result=igraph_community_fastgreedy(&graph, weights, &merges, &modularity);
 
15297
 
 
15298
  /* Write the result */
 
15299
  igraph_destroy(&graph);
 
15300
  if (weights) { igraph_vector_destroy(weights); }
 
15301
  shell_write_matrix(&merges, shell_arg_merges); 
 
15302
  igraph_matrix_destroy(&merges);
 
15303
  shell_write_vector(&modularity, shell_arg_modularity); 
 
15304
  igraph_vector_destroy(&modularity);
 
15305
 
 
15306
  return 0;
 
15307
}
 
15308
 
 
15309
/*-------------------------------------------/
 
15310
/ igraph_community_to_membership             /
 
15311
/-------------------------------------------*/
 
15312
void shell_igraph_community_to_membership_usage(char **argv) {
 
15313
  printf("%s --graph=<graph> --merges=<merges> --steps=<steps> --membership=<membership> --csize=<csize>\n", basename(argv[0]));
 
15314
  exit(1);
 
15315
}
 
15316
 
 
15317
int shell_igraph_community_to_membership(int argc, char **argv) {
 
15318
 
 
15319
  igraph_t graph;
 
15320
  igraph_matrix_t merges;
 
15321
  igraph_integer_t steps;
 
15322
  igraph_vector_t membership;
 
15323
  igraph_vector_t csize;
 
15324
  char* shell_arg_membership=0;
 
15325
  char* shell_arg_csize=0;
 
15326
  int shell_result;
 
15327
 
 
15328
 
 
15329
  int shell_seen[5];
 
15330
  int shell_index=-1;
 
15331
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15332
                                   { "merges",required_argument,0,1 },
 
15333
                                   { "steps",required_argument,0,2 },
 
15334
                                   { "membership",required_argument,0,3 },
 
15335
                                   { "csize",required_argument,0,4 },
 
15336
                                   { "help",no_argument,0,5 },
 
15337
                                   { 0,0,0,0 }
 
15338
                                 };
 
15339
 
 
15340
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15341
  memset(shell_seen, 0, 5*sizeof(int));
 
15342
 
 
15343
  
 
15344
  /* Parse arguments and read input */
 
15345
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15346
 
 
15347
    if (shell_index==-1) {
 
15348
      exit(1);
 
15349
    }
 
15350
 
 
15351
    if (shell_seen[shell_index]==1) {
 
15352
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15353
              shell_options[shell_index].name);
 
15354
      exit(1);
 
15355
    }
 
15356
    shell_seen[shell_index]=1;  
 
15357
 
 
15358
    switch (shell_index) {
 
15359
    case 0: /* graph */
 
15360
      shell_read_graph(&graph, optarg);
 
15361
      break;
 
15362
    case 1: /* merges */
 
15363
      shell_read_matrix(&merges, optarg);
 
15364
      break;
 
15365
    case 2: /* steps */
 
15366
      shell_read_integer(&steps, optarg);
 
15367
      break;
 
15368
    case 3: /* membership */
 
15369
      shell_arg_membership=strdup(optarg); 
 
15370
  igraph_vector_init(&membership, 0);
 
15371
      break;
 
15372
    case 4: /* csize */
 
15373
      shell_arg_csize=strdup(optarg); 
 
15374
  igraph_vector_init(&csize, 0);
 
15375
      break;
 
15376
    case 5:
 
15377
      shell_igraph_community_to_membership_usage(argv);
 
15378
      break;
 
15379
    default:
 
15380
      break;
 
15381
    }
 
15382
 
 
15383
    shell_index=-1;
 
15384
  }
 
15385
 
 
15386
  /* Check that we have all arguments */
 
15387
  for (shell_index=0; shell_index<5; shell_index++) {
 
15388
    if (!shell_seen[shell_index]) {
 
15389
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15390
              shell_options[shell_index].name);
 
15391
      exit(1);
 
15392
    }
 
15393
  }
 
15394
 
 
15395
  /* Do the operation */
 
15396
  shell_result=igraph_community_to_membership(&graph, &merges, steps, &membership, &csize);
 
15397
 
 
15398
  /* Write the result */
 
15399
  igraph_destroy(&graph);
 
15400
  igraph_matrix_destroy(&merges);
 
15401
  shell_write_vector(&membership, shell_arg_membership); 
 
15402
  igraph_vector_destroy(&membership);
 
15403
  shell_write_vector(&csize, shell_arg_csize); 
 
15404
  igraph_vector_destroy(&csize);
 
15405
 
 
15406
  return 0;
 
15407
}
 
15408
 
 
15409
/*-------------------------------------------/
 
15410
/ igraph_le_community_to_membership          /
 
15411
/-------------------------------------------*/
 
15412
void shell_igraph_le_community_to_membership_usage(char **argv) {
 
15413
  printf("%s --merges=<merges> --steps=<steps> --membership=<membership> --membership-out=<membership-out> --csize=<csize>\n", basename(argv[0]));
 
15414
  exit(1);
 
15415
}
 
15416
 
 
15417
int shell_igraph_le_community_to_membership(int argc, char **argv) {
 
15418
 
 
15419
  igraph_matrix_t merges;
 
15420
  igraph_integer_t steps;
 
15421
  igraph_vector_t membership;
 
15422
  igraph_vector_t v_csize; igraph_vector_t *csize=0;
 
15423
  char* shell_arg_membership=0;
 
15424
  char* shell_arg_csize=0;
 
15425
  int shell_result;
 
15426
 
 
15427
 
 
15428
  int shell_seen[5];
 
15429
  int shell_index=-1;
 
15430
  struct option shell_options[]= { { "merges",required_argument,0,0 },
 
15431
                                   { "steps",required_argument,0,1 },
 
15432
                                   { "membership",required_argument,0,2 },
 
15433
                                   { "membership-out",required_argument,0,3 },
 
15434
                                   { "csize",required_argument,0,4 },
 
15435
                                   { "help",no_argument,0,5 },
 
15436
                                   { 0,0,0,0 }
 
15437
                                 };
 
15438
 
 
15439
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15440
  memset(shell_seen, 0, 5*sizeof(int));
 
15441
 
 
15442
  
 
15443
  /* Parse arguments and read input */
 
15444
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15445
 
 
15446
    if (shell_index==-1) {
 
15447
      exit(1);
 
15448
    }
 
15449
 
 
15450
    if (shell_seen[shell_index]==1) {
 
15451
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15452
              shell_options[shell_index].name);
 
15453
      exit(1);
 
15454
    }
 
15455
    shell_seen[shell_index]=1;  
 
15456
 
 
15457
    switch (shell_index) {
 
15458
    case 0: /* merges */
 
15459
      shell_read_matrix(&merges, optarg);
 
15460
      break;
 
15461
    case 1: /* steps */
 
15462
      shell_read_integer(&steps, optarg);
 
15463
      break;
 
15464
    case 2: /* membership */
 
15465
      shell_read_vector(&membership, optarg);
 
15466
      break;
 
15467
    case 3: /* membership-out */
 
15468
      shell_arg_membership=strdup(optarg); 
 
15469
  igraph_vector_init(&membership, 0);
 
15470
      break;
 
15471
    case 4: /* csize */
 
15472
      csize=&v_csize; igraph_vector_init(csize, 0); 
 
15473
  shell_arg_csize=strdup(optarg);
 
15474
      break;
 
15475
    case 5:
 
15476
      shell_igraph_le_community_to_membership_usage(argv);
 
15477
      break;
 
15478
    default:
 
15479
      break;
 
15480
    }
 
15481
 
 
15482
    shell_index=-1;
 
15483
  }
 
15484
 
 
15485
  /* Check that we have all arguments */
 
15486
  for (shell_index=0; shell_index<5; shell_index++) {
 
15487
    if (!shell_seen[shell_index]) {
 
15488
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15489
              shell_options[shell_index].name);
 
15490
      exit(1);
 
15491
    }
 
15492
  }
 
15493
 
 
15494
  /* Do the operation */
 
15495
  shell_result=igraph_le_community_to_membership(&merges, steps, &membership, csize);
 
15496
 
 
15497
  /* Write the result */
 
15498
  igraph_matrix_destroy(&merges);
 
15499
  igraph_vector_destroy(&membership);
 
15500
  shell_write_vector(&membership, shell_arg_membership); 
 
15501
  igraph_vector_destroy(&membership);
 
15502
  if (csize) { shell_write_vector(csize, shell_arg_csize); 
 
15503
  igraph_vector_destroy(csize); }
 
15504
 
 
15505
  return 0;
 
15506
}
 
15507
 
 
15508
/*-------------------------------------------/
 
15509
/ igraph_modularity                          /
 
15510
/-------------------------------------------*/
 
15511
void shell_igraph_modularity_usage(char **argv) {
 
15512
  printf("%s --graph=<graph> --membership=<membership> --modularity=<modularity> --weights=<weights>\n", basename(argv[0]));
 
15513
  exit(1);
 
15514
}
 
15515
 
 
15516
int shell_igraph_modularity(int argc, char **argv) {
 
15517
 
 
15518
  igraph_t graph;
 
15519
  igraph_vector_t membership;
 
15520
  igraph_real_t modularity;
 
15521
  igraph_vector_t v_weights; igraph_vector_t *weights=0=NULL;
 
15522
  char* shell_arg_modularity=0;
 
15523
  int shell_result;
 
15524
 
 
15525
 
 
15526
  int shell_seen[4];
 
15527
  int shell_index=-1;
 
15528
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15529
                                   { "membership",required_argument,0,1 },
 
15530
                                   { "modularity",required_argument,0,2 },
 
15531
                                   { "weights",required_argument,0,3 },
 
15532
                                   { "help",no_argument,0,4 },
 
15533
                                   { 0,0,0,0 }
 
15534
                                 };
 
15535
 
 
15536
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15537
  memset(shell_seen, 0, 4*sizeof(int));
 
15538
  shell_seen[3]=2;
 
15539
  
 
15540
  /* Parse arguments and read input */
 
15541
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15542
 
 
15543
    if (shell_index==-1) {
 
15544
      exit(1);
 
15545
    }
 
15546
 
 
15547
    if (shell_seen[shell_index]==1) {
 
15548
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15549
              shell_options[shell_index].name);
 
15550
      exit(1);
 
15551
    }
 
15552
    shell_seen[shell_index]=1;  
 
15553
 
 
15554
    switch (shell_index) {
 
15555
    case 0: /* graph */
 
15556
      shell_read_graph(&graph, optarg);
 
15557
      break;
 
15558
    case 1: /* membership */
 
15559
      shell_read_vector(&membership, optarg);
 
15560
      break;
 
15561
    case 2: /* modularity */
 
15562
      shell_arg_modularity=strdup(optarg);
 
15563
      break;
 
15564
    case 3: /* weights */
 
15565
      weights=&v_weights; shell_read_vector(weights, optarg);
 
15566
      break;
 
15567
    case 4:
 
15568
      shell_igraph_modularity_usage(argv);
 
15569
      break;
 
15570
    default:
 
15571
      break;
 
15572
    }
 
15573
 
 
15574
    shell_index=-1;
 
15575
  }
 
15576
 
 
15577
  /* Check that we have all arguments */
 
15578
  for (shell_index=0; shell_index<4; shell_index++) {
 
15579
    if (!shell_seen[shell_index]) {
 
15580
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15581
              shell_options[shell_index].name);
 
15582
      exit(1);
 
15583
    }
 
15584
  }
 
15585
 
 
15586
  /* Do the operation */
 
15587
  shell_result=igraph_modularity(&graph, &membership, &modularity, weights);
 
15588
 
 
15589
  /* Write the result */
 
15590
  igraph_destroy(&graph);
 
15591
  igraph_vector_destroy(&membership);
 
15592
  shell_write_real(modularity, shell_arg_modularity);
 
15593
  if (weights) { igraph_vector_destroy(weights); }
 
15594
 
 
15595
  return 0;
 
15596
}
 
15597
 
 
15598
/*-------------------------------------------/
 
15599
/ igraph_community_leading_eigenvector       /
 
15600
/-------------------------------------------*/
 
15601
void shell_igraph_community_leading_eigenvector_usage(char **argv) {
 
15602
  printf("%s --graph=<graph> --merges=<merges> --membership=<membership> --steps=<steps>\n", basename(argv[0]));
 
15603
  exit(1);
 
15604
}
 
15605
 
 
15606
int shell_igraph_community_leading_eigenvector(int argc, char **argv) {
 
15607
 
 
15608
  igraph_t graph;
 
15609
  igraph_matrix_t merges;
 
15610
  igraph_vector_t membership;
 
15611
  igraph_integer_t steps=-1;
 
15612
 
 
15613
  char* shell_arg_merges=0;
 
15614
  char* shell_arg_membership=0;
 
15615
  char* shell_arg_options=0;
 
15616
  int shell_result;
 
15617
 
 
15618
 
 
15619
  int shell_seen[4];
 
15620
  int shell_index=-1;
 
15621
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15622
                                   { "merges",required_argument,0,1 },
 
15623
                                   { "membership",required_argument,0,2 },
 
15624
                                   { "steps",required_argument,0,3 },
 
15625
                                   { "help",no_argument,0,4 },
 
15626
                                   { 0,0,0,0 }
 
15627
                                 };
 
15628
 
 
15629
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15630
  memset(shell_seen, 0, 4*sizeof(int));
 
15631
  shell_seen[3]=2;
 
15632
  
 
15633
  /* Parse arguments and read input */
 
15634
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15635
 
 
15636
    if (shell_index==-1) {
 
15637
      exit(1);
 
15638
    }
 
15639
 
 
15640
    if (shell_seen[shell_index]==1) {
 
15641
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15642
              shell_options[shell_index].name);
 
15643
      exit(1);
 
15644
    }
 
15645
    shell_seen[shell_index]=1;  
 
15646
 
 
15647
    switch (shell_index) {
 
15648
    case 0: /* graph */
 
15649
      shell_read_graph(&graph, optarg);
 
15650
      break;
 
15651
    case 1: /* merges */
 
15652
      shell_arg_merges=strdup(optarg); 
 
15653
  igraph_matrix_init(&merges, 0, 0);
 
15654
      break;
 
15655
    case 2: /* membership */
 
15656
      shell_arg_membership=strdup(optarg); 
 
15657
  igraph_vector_init(&membership, 0);
 
15658
      break;
 
15659
    case 3: /* steps */
 
15660
      shell_read_integer(&steps, optarg);
 
15661
      break;
 
15662
    case 4:
 
15663
      shell_igraph_community_leading_eigenvector_usage(argv);
 
15664
      break;
 
15665
    default:
 
15666
      break;
 
15667
    }
 
15668
 
 
15669
    shell_index=-1;
 
15670
  }
 
15671
 
 
15672
  /* Check that we have all arguments */
 
15673
  for (shell_index=0; shell_index<4; shell_index++) {
 
15674
    if (!shell_seen[shell_index]) {
 
15675
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15676
              shell_options[shell_index].name);
 
15677
      exit(1);
 
15678
    }
 
15679
  }
 
15680
 
 
15681
  /* Do the operation */
 
15682
  shell_result=igraph_community_leading_eigenvector(&graph, &merges, &membership, steps, 0);
 
15683
 
 
15684
  /* Write the result */
 
15685
  igraph_destroy(&graph);
 
15686
  shell_write_matrix(&merges, shell_arg_merges); 
 
15687
  igraph_matrix_destroy(&merges);
 
15688
  shell_write_vector(&membership, shell_arg_membership); 
 
15689
  igraph_vector_destroy(&membership);
 
15690
 
 
15691
  return 0;
 
15692
}
 
15693
 
 
15694
/*-------------------------------------------/
 
15695
/ igraph_community_leading_eigenvector_naive /
 
15696
/-------------------------------------------*/
 
15697
void shell_igraph_community_leading_eigenvector_naive_usage(char **argv) {
 
15698
  printf("%s --graph=<graph> --merges=<merges> --membership=<membership> --steps=<steps>\n", basename(argv[0]));
 
15699
  exit(1);
 
15700
}
 
15701
 
 
15702
int shell_igraph_community_leading_eigenvector_naive(int argc, char **argv) {
 
15703
 
 
15704
  igraph_t graph;
 
15705
  igraph_matrix_t merges;
 
15706
  igraph_vector_t membership;
 
15707
  igraph_integer_t steps=-1;
 
15708
 
 
15709
  char* shell_arg_merges=0;
 
15710
  char* shell_arg_membership=0;
 
15711
  char* shell_arg_options=0;
 
15712
  int shell_result;
 
15713
 
 
15714
 
 
15715
  int shell_seen[4];
 
15716
  int shell_index=-1;
 
15717
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15718
                                   { "merges",required_argument,0,1 },
 
15719
                                   { "membership",required_argument,0,2 },
 
15720
                                   { "steps",required_argument,0,3 },
 
15721
                                   { "help",no_argument,0,4 },
 
15722
                                   { 0,0,0,0 }
 
15723
                                 };
 
15724
 
 
15725
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15726
  memset(shell_seen, 0, 4*sizeof(int));
 
15727
  shell_seen[3]=2;
 
15728
  
 
15729
  /* Parse arguments and read input */
 
15730
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15731
 
 
15732
    if (shell_index==-1) {
 
15733
      exit(1);
 
15734
    }
 
15735
 
 
15736
    if (shell_seen[shell_index]==1) {
 
15737
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15738
              shell_options[shell_index].name);
 
15739
      exit(1);
 
15740
    }
 
15741
    shell_seen[shell_index]=1;  
 
15742
 
 
15743
    switch (shell_index) {
 
15744
    case 0: /* graph */
 
15745
      shell_read_graph(&graph, optarg);
 
15746
      break;
 
15747
    case 1: /* merges */
 
15748
      shell_arg_merges=strdup(optarg); 
 
15749
  igraph_matrix_init(&merges, 0, 0);
 
15750
      break;
 
15751
    case 2: /* membership */
 
15752
      shell_arg_membership=strdup(optarg); 
 
15753
  igraph_vector_init(&membership, 0);
 
15754
      break;
 
15755
    case 3: /* steps */
 
15756
      shell_read_integer(&steps, optarg);
 
15757
      break;
 
15758
    case 4:
 
15759
      shell_igraph_community_leading_eigenvector_naive_usage(argv);
 
15760
      break;
 
15761
    default:
 
15762
      break;
 
15763
    }
 
15764
 
 
15765
    shell_index=-1;
 
15766
  }
 
15767
 
 
15768
  /* Check that we have all arguments */
 
15769
  for (shell_index=0; shell_index<4; shell_index++) {
 
15770
    if (!shell_seen[shell_index]) {
 
15771
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15772
              shell_options[shell_index].name);
 
15773
      exit(1);
 
15774
    }
 
15775
  }
 
15776
 
 
15777
  /* Do the operation */
 
15778
  shell_result=igraph_community_leading_eigenvector_naive(&graph, &merges, &membership, steps, 0);
 
15779
 
 
15780
  /* Write the result */
 
15781
  igraph_destroy(&graph);
 
15782
  shell_write_matrix(&merges, shell_arg_merges); 
 
15783
  igraph_matrix_destroy(&merges);
 
15784
  shell_write_vector(&membership, shell_arg_membership); 
 
15785
  igraph_vector_destroy(&membership);
 
15786
 
 
15787
  return 0;
 
15788
}
 
15789
 
 
15790
/*-------------------------------------------/
 
15791
/ igraph_community_leading_eigenvector_step  /
 
15792
/-------------------------------------------*/
 
15793
void shell_igraph_community_leading_eigenvector_step_usage(char **argv) {
 
15794
  printf("%s --graph=<graph> --membership=<membership> --membership-out=<membership-out> --community=<community> --split=<split> --eigenvector=<eigenvector> --eigenvalue=<eigenvalue>\n", basename(argv[0]));
 
15795
  exit(1);
 
15796
}
 
15797
 
 
15798
int shell_igraph_community_leading_eigenvector_step(int argc, char **argv) {
 
15799
 
 
15800
  igraph_t graph;
 
15801
  igraph_vector_t membership;
 
15802
  igraph_integer_t community;
 
15803
  igraph_bool_t split;
 
15804
  igraph_vector_t v_eigenvector; igraph_vector_t *eigenvector=0;
 
15805
  igraph_real_t eigenvalue;
 
15806
 
 
15807
 
 
15808
  char* shell_arg_membership=0;
 
15809
  char* shell_arg_split=0;
 
15810
  char* shell_arg_eigenvector=0;
 
15811
  char* shell_arg_eigenvalue=0;
 
15812
  char* shell_arg_options=0;
 
15813
  int shell_result;
 
15814
 
 
15815
 
 
15816
  int shell_seen[7];
 
15817
  int shell_index=-1;
 
15818
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15819
                                   { "membership",required_argument,0,1 },
 
15820
                                   { "membership-out",required_argument,0,2 },
 
15821
                                   { "community",required_argument,0,3 },
 
15822
                                   { "split",required_argument,0,4 },
 
15823
                                   { "eigenvector",required_argument,0,5 },
 
15824
                                   { "eigenvalue",required_argument,0,6 },
 
15825
                                   { "help",no_argument,0,7 },
 
15826
                                   { 0,0,0,0 }
 
15827
                                 };
 
15828
 
 
15829
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15830
  memset(shell_seen, 0, 7*sizeof(int));
 
15831
 
 
15832
  
 
15833
  /* Parse arguments and read input */
 
15834
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15835
 
 
15836
    if (shell_index==-1) {
 
15837
      exit(1);
 
15838
    }
 
15839
 
 
15840
    if (shell_seen[shell_index]==1) {
 
15841
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15842
              shell_options[shell_index].name);
 
15843
      exit(1);
 
15844
    }
 
15845
    shell_seen[shell_index]=1;  
 
15846
 
 
15847
    switch (shell_index) {
 
15848
    case 0: /* graph */
 
15849
      shell_read_graph(&graph, optarg);
 
15850
      break;
 
15851
    case 1: /* membership */
 
15852
      shell_read_vector(&membership, optarg);
 
15853
      break;
 
15854
    case 2: /* membership-out */
 
15855
      shell_arg_membership=strdup(optarg); 
 
15856
  igraph_vector_init(&membership, 0);
 
15857
      break;
 
15858
    case 3: /* community */
 
15859
      shell_read_integer(&community, optarg);
 
15860
      break;
 
15861
    case 4: /* split */
 
15862
      
 
15863
      break;
 
15864
    case 5: /* eigenvector */
 
15865
      eigenvector=&v_eigenvector; igraph_vector_init(eigenvector, 0); 
 
15866
  shell_arg_eigenvector=strdup(optarg);
 
15867
      break;
 
15868
    case 6: /* eigenvalue */
 
15869
      shell_arg_eigenvalue=strdup(optarg);
 
15870
      break;
 
15871
    case 7:
 
15872
      shell_igraph_community_leading_eigenvector_step_usage(argv);
 
15873
      break;
 
15874
    default:
 
15875
      break;
 
15876
    }
 
15877
 
 
15878
    shell_index=-1;
 
15879
  }
 
15880
 
 
15881
  /* Check that we have all arguments */
 
15882
  for (shell_index=0; shell_index<7; shell_index++) {
 
15883
    if (!shell_seen[shell_index]) {
 
15884
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15885
              shell_options[shell_index].name);
 
15886
      exit(1);
 
15887
    }
 
15888
  }
 
15889
 
 
15890
  /* Do the operation */
 
15891
  shell_result=igraph_community_leading_eigenvector_step(&graph, &membership, community, &split, eigenvector, &eigenvalue, 0, 0);
 
15892
 
 
15893
  /* Write the result */
 
15894
  igraph_destroy(&graph);
 
15895
  igraph_vector_destroy(&membership);
 
15896
  shell_write_vector(&membership, shell_arg_membership); 
 
15897
  igraph_vector_destroy(&membership);
 
15898
  shell_write_boolean(split, shell_arg_split);
 
15899
  if (eigenvector) { shell_write_vector(eigenvector, shell_arg_eigenvector); 
 
15900
  igraph_vector_destroy(eigenvector); }
 
15901
  shell_write_real(eigenvalue, shell_arg_eigenvalue);
 
15902
 
 
15903
  return 0;
 
15904
}
 
15905
 
 
15906
/*-------------------------------------------/
 
15907
/ igraph_community_label_propagation         /
 
15908
/-------------------------------------------*/
 
15909
void shell_igraph_community_label_propagation_usage(char **argv) {
 
15910
  printf("%s --graph=<graph> --membership=<membership> --initial=<initial>\n", basename(argv[0]));
 
15911
  exit(1);
 
15912
}
 
15913
 
 
15914
int shell_igraph_community_label_propagation(int argc, char **argv) {
 
15915
 
 
15916
  igraph_t graph;
 
15917
  igraph_vector_t membership;
 
15918
 
 
15919
  igraph_vector_t v_initial; igraph_vector_t *initial=0=NULL;
 
15920
 
 
15921
  char* shell_arg_membership=0;
 
15922
  int shell_result;
 
15923
 
 
15924
 
 
15925
  int shell_seen[3];
 
15926
  int shell_index=-1;
 
15927
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
15928
                                   { "membership",required_argument,0,1 },
 
15929
                                   { "initial",required_argument,0,2 },
 
15930
                                   { "help",no_argument,0,3 },
 
15931
                                   { 0,0,0,0 }
 
15932
                                 };
 
15933
 
 
15934
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
15935
  memset(shell_seen, 0, 3*sizeof(int));
 
15936
  shell_seen[2]=2;
 
15937
  
 
15938
  /* Parse arguments and read input */
 
15939
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
15940
 
 
15941
    if (shell_index==-1) {
 
15942
      exit(1);
 
15943
    }
 
15944
 
 
15945
    if (shell_seen[shell_index]==1) {
 
15946
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
15947
              shell_options[shell_index].name);
 
15948
      exit(1);
 
15949
    }
 
15950
    shell_seen[shell_index]=1;  
 
15951
 
 
15952
    switch (shell_index) {
 
15953
    case 0: /* graph */
 
15954
      shell_read_graph(&graph, optarg);
 
15955
      break;
 
15956
    case 1: /* membership */
 
15957
      shell_arg_membership=strdup(optarg); 
 
15958
  igraph_vector_init(&membership, 0);
 
15959
      break;
 
15960
    case 2: /* initial */
 
15961
      initial=&v_initial; shell_read_vector(initial, optarg);
 
15962
      break;
 
15963
    case 3:
 
15964
      shell_igraph_community_label_propagation_usage(argv);
 
15965
      break;
 
15966
    default:
 
15967
      break;
 
15968
    }
 
15969
 
 
15970
    shell_index=-1;
 
15971
  }
 
15972
 
 
15973
  /* Check that we have all arguments */
 
15974
  for (shell_index=0; shell_index<3; shell_index++) {
 
15975
    if (!shell_seen[shell_index]) {
 
15976
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
15977
              shell_options[shell_index].name);
 
15978
      exit(1);
 
15979
    }
 
15980
  }
 
15981
 
 
15982
  /* Do the operation */
 
15983
  shell_result=igraph_community_label_propagation(&graph, &membership, 0, initial, fixed);
 
15984
 
 
15985
  /* Write the result */
 
15986
  igraph_destroy(&graph);
 
15987
  shell_write_vector(&membership, shell_arg_membership); 
 
15988
  igraph_vector_destroy(&membership);
 
15989
  if (initial) { igraph_vector_destroy(initial); }
 
15990
 
 
15991
  return 0;
 
15992
}
 
15993
 
 
15994
/*-------------------------------------------/
 
15995
/ igraph_get_adjacency                       /
 
15996
/-------------------------------------------*/
 
15997
void shell_igraph_get_adjacency_usage(char **argv) {
 
15998
  printf("%s --graph=<graph> --res=<res> --type=<type>\n", basename(argv[0]));
 
15999
  exit(1);
 
16000
}
 
16001
 
 
16002
int shell_igraph_get_adjacency(int argc, char **argv) {
 
16003
 
 
16004
  igraph_t graph;
 
16005
  igraph_matrix_t res;
 
16006
  igraph_get_adjacency_t type=IGRAPH_GET_ADJACENCY_BOTH;
 
16007
  char* shell_arg_res=0;
 
16008
  int shell_result;
 
16009
 
 
16010
 
 
16011
  int shell_seen[3];
 
16012
  int shell_index=-1;
 
16013
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16014
                                   { "res",required_argument,0,1 },
 
16015
                                   { "type",required_argument,0,2 },
 
16016
                                   { "help",no_argument,0,3 },
 
16017
                                   { 0,0,0,0 }
 
16018
                                 };
 
16019
 
 
16020
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16021
  memset(shell_seen, 0, 3*sizeof(int));
 
16022
  shell_seen[2]=2;
 
16023
  
 
16024
  /* Parse arguments and read input */
 
16025
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16026
 
 
16027
    if (shell_index==-1) {
 
16028
      exit(1);
 
16029
    }
 
16030
 
 
16031
    if (shell_seen[shell_index]==1) {
 
16032
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16033
              shell_options[shell_index].name);
 
16034
      exit(1);
 
16035
    }
 
16036
    shell_seen[shell_index]=1;  
 
16037
 
 
16038
    switch (shell_index) {
 
16039
    case 0: /* graph */
 
16040
      shell_read_graph(&graph, optarg);
 
16041
      break;
 
16042
    case 1: /* res */
 
16043
      shell_arg_res=strdup(optarg); 
 
16044
  igraph_matrix_init(&res, 0, 0);
 
16045
      break;
 
16046
    case 2: /* type */
 
16047
      shell_read_enum(&type, optarg, "upper", 0, "lower", 1, "both", 2, 0);
 
16048
      break;
 
16049
    case 3:
 
16050
      shell_igraph_get_adjacency_usage(argv);
 
16051
      break;
 
16052
    default:
 
16053
      break;
 
16054
    }
 
16055
 
 
16056
    shell_index=-1;
 
16057
  }
 
16058
 
 
16059
  /* Check that we have all arguments */
 
16060
  for (shell_index=0; shell_index<3; shell_index++) {
 
16061
    if (!shell_seen[shell_index]) {
 
16062
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16063
              shell_options[shell_index].name);
 
16064
      exit(1);
 
16065
    }
 
16066
  }
 
16067
 
 
16068
  /* Do the operation */
 
16069
  shell_result=igraph_get_adjacency(&graph, &res, type);
 
16070
 
 
16071
  /* Write the result */
 
16072
  igraph_destroy(&graph);
 
16073
  shell_write_matrix(&res, shell_arg_res); 
 
16074
  igraph_matrix_destroy(&res);
 
16075
 
 
16076
  return 0;
 
16077
}
 
16078
 
 
16079
/*-------------------------------------------/
 
16080
/ igraph_get_edgelist                        /
 
16081
/-------------------------------------------*/
 
16082
void shell_igraph_get_edgelist_usage(char **argv) {
 
16083
  printf("%s --graph=<graph> --res=<res> --bycol=<bycol>\n", basename(argv[0]));
 
16084
  exit(1);
 
16085
}
 
16086
 
 
16087
int shell_igraph_get_edgelist(int argc, char **argv) {
 
16088
 
 
16089
  igraph_t graph;
 
16090
  igraph_vector_t res;
 
16091
  igraph_bool_t bycol=0;
 
16092
  char* shell_arg_res=0;
 
16093
  int shell_result;
 
16094
 
 
16095
 
 
16096
  int shell_seen[3];
 
16097
  int shell_index=-1;
 
16098
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16099
                                   { "res",required_argument,0,1 },
 
16100
                                   { "bycol",required_argument,0,2 },
 
16101
                                   { "help",no_argument,0,3 },
 
16102
                                   { 0,0,0,0 }
 
16103
                                 };
 
16104
 
 
16105
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16106
  memset(shell_seen, 0, 3*sizeof(int));
 
16107
  shell_seen[2]=2;
 
16108
  
 
16109
  /* Parse arguments and read input */
 
16110
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16111
 
 
16112
    if (shell_index==-1) {
 
16113
      exit(1);
 
16114
    }
 
16115
 
 
16116
    if (shell_seen[shell_index]==1) {
 
16117
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16118
              shell_options[shell_index].name);
 
16119
      exit(1);
 
16120
    }
 
16121
    shell_seen[shell_index]=1;  
 
16122
 
 
16123
    switch (shell_index) {
 
16124
    case 0: /* graph */
 
16125
      shell_read_graph(&graph, optarg);
 
16126
      break;
 
16127
    case 1: /* res */
 
16128
      shell_arg_res=strdup(optarg); 
 
16129
  igraph_vector_init(&res, 0);
 
16130
      break;
 
16131
    case 2: /* bycol */
 
16132
      shell_read_boolean(&bycol, optarg);
 
16133
      break;
 
16134
    case 3:
 
16135
      shell_igraph_get_edgelist_usage(argv);
 
16136
      break;
 
16137
    default:
 
16138
      break;
 
16139
    }
 
16140
 
 
16141
    shell_index=-1;
 
16142
  }
 
16143
 
 
16144
  /* Check that we have all arguments */
 
16145
  for (shell_index=0; shell_index<3; shell_index++) {
 
16146
    if (!shell_seen[shell_index]) {
 
16147
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16148
              shell_options[shell_index].name);
 
16149
      exit(1);
 
16150
    }
 
16151
  }
 
16152
 
 
16153
  /* Do the operation */
 
16154
  shell_result=igraph_get_edgelist(&graph, &res, bycol);
 
16155
 
 
16156
  /* Write the result */
 
16157
  igraph_destroy(&graph);
 
16158
  shell_write_vector(&res, shell_arg_res); 
 
16159
  igraph_vector_destroy(&res);
 
16160
 
 
16161
  return 0;
 
16162
}
 
16163
 
 
16164
/*-------------------------------------------/
 
16165
/ igraph_to_directed                         /
 
16166
/-------------------------------------------*/
 
16167
void shell_igraph_to_directed_usage(char **argv) {
 
16168
  printf("%s --graph=<graph> --graph-out=<graph-out> --flags=<flags>\n", basename(argv[0]));
 
16169
  exit(1);
 
16170
}
 
16171
 
 
16172
int shell_igraph_to_directed(int argc, char **argv) {
 
16173
 
 
16174
  igraph_t graph;
 
16175
  igraph_to_directed_t flags=IGRAPH_TO_DIRECTED_MUTUAL;
 
16176
  char* shell_arg_graph=0;
 
16177
  int shell_result;
 
16178
 
 
16179
 
 
16180
  int shell_seen[3];
 
16181
  int shell_index=-1;
 
16182
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16183
                                   { "graph-out",required_argument,0,1 },
 
16184
                                   { "flags",required_argument,0,2 },
 
16185
                                   { "help",no_argument,0,3 },
 
16186
                                   { 0,0,0,0 }
 
16187
                                 };
 
16188
 
 
16189
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16190
  memset(shell_seen, 0, 3*sizeof(int));
 
16191
  shell_seen[2]=2;
 
16192
  
 
16193
  /* Parse arguments and read input */
 
16194
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16195
 
 
16196
    if (shell_index==-1) {
 
16197
      exit(1);
 
16198
    }
 
16199
 
 
16200
    if (shell_seen[shell_index]==1) {
 
16201
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16202
              shell_options[shell_index].name);
 
16203
      exit(1);
 
16204
    }
 
16205
    shell_seen[shell_index]=1;  
 
16206
 
 
16207
    switch (shell_index) {
 
16208
    case 0: /* graph */
 
16209
      shell_read_graph(&graph, optarg);
 
16210
      break;
 
16211
    case 1: /* graph-out */
 
16212
      shell_arg_graph=strdup(optarg);
 
16213
      break;
 
16214
    case 2: /* flags */
 
16215
      shell_read_enum(&flags, optarg, "arbitrary", 0, "mutual", 1, 0);
 
16216
      break;
 
16217
    case 3:
 
16218
      shell_igraph_to_directed_usage(argv);
 
16219
      break;
 
16220
    default:
 
16221
      break;
 
16222
    }
 
16223
 
 
16224
    shell_index=-1;
 
16225
  }
 
16226
 
 
16227
  /* Check that we have all arguments */
 
16228
  for (shell_index=0; shell_index<3; shell_index++) {
 
16229
    if (!shell_seen[shell_index]) {
 
16230
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16231
              shell_options[shell_index].name);
 
16232
      exit(1);
 
16233
    }
 
16234
  }
 
16235
 
 
16236
  /* Do the operation */
 
16237
  shell_result=igraph_to_directed(&graph, flags);
 
16238
 
 
16239
  /* Write the result */
 
16240
  igraph_destroy(&graph);
 
16241
  shell_write_graph(&graph, shell_arg_graph); 
 
16242
  igraph_destroy(&graph);
 
16243
 
 
16244
  return 0;
 
16245
}
 
16246
 
 
16247
/*-------------------------------------------/
 
16248
/ igraph_to_undirected                       /
 
16249
/-------------------------------------------*/
 
16250
void shell_igraph_to_undirected_usage(char **argv) {
 
16251
  printf("%s --graph=<graph> --graph-out=<graph-out> --flags=<flags>\n", basename(argv[0]));
 
16252
  exit(1);
 
16253
}
 
16254
 
 
16255
int shell_igraph_to_undirected(int argc, char **argv) {
 
16256
 
 
16257
  igraph_t graph;
 
16258
  igraph_to_undirected_t flags=IGRAPH_TO_UNDIRECTED_COLLAPSE;
 
16259
  char* shell_arg_graph=0;
 
16260
  int shell_result;
 
16261
 
 
16262
 
 
16263
  int shell_seen[3];
 
16264
  int shell_index=-1;
 
16265
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16266
                                   { "graph-out",required_argument,0,1 },
 
16267
                                   { "flags",required_argument,0,2 },
 
16268
                                   { "help",no_argument,0,3 },
 
16269
                                   { 0,0,0,0 }
 
16270
                                 };
 
16271
 
 
16272
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16273
  memset(shell_seen, 0, 3*sizeof(int));
 
16274
  shell_seen[2]=2;
 
16275
  
 
16276
  /* Parse arguments and read input */
 
16277
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16278
 
 
16279
    if (shell_index==-1) {
 
16280
      exit(1);
 
16281
    }
 
16282
 
 
16283
    if (shell_seen[shell_index]==1) {
 
16284
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16285
              shell_options[shell_index].name);
 
16286
      exit(1);
 
16287
    }
 
16288
    shell_seen[shell_index]=1;  
 
16289
 
 
16290
    switch (shell_index) {
 
16291
    case 0: /* graph */
 
16292
      shell_read_graph(&graph, optarg);
 
16293
      break;
 
16294
    case 1: /* graph-out */
 
16295
      shell_arg_graph=strdup(optarg);
 
16296
      break;
 
16297
    case 2: /* flags */
 
16298
      shell_read_enum(&flags, optarg, "each", 0, "collapse", 0);
 
16299
      break;
 
16300
    case 3:
 
16301
      shell_igraph_to_undirected_usage(argv);
 
16302
      break;
 
16303
    default:
 
16304
      break;
 
16305
    }
 
16306
 
 
16307
    shell_index=-1;
 
16308
  }
 
16309
 
 
16310
  /* Check that we have all arguments */
 
16311
  for (shell_index=0; shell_index<3; shell_index++) {
 
16312
    if (!shell_seen[shell_index]) {
 
16313
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16314
              shell_options[shell_index].name);
 
16315
      exit(1);
 
16316
    }
 
16317
  }
 
16318
 
 
16319
  /* Do the operation */
 
16320
  shell_result=igraph_to_undirected(&graph, flags);
 
16321
 
 
16322
  /* Write the result */
 
16323
  igraph_destroy(&graph);
 
16324
  shell_write_graph(&graph, shell_arg_graph); 
 
16325
  igraph_destroy(&graph);
 
16326
 
 
16327
  return 0;
 
16328
}
 
16329
 
 
16330
/*-------------------------------------------/
 
16331
/ igraph_read_graph_edgelist                 /
 
16332
/-------------------------------------------*/
 
16333
void shell_igraph_read_graph_edgelist_usage(char **argv) {
 
16334
  printf("%s --graph=<graph> --instream=<instream> --n=<n> --directed=<directed>\n", basename(argv[0]));
 
16335
  exit(1);
 
16336
}
 
16337
 
 
16338
int shell_igraph_read_graph_edgelist(int argc, char **argv) {
 
16339
 
 
16340
  igraph_t graph;
 
16341
  FILE* instream=0;
 
16342
  igraph_integer_t n=0;
 
16343
  igraph_bool_t directed=1;
 
16344
  char* shell_arg_graph=0;
 
16345
  int shell_result;
 
16346
 
 
16347
 
 
16348
  int shell_seen[4];
 
16349
  int shell_index=-1;
 
16350
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16351
                                   { "instream",required_argument,0,1 },
 
16352
                                   { "n",required_argument,0,2 },
 
16353
                                   { "directed",required_argument,0,3 },
 
16354
                                   { "help",no_argument,0,4 },
 
16355
                                   { 0,0,0,0 }
 
16356
                                 };
 
16357
 
 
16358
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16359
  memset(shell_seen, 0, 4*sizeof(int));
 
16360
  shell_seen[2]=2;
 
16361
  shell_seen[3]=2;
 
16362
  
 
16363
  /* Parse arguments and read input */
 
16364
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16365
 
 
16366
    if (shell_index==-1) {
 
16367
      exit(1);
 
16368
    }
 
16369
 
 
16370
    if (shell_seen[shell_index]==1) {
 
16371
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16372
              shell_options[shell_index].name);
 
16373
      exit(1);
 
16374
    }
 
16375
    shell_seen[shell_index]=1;  
 
16376
 
 
16377
    switch (shell_index) {
 
16378
    case 0: /* graph */
 
16379
      shell_arg_graph=strdup(optarg);
 
16380
      break;
 
16381
    case 1: /* instream */
 
16382
      shell_read_file(&instream, optarg, "r");
 
16383
      break;
 
16384
    case 2: /* n */
 
16385
      shell_read_integer(&n, optarg);
 
16386
      break;
 
16387
    case 3: /* directed */
 
16388
      shell_read_boolean(&directed, optarg);
 
16389
      break;
 
16390
    case 4:
 
16391
      shell_igraph_read_graph_edgelist_usage(argv);
 
16392
      break;
 
16393
    default:
 
16394
      break;
 
16395
    }
 
16396
 
 
16397
    shell_index=-1;
 
16398
  }
 
16399
 
 
16400
  /* Check that we have all arguments */
 
16401
  for (shell_index=0; shell_index<4; shell_index++) {
 
16402
    if (!shell_seen[shell_index]) {
 
16403
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16404
              shell_options[shell_index].name);
 
16405
      exit(1);
 
16406
    }
 
16407
  }
 
16408
 
 
16409
  /* Do the operation */
 
16410
  shell_result=igraph_read_graph_edgelist(&graph, instream, n, directed);
 
16411
 
 
16412
  /* Write the result */
 
16413
  shell_write_graph(&graph, shell_arg_graph); 
 
16414
  igraph_destroy(&graph);
 
16415
  fclose(instream);
 
16416
 
 
16417
  return 0;
 
16418
}
 
16419
 
 
16420
/*-------------------------------------------/
 
16421
/ igraph_read_graph_ncol                     /
 
16422
/-------------------------------------------*/
 
16423
void shell_igraph_read_graph_ncol_usage(char **argv) {
 
16424
  printf("%s --graph=<graph> --instream=<instream> --predefnames=<predefnames> --names=<names> --weights=<weights> --directed=<directed>\n", basename(argv[0]));
 
16425
  exit(1);
 
16426
}
 
16427
 
 
16428
int shell_igraph_read_graph_ncol(int argc, char **argv) {
 
16429
 
 
16430
  igraph_t graph;
 
16431
  FILE* instream=0;
 
16432
  igraph_strvector_t v_predefnames; igraph_strvector_t *predefnames=0;;
 
16433
  igraph_bool_t names=1;
 
16434
  igraph_bool_t weights=1;
 
16435
  igraph_bool_t directed=1;
 
16436
  char* shell_arg_graph=0;
 
16437
  int shell_result;
 
16438
 
 
16439
 
 
16440
  int shell_seen[6];
 
16441
  int shell_index=-1;
 
16442
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16443
                                   { "instream",required_argument,0,1 },
 
16444
                                   { "predefnames",required_argument,0,2 },
 
16445
                                   { "names",required_argument,0,3 },
 
16446
                                   { "weights",required_argument,0,4 },
 
16447
                                   { "directed",required_argument,0,5 },
 
16448
                                   { "help",no_argument,0,6 },
 
16449
                                   { 0,0,0,0 }
 
16450
                                 };
 
16451
 
 
16452
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16453
  memset(shell_seen, 0, 6*sizeof(int));
 
16454
  shell_seen[3]=2;
 
16455
  shell_seen[4]=2;
 
16456
  shell_seen[5]=2;
 
16457
  
 
16458
  /* Parse arguments and read input */
 
16459
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16460
 
 
16461
    if (shell_index==-1) {
 
16462
      exit(1);
 
16463
    }
 
16464
 
 
16465
    if (shell_seen[shell_index]==1) {
 
16466
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16467
              shell_options[shell_index].name);
 
16468
      exit(1);
 
16469
    }
 
16470
    shell_seen[shell_index]=1;  
 
16471
 
 
16472
    switch (shell_index) {
 
16473
    case 0: /* graph */
 
16474
      shell_arg_graph=strdup(optarg);
 
16475
      break;
 
16476
    case 1: /* instream */
 
16477
      shell_read_file(&instream, optarg, "r");
 
16478
      break;
 
16479
    case 2: /* predefnames */
 
16480
      predefnames=&v_predefnames; shell_read_strvector(predefnames, optarg);
 
16481
      break;
 
16482
    case 3: /* names */
 
16483
      shell_read_boolean(&names, optarg);
 
16484
      break;
 
16485
    case 4: /* weights */
 
16486
      shell_read_boolean(&weights, optarg);
 
16487
      break;
 
16488
    case 5: /* directed */
 
16489
      shell_read_boolean(&directed, optarg);
 
16490
      break;
 
16491
    case 6:
 
16492
      shell_igraph_read_graph_ncol_usage(argv);
 
16493
      break;
 
16494
    default:
 
16495
      break;
 
16496
    }
 
16497
 
 
16498
    shell_index=-1;
 
16499
  }
 
16500
 
 
16501
  /* Check that we have all arguments */
 
16502
  for (shell_index=0; shell_index<6; shell_index++) {
 
16503
    if (!shell_seen[shell_index]) {
 
16504
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16505
              shell_options[shell_index].name);
 
16506
      exit(1);
 
16507
    }
 
16508
  }
 
16509
 
 
16510
  /* Do the operation */
 
16511
  shell_result=igraph_read_graph_ncol(&graph, instream, predefnames, names, weights, directed);
 
16512
 
 
16513
  /* Write the result */
 
16514
  shell_write_graph(&graph, shell_arg_graph); 
 
16515
  igraph_destroy(&graph);
 
16516
  fclose(instream);
 
16517
  if (predefnames) { igraph_strvector_destroy(predefnames); }
 
16518
 
 
16519
  return 0;
 
16520
}
 
16521
 
 
16522
/*-------------------------------------------/
 
16523
/ igraph_read_graph_lgl                      /
 
16524
/-------------------------------------------*/
 
16525
void shell_igraph_read_graph_lgl_usage(char **argv) {
 
16526
  printf("%s --graph=<graph> --instream=<instream> --names=<names> --weights=<weights>\n", basename(argv[0]));
 
16527
  exit(1);
 
16528
}
 
16529
 
 
16530
int shell_igraph_read_graph_lgl(int argc, char **argv) {
 
16531
 
 
16532
  igraph_t graph;
 
16533
  FILE* instream=0;
 
16534
  igraph_bool_t names=1;
 
16535
  igraph_bool_t weights=1;
 
16536
  char* shell_arg_graph=0;
 
16537
  int shell_result;
 
16538
 
 
16539
 
 
16540
  int shell_seen[4];
 
16541
  int shell_index=-1;
 
16542
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16543
                                   { "instream",required_argument,0,1 },
 
16544
                                   { "names",required_argument,0,2 },
 
16545
                                   { "weights",required_argument,0,3 },
 
16546
                                   { "help",no_argument,0,4 },
 
16547
                                   { 0,0,0,0 }
 
16548
                                 };
 
16549
 
 
16550
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16551
  memset(shell_seen, 0, 4*sizeof(int));
 
16552
  shell_seen[2]=2;
 
16553
  shell_seen[3]=2;
 
16554
  
 
16555
  /* Parse arguments and read input */
 
16556
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16557
 
 
16558
    if (shell_index==-1) {
 
16559
      exit(1);
 
16560
    }
 
16561
 
 
16562
    if (shell_seen[shell_index]==1) {
 
16563
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16564
              shell_options[shell_index].name);
 
16565
      exit(1);
 
16566
    }
 
16567
    shell_seen[shell_index]=1;  
 
16568
 
 
16569
    switch (shell_index) {
 
16570
    case 0: /* graph */
 
16571
      shell_arg_graph=strdup(optarg);
 
16572
      break;
 
16573
    case 1: /* instream */
 
16574
      shell_read_file(&instream, optarg, "r");
 
16575
      break;
 
16576
    case 2: /* names */
 
16577
      shell_read_boolean(&names, optarg);
 
16578
      break;
 
16579
    case 3: /* weights */
 
16580
      shell_read_boolean(&weights, optarg);
 
16581
      break;
 
16582
    case 4:
 
16583
      shell_igraph_read_graph_lgl_usage(argv);
 
16584
      break;
 
16585
    default:
 
16586
      break;
 
16587
    }
 
16588
 
 
16589
    shell_index=-1;
 
16590
  }
 
16591
 
 
16592
  /* Check that we have all arguments */
 
16593
  for (shell_index=0; shell_index<4; shell_index++) {
 
16594
    if (!shell_seen[shell_index]) {
 
16595
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16596
              shell_options[shell_index].name);
 
16597
      exit(1);
 
16598
    }
 
16599
  }
 
16600
 
 
16601
  /* Do the operation */
 
16602
  shell_result=igraph_read_graph_lgl(&graph, instream, names, weights);
 
16603
 
 
16604
  /* Write the result */
 
16605
  shell_write_graph(&graph, shell_arg_graph); 
 
16606
  igraph_destroy(&graph);
 
16607
  fclose(instream);
 
16608
 
 
16609
  return 0;
 
16610
}
 
16611
 
 
16612
/*-------------------------------------------/
 
16613
/ igraph_read_graph_pajek                    /
 
16614
/-------------------------------------------*/
 
16615
void shell_igraph_read_graph_pajek_usage(char **argv) {
 
16616
  printf("%s --graph=<graph> --instream=<instream>\n", basename(argv[0]));
 
16617
  exit(1);
 
16618
}
 
16619
 
 
16620
int shell_igraph_read_graph_pajek(int argc, char **argv) {
 
16621
 
 
16622
  igraph_t graph;
 
16623
  FILE* instream=0;
 
16624
  char* shell_arg_graph=0;
 
16625
  int shell_result;
 
16626
 
 
16627
 
 
16628
  int shell_seen[2];
 
16629
  int shell_index=-1;
 
16630
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16631
                                   { "instream",required_argument,0,1 },
 
16632
                                   { "help",no_argument,0,2 },
 
16633
                                   { 0,0,0,0 }
 
16634
                                 };
 
16635
 
 
16636
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16637
  memset(shell_seen, 0, 2*sizeof(int));
 
16638
 
 
16639
  
 
16640
  /* Parse arguments and read input */
 
16641
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16642
 
 
16643
    if (shell_index==-1) {
 
16644
      exit(1);
 
16645
    }
 
16646
 
 
16647
    if (shell_seen[shell_index]==1) {
 
16648
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16649
              shell_options[shell_index].name);
 
16650
      exit(1);
 
16651
    }
 
16652
    shell_seen[shell_index]=1;  
 
16653
 
 
16654
    switch (shell_index) {
 
16655
    case 0: /* graph */
 
16656
      shell_arg_graph=strdup(optarg);
 
16657
      break;
 
16658
    case 1: /* instream */
 
16659
      shell_read_file(&instream, optarg, "r");
 
16660
      break;
 
16661
    case 2:
 
16662
      shell_igraph_read_graph_pajek_usage(argv);
 
16663
      break;
 
16664
    default:
 
16665
      break;
 
16666
    }
 
16667
 
 
16668
    shell_index=-1;
 
16669
  }
 
16670
 
 
16671
  /* Check that we have all arguments */
 
16672
  for (shell_index=0; shell_index<2; shell_index++) {
 
16673
    if (!shell_seen[shell_index]) {
 
16674
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16675
              shell_options[shell_index].name);
 
16676
      exit(1);
 
16677
    }
 
16678
  }
 
16679
 
 
16680
  /* Do the operation */
 
16681
  shell_result=igraph_read_graph_pajek(&graph, instream);
 
16682
 
 
16683
  /* Write the result */
 
16684
  shell_write_graph(&graph, shell_arg_graph); 
 
16685
  igraph_destroy(&graph);
 
16686
  fclose(instream);
 
16687
 
 
16688
  return 0;
 
16689
}
 
16690
 
 
16691
/*-------------------------------------------/
 
16692
/ igraph_read_graph_graphml                  /
 
16693
/-------------------------------------------*/
 
16694
void shell_igraph_read_graph_graphml_usage(char **argv) {
 
16695
  printf("%s --graph=<graph> --instream=<instream> --index=<index>\n", basename(argv[0]));
 
16696
  exit(1);
 
16697
}
 
16698
 
 
16699
int shell_igraph_read_graph_graphml(int argc, char **argv) {
 
16700
 
 
16701
  igraph_t graph;
 
16702
  FILE* instream=0;
 
16703
  int index=0;
 
16704
  char* shell_arg_graph=0;
 
16705
  int shell_result;
 
16706
 
 
16707
 
 
16708
  int shell_seen[3];
 
16709
  int shell_index=-1;
 
16710
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16711
                                   { "instream",required_argument,0,1 },
 
16712
                                   { "index",required_argument,0,2 },
 
16713
                                   { "help",no_argument,0,3 },
 
16714
                                   { 0,0,0,0 }
 
16715
                                 };
 
16716
 
 
16717
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16718
  memset(shell_seen, 0, 3*sizeof(int));
 
16719
  shell_seen[2]=2;
 
16720
  
 
16721
  /* Parse arguments and read input */
 
16722
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16723
 
 
16724
    if (shell_index==-1) {
 
16725
      exit(1);
 
16726
    }
 
16727
 
 
16728
    if (shell_seen[shell_index]==1) {
 
16729
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16730
              shell_options[shell_index].name);
 
16731
      exit(1);
 
16732
    }
 
16733
    shell_seen[shell_index]=1;  
 
16734
 
 
16735
    switch (shell_index) {
 
16736
    case 0: /* graph */
 
16737
      shell_arg_graph=strdup(optarg);
 
16738
      break;
 
16739
    case 1: /* instream */
 
16740
      shell_read_file(&instream, optarg, "r");
 
16741
      break;
 
16742
    case 2: /* index */
 
16743
      shell_read_int(&index, optarg);
 
16744
      break;
 
16745
    case 3:
 
16746
      shell_igraph_read_graph_graphml_usage(argv);
 
16747
      break;
 
16748
    default:
 
16749
      break;
 
16750
    }
 
16751
 
 
16752
    shell_index=-1;
 
16753
  }
 
16754
 
 
16755
  /* Check that we have all arguments */
 
16756
  for (shell_index=0; shell_index<3; shell_index++) {
 
16757
    if (!shell_seen[shell_index]) {
 
16758
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16759
              shell_options[shell_index].name);
 
16760
      exit(1);
 
16761
    }
 
16762
  }
 
16763
 
 
16764
  /* Do the operation */
 
16765
  shell_result=igraph_read_graph_graphml(&graph, instream, index);
 
16766
 
 
16767
  /* Write the result */
 
16768
  shell_write_graph(&graph, shell_arg_graph); 
 
16769
  igraph_destroy(&graph);
 
16770
  fclose(instream);
 
16771
 
 
16772
  return 0;
 
16773
}
 
16774
 
 
16775
/*-------------------------------------------/
 
16776
/ igraph_read_graph_dimacs                   /
 
16777
/-------------------------------------------*/
 
16778
void shell_igraph_read_graph_dimacs_usage(char **argv) {
 
16779
  printf("%s --graph=<graph> --instream=<instream> --source=<source> --target=<target> --capacity=<capacity> --directed=<directed>\n", basename(argv[0]));
 
16780
  exit(1);
 
16781
}
 
16782
 
 
16783
int shell_igraph_read_graph_dimacs(int argc, char **argv) {
 
16784
 
 
16785
  igraph_t graph;
 
16786
  FILE* instream=0;
 
16787
  igraph_integer_t source;
 
16788
  igraph_integer_t target;
 
16789
  igraph_vector_t capacity;
 
16790
  igraph_bool_t directed=1;
 
16791
  char* shell_arg_graph=0;
 
16792
  char* shell_arg_source=0;
 
16793
  char* shell_arg_target=0;
 
16794
  char* shell_arg_capacity=0;
 
16795
  int shell_result;
 
16796
 
 
16797
 
 
16798
  int shell_seen[6];
 
16799
  int shell_index=-1;
 
16800
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16801
                                   { "instream",required_argument,0,1 },
 
16802
                                   { "source",required_argument,0,2 },
 
16803
                                   { "target",required_argument,0,3 },
 
16804
                                   { "capacity",required_argument,0,4 },
 
16805
                                   { "directed",required_argument,0,5 },
 
16806
                                   { "help",no_argument,0,6 },
 
16807
                                   { 0,0,0,0 }
 
16808
                                 };
 
16809
 
 
16810
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16811
  memset(shell_seen, 0, 6*sizeof(int));
 
16812
  shell_seen[5]=2;
 
16813
  
 
16814
  /* Parse arguments and read input */
 
16815
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16816
 
 
16817
    if (shell_index==-1) {
 
16818
      exit(1);
 
16819
    }
 
16820
 
 
16821
    if (shell_seen[shell_index]==1) {
 
16822
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16823
              shell_options[shell_index].name);
 
16824
      exit(1);
 
16825
    }
 
16826
    shell_seen[shell_index]=1;  
 
16827
 
 
16828
    switch (shell_index) {
 
16829
    case 0: /* graph */
 
16830
      shell_arg_graph=strdup(optarg);
 
16831
      break;
 
16832
    case 1: /* instream */
 
16833
      shell_read_file(&instream, optarg, "r");
 
16834
      break;
 
16835
    case 2: /* source */
 
16836
      shell_arg_source=strdup(optarg);
 
16837
      break;
 
16838
    case 3: /* target */
 
16839
      shell_arg_target=strdup(optarg);
 
16840
      break;
 
16841
    case 4: /* capacity */
 
16842
      shell_arg_capacity=strdup(optarg); 
 
16843
  igraph_vector_init(&capacity, 0);
 
16844
      break;
 
16845
    case 5: /* directed */
 
16846
      shell_read_boolean(&directed, optarg);
 
16847
      break;
 
16848
    case 6:
 
16849
      shell_igraph_read_graph_dimacs_usage(argv);
 
16850
      break;
 
16851
    default:
 
16852
      break;
 
16853
    }
 
16854
 
 
16855
    shell_index=-1;
 
16856
  }
 
16857
 
 
16858
  /* Check that we have all arguments */
 
16859
  for (shell_index=0; shell_index<6; shell_index++) {
 
16860
    if (!shell_seen[shell_index]) {
 
16861
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16862
              shell_options[shell_index].name);
 
16863
      exit(1);
 
16864
    }
 
16865
  }
 
16866
 
 
16867
  /* Do the operation */
 
16868
  shell_result=igraph_read_graph_dimacs(&graph, instream, &source, &target, &capacity, directed);
 
16869
 
 
16870
  /* Write the result */
 
16871
  shell_write_graph(&graph, shell_arg_graph); 
 
16872
  igraph_destroy(&graph);
 
16873
  fclose(instream);
 
16874
  shell_write_integer(source, shell_arg_source);
 
16875
  shell_write_integer(target, shell_arg_target);
 
16876
  shell_write_vector(&capacity, shell_arg_capacity); 
 
16877
  igraph_vector_destroy(&capacity);
 
16878
 
 
16879
  return 0;
 
16880
}
 
16881
 
 
16882
/*-------------------------------------------/
 
16883
/ igraph_read_graph_graphdb                  /
 
16884
/-------------------------------------------*/
 
16885
void shell_igraph_read_graph_graphdb_usage(char **argv) {
 
16886
  printf("%s --graph=<graph> --instream=<instream> --directed=<directed>\n", basename(argv[0]));
 
16887
  exit(1);
 
16888
}
 
16889
 
 
16890
int shell_igraph_read_graph_graphdb(int argc, char **argv) {
 
16891
 
 
16892
  igraph_t graph;
 
16893
  FILE* instream=0;
 
16894
  igraph_bool_t directed=0;
 
16895
  char* shell_arg_graph=0;
 
16896
  int shell_result;
 
16897
 
 
16898
 
 
16899
  int shell_seen[3];
 
16900
  int shell_index=-1;
 
16901
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16902
                                   { "instream",required_argument,0,1 },
 
16903
                                   { "directed",required_argument,0,2 },
 
16904
                                   { "help",no_argument,0,3 },
 
16905
                                   { 0,0,0,0 }
 
16906
                                 };
 
16907
 
 
16908
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16909
  memset(shell_seen, 0, 3*sizeof(int));
 
16910
  shell_seen[2]=2;
 
16911
  
 
16912
  /* Parse arguments and read input */
 
16913
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16914
 
 
16915
    if (shell_index==-1) {
 
16916
      exit(1);
 
16917
    }
 
16918
 
 
16919
    if (shell_seen[shell_index]==1) {
 
16920
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
16921
              shell_options[shell_index].name);
 
16922
      exit(1);
 
16923
    }
 
16924
    shell_seen[shell_index]=1;  
 
16925
 
 
16926
    switch (shell_index) {
 
16927
    case 0: /* graph */
 
16928
      shell_arg_graph=strdup(optarg);
 
16929
      break;
 
16930
    case 1: /* instream */
 
16931
      shell_read_file(&instream, optarg, "r");
 
16932
      break;
 
16933
    case 2: /* directed */
 
16934
      shell_read_boolean(&directed, optarg);
 
16935
      break;
 
16936
    case 3:
 
16937
      shell_igraph_read_graph_graphdb_usage(argv);
 
16938
      break;
 
16939
    default:
 
16940
      break;
 
16941
    }
 
16942
 
 
16943
    shell_index=-1;
 
16944
  }
 
16945
 
 
16946
  /* Check that we have all arguments */
 
16947
  for (shell_index=0; shell_index<3; shell_index++) {
 
16948
    if (!shell_seen[shell_index]) {
 
16949
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
16950
              shell_options[shell_index].name);
 
16951
      exit(1);
 
16952
    }
 
16953
  }
 
16954
 
 
16955
  /* Do the operation */
 
16956
  shell_result=igraph_read_graph_graphdb(&graph, instream, directed);
 
16957
 
 
16958
  /* Write the result */
 
16959
  shell_write_graph(&graph, shell_arg_graph); 
 
16960
  igraph_destroy(&graph);
 
16961
  fclose(instream);
 
16962
 
 
16963
  return 0;
 
16964
}
 
16965
 
 
16966
/*-------------------------------------------/
 
16967
/ igraph_read_graph_gml                      /
 
16968
/-------------------------------------------*/
 
16969
void shell_igraph_read_graph_gml_usage(char **argv) {
 
16970
  printf("%s --graph=<graph> --instream=<instream>\n", basename(argv[0]));
 
16971
  exit(1);
 
16972
}
 
16973
 
 
16974
int shell_igraph_read_graph_gml(int argc, char **argv) {
 
16975
 
 
16976
  igraph_t graph;
 
16977
  FILE* instream=0;
 
16978
  char* shell_arg_graph=0;
 
16979
  int shell_result;
 
16980
 
 
16981
 
 
16982
  int shell_seen[2];
 
16983
  int shell_index=-1;
 
16984
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
16985
                                   { "instream",required_argument,0,1 },
 
16986
                                   { "help",no_argument,0,2 },
 
16987
                                   { 0,0,0,0 }
 
16988
                                 };
 
16989
 
 
16990
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
16991
  memset(shell_seen, 0, 2*sizeof(int));
 
16992
 
 
16993
  
 
16994
  /* Parse arguments and read input */
 
16995
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
16996
 
 
16997
    if (shell_index==-1) {
 
16998
      exit(1);
 
16999
    }
 
17000
 
 
17001
    if (shell_seen[shell_index]==1) {
 
17002
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17003
              shell_options[shell_index].name);
 
17004
      exit(1);
 
17005
    }
 
17006
    shell_seen[shell_index]=1;  
 
17007
 
 
17008
    switch (shell_index) {
 
17009
    case 0: /* graph */
 
17010
      shell_arg_graph=strdup(optarg);
 
17011
      break;
 
17012
    case 1: /* instream */
 
17013
      shell_read_file(&instream, optarg, "r");
 
17014
      break;
 
17015
    case 2:
 
17016
      shell_igraph_read_graph_gml_usage(argv);
 
17017
      break;
 
17018
    default:
 
17019
      break;
 
17020
    }
 
17021
 
 
17022
    shell_index=-1;
 
17023
  }
 
17024
 
 
17025
  /* Check that we have all arguments */
 
17026
  for (shell_index=0; shell_index<2; shell_index++) {
 
17027
    if (!shell_seen[shell_index]) {
 
17028
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17029
              shell_options[shell_index].name);
 
17030
      exit(1);
 
17031
    }
 
17032
  }
 
17033
 
 
17034
  /* Do the operation */
 
17035
  shell_result=igraph_read_graph_gml(&graph, instream);
 
17036
 
 
17037
  /* Write the result */
 
17038
  shell_write_graph(&graph, shell_arg_graph); 
 
17039
  igraph_destroy(&graph);
 
17040
  fclose(instream);
 
17041
 
 
17042
  return 0;
 
17043
}
 
17044
 
 
17045
/*-------------------------------------------/
 
17046
/ igraph_write_graph_edgelist                /
 
17047
/-------------------------------------------*/
 
17048
void shell_igraph_write_graph_edgelist_usage(char **argv) {
 
17049
  printf("%s --graph=<graph> --outstream=<outstream>\n", basename(argv[0]));
 
17050
  exit(1);
 
17051
}
 
17052
 
 
17053
int shell_igraph_write_graph_edgelist(int argc, char **argv) {
 
17054
 
 
17055
  igraph_t graph;
 
17056
  FILE* outstream=0;
 
17057
  int shell_result;
 
17058
 
 
17059
 
 
17060
  int shell_seen[2];
 
17061
  int shell_index=-1;
 
17062
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17063
                                   { "outstream",required_argument,0,1 },
 
17064
                                   { "help",no_argument,0,2 },
 
17065
                                   { 0,0,0,0 }
 
17066
                                 };
 
17067
 
 
17068
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17069
  memset(shell_seen, 0, 2*sizeof(int));
 
17070
 
 
17071
  
 
17072
  /* Parse arguments and read input */
 
17073
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17074
 
 
17075
    if (shell_index==-1) {
 
17076
      exit(1);
 
17077
    }
 
17078
 
 
17079
    if (shell_seen[shell_index]==1) {
 
17080
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17081
              shell_options[shell_index].name);
 
17082
      exit(1);
 
17083
    }
 
17084
    shell_seen[shell_index]=1;  
 
17085
 
 
17086
    switch (shell_index) {
 
17087
    case 0: /* graph */
 
17088
      shell_read_graph(&graph, optarg);
 
17089
      break;
 
17090
    case 1: /* outstream */
 
17091
      shell_read_file(&outstream, optarg, "w");
 
17092
      break;
 
17093
    case 2:
 
17094
      shell_igraph_write_graph_edgelist_usage(argv);
 
17095
      break;
 
17096
    default:
 
17097
      break;
 
17098
    }
 
17099
 
 
17100
    shell_index=-1;
 
17101
  }
 
17102
 
 
17103
  /* Check that we have all arguments */
 
17104
  for (shell_index=0; shell_index<2; shell_index++) {
 
17105
    if (!shell_seen[shell_index]) {
 
17106
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17107
              shell_options[shell_index].name);
 
17108
      exit(1);
 
17109
    }
 
17110
  }
 
17111
 
 
17112
  /* Do the operation */
 
17113
  shell_result=igraph_write_graph_edgelist(&graph, outstream);
 
17114
 
 
17115
  /* Write the result */
 
17116
  igraph_destroy(&graph);
 
17117
  fclose(outstream);
 
17118
 
 
17119
  return 0;
 
17120
}
 
17121
 
 
17122
/*-------------------------------------------/
 
17123
/ igraph_write_graph_ncol                    /
 
17124
/-------------------------------------------*/
 
17125
void shell_igraph_write_graph_ncol_usage(char **argv) {
 
17126
  printf("%s --graph=<graph> --outstream=<outstream> --names=<names> --weights=<weights>\n", basename(argv[0]));
 
17127
  exit(1);
 
17128
}
 
17129
 
 
17130
int shell_igraph_write_graph_ncol(int argc, char **argv) {
 
17131
 
 
17132
  igraph_t graph;
 
17133
  FILE* outstream=0;
 
17134
  char * names="name";
 
17135
  char * weights="weight";
 
17136
  int shell_result;
 
17137
 
 
17138
 
 
17139
  int shell_seen[4];
 
17140
  int shell_index=-1;
 
17141
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17142
                                   { "outstream",required_argument,0,1 },
 
17143
                                   { "names",required_argument,0,2 },
 
17144
                                   { "weights",required_argument,0,3 },
 
17145
                                   { "help",no_argument,0,4 },
 
17146
                                   { 0,0,0,0 }
 
17147
                                 };
 
17148
 
 
17149
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17150
  memset(shell_seen, 0, 4*sizeof(int));
 
17151
  shell_seen[2]=2;
 
17152
  shell_seen[3]=2;
 
17153
  
 
17154
  /* Parse arguments and read input */
 
17155
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17156
 
 
17157
    if (shell_index==-1) {
 
17158
      exit(1);
 
17159
    }
 
17160
 
 
17161
    if (shell_seen[shell_index]==1) {
 
17162
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17163
              shell_options[shell_index].name);
 
17164
      exit(1);
 
17165
    }
 
17166
    shell_seen[shell_index]=1;  
 
17167
 
 
17168
    switch (shell_index) {
 
17169
    case 0: /* graph */
 
17170
      shell_read_graph(&graph, optarg);
 
17171
      break;
 
17172
    case 1: /* outstream */
 
17173
      shell_read_file(&outstream, optarg, "w");
 
17174
      break;
 
17175
    case 2: /* names */
 
17176
      names=strdup(optarg);
 
17177
      break;
 
17178
    case 3: /* weights */
 
17179
      weights=strdup(optarg);
 
17180
      break;
 
17181
    case 4:
 
17182
      shell_igraph_write_graph_ncol_usage(argv);
 
17183
      break;
 
17184
    default:
 
17185
      break;
 
17186
    }
 
17187
 
 
17188
    shell_index=-1;
 
17189
  }
 
17190
 
 
17191
  /* Check that we have all arguments */
 
17192
  for (shell_index=0; shell_index<4; shell_index++) {
 
17193
    if (!shell_seen[shell_index]) {
 
17194
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17195
              shell_options[shell_index].name);
 
17196
      exit(1);
 
17197
    }
 
17198
  }
 
17199
 
 
17200
  /* Do the operation */
 
17201
  shell_result=igraph_write_graph_ncol(&graph, outstream, names, weights);
 
17202
 
 
17203
  /* Write the result */
 
17204
  igraph_destroy(&graph);
 
17205
  fclose(outstream);
 
17206
  free(names);
 
17207
  free(weights);
 
17208
 
 
17209
  return 0;
 
17210
}
 
17211
 
 
17212
/*-------------------------------------------/
 
17213
/ igraph_write_graph_lgl                     /
 
17214
/-------------------------------------------*/
 
17215
void shell_igraph_write_graph_lgl_usage(char **argv) {
 
17216
  printf("%s --graph=<graph> --outstream=<outstream> --names=<names> --weights=<weights> --isolates=<isolates>\n", basename(argv[0]));
 
17217
  exit(1);
 
17218
}
 
17219
 
 
17220
int shell_igraph_write_graph_lgl(int argc, char **argv) {
 
17221
 
 
17222
  igraph_t graph;
 
17223
  FILE* outstream=0;
 
17224
  char * names="name";
 
17225
  char * weights="weight";
 
17226
  igraph_bool_t isolates=1;
 
17227
  int shell_result;
 
17228
 
 
17229
 
 
17230
  int shell_seen[5];
 
17231
  int shell_index=-1;
 
17232
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17233
                                   { "outstream",required_argument,0,1 },
 
17234
                                   { "names",required_argument,0,2 },
 
17235
                                   { "weights",required_argument,0,3 },
 
17236
                                   { "isolates",required_argument,0,4 },
 
17237
                                   { "help",no_argument,0,5 },
 
17238
                                   { 0,0,0,0 }
 
17239
                                 };
 
17240
 
 
17241
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17242
  memset(shell_seen, 0, 5*sizeof(int));
 
17243
  shell_seen[2]=2;
 
17244
  shell_seen[3]=2;
 
17245
  shell_seen[4]=2;
 
17246
  
 
17247
  /* Parse arguments and read input */
 
17248
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17249
 
 
17250
    if (shell_index==-1) {
 
17251
      exit(1);
 
17252
    }
 
17253
 
 
17254
    if (shell_seen[shell_index]==1) {
 
17255
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17256
              shell_options[shell_index].name);
 
17257
      exit(1);
 
17258
    }
 
17259
    shell_seen[shell_index]=1;  
 
17260
 
 
17261
    switch (shell_index) {
 
17262
    case 0: /* graph */
 
17263
      shell_read_graph(&graph, optarg);
 
17264
      break;
 
17265
    case 1: /* outstream */
 
17266
      shell_read_file(&outstream, optarg, "w");
 
17267
      break;
 
17268
    case 2: /* names */
 
17269
      names=strdup(optarg);
 
17270
      break;
 
17271
    case 3: /* weights */
 
17272
      weights=strdup(optarg);
 
17273
      break;
 
17274
    case 4: /* isolates */
 
17275
      shell_read_boolean(&isolates, optarg);
 
17276
      break;
 
17277
    case 5:
 
17278
      shell_igraph_write_graph_lgl_usage(argv);
 
17279
      break;
 
17280
    default:
 
17281
      break;
 
17282
    }
 
17283
 
 
17284
    shell_index=-1;
 
17285
  }
 
17286
 
 
17287
  /* Check that we have all arguments */
 
17288
  for (shell_index=0; shell_index<5; shell_index++) {
 
17289
    if (!shell_seen[shell_index]) {
 
17290
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17291
              shell_options[shell_index].name);
 
17292
      exit(1);
 
17293
    }
 
17294
  }
 
17295
 
 
17296
  /* Do the operation */
 
17297
  shell_result=igraph_write_graph_lgl(&graph, outstream, names, weights, isolates);
 
17298
 
 
17299
  /* Write the result */
 
17300
  igraph_destroy(&graph);
 
17301
  fclose(outstream);
 
17302
  free(names);
 
17303
  free(weights);
 
17304
 
 
17305
  return 0;
 
17306
}
 
17307
 
 
17308
/*-------------------------------------------/
 
17309
/ igraph_write_graph_graphml                 /
 
17310
/-------------------------------------------*/
 
17311
void shell_igraph_write_graph_graphml_usage(char **argv) {
 
17312
  printf("%s --graph=<graph> --outstream=<outstream>\n", basename(argv[0]));
 
17313
  exit(1);
 
17314
}
 
17315
 
 
17316
int shell_igraph_write_graph_graphml(int argc, char **argv) {
 
17317
 
 
17318
  igraph_t graph;
 
17319
  FILE* outstream=0;
 
17320
  int shell_result;
 
17321
 
 
17322
 
 
17323
  int shell_seen[2];
 
17324
  int shell_index=-1;
 
17325
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17326
                                   { "outstream",required_argument,0,1 },
 
17327
                                   { "help",no_argument,0,2 },
 
17328
                                   { 0,0,0,0 }
 
17329
                                 };
 
17330
 
 
17331
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17332
  memset(shell_seen, 0, 2*sizeof(int));
 
17333
 
 
17334
  
 
17335
  /* Parse arguments and read input */
 
17336
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17337
 
 
17338
    if (shell_index==-1) {
 
17339
      exit(1);
 
17340
    }
 
17341
 
 
17342
    if (shell_seen[shell_index]==1) {
 
17343
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17344
              shell_options[shell_index].name);
 
17345
      exit(1);
 
17346
    }
 
17347
    shell_seen[shell_index]=1;  
 
17348
 
 
17349
    switch (shell_index) {
 
17350
    case 0: /* graph */
 
17351
      shell_read_graph(&graph, optarg);
 
17352
      break;
 
17353
    case 1: /* outstream */
 
17354
      shell_read_file(&outstream, optarg, "w");
 
17355
      break;
 
17356
    case 2:
 
17357
      shell_igraph_write_graph_graphml_usage(argv);
 
17358
      break;
 
17359
    default:
 
17360
      break;
 
17361
    }
 
17362
 
 
17363
    shell_index=-1;
 
17364
  }
 
17365
 
 
17366
  /* Check that we have all arguments */
 
17367
  for (shell_index=0; shell_index<2; shell_index++) {
 
17368
    if (!shell_seen[shell_index]) {
 
17369
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17370
              shell_options[shell_index].name);
 
17371
      exit(1);
 
17372
    }
 
17373
  }
 
17374
 
 
17375
  /* Do the operation */
 
17376
  shell_result=igraph_write_graph_graphml(&graph, outstream);
 
17377
 
 
17378
  /* Write the result */
 
17379
  igraph_destroy(&graph);
 
17380
  fclose(outstream);
 
17381
 
 
17382
  return 0;
 
17383
}
 
17384
 
 
17385
/*-------------------------------------------/
 
17386
/ igraph_write_graph_pajek                   /
 
17387
/-------------------------------------------*/
 
17388
void shell_igraph_write_graph_pajek_usage(char **argv) {
 
17389
  printf("%s --graph=<graph> --outstream=<outstream>\n", basename(argv[0]));
 
17390
  exit(1);
 
17391
}
 
17392
 
 
17393
int shell_igraph_write_graph_pajek(int argc, char **argv) {
 
17394
 
 
17395
  igraph_t graph;
 
17396
  FILE* outstream=0;
 
17397
  int shell_result;
 
17398
 
 
17399
 
 
17400
  int shell_seen[2];
 
17401
  int shell_index=-1;
 
17402
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17403
                                   { "outstream",required_argument,0,1 },
 
17404
                                   { "help",no_argument,0,2 },
 
17405
                                   { 0,0,0,0 }
 
17406
                                 };
 
17407
 
 
17408
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17409
  memset(shell_seen, 0, 2*sizeof(int));
 
17410
 
 
17411
  
 
17412
  /* Parse arguments and read input */
 
17413
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17414
 
 
17415
    if (shell_index==-1) {
 
17416
      exit(1);
 
17417
    }
 
17418
 
 
17419
    if (shell_seen[shell_index]==1) {
 
17420
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17421
              shell_options[shell_index].name);
 
17422
      exit(1);
 
17423
    }
 
17424
    shell_seen[shell_index]=1;  
 
17425
 
 
17426
    switch (shell_index) {
 
17427
    case 0: /* graph */
 
17428
      shell_read_graph(&graph, optarg);
 
17429
      break;
 
17430
    case 1: /* outstream */
 
17431
      shell_read_file(&outstream, optarg, "w");
 
17432
      break;
 
17433
    case 2:
 
17434
      shell_igraph_write_graph_pajek_usage(argv);
 
17435
      break;
 
17436
    default:
 
17437
      break;
 
17438
    }
 
17439
 
 
17440
    shell_index=-1;
 
17441
  }
 
17442
 
 
17443
  /* Check that we have all arguments */
 
17444
  for (shell_index=0; shell_index<2; shell_index++) {
 
17445
    if (!shell_seen[shell_index]) {
 
17446
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17447
              shell_options[shell_index].name);
 
17448
      exit(1);
 
17449
    }
 
17450
  }
 
17451
 
 
17452
  /* Do the operation */
 
17453
  shell_result=igraph_write_graph_pajek(&graph, outstream);
 
17454
 
 
17455
  /* Write the result */
 
17456
  igraph_destroy(&graph);
 
17457
  fclose(outstream);
 
17458
 
 
17459
  return 0;
 
17460
}
 
17461
 
 
17462
/*-------------------------------------------/
 
17463
/ igraph_write_graph_dimacs                  /
 
17464
/-------------------------------------------*/
 
17465
void shell_igraph_write_graph_dimacs_usage(char **argv) {
 
17466
  printf("%s --graph=<graph> --outstream=<outstream> --source=<source> --target=<target> --capacity=<capacity>\n", basename(argv[0]));
 
17467
  exit(1);
 
17468
}
 
17469
 
 
17470
int shell_igraph_write_graph_dimacs(int argc, char **argv) {
 
17471
 
 
17472
  igraph_t graph;
 
17473
  FILE* outstream=0;
 
17474
  long int source=0;
 
17475
  long int target=0;
 
17476
  igraph_vector_t capacity;
 
17477
  int shell_result;
 
17478
 
 
17479
 
 
17480
  int shell_seen[5];
 
17481
  int shell_index=-1;
 
17482
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17483
                                   { "outstream",required_argument,0,1 },
 
17484
                                   { "source",required_argument,0,2 },
 
17485
                                   { "target",required_argument,0,3 },
 
17486
                                   { "capacity",required_argument,0,4 },
 
17487
                                   { "help",no_argument,0,5 },
 
17488
                                   { 0,0,0,0 }
 
17489
                                 };
 
17490
 
 
17491
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17492
  memset(shell_seen, 0, 5*sizeof(int));
 
17493
  shell_seen[2]=2;
 
17494
  shell_seen[3]=2;
 
17495
  
 
17496
  /* Parse arguments and read input */
 
17497
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17498
 
 
17499
    if (shell_index==-1) {
 
17500
      exit(1);
 
17501
    }
 
17502
 
 
17503
    if (shell_seen[shell_index]==1) {
 
17504
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17505
              shell_options[shell_index].name);
 
17506
      exit(1);
 
17507
    }
 
17508
    shell_seen[shell_index]=1;  
 
17509
 
 
17510
    switch (shell_index) {
 
17511
    case 0: /* graph */
 
17512
      shell_read_graph(&graph, optarg);
 
17513
      break;
 
17514
    case 1: /* outstream */
 
17515
      shell_read_file(&outstream, optarg, "w");
 
17516
      break;
 
17517
    case 2: /* source */
 
17518
      shell_read_longint(&source, optarg);
 
17519
      break;
 
17520
    case 3: /* target */
 
17521
      shell_read_longint(&target, optarg);
 
17522
      break;
 
17523
    case 4: /* capacity */
 
17524
      shell_read_vector(&capacity, optarg);
 
17525
      break;
 
17526
    case 5:
 
17527
      shell_igraph_write_graph_dimacs_usage(argv);
 
17528
      break;
 
17529
    default:
 
17530
      break;
 
17531
    }
 
17532
 
 
17533
    shell_index=-1;
 
17534
  }
 
17535
 
 
17536
  /* Check that we have all arguments */
 
17537
  for (shell_index=0; shell_index<5; shell_index++) {
 
17538
    if (!shell_seen[shell_index]) {
 
17539
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17540
              shell_options[shell_index].name);
 
17541
      exit(1);
 
17542
    }
 
17543
  }
 
17544
 
 
17545
  /* Do the operation */
 
17546
  shell_result=igraph_write_graph_dimacs(&graph, outstream, source, target, &capacity);
 
17547
 
 
17548
  /* Write the result */
 
17549
  igraph_destroy(&graph);
 
17550
  fclose(outstream);
 
17551
  igraph_vector_destroy(&capacity);
 
17552
 
 
17553
  return 0;
 
17554
}
 
17555
 
 
17556
/*-------------------------------------------/
 
17557
/ igraph_write_graph_gml                     /
 
17558
/-------------------------------------------*/
 
17559
void shell_igraph_write_graph_gml_usage(char **argv) {
 
17560
  printf("%s --graph=<graph> --outstream=<outstream> --id=<id> --creator=<creator>\n", basename(argv[0]));
 
17561
  exit(1);
 
17562
}
 
17563
 
 
17564
int shell_igraph_write_graph_gml(int argc, char **argv) {
 
17565
 
 
17566
  igraph_t graph;
 
17567
  FILE* outstream=0;
 
17568
  igraph_vector_t id;
 
17569
  char * creator="igraph";
 
17570
  int shell_result;
 
17571
 
 
17572
 
 
17573
  int shell_seen[4];
 
17574
  int shell_index=-1;
 
17575
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17576
                                   { "outstream",required_argument,0,1 },
 
17577
                                   { "id",required_argument,0,2 },
 
17578
                                   { "creator",required_argument,0,3 },
 
17579
                                   { "help",no_argument,0,4 },
 
17580
                                   { 0,0,0,0 }
 
17581
                                 };
 
17582
 
 
17583
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17584
  memset(shell_seen, 0, 4*sizeof(int));
 
17585
  shell_seen[3]=2;
 
17586
  
 
17587
  /* Parse arguments and read input */
 
17588
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17589
 
 
17590
    if (shell_index==-1) {
 
17591
      exit(1);
 
17592
    }
 
17593
 
 
17594
    if (shell_seen[shell_index]==1) {
 
17595
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17596
              shell_options[shell_index].name);
 
17597
      exit(1);
 
17598
    }
 
17599
    shell_seen[shell_index]=1;  
 
17600
 
 
17601
    switch (shell_index) {
 
17602
    case 0: /* graph */
 
17603
      shell_read_graph(&graph, optarg);
 
17604
      break;
 
17605
    case 1: /* outstream */
 
17606
      shell_read_file(&outstream, optarg, "w");
 
17607
      break;
 
17608
    case 2: /* id */
 
17609
      shell_read_vector(&id, optarg);
 
17610
      break;
 
17611
    case 3: /* creator */
 
17612
      creator=strdup(optarg);
 
17613
      break;
 
17614
    case 4:
 
17615
      shell_igraph_write_graph_gml_usage(argv);
 
17616
      break;
 
17617
    default:
 
17618
      break;
 
17619
    }
 
17620
 
 
17621
    shell_index=-1;
 
17622
  }
 
17623
 
 
17624
  /* Check that we have all arguments */
 
17625
  for (shell_index=0; shell_index<4; shell_index++) {
 
17626
    if (!shell_seen[shell_index]) {
 
17627
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17628
              shell_options[shell_index].name);
 
17629
      exit(1);
 
17630
    }
 
17631
  }
 
17632
 
 
17633
  /* Do the operation */
 
17634
  shell_result=igraph_write_graph_gml(&graph, outstream, &id, creator);
 
17635
 
 
17636
  /* Write the result */
 
17637
  igraph_destroy(&graph);
 
17638
  fclose(outstream);
 
17639
  igraph_vector_destroy(&id);
 
17640
  free(creator);
 
17641
 
 
17642
  return 0;
 
17643
}
 
17644
 
 
17645
/*-------------------------------------------/
 
17646
/ igraph_write_graph_dot                     /
 
17647
/-------------------------------------------*/
 
17648
void shell_igraph_write_graph_dot_usage(char **argv) {
 
17649
  printf("%s --graph=<graph> --outstream=<outstream>\n", basename(argv[0]));
 
17650
  exit(1);
 
17651
}
 
17652
 
 
17653
int shell_igraph_write_graph_dot(int argc, char **argv) {
 
17654
 
 
17655
  igraph_t graph;
 
17656
  FILE* outstream=0;
 
17657
  int shell_result;
 
17658
 
 
17659
 
 
17660
  int shell_seen[2];
 
17661
  int shell_index=-1;
 
17662
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17663
                                   { "outstream",required_argument,0,1 },
 
17664
                                   { "help",no_argument,0,2 },
 
17665
                                   { 0,0,0,0 }
 
17666
                                 };
 
17667
 
 
17668
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17669
  memset(shell_seen, 0, 2*sizeof(int));
 
17670
 
 
17671
  
 
17672
  /* Parse arguments and read input */
 
17673
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17674
 
 
17675
    if (shell_index==-1) {
 
17676
      exit(1);
 
17677
    }
 
17678
 
 
17679
    if (shell_seen[shell_index]==1) {
 
17680
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17681
              shell_options[shell_index].name);
 
17682
      exit(1);
 
17683
    }
 
17684
    shell_seen[shell_index]=1;  
 
17685
 
 
17686
    switch (shell_index) {
 
17687
    case 0: /* graph */
 
17688
      shell_read_graph(&graph, optarg);
 
17689
      break;
 
17690
    case 1: /* outstream */
 
17691
      shell_read_file(&outstream, optarg, "w");
 
17692
      break;
 
17693
    case 2:
 
17694
      shell_igraph_write_graph_dot_usage(argv);
 
17695
      break;
 
17696
    default:
 
17697
      break;
 
17698
    }
 
17699
 
 
17700
    shell_index=-1;
 
17701
  }
 
17702
 
 
17703
  /* Check that we have all arguments */
 
17704
  for (shell_index=0; shell_index<2; shell_index++) {
 
17705
    if (!shell_seen[shell_index]) {
 
17706
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17707
              shell_options[shell_index].name);
 
17708
      exit(1);
 
17709
    }
 
17710
  }
 
17711
 
 
17712
  /* Do the operation */
 
17713
  shell_result=igraph_write_graph_dot(&graph, outstream);
 
17714
 
 
17715
  /* Write the result */
 
17716
  igraph_destroy(&graph);
 
17717
  fclose(outstream);
 
17718
 
 
17719
  return 0;
 
17720
}
 
17721
 
 
17722
/*-------------------------------------------/
 
17723
/ igraph_motifs_randesu                      /
 
17724
/-------------------------------------------*/
 
17725
void shell_igraph_motifs_randesu_usage(char **argv) {
 
17726
  printf("%s --graph=<graph> --hist=<hist> --size=<size> --cut_prob=<cut_prob>\n", basename(argv[0]));
 
17727
  exit(1);
 
17728
}
 
17729
 
 
17730
int shell_igraph_motifs_randesu(int argc, char **argv) {
 
17731
 
 
17732
  igraph_t graph;
 
17733
  igraph_vector_t hist;
 
17734
  int size=3;
 
17735
  igraph_vector_t cut_prob;
 
17736
  char* shell_arg_hist=0;
 
17737
  int shell_result;
 
17738
 
 
17739
 
 
17740
  int shell_seen[4];
 
17741
  int shell_index=-1;
 
17742
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17743
                                   { "hist",required_argument,0,1 },
 
17744
                                   { "size",required_argument,0,2 },
 
17745
                                   { "cut_prob",required_argument,0,3 },
 
17746
                                   { "help",no_argument,0,4 },
 
17747
                                   { 0,0,0,0 }
 
17748
                                 };
 
17749
 
 
17750
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17751
  memset(shell_seen, 0, 4*sizeof(int));
 
17752
  shell_seen[2]=2;
 
17753
  
 
17754
  /* Parse arguments and read input */
 
17755
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17756
 
 
17757
    if (shell_index==-1) {
 
17758
      exit(1);
 
17759
    }
 
17760
 
 
17761
    if (shell_seen[shell_index]==1) {
 
17762
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17763
              shell_options[shell_index].name);
 
17764
      exit(1);
 
17765
    }
 
17766
    shell_seen[shell_index]=1;  
 
17767
 
 
17768
    switch (shell_index) {
 
17769
    case 0: /* graph */
 
17770
      shell_read_graph(&graph, optarg);
 
17771
      break;
 
17772
    case 1: /* hist */
 
17773
      shell_arg_hist=strdup(optarg); 
 
17774
  igraph_vector_init(&hist, 0);
 
17775
      break;
 
17776
    case 2: /* size */
 
17777
      shell_read_int(&size, optarg);
 
17778
      break;
 
17779
    case 3: /* cut_prob */
 
17780
      shell_read_vector(&cut_prob, optarg);
 
17781
      break;
 
17782
    case 4:
 
17783
      shell_igraph_motifs_randesu_usage(argv);
 
17784
      break;
 
17785
    default:
 
17786
      break;
 
17787
    }
 
17788
 
 
17789
    shell_index=-1;
 
17790
  }
 
17791
 
 
17792
  /* Check that we have all arguments */
 
17793
  for (shell_index=0; shell_index<4; shell_index++) {
 
17794
    if (!shell_seen[shell_index]) {
 
17795
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17796
              shell_options[shell_index].name);
 
17797
      exit(1);
 
17798
    }
 
17799
  }
 
17800
 
 
17801
  /* Do the operation */
 
17802
  shell_result=igraph_motifs_randesu(&graph, &hist, size, &cut_prob);
 
17803
 
 
17804
  /* Write the result */
 
17805
  igraph_destroy(&graph);
 
17806
  shell_write_vector(&hist, shell_arg_hist); 
 
17807
  igraph_vector_destroy(&hist);
 
17808
  igraph_vector_destroy(&cut_prob);
 
17809
 
 
17810
  return 0;
 
17811
}
 
17812
 
 
17813
/*-------------------------------------------/
 
17814
/ igraph_motifs_randesu_estimate             /
 
17815
/-------------------------------------------*/
 
17816
void shell_igraph_motifs_randesu_estimate_usage(char **argv) {
 
17817
  printf("%s --graph=<graph> --est=<est> --size=<size> --cut_prob=<cut_prob> --sample_size=<sample_size> --sample=<sample>\n", basename(argv[0]));
 
17818
  exit(1);
 
17819
}
 
17820
 
 
17821
int shell_igraph_motifs_randesu_estimate(int argc, char **argv) {
 
17822
 
 
17823
  igraph_t graph;
 
17824
  igraph_integer_t est;
 
17825
  int size=3;
 
17826
  igraph_vector_t cut_prob;
 
17827
  igraph_integer_t sample_size;
 
17828
  igraph_vector_t v_sample; igraph_vector_t *sample=0;
 
17829
  char* shell_arg_est=0;
 
17830
  int shell_result;
 
17831
 
 
17832
 
 
17833
  int shell_seen[6];
 
17834
  int shell_index=-1;
 
17835
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17836
                                   { "est",required_argument,0,1 },
 
17837
                                   { "size",required_argument,0,2 },
 
17838
                                   { "cut_prob",required_argument,0,3 },
 
17839
                                   { "sample_size",required_argument,0,4 },
 
17840
                                   { "sample",required_argument,0,5 },
 
17841
                                   { "help",no_argument,0,6 },
 
17842
                                   { 0,0,0,0 }
 
17843
                                 };
 
17844
 
 
17845
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17846
  memset(shell_seen, 0, 6*sizeof(int));
 
17847
  shell_seen[2]=2;
 
17848
  
 
17849
  /* Parse arguments and read input */
 
17850
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17851
 
 
17852
    if (shell_index==-1) {
 
17853
      exit(1);
 
17854
    }
 
17855
 
 
17856
    if (shell_seen[shell_index]==1) {
 
17857
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17858
              shell_options[shell_index].name);
 
17859
      exit(1);
 
17860
    }
 
17861
    shell_seen[shell_index]=1;  
 
17862
 
 
17863
    switch (shell_index) {
 
17864
    case 0: /* graph */
 
17865
      shell_read_graph(&graph, optarg);
 
17866
      break;
 
17867
    case 1: /* est */
 
17868
      shell_arg_est=strdup(optarg);
 
17869
      break;
 
17870
    case 2: /* size */
 
17871
      shell_read_int(&size, optarg);
 
17872
      break;
 
17873
    case 3: /* cut_prob */
 
17874
      shell_read_vector(&cut_prob, optarg);
 
17875
      break;
 
17876
    case 4: /* sample_size */
 
17877
      shell_read_integer(&sample_size, optarg);
 
17878
      break;
 
17879
    case 5: /* sample */
 
17880
      sample=&v_sample; shell_read_vector(sample, optarg);
 
17881
      break;
 
17882
    case 6:
 
17883
      shell_igraph_motifs_randesu_estimate_usage(argv);
 
17884
      break;
 
17885
    default:
 
17886
      break;
 
17887
    }
 
17888
 
 
17889
    shell_index=-1;
 
17890
  }
 
17891
 
 
17892
  /* Check that we have all arguments */
 
17893
  for (shell_index=0; shell_index<6; shell_index++) {
 
17894
    if (!shell_seen[shell_index]) {
 
17895
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17896
              shell_options[shell_index].name);
 
17897
      exit(1);
 
17898
    }
 
17899
  }
 
17900
 
 
17901
  /* Do the operation */
 
17902
  shell_result=igraph_motifs_randesu_estimate(&graph, &est, size, &cut_prob, sample_size, sample);
 
17903
 
 
17904
  /* Write the result */
 
17905
  igraph_destroy(&graph);
 
17906
  shell_write_integer(est, shell_arg_est);
 
17907
  igraph_vector_destroy(&cut_prob);
 
17908
  if (sample) { igraph_vector_destroy(sample); }
 
17909
 
 
17910
  return 0;
 
17911
}
 
17912
 
 
17913
/*-------------------------------------------/
 
17914
/ igraph_motifs_randesu_no                   /
 
17915
/-------------------------------------------*/
 
17916
void shell_igraph_motifs_randesu_no_usage(char **argv) {
 
17917
  printf("%s --graph=<graph> --no=<no> --size=<size> --cut_prob=<cut_prob>\n", basename(argv[0]));
 
17918
  exit(1);
 
17919
}
 
17920
 
 
17921
int shell_igraph_motifs_randesu_no(int argc, char **argv) {
 
17922
 
 
17923
  igraph_t graph;
 
17924
  igraph_integer_t no;
 
17925
  int size=3;
 
17926
  igraph_vector_t cut_prob;
 
17927
  char* shell_arg_no=0;
 
17928
  int shell_result;
 
17929
 
 
17930
 
 
17931
  int shell_seen[4];
 
17932
  int shell_index=-1;
 
17933
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
17934
                                   { "no",required_argument,0,1 },
 
17935
                                   { "size",required_argument,0,2 },
 
17936
                                   { "cut_prob",required_argument,0,3 },
 
17937
                                   { "help",no_argument,0,4 },
 
17938
                                   { 0,0,0,0 }
 
17939
                                 };
 
17940
 
 
17941
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
17942
  memset(shell_seen, 0, 4*sizeof(int));
 
17943
  shell_seen[2]=2;
 
17944
  
 
17945
  /* Parse arguments and read input */
 
17946
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
17947
 
 
17948
    if (shell_index==-1) {
 
17949
      exit(1);
 
17950
    }
 
17951
 
 
17952
    if (shell_seen[shell_index]==1) {
 
17953
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
17954
              shell_options[shell_index].name);
 
17955
      exit(1);
 
17956
    }
 
17957
    shell_seen[shell_index]=1;  
 
17958
 
 
17959
    switch (shell_index) {
 
17960
    case 0: /* graph */
 
17961
      shell_read_graph(&graph, optarg);
 
17962
      break;
 
17963
    case 1: /* no */
 
17964
      shell_arg_no=strdup(optarg);
 
17965
      break;
 
17966
    case 2: /* size */
 
17967
      shell_read_int(&size, optarg);
 
17968
      break;
 
17969
    case 3: /* cut_prob */
 
17970
      shell_read_vector(&cut_prob, optarg);
 
17971
      break;
 
17972
    case 4:
 
17973
      shell_igraph_motifs_randesu_no_usage(argv);
 
17974
      break;
 
17975
    default:
 
17976
      break;
 
17977
    }
 
17978
 
 
17979
    shell_index=-1;
 
17980
  }
 
17981
 
 
17982
  /* Check that we have all arguments */
 
17983
  for (shell_index=0; shell_index<4; shell_index++) {
 
17984
    if (!shell_seen[shell_index]) {
 
17985
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
17986
              shell_options[shell_index].name);
 
17987
      exit(1);
 
17988
    }
 
17989
  }
 
17990
 
 
17991
  /* Do the operation */
 
17992
  shell_result=igraph_motifs_randesu_no(&graph, &no, size, &cut_prob);
 
17993
 
 
17994
  /* Write the result */
 
17995
  igraph_destroy(&graph);
 
17996
  shell_write_integer(no, shell_arg_no);
 
17997
  igraph_vector_destroy(&cut_prob);
 
17998
 
 
17999
  return 0;
 
18000
}
 
18001
 
 
18002
/*-------------------------------------------/
 
18003
/ igraph_dyad_census                         /
 
18004
/-------------------------------------------*/
 
18005
void shell_igraph_dyad_census_usage(char **argv) {
 
18006
  printf("%s --graph=<graph> --mut=<mut> --asym=<asym> --null=<null>\n", basename(argv[0]));
 
18007
  exit(1);
 
18008
}
 
18009
 
 
18010
int shell_igraph_dyad_census(int argc, char **argv) {
 
18011
 
 
18012
  igraph_t graph;
 
18013
  igraph_integer_t mut;
 
18014
  igraph_integer_t asym;
 
18015
  igraph_integer_t null;
 
18016
  char* shell_arg_mut=0;
 
18017
  char* shell_arg_asym=0;
 
18018
  char* shell_arg_null=0;
 
18019
  int shell_result;
 
18020
 
 
18021
 
 
18022
  int shell_seen[4];
 
18023
  int shell_index=-1;
 
18024
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
18025
                                   { "mut",required_argument,0,1 },
 
18026
                                   { "asym",required_argument,0,2 },
 
18027
                                   { "null",required_argument,0,3 },
 
18028
                                   { "help",no_argument,0,4 },
 
18029
                                   { 0,0,0,0 }
 
18030
                                 };
 
18031
 
 
18032
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18033
  memset(shell_seen, 0, 4*sizeof(int));
 
18034
 
 
18035
  
 
18036
  /* Parse arguments and read input */
 
18037
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18038
 
 
18039
    if (shell_index==-1) {
 
18040
      exit(1);
 
18041
    }
 
18042
 
 
18043
    if (shell_seen[shell_index]==1) {
 
18044
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18045
              shell_options[shell_index].name);
 
18046
      exit(1);
 
18047
    }
 
18048
    shell_seen[shell_index]=1;  
 
18049
 
 
18050
    switch (shell_index) {
 
18051
    case 0: /* graph */
 
18052
      shell_read_graph(&graph, optarg);
 
18053
      break;
 
18054
    case 1: /* mut */
 
18055
      shell_arg_mut=strdup(optarg);
 
18056
      break;
 
18057
    case 2: /* asym */
 
18058
      shell_arg_asym=strdup(optarg);
 
18059
      break;
 
18060
    case 3: /* null */
 
18061
      shell_arg_null=strdup(optarg);
 
18062
      break;
 
18063
    case 4:
 
18064
      shell_igraph_dyad_census_usage(argv);
 
18065
      break;
 
18066
    default:
 
18067
      break;
 
18068
    }
 
18069
 
 
18070
    shell_index=-1;
 
18071
  }
 
18072
 
 
18073
  /* Check that we have all arguments */
 
18074
  for (shell_index=0; shell_index<4; shell_index++) {
 
18075
    if (!shell_seen[shell_index]) {
 
18076
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18077
              shell_options[shell_index].name);
 
18078
      exit(1);
 
18079
    }
 
18080
  }
 
18081
 
 
18082
  /* Do the operation */
 
18083
  shell_result=igraph_dyad_census(&graph, &mut, &asym, &null);
 
18084
 
 
18085
  /* Write the result */
 
18086
  igraph_destroy(&graph);
 
18087
  shell_write_integer(mut, shell_arg_mut);
 
18088
  shell_write_integer(asym, shell_arg_asym);
 
18089
  shell_write_integer(null, shell_arg_null);
 
18090
 
 
18091
  return 0;
 
18092
}
 
18093
 
 
18094
/*-------------------------------------------/
 
18095
/ igraph_triad_census                        /
 
18096
/-------------------------------------------*/
 
18097
void shell_igraph_triad_census_usage(char **argv) {
 
18098
  printf("%s --graph=<graph> --res=<res>\n", basename(argv[0]));
 
18099
  exit(1);
 
18100
}
 
18101
 
 
18102
int shell_igraph_triad_census(int argc, char **argv) {
 
18103
 
 
18104
  igraph_t graph;
 
18105
  igraph_vector_t res;
 
18106
  char* shell_arg_res=0;
 
18107
  int shell_result;
 
18108
 
 
18109
 
 
18110
  int shell_seen[2];
 
18111
  int shell_index=-1;
 
18112
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
18113
                                   { "res",required_argument,0,1 },
 
18114
                                   { "help",no_argument,0,2 },
 
18115
                                   { 0,0,0,0 }
 
18116
                                 };
 
18117
 
 
18118
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18119
  memset(shell_seen, 0, 2*sizeof(int));
 
18120
 
 
18121
  
 
18122
  /* Parse arguments and read input */
 
18123
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18124
 
 
18125
    if (shell_index==-1) {
 
18126
      exit(1);
 
18127
    }
 
18128
 
 
18129
    if (shell_seen[shell_index]==1) {
 
18130
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18131
              shell_options[shell_index].name);
 
18132
      exit(1);
 
18133
    }
 
18134
    shell_seen[shell_index]=1;  
 
18135
 
 
18136
    switch (shell_index) {
 
18137
    case 0: /* graph */
 
18138
      shell_read_graph(&graph, optarg);
 
18139
      break;
 
18140
    case 1: /* res */
 
18141
      shell_arg_res=strdup(optarg); 
 
18142
  igraph_vector_init(&res, 0);
 
18143
      break;
 
18144
    case 2:
 
18145
      shell_igraph_triad_census_usage(argv);
 
18146
      break;
 
18147
    default:
 
18148
      break;
 
18149
    }
 
18150
 
 
18151
    shell_index=-1;
 
18152
  }
 
18153
 
 
18154
  /* Check that we have all arguments */
 
18155
  for (shell_index=0; shell_index<2; shell_index++) {
 
18156
    if (!shell_seen[shell_index]) {
 
18157
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18158
              shell_options[shell_index].name);
 
18159
      exit(1);
 
18160
    }
 
18161
  }
 
18162
 
 
18163
  /* Do the operation */
 
18164
  shell_result=igraph_triad_census(&graph, &res);
 
18165
 
 
18166
  /* Write the result */
 
18167
  igraph_destroy(&graph);
 
18168
  shell_write_vector(&res, shell_arg_res); 
 
18169
  igraph_vector_destroy(&res);
 
18170
 
 
18171
  return 0;
 
18172
}
 
18173
 
 
18174
/*-------------------------------------------/
 
18175
/ igraph_disjoint_union                      /
 
18176
/-------------------------------------------*/
 
18177
void shell_igraph_disjoint_union_usage(char **argv) {
 
18178
  printf("%s --res=<res> --left=<left> --right=<right>\n", basename(argv[0]));
 
18179
  exit(1);
 
18180
}
 
18181
 
 
18182
int shell_igraph_disjoint_union(int argc, char **argv) {
 
18183
 
 
18184
  igraph_t res;
 
18185
  igraph_t left;
 
18186
  igraph_t right;
 
18187
  char* shell_arg_res=0;
 
18188
  int shell_result;
 
18189
 
 
18190
 
 
18191
  int shell_seen[3];
 
18192
  int shell_index=-1;
 
18193
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18194
                                   { "left",required_argument,0,1 },
 
18195
                                   { "right",required_argument,0,2 },
 
18196
                                   { "help",no_argument,0,3 },
 
18197
                                   { 0,0,0,0 }
 
18198
                                 };
 
18199
 
 
18200
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18201
  memset(shell_seen, 0, 3*sizeof(int));
 
18202
 
 
18203
  
 
18204
  /* Parse arguments and read input */
 
18205
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18206
 
 
18207
    if (shell_index==-1) {
 
18208
      exit(1);
 
18209
    }
 
18210
 
 
18211
    if (shell_seen[shell_index]==1) {
 
18212
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18213
              shell_options[shell_index].name);
 
18214
      exit(1);
 
18215
    }
 
18216
    shell_seen[shell_index]=1;  
 
18217
 
 
18218
    switch (shell_index) {
 
18219
    case 0: /* res */
 
18220
      shell_arg_res=strdup(optarg);
 
18221
      break;
 
18222
    case 1: /* left */
 
18223
      shell_read_graph(&left, optarg);
 
18224
      break;
 
18225
    case 2: /* right */
 
18226
      shell_read_graph(&right, optarg);
 
18227
      break;
 
18228
    case 3:
 
18229
      shell_igraph_disjoint_union_usage(argv);
 
18230
      break;
 
18231
    default:
 
18232
      break;
 
18233
    }
 
18234
 
 
18235
    shell_index=-1;
 
18236
  }
 
18237
 
 
18238
  /* Check that we have all arguments */
 
18239
  for (shell_index=0; shell_index<3; shell_index++) {
 
18240
    if (!shell_seen[shell_index]) {
 
18241
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18242
              shell_options[shell_index].name);
 
18243
      exit(1);
 
18244
    }
 
18245
  }
 
18246
 
 
18247
  /* Do the operation */
 
18248
  shell_result=igraph_disjoint_union(&res, &left, &right);
 
18249
 
 
18250
  /* Write the result */
 
18251
  shell_write_graph(&res, shell_arg_res); 
 
18252
  igraph_destroy(&res);
 
18253
  igraph_destroy(&left);
 
18254
  igraph_destroy(&right);
 
18255
 
 
18256
  return 0;
 
18257
}
 
18258
 
 
18259
/*-------------------------------------------/
 
18260
/ igraph_disjoint_union_many                 /
 
18261
/-------------------------------------------*/
 
18262
void shell_igraph_disjoint_union_many_usage(char **argv) {
 
18263
  printf("%s --res=<res> --graphs=<graphs>\n", basename(argv[0]));
 
18264
  exit(1);
 
18265
}
 
18266
 
 
18267
int shell_igraph_disjoint_union_many(int argc, char **argv) {
 
18268
 
 
18269
  igraph_t res;
 
18270
  igraph_vector_ptr_t graphs;
 
18271
  char* shell_arg_res=0;
 
18272
  int shell_result;
 
18273
 
 
18274
 
 
18275
  int shell_seen[2];
 
18276
  int shell_index=-1;
 
18277
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18278
                                   { "graphs",required_argument,0,1 },
 
18279
                                   { "help",no_argument,0,2 },
 
18280
                                   { 0,0,0,0 }
 
18281
                                 };
 
18282
 
 
18283
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18284
  memset(shell_seen, 0, 2*sizeof(int));
 
18285
 
 
18286
  
 
18287
  /* Parse arguments and read input */
 
18288
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18289
 
 
18290
    if (shell_index==-1) {
 
18291
      exit(1);
 
18292
    }
 
18293
 
 
18294
    if (shell_seen[shell_index]==1) {
 
18295
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18296
              shell_options[shell_index].name);
 
18297
      exit(1);
 
18298
    }
 
18299
    shell_seen[shell_index]=1;  
 
18300
 
 
18301
    switch (shell_index) {
 
18302
    case 0: /* res */
 
18303
      shell_arg_res=strdup(optarg);
 
18304
      break;
 
18305
    case 1: /* graphs */
 
18306
      shell_read_graphlist(&graphs, optarg);
 
18307
      break;
 
18308
    case 2:
 
18309
      shell_igraph_disjoint_union_many_usage(argv);
 
18310
      break;
 
18311
    default:
 
18312
      break;
 
18313
    }
 
18314
 
 
18315
    shell_index=-1;
 
18316
  }
 
18317
 
 
18318
  /* Check that we have all arguments */
 
18319
  for (shell_index=0; shell_index<2; shell_index++) {
 
18320
    if (!shell_seen[shell_index]) {
 
18321
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18322
              shell_options[shell_index].name);
 
18323
      exit(1);
 
18324
    }
 
18325
  }
 
18326
 
 
18327
  /* Do the operation */
 
18328
  shell_result=igraph_disjoint_union_many(&res, &graphs);
 
18329
 
 
18330
  /* Write the result */
 
18331
  shell_write_graph(&res, shell_arg_res); 
 
18332
  igraph_destroy(&res);
 
18333
  shell_free_graphlist(&graphs); 
 
18334
  igraph_vector_ptr_destroy(&graphs);
 
18335
 
 
18336
  return 0;
 
18337
}
 
18338
 
 
18339
/*-------------------------------------------/
 
18340
/ igraph_union                               /
 
18341
/-------------------------------------------*/
 
18342
void shell_igraph_union_usage(char **argv) {
 
18343
  printf("%s --res=<res> --left=<left> --right=<right>\n", basename(argv[0]));
 
18344
  exit(1);
 
18345
}
 
18346
 
 
18347
int shell_igraph_union(int argc, char **argv) {
 
18348
 
 
18349
  igraph_t res;
 
18350
  igraph_t left;
 
18351
  igraph_t right;
 
18352
  char* shell_arg_res=0;
 
18353
  int shell_result;
 
18354
 
 
18355
 
 
18356
  int shell_seen[3];
 
18357
  int shell_index=-1;
 
18358
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18359
                                   { "left",required_argument,0,1 },
 
18360
                                   { "right",required_argument,0,2 },
 
18361
                                   { "help",no_argument,0,3 },
 
18362
                                   { 0,0,0,0 }
 
18363
                                 };
 
18364
 
 
18365
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18366
  memset(shell_seen, 0, 3*sizeof(int));
 
18367
 
 
18368
  
 
18369
  /* Parse arguments and read input */
 
18370
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18371
 
 
18372
    if (shell_index==-1) {
 
18373
      exit(1);
 
18374
    }
 
18375
 
 
18376
    if (shell_seen[shell_index]==1) {
 
18377
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18378
              shell_options[shell_index].name);
 
18379
      exit(1);
 
18380
    }
 
18381
    shell_seen[shell_index]=1;  
 
18382
 
 
18383
    switch (shell_index) {
 
18384
    case 0: /* res */
 
18385
      shell_arg_res=strdup(optarg);
 
18386
      break;
 
18387
    case 1: /* left */
 
18388
      shell_read_graph(&left, optarg);
 
18389
      break;
 
18390
    case 2: /* right */
 
18391
      shell_read_graph(&right, optarg);
 
18392
      break;
 
18393
    case 3:
 
18394
      shell_igraph_union_usage(argv);
 
18395
      break;
 
18396
    default:
 
18397
      break;
 
18398
    }
 
18399
 
 
18400
    shell_index=-1;
 
18401
  }
 
18402
 
 
18403
  /* Check that we have all arguments */
 
18404
  for (shell_index=0; shell_index<3; shell_index++) {
 
18405
    if (!shell_seen[shell_index]) {
 
18406
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18407
              shell_options[shell_index].name);
 
18408
      exit(1);
 
18409
    }
 
18410
  }
 
18411
 
 
18412
  /* Do the operation */
 
18413
  shell_result=igraph_union(&res, &left, &right);
 
18414
 
 
18415
  /* Write the result */
 
18416
  shell_write_graph(&res, shell_arg_res); 
 
18417
  igraph_destroy(&res);
 
18418
  igraph_destroy(&left);
 
18419
  igraph_destroy(&right);
 
18420
 
 
18421
  return 0;
 
18422
}
 
18423
 
 
18424
/*-------------------------------------------/
 
18425
/ igraph_union_many                          /
 
18426
/-------------------------------------------*/
 
18427
void shell_igraph_union_many_usage(char **argv) {
 
18428
  printf("%s --res=<res> --graphs=<graphs>\n", basename(argv[0]));
 
18429
  exit(1);
 
18430
}
 
18431
 
 
18432
int shell_igraph_union_many(int argc, char **argv) {
 
18433
 
 
18434
  igraph_t res;
 
18435
  igraph_vector_ptr_t graphs;
 
18436
  char* shell_arg_res=0;
 
18437
  int shell_result;
 
18438
 
 
18439
 
 
18440
  int shell_seen[2];
 
18441
  int shell_index=-1;
 
18442
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18443
                                   { "graphs",required_argument,0,1 },
 
18444
                                   { "help",no_argument,0,2 },
 
18445
                                   { 0,0,0,0 }
 
18446
                                 };
 
18447
 
 
18448
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18449
  memset(shell_seen, 0, 2*sizeof(int));
 
18450
 
 
18451
  
 
18452
  /* Parse arguments and read input */
 
18453
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18454
 
 
18455
    if (shell_index==-1) {
 
18456
      exit(1);
 
18457
    }
 
18458
 
 
18459
    if (shell_seen[shell_index]==1) {
 
18460
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18461
              shell_options[shell_index].name);
 
18462
      exit(1);
 
18463
    }
 
18464
    shell_seen[shell_index]=1;  
 
18465
 
 
18466
    switch (shell_index) {
 
18467
    case 0: /* res */
 
18468
      shell_arg_res=strdup(optarg);
 
18469
      break;
 
18470
    case 1: /* graphs */
 
18471
      shell_read_graphlist(&graphs, optarg);
 
18472
      break;
 
18473
    case 2:
 
18474
      shell_igraph_union_many_usage(argv);
 
18475
      break;
 
18476
    default:
 
18477
      break;
 
18478
    }
 
18479
 
 
18480
    shell_index=-1;
 
18481
  }
 
18482
 
 
18483
  /* Check that we have all arguments */
 
18484
  for (shell_index=0; shell_index<2; shell_index++) {
 
18485
    if (!shell_seen[shell_index]) {
 
18486
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18487
              shell_options[shell_index].name);
 
18488
      exit(1);
 
18489
    }
 
18490
  }
 
18491
 
 
18492
  /* Do the operation */
 
18493
  shell_result=igraph_union_many(&res, &graphs);
 
18494
 
 
18495
  /* Write the result */
 
18496
  shell_write_graph(&res, shell_arg_res); 
 
18497
  igraph_destroy(&res);
 
18498
  shell_free_graphlist(&graphs); 
 
18499
  igraph_vector_ptr_destroy(&graphs);
 
18500
 
 
18501
  return 0;
 
18502
}
 
18503
 
 
18504
/*-------------------------------------------/
 
18505
/ igraph_intersection                        /
 
18506
/-------------------------------------------*/
 
18507
void shell_igraph_intersection_usage(char **argv) {
 
18508
  printf("%s --res=<res> --left=<left> --right=<right>\n", basename(argv[0]));
 
18509
  exit(1);
 
18510
}
 
18511
 
 
18512
int shell_igraph_intersection(int argc, char **argv) {
 
18513
 
 
18514
  igraph_t res;
 
18515
  igraph_t left;
 
18516
  igraph_t right;
 
18517
  char* shell_arg_res=0;
 
18518
  int shell_result;
 
18519
 
 
18520
 
 
18521
  int shell_seen[3];
 
18522
  int shell_index=-1;
 
18523
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18524
                                   { "left",required_argument,0,1 },
 
18525
                                   { "right",required_argument,0,2 },
 
18526
                                   { "help",no_argument,0,3 },
 
18527
                                   { 0,0,0,0 }
 
18528
                                 };
 
18529
 
 
18530
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18531
  memset(shell_seen, 0, 3*sizeof(int));
 
18532
 
 
18533
  
 
18534
  /* Parse arguments and read input */
 
18535
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18536
 
 
18537
    if (shell_index==-1) {
 
18538
      exit(1);
 
18539
    }
 
18540
 
 
18541
    if (shell_seen[shell_index]==1) {
 
18542
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18543
              shell_options[shell_index].name);
 
18544
      exit(1);
 
18545
    }
 
18546
    shell_seen[shell_index]=1;  
 
18547
 
 
18548
    switch (shell_index) {
 
18549
    case 0: /* res */
 
18550
      shell_arg_res=strdup(optarg);
 
18551
      break;
 
18552
    case 1: /* left */
 
18553
      shell_read_graph(&left, optarg);
 
18554
      break;
 
18555
    case 2: /* right */
 
18556
      shell_read_graph(&right, optarg);
 
18557
      break;
 
18558
    case 3:
 
18559
      shell_igraph_intersection_usage(argv);
 
18560
      break;
 
18561
    default:
 
18562
      break;
 
18563
    }
 
18564
 
 
18565
    shell_index=-1;
 
18566
  }
 
18567
 
 
18568
  /* Check that we have all arguments */
 
18569
  for (shell_index=0; shell_index<3; shell_index++) {
 
18570
    if (!shell_seen[shell_index]) {
 
18571
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18572
              shell_options[shell_index].name);
 
18573
      exit(1);
 
18574
    }
 
18575
  }
 
18576
 
 
18577
  /* Do the operation */
 
18578
  shell_result=igraph_intersection(&res, &left, &right);
 
18579
 
 
18580
  /* Write the result */
 
18581
  shell_write_graph(&res, shell_arg_res); 
 
18582
  igraph_destroy(&res);
 
18583
  igraph_destroy(&left);
 
18584
  igraph_destroy(&right);
 
18585
 
 
18586
  return 0;
 
18587
}
 
18588
 
 
18589
/*-------------------------------------------/
 
18590
/ igraph_intersection_many                   /
 
18591
/-------------------------------------------*/
 
18592
void shell_igraph_intersection_many_usage(char **argv) {
 
18593
  printf("%s --res=<res> --graphs=<graphs>\n", basename(argv[0]));
 
18594
  exit(1);
 
18595
}
 
18596
 
 
18597
int shell_igraph_intersection_many(int argc, char **argv) {
 
18598
 
 
18599
  igraph_t res;
 
18600
  igraph_vector_ptr_t graphs;
 
18601
  char* shell_arg_res=0;
 
18602
  int shell_result;
 
18603
 
 
18604
 
 
18605
  int shell_seen[2];
 
18606
  int shell_index=-1;
 
18607
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18608
                                   { "graphs",required_argument,0,1 },
 
18609
                                   { "help",no_argument,0,2 },
 
18610
                                   { 0,0,0,0 }
 
18611
                                 };
 
18612
 
 
18613
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18614
  memset(shell_seen, 0, 2*sizeof(int));
 
18615
 
 
18616
  
 
18617
  /* Parse arguments and read input */
 
18618
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18619
 
 
18620
    if (shell_index==-1) {
 
18621
      exit(1);
 
18622
    }
 
18623
 
 
18624
    if (shell_seen[shell_index]==1) {
 
18625
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18626
              shell_options[shell_index].name);
 
18627
      exit(1);
 
18628
    }
 
18629
    shell_seen[shell_index]=1;  
 
18630
 
 
18631
    switch (shell_index) {
 
18632
    case 0: /* res */
 
18633
      shell_arg_res=strdup(optarg);
 
18634
      break;
 
18635
    case 1: /* graphs */
 
18636
      shell_read_graphlist(&graphs, optarg);
 
18637
      break;
 
18638
    case 2:
 
18639
      shell_igraph_intersection_many_usage(argv);
 
18640
      break;
 
18641
    default:
 
18642
      break;
 
18643
    }
 
18644
 
 
18645
    shell_index=-1;
 
18646
  }
 
18647
 
 
18648
  /* Check that we have all arguments */
 
18649
  for (shell_index=0; shell_index<2; shell_index++) {
 
18650
    if (!shell_seen[shell_index]) {
 
18651
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18652
              shell_options[shell_index].name);
 
18653
      exit(1);
 
18654
    }
 
18655
  }
 
18656
 
 
18657
  /* Do the operation */
 
18658
  shell_result=igraph_intersection_many(&res, &graphs);
 
18659
 
 
18660
  /* Write the result */
 
18661
  shell_write_graph(&res, shell_arg_res); 
 
18662
  igraph_destroy(&res);
 
18663
  shell_free_graphlist(&graphs); 
 
18664
  igraph_vector_ptr_destroy(&graphs);
 
18665
 
 
18666
  return 0;
 
18667
}
 
18668
 
 
18669
/*-------------------------------------------/
 
18670
/ igraph_difference                          /
 
18671
/-------------------------------------------*/
 
18672
void shell_igraph_difference_usage(char **argv) {
 
18673
  printf("%s --res=<res> --orig=<orig> --sub=<sub>\n", basename(argv[0]));
 
18674
  exit(1);
 
18675
}
 
18676
 
 
18677
int shell_igraph_difference(int argc, char **argv) {
 
18678
 
 
18679
  igraph_t res;
 
18680
  igraph_t orig;
 
18681
  igraph_t sub;
 
18682
  char* shell_arg_res=0;
 
18683
  int shell_result;
 
18684
 
 
18685
 
 
18686
  int shell_seen[3];
 
18687
  int shell_index=-1;
 
18688
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18689
                                   { "orig",required_argument,0,1 },
 
18690
                                   { "sub",required_argument,0,2 },
 
18691
                                   { "help",no_argument,0,3 },
 
18692
                                   { 0,0,0,0 }
 
18693
                                 };
 
18694
 
 
18695
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18696
  memset(shell_seen, 0, 3*sizeof(int));
 
18697
 
 
18698
  
 
18699
  /* Parse arguments and read input */
 
18700
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18701
 
 
18702
    if (shell_index==-1) {
 
18703
      exit(1);
 
18704
    }
 
18705
 
 
18706
    if (shell_seen[shell_index]==1) {
 
18707
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18708
              shell_options[shell_index].name);
 
18709
      exit(1);
 
18710
    }
 
18711
    shell_seen[shell_index]=1;  
 
18712
 
 
18713
    switch (shell_index) {
 
18714
    case 0: /* res */
 
18715
      shell_arg_res=strdup(optarg);
 
18716
      break;
 
18717
    case 1: /* orig */
 
18718
      shell_read_graph(&orig, optarg);
 
18719
      break;
 
18720
    case 2: /* sub */
 
18721
      shell_read_graph(&sub, optarg);
 
18722
      break;
 
18723
    case 3:
 
18724
      shell_igraph_difference_usage(argv);
 
18725
      break;
 
18726
    default:
 
18727
      break;
 
18728
    }
 
18729
 
 
18730
    shell_index=-1;
 
18731
  }
 
18732
 
 
18733
  /* Check that we have all arguments */
 
18734
  for (shell_index=0; shell_index<3; shell_index++) {
 
18735
    if (!shell_seen[shell_index]) {
 
18736
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18737
              shell_options[shell_index].name);
 
18738
      exit(1);
 
18739
    }
 
18740
  }
 
18741
 
 
18742
  /* Do the operation */
 
18743
  shell_result=igraph_difference(&res, &orig, &sub);
 
18744
 
 
18745
  /* Write the result */
 
18746
  shell_write_graph(&res, shell_arg_res); 
 
18747
  igraph_destroy(&res);
 
18748
  igraph_destroy(&orig);
 
18749
  igraph_destroy(&sub);
 
18750
 
 
18751
  return 0;
 
18752
}
 
18753
 
 
18754
/*-------------------------------------------/
 
18755
/ igraph_complementer                        /
 
18756
/-------------------------------------------*/
 
18757
void shell_igraph_complementer_usage(char **argv) {
 
18758
  printf("%s --res=<res> --graph=<graph> --loops=<loops>\n", basename(argv[0]));
 
18759
  exit(1);
 
18760
}
 
18761
 
 
18762
int shell_igraph_complementer(int argc, char **argv) {
 
18763
 
 
18764
  igraph_t res;
 
18765
  igraph_t graph;
 
18766
  igraph_bool_t loops=0;
 
18767
  char* shell_arg_res=0;
 
18768
  int shell_result;
 
18769
 
 
18770
 
 
18771
  int shell_seen[3];
 
18772
  int shell_index=-1;
 
18773
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18774
                                   { "graph",required_argument,0,1 },
 
18775
                                   { "loops",required_argument,0,2 },
 
18776
                                   { "help",no_argument,0,3 },
 
18777
                                   { 0,0,0,0 }
 
18778
                                 };
 
18779
 
 
18780
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18781
  memset(shell_seen, 0, 3*sizeof(int));
 
18782
  shell_seen[2]=2;
 
18783
  
 
18784
  /* Parse arguments and read input */
 
18785
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18786
 
 
18787
    if (shell_index==-1) {
 
18788
      exit(1);
 
18789
    }
 
18790
 
 
18791
    if (shell_seen[shell_index]==1) {
 
18792
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18793
              shell_options[shell_index].name);
 
18794
      exit(1);
 
18795
    }
 
18796
    shell_seen[shell_index]=1;  
 
18797
 
 
18798
    switch (shell_index) {
 
18799
    case 0: /* res */
 
18800
      shell_arg_res=strdup(optarg);
 
18801
      break;
 
18802
    case 1: /* graph */
 
18803
      shell_read_graph(&graph, optarg);
 
18804
      break;
 
18805
    case 2: /* loops */
 
18806
      shell_read_boolean(&loops, optarg);
 
18807
      break;
 
18808
    case 3:
 
18809
      shell_igraph_complementer_usage(argv);
 
18810
      break;
 
18811
    default:
 
18812
      break;
 
18813
    }
 
18814
 
 
18815
    shell_index=-1;
 
18816
  }
 
18817
 
 
18818
  /* Check that we have all arguments */
 
18819
  for (shell_index=0; shell_index<3; shell_index++) {
 
18820
    if (!shell_seen[shell_index]) {
 
18821
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18822
              shell_options[shell_index].name);
 
18823
      exit(1);
 
18824
    }
 
18825
  }
 
18826
 
 
18827
  /* Do the operation */
 
18828
  shell_result=igraph_complementer(&res, &graph, loops);
 
18829
 
 
18830
  /* Write the result */
 
18831
  shell_write_graph(&res, shell_arg_res); 
 
18832
  igraph_destroy(&res);
 
18833
  igraph_destroy(&graph);
 
18834
 
 
18835
  return 0;
 
18836
}
 
18837
 
 
18838
/*-------------------------------------------/
 
18839
/ igraph_compose                             /
 
18840
/-------------------------------------------*/
 
18841
void shell_igraph_compose_usage(char **argv) {
 
18842
  printf("%s --res=<res> --g1=<g1> --g2=<g2>\n", basename(argv[0]));
 
18843
  exit(1);
 
18844
}
 
18845
 
 
18846
int shell_igraph_compose(int argc, char **argv) {
 
18847
 
 
18848
  igraph_t res;
 
18849
  igraph_t g1;
 
18850
  igraph_t g2;
 
18851
  char* shell_arg_res=0;
 
18852
  int shell_result;
 
18853
 
 
18854
 
 
18855
  int shell_seen[3];
 
18856
  int shell_index=-1;
 
18857
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
18858
                                   { "g1",required_argument,0,1 },
 
18859
                                   { "g2",required_argument,0,2 },
 
18860
                                   { "help",no_argument,0,3 },
 
18861
                                   { 0,0,0,0 }
 
18862
                                 };
 
18863
 
 
18864
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18865
  memset(shell_seen, 0, 3*sizeof(int));
 
18866
 
 
18867
  
 
18868
  /* Parse arguments and read input */
 
18869
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18870
 
 
18871
    if (shell_index==-1) {
 
18872
      exit(1);
 
18873
    }
 
18874
 
 
18875
    if (shell_seen[shell_index]==1) {
 
18876
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18877
              shell_options[shell_index].name);
 
18878
      exit(1);
 
18879
    }
 
18880
    shell_seen[shell_index]=1;  
 
18881
 
 
18882
    switch (shell_index) {
 
18883
    case 0: /* res */
 
18884
      shell_arg_res=strdup(optarg);
 
18885
      break;
 
18886
    case 1: /* g1 */
 
18887
      shell_read_graph(&g1, optarg);
 
18888
      break;
 
18889
    case 2: /* g2 */
 
18890
      shell_read_graph(&g2, optarg);
 
18891
      break;
 
18892
    case 3:
 
18893
      shell_igraph_compose_usage(argv);
 
18894
      break;
 
18895
    default:
 
18896
      break;
 
18897
    }
 
18898
 
 
18899
    shell_index=-1;
 
18900
  }
 
18901
 
 
18902
  /* Check that we have all arguments */
 
18903
  for (shell_index=0; shell_index<3; shell_index++) {
 
18904
    if (!shell_seen[shell_index]) {
 
18905
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
18906
              shell_options[shell_index].name);
 
18907
      exit(1);
 
18908
    }
 
18909
  }
 
18910
 
 
18911
  /* Do the operation */
 
18912
  shell_result=igraph_compose(&res, &g1, &g2);
 
18913
 
 
18914
  /* Write the result */
 
18915
  shell_write_graph(&res, shell_arg_res); 
 
18916
  igraph_destroy(&res);
 
18917
  igraph_destroy(&g1);
 
18918
  igraph_destroy(&g2);
 
18919
 
 
18920
  return 0;
 
18921
}
 
18922
 
 
18923
/*-------------------------------------------/
 
18924
/ igraph_maxflow_value                       /
 
18925
/-------------------------------------------*/
 
18926
void shell_igraph_maxflow_value_usage(char **argv) {
 
18927
  printf("%s --graph=<graph> --value=<value> --source=<source> --target=<target> --capacity=<capacity>\n", basename(argv[0]));
 
18928
  exit(1);
 
18929
}
 
18930
 
 
18931
int shell_igraph_maxflow_value(int argc, char **argv) {
 
18932
 
 
18933
  igraph_t graph;
 
18934
  igraph_real_t value;
 
18935
  igraph_integer_t source;
 
18936
  igraph_integer_t target;
 
18937
  igraph_vector_t v_capacity; igraph_vector_t *capacity=0;
 
18938
  char* shell_arg_value=0;
 
18939
  int shell_result;
 
18940
 
 
18941
 
 
18942
  int shell_seen[5];
 
18943
  int shell_index=-1;
 
18944
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
18945
                                   { "value",required_argument,0,1 },
 
18946
                                   { "source",required_argument,0,2 },
 
18947
                                   { "target",required_argument,0,3 },
 
18948
                                   { "capacity",required_argument,0,4 },
 
18949
                                   { "help",no_argument,0,5 },
 
18950
                                   { 0,0,0,0 }
 
18951
                                 };
 
18952
 
 
18953
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
18954
  memset(shell_seen, 0, 5*sizeof(int));
 
18955
 
 
18956
  
 
18957
  /* Parse arguments and read input */
 
18958
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
18959
 
 
18960
    if (shell_index==-1) {
 
18961
      exit(1);
 
18962
    }
 
18963
 
 
18964
    if (shell_seen[shell_index]==1) {
 
18965
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
18966
              shell_options[shell_index].name);
 
18967
      exit(1);
 
18968
    }
 
18969
    shell_seen[shell_index]=1;  
 
18970
 
 
18971
    switch (shell_index) {
 
18972
    case 0: /* graph */
 
18973
      shell_read_graph(&graph, optarg);
 
18974
      break;
 
18975
    case 1: /* value */
 
18976
      shell_arg_value=strdup(optarg);
 
18977
      break;
 
18978
    case 2: /* source */
 
18979
      shell_read_integer(&source, optarg);
 
18980
      break;
 
18981
    case 3: /* target */
 
18982
      shell_read_integer(&target, optarg);
 
18983
      break;
 
18984
    case 4: /* capacity */
 
18985
      capacity=&v_capacity; shell_read_vector(capacity, optarg);
 
18986
      break;
 
18987
    case 5:
 
18988
      shell_igraph_maxflow_value_usage(argv);
 
18989
      break;
 
18990
    default:
 
18991
      break;
 
18992
    }
 
18993
 
 
18994
    shell_index=-1;
 
18995
  }
 
18996
 
 
18997
  /* Check that we have all arguments */
 
18998
  for (shell_index=0; shell_index<5; shell_index++) {
 
18999
    if (!shell_seen[shell_index]) {
 
19000
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19001
              shell_options[shell_index].name);
 
19002
      exit(1);
 
19003
    }
 
19004
  }
 
19005
 
 
19006
  /* Do the operation */
 
19007
  shell_result=igraph_maxflow_value(&graph, &value, source, target, capacity);
 
19008
 
 
19009
  /* Write the result */
 
19010
  igraph_destroy(&graph);
 
19011
  shell_write_real(value, shell_arg_value);
 
19012
  if (capacity) { igraph_vector_destroy(capacity); }
 
19013
 
 
19014
  return 0;
 
19015
}
 
19016
 
 
19017
/*-------------------------------------------/
 
19018
/ igraph_mincut_value                        /
 
19019
/-------------------------------------------*/
 
19020
void shell_igraph_mincut_value_usage(char **argv) {
 
19021
  printf("%s --graph=<graph> --res=<res> --capacity=<capacity>\n", basename(argv[0]));
 
19022
  exit(1);
 
19023
}
 
19024
 
 
19025
int shell_igraph_mincut_value(int argc, char **argv) {
 
19026
 
 
19027
  igraph_t graph;
 
19028
  igraph_real_t res;
 
19029
  igraph_vector_t v_capacity; igraph_vector_t *capacity=0;
 
19030
  char* shell_arg_res=0;
 
19031
  int shell_result;
 
19032
 
 
19033
 
 
19034
  int shell_seen[3];
 
19035
  int shell_index=-1;
 
19036
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19037
                                   { "res",required_argument,0,1 },
 
19038
                                   { "capacity",required_argument,0,2 },
 
19039
                                   { "help",no_argument,0,3 },
 
19040
                                   { 0,0,0,0 }
 
19041
                                 };
 
19042
 
 
19043
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19044
  memset(shell_seen, 0, 3*sizeof(int));
 
19045
 
 
19046
  
 
19047
  /* Parse arguments and read input */
 
19048
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19049
 
 
19050
    if (shell_index==-1) {
 
19051
      exit(1);
 
19052
    }
 
19053
 
 
19054
    if (shell_seen[shell_index]==1) {
 
19055
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19056
              shell_options[shell_index].name);
 
19057
      exit(1);
 
19058
    }
 
19059
    shell_seen[shell_index]=1;  
 
19060
 
 
19061
    switch (shell_index) {
 
19062
    case 0: /* graph */
 
19063
      shell_read_graph(&graph, optarg);
 
19064
      break;
 
19065
    case 1: /* res */
 
19066
      shell_arg_res=strdup(optarg);
 
19067
      break;
 
19068
    case 2: /* capacity */
 
19069
      capacity=&v_capacity; shell_read_vector(capacity, optarg);
 
19070
      break;
 
19071
    case 3:
 
19072
      shell_igraph_mincut_value_usage(argv);
 
19073
      break;
 
19074
    default:
 
19075
      break;
 
19076
    }
 
19077
 
 
19078
    shell_index=-1;
 
19079
  }
 
19080
 
 
19081
  /* Check that we have all arguments */
 
19082
  for (shell_index=0; shell_index<3; shell_index++) {
 
19083
    if (!shell_seen[shell_index]) {
 
19084
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19085
              shell_options[shell_index].name);
 
19086
      exit(1);
 
19087
    }
 
19088
  }
 
19089
 
 
19090
  /* Do the operation */
 
19091
  shell_result=igraph_mincut_value(&graph, &res, capacity);
 
19092
 
 
19093
  /* Write the result */
 
19094
  igraph_destroy(&graph);
 
19095
  shell_write_real(res, shell_arg_res);
 
19096
  if (capacity) { igraph_vector_destroy(capacity); }
 
19097
 
 
19098
  return 0;
 
19099
}
 
19100
 
 
19101
/*-------------------------------------------/
 
19102
/ igraph_st_mincut_value                     /
 
19103
/-------------------------------------------*/
 
19104
void shell_igraph_st_mincut_value_usage(char **argv) {
 
19105
  printf("%s --graph=<graph> --res=<res> --source=<source> --target=<target> --capacity=<capacity>\n", basename(argv[0]));
 
19106
  exit(1);
 
19107
}
 
19108
 
 
19109
int shell_igraph_st_mincut_value(int argc, char **argv) {
 
19110
 
 
19111
  igraph_t graph;
 
19112
  igraph_real_t res;
 
19113
  igraph_integer_t source;
 
19114
  igraph_integer_t target;
 
19115
  igraph_vector_t v_capacity; igraph_vector_t *capacity=0;
 
19116
  char* shell_arg_res=0;
 
19117
  int shell_result;
 
19118
 
 
19119
 
 
19120
  int shell_seen[5];
 
19121
  int shell_index=-1;
 
19122
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19123
                                   { "res",required_argument,0,1 },
 
19124
                                   { "source",required_argument,0,2 },
 
19125
                                   { "target",required_argument,0,3 },
 
19126
                                   { "capacity",required_argument,0,4 },
 
19127
                                   { "help",no_argument,0,5 },
 
19128
                                   { 0,0,0,0 }
 
19129
                                 };
 
19130
 
 
19131
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19132
  memset(shell_seen, 0, 5*sizeof(int));
 
19133
 
 
19134
  
 
19135
  /* Parse arguments and read input */
 
19136
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19137
 
 
19138
    if (shell_index==-1) {
 
19139
      exit(1);
 
19140
    }
 
19141
 
 
19142
    if (shell_seen[shell_index]==1) {
 
19143
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19144
              shell_options[shell_index].name);
 
19145
      exit(1);
 
19146
    }
 
19147
    shell_seen[shell_index]=1;  
 
19148
 
 
19149
    switch (shell_index) {
 
19150
    case 0: /* graph */
 
19151
      shell_read_graph(&graph, optarg);
 
19152
      break;
 
19153
    case 1: /* res */
 
19154
      shell_arg_res=strdup(optarg);
 
19155
      break;
 
19156
    case 2: /* source */
 
19157
      shell_read_integer(&source, optarg);
 
19158
      break;
 
19159
    case 3: /* target */
 
19160
      shell_read_integer(&target, optarg);
 
19161
      break;
 
19162
    case 4: /* capacity */
 
19163
      capacity=&v_capacity; shell_read_vector(capacity, optarg);
 
19164
      break;
 
19165
    case 5:
 
19166
      shell_igraph_st_mincut_value_usage(argv);
 
19167
      break;
 
19168
    default:
 
19169
      break;
 
19170
    }
 
19171
 
 
19172
    shell_index=-1;
 
19173
  }
 
19174
 
 
19175
  /* Check that we have all arguments */
 
19176
  for (shell_index=0; shell_index<5; shell_index++) {
 
19177
    if (!shell_seen[shell_index]) {
 
19178
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19179
              shell_options[shell_index].name);
 
19180
      exit(1);
 
19181
    }
 
19182
  }
 
19183
 
 
19184
  /* Do the operation */
 
19185
  shell_result=igraph_st_mincut_value(&graph, &res, source, target, capacity);
 
19186
 
 
19187
  /* Write the result */
 
19188
  igraph_destroy(&graph);
 
19189
  shell_write_real(res, shell_arg_res);
 
19190
  if (capacity) { igraph_vector_destroy(capacity); }
 
19191
 
 
19192
  return 0;
 
19193
}
 
19194
 
 
19195
/*-------------------------------------------/
 
19196
/ igraph_mincut                              /
 
19197
/-------------------------------------------*/
 
19198
void shell_igraph_mincut_usage(char **argv) {
 
19199
  printf("%s --graph=<graph> --value=<value> --partition=<partition> --partition2=<partition2> --cut=<cut> --capacity=<capacity>\n", basename(argv[0]));
 
19200
  exit(1);
 
19201
}
 
19202
 
 
19203
int shell_igraph_mincut(int argc, char **argv) {
 
19204
 
 
19205
  igraph_t graph;
 
19206
  igraph_real_t value;
 
19207
  igraph_vector_t partition;
 
19208
  igraph_vector_t partition2;
 
19209
  igraph_vector_t cut;
 
19210
  igraph_vector_t v_capacity; igraph_vector_t *capacity=0;
 
19211
  char* shell_arg_value=0;
 
19212
  char* shell_arg_partition=0;
 
19213
  char* shell_arg_partition2=0;
 
19214
  char* shell_arg_cut=0;
 
19215
  int shell_result;
 
19216
 
 
19217
 
 
19218
  int shell_seen[6];
 
19219
  int shell_index=-1;
 
19220
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19221
                                   { "value",required_argument,0,1 },
 
19222
                                   { "partition",required_argument,0,2 },
 
19223
                                   { "partition2",required_argument,0,3 },
 
19224
                                   { "cut",required_argument,0,4 },
 
19225
                                   { "capacity",required_argument,0,5 },
 
19226
                                   { "help",no_argument,0,6 },
 
19227
                                   { 0,0,0,0 }
 
19228
                                 };
 
19229
 
 
19230
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19231
  memset(shell_seen, 0, 6*sizeof(int));
 
19232
 
 
19233
  
 
19234
  /* Parse arguments and read input */
 
19235
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19236
 
 
19237
    if (shell_index==-1) {
 
19238
      exit(1);
 
19239
    }
 
19240
 
 
19241
    if (shell_seen[shell_index]==1) {
 
19242
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19243
              shell_options[shell_index].name);
 
19244
      exit(1);
 
19245
    }
 
19246
    shell_seen[shell_index]=1;  
 
19247
 
 
19248
    switch (shell_index) {
 
19249
    case 0: /* graph */
 
19250
      shell_read_graph(&graph, optarg);
 
19251
      break;
 
19252
    case 1: /* value */
 
19253
      shell_arg_value=strdup(optarg);
 
19254
      break;
 
19255
    case 2: /* partition */
 
19256
      shell_arg_partition=strdup(optarg); 
 
19257
  igraph_vector_init(&partition, 0);
 
19258
      break;
 
19259
    case 3: /* partition2 */
 
19260
      shell_arg_partition2=strdup(optarg); 
 
19261
  igraph_vector_init(&partition2, 0);
 
19262
      break;
 
19263
    case 4: /* cut */
 
19264
      shell_arg_cut=strdup(optarg); 
 
19265
  igraph_vector_init(&cut, 0);
 
19266
      break;
 
19267
    case 5: /* capacity */
 
19268
      capacity=&v_capacity; shell_read_vector(capacity, optarg);
 
19269
      break;
 
19270
    case 6:
 
19271
      shell_igraph_mincut_usage(argv);
 
19272
      break;
 
19273
    default:
 
19274
      break;
 
19275
    }
 
19276
 
 
19277
    shell_index=-1;
 
19278
  }
 
19279
 
 
19280
  /* Check that we have all arguments */
 
19281
  for (shell_index=0; shell_index<6; shell_index++) {
 
19282
    if (!shell_seen[shell_index]) {
 
19283
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19284
              shell_options[shell_index].name);
 
19285
      exit(1);
 
19286
    }
 
19287
  }
 
19288
 
 
19289
  /* Do the operation */
 
19290
  shell_result=igraph_mincut(&graph, &value, &partition, &partition2, &cut, capacity);
 
19291
 
 
19292
  /* Write the result */
 
19293
  igraph_destroy(&graph);
 
19294
  shell_write_real(value, shell_arg_value);
 
19295
  shell_write_vector(&partition, shell_arg_partition); 
 
19296
  igraph_vector_destroy(&partition);
 
19297
  shell_write_vector(&partition2, shell_arg_partition2); 
 
19298
  igraph_vector_destroy(&partition2);
 
19299
  shell_write_vector(&cut, shell_arg_cut); 
 
19300
  igraph_vector_destroy(&cut);
 
19301
  if (capacity) { igraph_vector_destroy(capacity); }
 
19302
 
 
19303
  return 0;
 
19304
}
 
19305
 
 
19306
/*-------------------------------------------/
 
19307
/ igraph_st_vertex_connectivity              /
 
19308
/-------------------------------------------*/
 
19309
void shell_igraph_st_vertex_connectivity_usage(char **argv) {
 
19310
  printf("%s --graph=<graph> --res=<res> --source=<source> --target=<target> --neighbors=<neighbors>\n", basename(argv[0]));
 
19311
  exit(1);
 
19312
}
 
19313
 
 
19314
int shell_igraph_st_vertex_connectivity(int argc, char **argv) {
 
19315
 
 
19316
  igraph_t graph;
 
19317
  igraph_integer_t res;
 
19318
  igraph_integer_t source;
 
19319
  igraph_integer_t target;
 
19320
  igraph_vconn_nei_t neighbors=IGRAPH_VCONN_NEI_INFINITY;
 
19321
  char* shell_arg_res=0;
 
19322
  int shell_result;
 
19323
 
 
19324
 
 
19325
  int shell_seen[5];
 
19326
  int shell_index=-1;
 
19327
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19328
                                   { "res",required_argument,0,1 },
 
19329
                                   { "source",required_argument,0,2 },
 
19330
                                   { "target",required_argument,0,3 },
 
19331
                                   { "neighbors",required_argument,0,4 },
 
19332
                                   { "help",no_argument,0,5 },
 
19333
                                   { 0,0,0,0 }
 
19334
                                 };
 
19335
 
 
19336
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19337
  memset(shell_seen, 0, 5*sizeof(int));
 
19338
  shell_seen[4]=2;
 
19339
  
 
19340
  /* Parse arguments and read input */
 
19341
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19342
 
 
19343
    if (shell_index==-1) {
 
19344
      exit(1);
 
19345
    }
 
19346
 
 
19347
    if (shell_seen[shell_index]==1) {
 
19348
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19349
              shell_options[shell_index].name);
 
19350
      exit(1);
 
19351
    }
 
19352
    shell_seen[shell_index]=1;  
 
19353
 
 
19354
    switch (shell_index) {
 
19355
    case 0: /* graph */
 
19356
      shell_read_graph(&graph, optarg);
 
19357
      break;
 
19358
    case 1: /* res */
 
19359
      shell_arg_res=strdup(optarg);
 
19360
      break;
 
19361
    case 2: /* source */
 
19362
      shell_read_integer(&source, optarg);
 
19363
      break;
 
19364
    case 3: /* target */
 
19365
      shell_read_integer(&target, optarg);
 
19366
      break;
 
19367
    case 4: /* neighbors */
 
19368
      shell_read_enum(&neighbors, optarg, "error", 0, "infinity", 1, "ignore", 2, 0);
 
19369
      break;
 
19370
    case 5:
 
19371
      shell_igraph_st_vertex_connectivity_usage(argv);
 
19372
      break;
 
19373
    default:
 
19374
      break;
 
19375
    }
 
19376
 
 
19377
    shell_index=-1;
 
19378
  }
 
19379
 
 
19380
  /* Check that we have all arguments */
 
19381
  for (shell_index=0; shell_index<5; shell_index++) {
 
19382
    if (!shell_seen[shell_index]) {
 
19383
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19384
              shell_options[shell_index].name);
 
19385
      exit(1);
 
19386
    }
 
19387
  }
 
19388
 
 
19389
  /* Do the operation */
 
19390
  shell_result=igraph_st_vertex_connectivity(&graph, &res, source, target, neighbors);
 
19391
 
 
19392
  /* Write the result */
 
19393
  igraph_destroy(&graph);
 
19394
  shell_write_integer(res, shell_arg_res);
 
19395
 
 
19396
  return 0;
 
19397
}
 
19398
 
 
19399
/*-------------------------------------------/
 
19400
/ igraph_vertex_connectivity                 /
 
19401
/-------------------------------------------*/
 
19402
void shell_igraph_vertex_connectivity_usage(char **argv) {
 
19403
  printf("%s --graph=<graph> --res=<res> --checks=<checks>\n", basename(argv[0]));
 
19404
  exit(1);
 
19405
}
 
19406
 
 
19407
int shell_igraph_vertex_connectivity(int argc, char **argv) {
 
19408
 
 
19409
  igraph_t graph;
 
19410
  igraph_integer_t res;
 
19411
  igraph_bool_t checks=1;
 
19412
  char* shell_arg_res=0;
 
19413
  int shell_result;
 
19414
 
 
19415
 
 
19416
  int shell_seen[3];
 
19417
  int shell_index=-1;
 
19418
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19419
                                   { "res",required_argument,0,1 },
 
19420
                                   { "checks",required_argument,0,2 },
 
19421
                                   { "help",no_argument,0,3 },
 
19422
                                   { 0,0,0,0 }
 
19423
                                 };
 
19424
 
 
19425
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19426
  memset(shell_seen, 0, 3*sizeof(int));
 
19427
  shell_seen[2]=2;
 
19428
  
 
19429
  /* Parse arguments and read input */
 
19430
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19431
 
 
19432
    if (shell_index==-1) {
 
19433
      exit(1);
 
19434
    }
 
19435
 
 
19436
    if (shell_seen[shell_index]==1) {
 
19437
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19438
              shell_options[shell_index].name);
 
19439
      exit(1);
 
19440
    }
 
19441
    shell_seen[shell_index]=1;  
 
19442
 
 
19443
    switch (shell_index) {
 
19444
    case 0: /* graph */
 
19445
      shell_read_graph(&graph, optarg);
 
19446
      break;
 
19447
    case 1: /* res */
 
19448
      shell_arg_res=strdup(optarg);
 
19449
      break;
 
19450
    case 2: /* checks */
 
19451
      shell_read_boolean(&checks, optarg);
 
19452
      break;
 
19453
    case 3:
 
19454
      shell_igraph_vertex_connectivity_usage(argv);
 
19455
      break;
 
19456
    default:
 
19457
      break;
 
19458
    }
 
19459
 
 
19460
    shell_index=-1;
 
19461
  }
 
19462
 
 
19463
  /* Check that we have all arguments */
 
19464
  for (shell_index=0; shell_index<3; shell_index++) {
 
19465
    if (!shell_seen[shell_index]) {
 
19466
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19467
              shell_options[shell_index].name);
 
19468
      exit(1);
 
19469
    }
 
19470
  }
 
19471
 
 
19472
  /* Do the operation */
 
19473
  shell_result=igraph_vertex_connectivity(&graph, &res, checks);
 
19474
 
 
19475
  /* Write the result */
 
19476
  igraph_destroy(&graph);
 
19477
  shell_write_integer(res, shell_arg_res);
 
19478
 
 
19479
  return 0;
 
19480
}
 
19481
 
 
19482
/*-------------------------------------------/
 
19483
/ igraph_st_edge_connectivity                /
 
19484
/-------------------------------------------*/
 
19485
void shell_igraph_st_edge_connectivity_usage(char **argv) {
 
19486
  printf("%s --graph=<graph> --res=<res> --source=<source> --target=<target>\n", basename(argv[0]));
 
19487
  exit(1);
 
19488
}
 
19489
 
 
19490
int shell_igraph_st_edge_connectivity(int argc, char **argv) {
 
19491
 
 
19492
  igraph_t graph;
 
19493
  igraph_integer_t res;
 
19494
  igraph_integer_t source;
 
19495
  igraph_integer_t target;
 
19496
  char* shell_arg_res=0;
 
19497
  int shell_result;
 
19498
 
 
19499
 
 
19500
  int shell_seen[4];
 
19501
  int shell_index=-1;
 
19502
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19503
                                   { "res",required_argument,0,1 },
 
19504
                                   { "source",required_argument,0,2 },
 
19505
                                   { "target",required_argument,0,3 },
 
19506
                                   { "help",no_argument,0,4 },
 
19507
                                   { 0,0,0,0 }
 
19508
                                 };
 
19509
 
 
19510
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19511
  memset(shell_seen, 0, 4*sizeof(int));
 
19512
 
 
19513
  
 
19514
  /* Parse arguments and read input */
 
19515
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19516
 
 
19517
    if (shell_index==-1) {
 
19518
      exit(1);
 
19519
    }
 
19520
 
 
19521
    if (shell_seen[shell_index]==1) {
 
19522
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19523
              shell_options[shell_index].name);
 
19524
      exit(1);
 
19525
    }
 
19526
    shell_seen[shell_index]=1;  
 
19527
 
 
19528
    switch (shell_index) {
 
19529
    case 0: /* graph */
 
19530
      shell_read_graph(&graph, optarg);
 
19531
      break;
 
19532
    case 1: /* res */
 
19533
      shell_arg_res=strdup(optarg);
 
19534
      break;
 
19535
    case 2: /* source */
 
19536
      shell_read_integer(&source, optarg);
 
19537
      break;
 
19538
    case 3: /* target */
 
19539
      shell_read_integer(&target, optarg);
 
19540
      break;
 
19541
    case 4:
 
19542
      shell_igraph_st_edge_connectivity_usage(argv);
 
19543
      break;
 
19544
    default:
 
19545
      break;
 
19546
    }
 
19547
 
 
19548
    shell_index=-1;
 
19549
  }
 
19550
 
 
19551
  /* Check that we have all arguments */
 
19552
  for (shell_index=0; shell_index<4; shell_index++) {
 
19553
    if (!shell_seen[shell_index]) {
 
19554
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19555
              shell_options[shell_index].name);
 
19556
      exit(1);
 
19557
    }
 
19558
  }
 
19559
 
 
19560
  /* Do the operation */
 
19561
  shell_result=igraph_st_edge_connectivity(&graph, &res, source, target);
 
19562
 
 
19563
  /* Write the result */
 
19564
  igraph_destroy(&graph);
 
19565
  shell_write_integer(res, shell_arg_res);
 
19566
 
 
19567
  return 0;
 
19568
}
 
19569
 
 
19570
/*-------------------------------------------/
 
19571
/ igraph_edge_connectivity                   /
 
19572
/-------------------------------------------*/
 
19573
void shell_igraph_edge_connectivity_usage(char **argv) {
 
19574
  printf("%s --graph=<graph> --res=<res> --checks=<checks>\n", basename(argv[0]));
 
19575
  exit(1);
 
19576
}
 
19577
 
 
19578
int shell_igraph_edge_connectivity(int argc, char **argv) {
 
19579
 
 
19580
  igraph_t graph;
 
19581
  igraph_integer_t res;
 
19582
  igraph_bool_t checks=1;
 
19583
  char* shell_arg_res=0;
 
19584
  int shell_result;
 
19585
 
 
19586
 
 
19587
  int shell_seen[3];
 
19588
  int shell_index=-1;
 
19589
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19590
                                   { "res",required_argument,0,1 },
 
19591
                                   { "checks",required_argument,0,2 },
 
19592
                                   { "help",no_argument,0,3 },
 
19593
                                   { 0,0,0,0 }
 
19594
                                 };
 
19595
 
 
19596
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19597
  memset(shell_seen, 0, 3*sizeof(int));
 
19598
  shell_seen[2]=2;
 
19599
  
 
19600
  /* Parse arguments and read input */
 
19601
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19602
 
 
19603
    if (shell_index==-1) {
 
19604
      exit(1);
 
19605
    }
 
19606
 
 
19607
    if (shell_seen[shell_index]==1) {
 
19608
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19609
              shell_options[shell_index].name);
 
19610
      exit(1);
 
19611
    }
 
19612
    shell_seen[shell_index]=1;  
 
19613
 
 
19614
    switch (shell_index) {
 
19615
    case 0: /* graph */
 
19616
      shell_read_graph(&graph, optarg);
 
19617
      break;
 
19618
    case 1: /* res */
 
19619
      shell_arg_res=strdup(optarg);
 
19620
      break;
 
19621
    case 2: /* checks */
 
19622
      shell_read_boolean(&checks, optarg);
 
19623
      break;
 
19624
    case 3:
 
19625
      shell_igraph_edge_connectivity_usage(argv);
 
19626
      break;
 
19627
    default:
 
19628
      break;
 
19629
    }
 
19630
 
 
19631
    shell_index=-1;
 
19632
  }
 
19633
 
 
19634
  /* Check that we have all arguments */
 
19635
  for (shell_index=0; shell_index<3; shell_index++) {
 
19636
    if (!shell_seen[shell_index]) {
 
19637
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19638
              shell_options[shell_index].name);
 
19639
      exit(1);
 
19640
    }
 
19641
  }
 
19642
 
 
19643
  /* Do the operation */
 
19644
  shell_result=igraph_edge_connectivity(&graph, &res, checks);
 
19645
 
 
19646
  /* Write the result */
 
19647
  igraph_destroy(&graph);
 
19648
  shell_write_integer(res, shell_arg_res);
 
19649
 
 
19650
  return 0;
 
19651
}
 
19652
 
 
19653
/*-------------------------------------------/
 
19654
/ igraph_edge_disjoint_paths                 /
 
19655
/-------------------------------------------*/
 
19656
void shell_igraph_edge_disjoint_paths_usage(char **argv) {
 
19657
  printf("%s --graph=<graph> --res=<res> --source=<source> --target=<target>\n", basename(argv[0]));
 
19658
  exit(1);
 
19659
}
 
19660
 
 
19661
int shell_igraph_edge_disjoint_paths(int argc, char **argv) {
 
19662
 
 
19663
  igraph_t graph;
 
19664
  igraph_integer_t res;
 
19665
  igraph_integer_t source;
 
19666
  igraph_integer_t target;
 
19667
  char* shell_arg_res=0;
 
19668
  int shell_result;
 
19669
 
 
19670
 
 
19671
  int shell_seen[4];
 
19672
  int shell_index=-1;
 
19673
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19674
                                   { "res",required_argument,0,1 },
 
19675
                                   { "source",required_argument,0,2 },
 
19676
                                   { "target",required_argument,0,3 },
 
19677
                                   { "help",no_argument,0,4 },
 
19678
                                   { 0,0,0,0 }
 
19679
                                 };
 
19680
 
 
19681
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19682
  memset(shell_seen, 0, 4*sizeof(int));
 
19683
 
 
19684
  
 
19685
  /* Parse arguments and read input */
 
19686
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19687
 
 
19688
    if (shell_index==-1) {
 
19689
      exit(1);
 
19690
    }
 
19691
 
 
19692
    if (shell_seen[shell_index]==1) {
 
19693
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19694
              shell_options[shell_index].name);
 
19695
      exit(1);
 
19696
    }
 
19697
    shell_seen[shell_index]=1;  
 
19698
 
 
19699
    switch (shell_index) {
 
19700
    case 0: /* graph */
 
19701
      shell_read_graph(&graph, optarg);
 
19702
      break;
 
19703
    case 1: /* res */
 
19704
      shell_arg_res=strdup(optarg);
 
19705
      break;
 
19706
    case 2: /* source */
 
19707
      shell_read_integer(&source, optarg);
 
19708
      break;
 
19709
    case 3: /* target */
 
19710
      shell_read_integer(&target, optarg);
 
19711
      break;
 
19712
    case 4:
 
19713
      shell_igraph_edge_disjoint_paths_usage(argv);
 
19714
      break;
 
19715
    default:
 
19716
      break;
 
19717
    }
 
19718
 
 
19719
    shell_index=-1;
 
19720
  }
 
19721
 
 
19722
  /* Check that we have all arguments */
 
19723
  for (shell_index=0; shell_index<4; shell_index++) {
 
19724
    if (!shell_seen[shell_index]) {
 
19725
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19726
              shell_options[shell_index].name);
 
19727
      exit(1);
 
19728
    }
 
19729
  }
 
19730
 
 
19731
  /* Do the operation */
 
19732
  shell_result=igraph_edge_disjoint_paths(&graph, &res, source, target);
 
19733
 
 
19734
  /* Write the result */
 
19735
  igraph_destroy(&graph);
 
19736
  shell_write_integer(res, shell_arg_res);
 
19737
 
 
19738
  return 0;
 
19739
}
 
19740
 
 
19741
/*-------------------------------------------/
 
19742
/ igraph_vertex_disjoint_paths               /
 
19743
/-------------------------------------------*/
 
19744
void shell_igraph_vertex_disjoint_paths_usage(char **argv) {
 
19745
  printf("%s --graph=<graph> --res=<res> --source=<source> --target=<target>\n", basename(argv[0]));
 
19746
  exit(1);
 
19747
}
 
19748
 
 
19749
int shell_igraph_vertex_disjoint_paths(int argc, char **argv) {
 
19750
 
 
19751
  igraph_t graph;
 
19752
  igraph_integer_t res;
 
19753
  igraph_integer_t source;
 
19754
  igraph_integer_t target;
 
19755
  char* shell_arg_res=0;
 
19756
  int shell_result;
 
19757
 
 
19758
 
 
19759
  int shell_seen[4];
 
19760
  int shell_index=-1;
 
19761
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19762
                                   { "res",required_argument,0,1 },
 
19763
                                   { "source",required_argument,0,2 },
 
19764
                                   { "target",required_argument,0,3 },
 
19765
                                   { "help",no_argument,0,4 },
 
19766
                                   { 0,0,0,0 }
 
19767
                                 };
 
19768
 
 
19769
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19770
  memset(shell_seen, 0, 4*sizeof(int));
 
19771
 
 
19772
  
 
19773
  /* Parse arguments and read input */
 
19774
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19775
 
 
19776
    if (shell_index==-1) {
 
19777
      exit(1);
 
19778
    }
 
19779
 
 
19780
    if (shell_seen[shell_index]==1) {
 
19781
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19782
              shell_options[shell_index].name);
 
19783
      exit(1);
 
19784
    }
 
19785
    shell_seen[shell_index]=1;  
 
19786
 
 
19787
    switch (shell_index) {
 
19788
    case 0: /* graph */
 
19789
      shell_read_graph(&graph, optarg);
 
19790
      break;
 
19791
    case 1: /* res */
 
19792
      shell_arg_res=strdup(optarg);
 
19793
      break;
 
19794
    case 2: /* source */
 
19795
      shell_read_integer(&source, optarg);
 
19796
      break;
 
19797
    case 3: /* target */
 
19798
      shell_read_integer(&target, optarg);
 
19799
      break;
 
19800
    case 4:
 
19801
      shell_igraph_vertex_disjoint_paths_usage(argv);
 
19802
      break;
 
19803
    default:
 
19804
      break;
 
19805
    }
 
19806
 
 
19807
    shell_index=-1;
 
19808
  }
 
19809
 
 
19810
  /* Check that we have all arguments */
 
19811
  for (shell_index=0; shell_index<4; shell_index++) {
 
19812
    if (!shell_seen[shell_index]) {
 
19813
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19814
              shell_options[shell_index].name);
 
19815
      exit(1);
 
19816
    }
 
19817
  }
 
19818
 
 
19819
  /* Do the operation */
 
19820
  shell_result=igraph_vertex_disjoint_paths(&graph, &res, source, target);
 
19821
 
 
19822
  /* Write the result */
 
19823
  igraph_destroy(&graph);
 
19824
  shell_write_integer(res, shell_arg_res);
 
19825
 
 
19826
  return 0;
 
19827
}
 
19828
 
 
19829
/*-------------------------------------------/
 
19830
/ igraph_adhesion                            /
 
19831
/-------------------------------------------*/
 
19832
void shell_igraph_adhesion_usage(char **argv) {
 
19833
  printf("%s --graph=<graph> --res=<res> --checks=<checks>\n", basename(argv[0]));
 
19834
  exit(1);
 
19835
}
 
19836
 
 
19837
int shell_igraph_adhesion(int argc, char **argv) {
 
19838
 
 
19839
  igraph_t graph;
 
19840
  igraph_integer_t res;
 
19841
  igraph_bool_t checks=1;
 
19842
  char* shell_arg_res=0;
 
19843
  int shell_result;
 
19844
 
 
19845
 
 
19846
  int shell_seen[3];
 
19847
  int shell_index=-1;
 
19848
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19849
                                   { "res",required_argument,0,1 },
 
19850
                                   { "checks",required_argument,0,2 },
 
19851
                                   { "help",no_argument,0,3 },
 
19852
                                   { 0,0,0,0 }
 
19853
                                 };
 
19854
 
 
19855
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19856
  memset(shell_seen, 0, 3*sizeof(int));
 
19857
  shell_seen[2]=2;
 
19858
  
 
19859
  /* Parse arguments and read input */
 
19860
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19861
 
 
19862
    if (shell_index==-1) {
 
19863
      exit(1);
 
19864
    }
 
19865
 
 
19866
    if (shell_seen[shell_index]==1) {
 
19867
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19868
              shell_options[shell_index].name);
 
19869
      exit(1);
 
19870
    }
 
19871
    shell_seen[shell_index]=1;  
 
19872
 
 
19873
    switch (shell_index) {
 
19874
    case 0: /* graph */
 
19875
      shell_read_graph(&graph, optarg);
 
19876
      break;
 
19877
    case 1: /* res */
 
19878
      shell_arg_res=strdup(optarg);
 
19879
      break;
 
19880
    case 2: /* checks */
 
19881
      shell_read_boolean(&checks, optarg);
 
19882
      break;
 
19883
    case 3:
 
19884
      shell_igraph_adhesion_usage(argv);
 
19885
      break;
 
19886
    default:
 
19887
      break;
 
19888
    }
 
19889
 
 
19890
    shell_index=-1;
 
19891
  }
 
19892
 
 
19893
  /* Check that we have all arguments */
 
19894
  for (shell_index=0; shell_index<3; shell_index++) {
 
19895
    if (!shell_seen[shell_index]) {
 
19896
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19897
              shell_options[shell_index].name);
 
19898
      exit(1);
 
19899
    }
 
19900
  }
 
19901
 
 
19902
  /* Do the operation */
 
19903
  shell_result=igraph_adhesion(&graph, &res, checks);
 
19904
 
 
19905
  /* Write the result */
 
19906
  igraph_destroy(&graph);
 
19907
  shell_write_integer(res, shell_arg_res);
 
19908
 
 
19909
  return 0;
 
19910
}
 
19911
 
 
19912
/*-------------------------------------------/
 
19913
/ igraph_cohesion                            /
 
19914
/-------------------------------------------*/
 
19915
void shell_igraph_cohesion_usage(char **argv) {
 
19916
  printf("%s --graph=<graph> --res=<res> --checks=<checks>\n", basename(argv[0]));
 
19917
  exit(1);
 
19918
}
 
19919
 
 
19920
int shell_igraph_cohesion(int argc, char **argv) {
 
19921
 
 
19922
  igraph_t graph;
 
19923
  igraph_integer_t res;
 
19924
  igraph_bool_t checks=1;
 
19925
  char* shell_arg_res=0;
 
19926
  int shell_result;
 
19927
 
 
19928
 
 
19929
  int shell_seen[3];
 
19930
  int shell_index=-1;
 
19931
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
19932
                                   { "res",required_argument,0,1 },
 
19933
                                   { "checks",required_argument,0,2 },
 
19934
                                   { "help",no_argument,0,3 },
 
19935
                                   { 0,0,0,0 }
 
19936
                                 };
 
19937
 
 
19938
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
19939
  memset(shell_seen, 0, 3*sizeof(int));
 
19940
  shell_seen[2]=2;
 
19941
  
 
19942
  /* Parse arguments and read input */
 
19943
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
19944
 
 
19945
    if (shell_index==-1) {
 
19946
      exit(1);
 
19947
    }
 
19948
 
 
19949
    if (shell_seen[shell_index]==1) {
 
19950
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
19951
              shell_options[shell_index].name);
 
19952
      exit(1);
 
19953
    }
 
19954
    shell_seen[shell_index]=1;  
 
19955
 
 
19956
    switch (shell_index) {
 
19957
    case 0: /* graph */
 
19958
      shell_read_graph(&graph, optarg);
 
19959
      break;
 
19960
    case 1: /* res */
 
19961
      shell_arg_res=strdup(optarg);
 
19962
      break;
 
19963
    case 2: /* checks */
 
19964
      shell_read_boolean(&checks, optarg);
 
19965
      break;
 
19966
    case 3:
 
19967
      shell_igraph_cohesion_usage(argv);
 
19968
      break;
 
19969
    default:
 
19970
      break;
 
19971
    }
 
19972
 
 
19973
    shell_index=-1;
 
19974
  }
 
19975
 
 
19976
  /* Check that we have all arguments */
 
19977
  for (shell_index=0; shell_index<3; shell_index++) {
 
19978
    if (!shell_seen[shell_index]) {
 
19979
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
19980
              shell_options[shell_index].name);
 
19981
      exit(1);
 
19982
    }
 
19983
  }
 
19984
 
 
19985
  /* Do the operation */
 
19986
  shell_result=igraph_cohesion(&graph, &res, checks);
 
19987
 
 
19988
  /* Write the result */
 
19989
  igraph_destroy(&graph);
 
19990
  shell_write_integer(res, shell_arg_res);
 
19991
 
 
19992
  return 0;
 
19993
}
 
19994
 
 
19995
/*-------------------------------------------/
 
19996
/ igraph_coreness                            /
 
19997
/-------------------------------------------*/
 
19998
void shell_igraph_coreness_usage(char **argv) {
 
19999
  printf("%s --graph=<graph> --cores=<cores> --mode=<mode>\n", basename(argv[0]));
 
20000
  exit(1);
 
20001
}
 
20002
 
 
20003
int shell_igraph_coreness(int argc, char **argv) {
 
20004
 
 
20005
  igraph_t graph;
 
20006
  igraph_vector_t cores;
 
20007
  igraph_neimode_t mode=IGRAPH_ALL;
 
20008
  char* shell_arg_cores=0;
 
20009
  int shell_result;
 
20010
 
 
20011
 
 
20012
  int shell_seen[3];
 
20013
  int shell_index=-1;
 
20014
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
20015
                                   { "cores",required_argument,0,1 },
 
20016
                                   { "mode",required_argument,0,2 },
 
20017
                                   { "help",no_argument,0,3 },
 
20018
                                   { 0,0,0,0 }
 
20019
                                 };
 
20020
 
 
20021
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20022
  memset(shell_seen, 0, 3*sizeof(int));
 
20023
  shell_seen[2]=2;
 
20024
  
 
20025
  /* Parse arguments and read input */
 
20026
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20027
 
 
20028
    if (shell_index==-1) {
 
20029
      exit(1);
 
20030
    }
 
20031
 
 
20032
    if (shell_seen[shell_index]==1) {
 
20033
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20034
              shell_options[shell_index].name);
 
20035
      exit(1);
 
20036
    }
 
20037
    shell_seen[shell_index]=1;  
 
20038
 
 
20039
    switch (shell_index) {
 
20040
    case 0: /* graph */
 
20041
      shell_read_graph(&graph, optarg);
 
20042
      break;
 
20043
    case 1: /* cores */
 
20044
      shell_arg_cores=strdup(optarg); 
 
20045
  igraph_vector_init(&cores, 0);
 
20046
      break;
 
20047
    case 2: /* mode */
 
20048
      shell_read_enum(&mode, optarg, "out", 1, "in", 2, "all", 3, "total", 3, 0);
 
20049
      break;
 
20050
    case 3:
 
20051
      shell_igraph_coreness_usage(argv);
 
20052
      break;
 
20053
    default:
 
20054
      break;
 
20055
    }
 
20056
 
 
20057
    shell_index=-1;
 
20058
  }
 
20059
 
 
20060
  /* Check that we have all arguments */
 
20061
  for (shell_index=0; shell_index<3; shell_index++) {
 
20062
    if (!shell_seen[shell_index]) {
 
20063
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20064
              shell_options[shell_index].name);
 
20065
      exit(1);
 
20066
    }
 
20067
  }
 
20068
 
 
20069
  /* Do the operation */
 
20070
  shell_result=igraph_coreness(&graph, &cores, mode);
 
20071
 
 
20072
  /* Write the result */
 
20073
  igraph_destroy(&graph);
 
20074
  shell_write_vector(&cores, shell_arg_cores); 
 
20075
  igraph_vector_destroy(&cores);
 
20076
 
 
20077
  return 0;
 
20078
}
 
20079
 
 
20080
/*-------------------------------------------/
 
20081
/ igraph_isoclass                            /
 
20082
/-------------------------------------------*/
 
20083
void shell_igraph_isoclass_usage(char **argv) {
 
20084
  printf("%s --graph=<graph> --isoclass=<isoclass>\n", basename(argv[0]));
 
20085
  exit(1);
 
20086
}
 
20087
 
 
20088
int shell_igraph_isoclass(int argc, char **argv) {
 
20089
 
 
20090
  igraph_t graph;
 
20091
  igraph_integer_t isoclass;
 
20092
  char* shell_arg_isoclass=0;
 
20093
  int shell_result;
 
20094
 
 
20095
 
 
20096
  int shell_seen[2];
 
20097
  int shell_index=-1;
 
20098
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
20099
                                   { "isoclass",required_argument,0,1 },
 
20100
                                   { "help",no_argument,0,2 },
 
20101
                                   { 0,0,0,0 }
 
20102
                                 };
 
20103
 
 
20104
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20105
  memset(shell_seen, 0, 2*sizeof(int));
 
20106
 
 
20107
  
 
20108
  /* Parse arguments and read input */
 
20109
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20110
 
 
20111
    if (shell_index==-1) {
 
20112
      exit(1);
 
20113
    }
 
20114
 
 
20115
    if (shell_seen[shell_index]==1) {
 
20116
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20117
              shell_options[shell_index].name);
 
20118
      exit(1);
 
20119
    }
 
20120
    shell_seen[shell_index]=1;  
 
20121
 
 
20122
    switch (shell_index) {
 
20123
    case 0: /* graph */
 
20124
      shell_read_graph(&graph, optarg);
 
20125
      break;
 
20126
    case 1: /* isoclass */
 
20127
      shell_arg_isoclass=strdup(optarg);
 
20128
      break;
 
20129
    case 2:
 
20130
      shell_igraph_isoclass_usage(argv);
 
20131
      break;
 
20132
    default:
 
20133
      break;
 
20134
    }
 
20135
 
 
20136
    shell_index=-1;
 
20137
  }
 
20138
 
 
20139
  /* Check that we have all arguments */
 
20140
  for (shell_index=0; shell_index<2; shell_index++) {
 
20141
    if (!shell_seen[shell_index]) {
 
20142
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20143
              shell_options[shell_index].name);
 
20144
      exit(1);
 
20145
    }
 
20146
  }
 
20147
 
 
20148
  /* Do the operation */
 
20149
  shell_result=igraph_isoclass(&graph, &isoclass);
 
20150
 
 
20151
  /* Write the result */
 
20152
  igraph_destroy(&graph);
 
20153
  shell_write_integer(isoclass, shell_arg_isoclass);
 
20154
 
 
20155
  return 0;
 
20156
}
 
20157
 
 
20158
/*-------------------------------------------/
 
20159
/ igraph_isomorphic                          /
 
20160
/-------------------------------------------*/
 
20161
void shell_igraph_isomorphic_usage(char **argv) {
 
20162
  printf("%s --graph1=<graph1> --graph2=<graph2> --iso=<iso>\n", basename(argv[0]));
 
20163
  exit(1);
 
20164
}
 
20165
 
 
20166
int shell_igraph_isomorphic(int argc, char **argv) {
 
20167
 
 
20168
  igraph_t graph1;
 
20169
  igraph_t graph2;
 
20170
  igraph_bool_t iso;
 
20171
  char* shell_arg_iso=0;
 
20172
  int shell_result;
 
20173
 
 
20174
 
 
20175
  int shell_seen[3];
 
20176
  int shell_index=-1;
 
20177
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20178
                                   { "graph2",required_argument,0,1 },
 
20179
                                   { "iso",required_argument,0,2 },
 
20180
                                   { "help",no_argument,0,3 },
 
20181
                                   { 0,0,0,0 }
 
20182
                                 };
 
20183
 
 
20184
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20185
  memset(shell_seen, 0, 3*sizeof(int));
 
20186
 
 
20187
  
 
20188
  /* Parse arguments and read input */
 
20189
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20190
 
 
20191
    if (shell_index==-1) {
 
20192
      exit(1);
 
20193
    }
 
20194
 
 
20195
    if (shell_seen[shell_index]==1) {
 
20196
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20197
              shell_options[shell_index].name);
 
20198
      exit(1);
 
20199
    }
 
20200
    shell_seen[shell_index]=1;  
 
20201
 
 
20202
    switch (shell_index) {
 
20203
    case 0: /* graph1 */
 
20204
      shell_read_graph(&graph1, optarg);
 
20205
      break;
 
20206
    case 1: /* graph2 */
 
20207
      shell_read_graph(&graph2, optarg);
 
20208
      break;
 
20209
    case 2: /* iso */
 
20210
      
 
20211
      break;
 
20212
    case 3:
 
20213
      shell_igraph_isomorphic_usage(argv);
 
20214
      break;
 
20215
    default:
 
20216
      break;
 
20217
    }
 
20218
 
 
20219
    shell_index=-1;
 
20220
  }
 
20221
 
 
20222
  /* Check that we have all arguments */
 
20223
  for (shell_index=0; shell_index<3; shell_index++) {
 
20224
    if (!shell_seen[shell_index]) {
 
20225
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20226
              shell_options[shell_index].name);
 
20227
      exit(1);
 
20228
    }
 
20229
  }
 
20230
 
 
20231
  /* Do the operation */
 
20232
  shell_result=igraph_isomorphic(&graph1, &graph2, &iso);
 
20233
 
 
20234
  /* Write the result */
 
20235
  igraph_destroy(&graph1);
 
20236
  igraph_destroy(&graph2);
 
20237
  shell_write_boolean(iso, shell_arg_iso);
 
20238
 
 
20239
  return 0;
 
20240
}
 
20241
 
 
20242
/*-------------------------------------------/
 
20243
/ igraph_isoclass_subgraph                   /
 
20244
/-------------------------------------------*/
 
20245
void shell_igraph_isoclass_subgraph_usage(char **argv) {
 
20246
  printf("%s --graph=<graph> --vids=<vids> --isoclass=<isoclass>\n", basename(argv[0]));
 
20247
  exit(1);
 
20248
}
 
20249
 
 
20250
int shell_igraph_isoclass_subgraph(int argc, char **argv) {
 
20251
 
 
20252
  igraph_t graph;
 
20253
  igraph_vector_t vids;
 
20254
  igraph_integer_t isoclass;
 
20255
  char* shell_arg_isoclass=0;
 
20256
  int shell_result;
 
20257
 
 
20258
 
 
20259
  int shell_seen[3];
 
20260
  int shell_index=-1;
 
20261
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
20262
                                   { "vids",required_argument,0,1 },
 
20263
                                   { "isoclass",required_argument,0,2 },
 
20264
                                   { "help",no_argument,0,3 },
 
20265
                                   { 0,0,0,0 }
 
20266
                                 };
 
20267
 
 
20268
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20269
  memset(shell_seen, 0, 3*sizeof(int));
 
20270
 
 
20271
  
 
20272
  /* Parse arguments and read input */
 
20273
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20274
 
 
20275
    if (shell_index==-1) {
 
20276
      exit(1);
 
20277
    }
 
20278
 
 
20279
    if (shell_seen[shell_index]==1) {
 
20280
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20281
              shell_options[shell_index].name);
 
20282
      exit(1);
 
20283
    }
 
20284
    shell_seen[shell_index]=1;  
 
20285
 
 
20286
    switch (shell_index) {
 
20287
    case 0: /* graph */
 
20288
      shell_read_graph(&graph, optarg);
 
20289
      break;
 
20290
    case 1: /* vids */
 
20291
      shell_read_vector(&vids, optarg);
 
20292
      break;
 
20293
    case 2: /* isoclass */
 
20294
      shell_arg_isoclass=strdup(optarg);
 
20295
      break;
 
20296
    case 3:
 
20297
      shell_igraph_isoclass_subgraph_usage(argv);
 
20298
      break;
 
20299
    default:
 
20300
      break;
 
20301
    }
 
20302
 
 
20303
    shell_index=-1;
 
20304
  }
 
20305
 
 
20306
  /* Check that we have all arguments */
 
20307
  for (shell_index=0; shell_index<3; shell_index++) {
 
20308
    if (!shell_seen[shell_index]) {
 
20309
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20310
              shell_options[shell_index].name);
 
20311
      exit(1);
 
20312
    }
 
20313
  }
 
20314
 
 
20315
  /* Do the operation */
 
20316
  shell_result=igraph_isoclass_subgraph(&graph, &vids, &isoclass);
 
20317
 
 
20318
  /* Write the result */
 
20319
  igraph_destroy(&graph);
 
20320
  igraph_vector_destroy(&vids);
 
20321
  shell_write_integer(isoclass, shell_arg_isoclass);
 
20322
 
 
20323
  return 0;
 
20324
}
 
20325
 
 
20326
/*-------------------------------------------/
 
20327
/ igraph_isoclass_create                     /
 
20328
/-------------------------------------------*/
 
20329
void shell_igraph_isoclass_create_usage(char **argv) {
 
20330
  printf("%s --graph=<graph> --size=<size> --number=<number> --directed=<directed>\n", basename(argv[0]));
 
20331
  exit(1);
 
20332
}
 
20333
 
 
20334
int shell_igraph_isoclass_create(int argc, char **argv) {
 
20335
 
 
20336
  igraph_t graph;
 
20337
  igraph_integer_t size;
 
20338
  igraph_integer_t number;
 
20339
  igraph_bool_t directed=1;
 
20340
  char* shell_arg_graph=0;
 
20341
  int shell_result;
 
20342
 
 
20343
 
 
20344
  int shell_seen[4];
 
20345
  int shell_index=-1;
 
20346
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
20347
                                   { "size",required_argument,0,1 },
 
20348
                                   { "number",required_argument,0,2 },
 
20349
                                   { "directed",required_argument,0,3 },
 
20350
                                   { "help",no_argument,0,4 },
 
20351
                                   { 0,0,0,0 }
 
20352
                                 };
 
20353
 
 
20354
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20355
  memset(shell_seen, 0, 4*sizeof(int));
 
20356
  shell_seen[3]=2;
 
20357
  
 
20358
  /* Parse arguments and read input */
 
20359
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20360
 
 
20361
    if (shell_index==-1) {
 
20362
      exit(1);
 
20363
    }
 
20364
 
 
20365
    if (shell_seen[shell_index]==1) {
 
20366
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20367
              shell_options[shell_index].name);
 
20368
      exit(1);
 
20369
    }
 
20370
    shell_seen[shell_index]=1;  
 
20371
 
 
20372
    switch (shell_index) {
 
20373
    case 0: /* graph */
 
20374
      shell_arg_graph=strdup(optarg);
 
20375
      break;
 
20376
    case 1: /* size */
 
20377
      shell_read_integer(&size, optarg);
 
20378
      break;
 
20379
    case 2: /* number */
 
20380
      shell_read_integer(&number, optarg);
 
20381
      break;
 
20382
    case 3: /* directed */
 
20383
      shell_read_boolean(&directed, optarg);
 
20384
      break;
 
20385
    case 4:
 
20386
      shell_igraph_isoclass_create_usage(argv);
 
20387
      break;
 
20388
    default:
 
20389
      break;
 
20390
    }
 
20391
 
 
20392
    shell_index=-1;
 
20393
  }
 
20394
 
 
20395
  /* Check that we have all arguments */
 
20396
  for (shell_index=0; shell_index<4; shell_index++) {
 
20397
    if (!shell_seen[shell_index]) {
 
20398
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20399
              shell_options[shell_index].name);
 
20400
      exit(1);
 
20401
    }
 
20402
  }
 
20403
 
 
20404
  /* Do the operation */
 
20405
  shell_result=igraph_isoclass_create(&graph, size, number, directed);
 
20406
 
 
20407
  /* Write the result */
 
20408
  shell_write_graph(&graph, shell_arg_graph); 
 
20409
  igraph_destroy(&graph);
 
20410
 
 
20411
  return 0;
 
20412
}
 
20413
 
 
20414
/*-------------------------------------------/
 
20415
/ igraph_isomorphic_vf2                      /
 
20416
/-------------------------------------------*/
 
20417
void shell_igraph_isomorphic_vf2_usage(char **argv) {
 
20418
  printf("%s --graph1=<graph1> --graph2=<graph2> --iso=<iso> --map12=<map12> --map21=<map21>\n", basename(argv[0]));
 
20419
  exit(1);
 
20420
}
 
20421
 
 
20422
int shell_igraph_isomorphic_vf2(int argc, char **argv) {
 
20423
 
 
20424
  igraph_t graph1;
 
20425
  igraph_t graph2;
 
20426
  igraph_bool_t iso;
 
20427
  igraph_vector_t v_map12; igraph_vector_t *map12=0;
 
20428
  igraph_vector_t v_map21; igraph_vector_t *map21=0;
 
20429
  char* shell_arg_iso=0;
 
20430
  char* shell_arg_map12=0;
 
20431
  char* shell_arg_map21=0;
 
20432
  int shell_result;
 
20433
 
 
20434
 
 
20435
  int shell_seen[5];
 
20436
  int shell_index=-1;
 
20437
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20438
                                   { "graph2",required_argument,0,1 },
 
20439
                                   { "iso",required_argument,0,2 },
 
20440
                                   { "map12",required_argument,0,3 },
 
20441
                                   { "map21",required_argument,0,4 },
 
20442
                                   { "help",no_argument,0,5 },
 
20443
                                   { 0,0,0,0 }
 
20444
                                 };
 
20445
 
 
20446
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20447
  memset(shell_seen, 0, 5*sizeof(int));
 
20448
 
 
20449
  
 
20450
  /* Parse arguments and read input */
 
20451
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20452
 
 
20453
    if (shell_index==-1) {
 
20454
      exit(1);
 
20455
    }
 
20456
 
 
20457
    if (shell_seen[shell_index]==1) {
 
20458
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20459
              shell_options[shell_index].name);
 
20460
      exit(1);
 
20461
    }
 
20462
    shell_seen[shell_index]=1;  
 
20463
 
 
20464
    switch (shell_index) {
 
20465
    case 0: /* graph1 */
 
20466
      shell_read_graph(&graph1, optarg);
 
20467
      break;
 
20468
    case 1: /* graph2 */
 
20469
      shell_read_graph(&graph2, optarg);
 
20470
      break;
 
20471
    case 2: /* iso */
 
20472
      
 
20473
      break;
 
20474
    case 3: /* map12 */
 
20475
      map12=&v_map12; igraph_vector_init(map12, 0); 
 
20476
  shell_arg_map12=strdup(optarg);
 
20477
      break;
 
20478
    case 4: /* map21 */
 
20479
      map21=&v_map21; igraph_vector_init(map21, 0); 
 
20480
  shell_arg_map21=strdup(optarg);
 
20481
      break;
 
20482
    case 5:
 
20483
      shell_igraph_isomorphic_vf2_usage(argv);
 
20484
      break;
 
20485
    default:
 
20486
      break;
 
20487
    }
 
20488
 
 
20489
    shell_index=-1;
 
20490
  }
 
20491
 
 
20492
  /* Check that we have all arguments */
 
20493
  for (shell_index=0; shell_index<5; shell_index++) {
 
20494
    if (!shell_seen[shell_index]) {
 
20495
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20496
              shell_options[shell_index].name);
 
20497
      exit(1);
 
20498
    }
 
20499
  }
 
20500
 
 
20501
  /* Do the operation */
 
20502
  shell_result=igraph_isomorphic_vf2(&graph1, &graph2, &iso, map12, map21);
 
20503
 
 
20504
  /* Write the result */
 
20505
  igraph_destroy(&graph1);
 
20506
  igraph_destroy(&graph2);
 
20507
  shell_write_boolean(iso, shell_arg_iso);
 
20508
  if (map12) { shell_write_vector(map12, shell_arg_map12); 
 
20509
  igraph_vector_destroy(map12); }
 
20510
  if (map21) { shell_write_vector(map21, shell_arg_map21); 
 
20511
  igraph_vector_destroy(map21); }
 
20512
 
 
20513
  return 0;
 
20514
}
 
20515
 
 
20516
/*-------------------------------------------/
 
20517
/ igraph_count_isomorphisms_vf2              /
 
20518
/-------------------------------------------*/
 
20519
void shell_igraph_count_isomorphisms_vf2_usage(char **argv) {
 
20520
  printf("%s --graph1=<graph1> --graph2=<graph2> --count=<count>\n", basename(argv[0]));
 
20521
  exit(1);
 
20522
}
 
20523
 
 
20524
int shell_igraph_count_isomorphisms_vf2(int argc, char **argv) {
 
20525
 
 
20526
  igraph_t graph1;
 
20527
  igraph_t graph2;
 
20528
  igraph_integer_t count;
 
20529
  char* shell_arg_count=0;
 
20530
  int shell_result;
 
20531
 
 
20532
 
 
20533
  int shell_seen[3];
 
20534
  int shell_index=-1;
 
20535
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20536
                                   { "graph2",required_argument,0,1 },
 
20537
                                   { "count",required_argument,0,2 },
 
20538
                                   { "help",no_argument,0,3 },
 
20539
                                   { 0,0,0,0 }
 
20540
                                 };
 
20541
 
 
20542
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20543
  memset(shell_seen, 0, 3*sizeof(int));
 
20544
 
 
20545
  
 
20546
  /* Parse arguments and read input */
 
20547
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20548
 
 
20549
    if (shell_index==-1) {
 
20550
      exit(1);
 
20551
    }
 
20552
 
 
20553
    if (shell_seen[shell_index]==1) {
 
20554
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20555
              shell_options[shell_index].name);
 
20556
      exit(1);
 
20557
    }
 
20558
    shell_seen[shell_index]=1;  
 
20559
 
 
20560
    switch (shell_index) {
 
20561
    case 0: /* graph1 */
 
20562
      shell_read_graph(&graph1, optarg);
 
20563
      break;
 
20564
    case 1: /* graph2 */
 
20565
      shell_read_graph(&graph2, optarg);
 
20566
      break;
 
20567
    case 2: /* count */
 
20568
      shell_arg_count=strdup(optarg);
 
20569
      break;
 
20570
    case 3:
 
20571
      shell_igraph_count_isomorphisms_vf2_usage(argv);
 
20572
      break;
 
20573
    default:
 
20574
      break;
 
20575
    }
 
20576
 
 
20577
    shell_index=-1;
 
20578
  }
 
20579
 
 
20580
  /* Check that we have all arguments */
 
20581
  for (shell_index=0; shell_index<3; shell_index++) {
 
20582
    if (!shell_seen[shell_index]) {
 
20583
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20584
              shell_options[shell_index].name);
 
20585
      exit(1);
 
20586
    }
 
20587
  }
 
20588
 
 
20589
  /* Do the operation */
 
20590
  shell_result=igraph_count_isomorphisms_vf2(&graph1, &graph2, &count);
 
20591
 
 
20592
  /* Write the result */
 
20593
  igraph_destroy(&graph1);
 
20594
  igraph_destroy(&graph2);
 
20595
  shell_write_integer(count, shell_arg_count);
 
20596
 
 
20597
  return 0;
 
20598
}
 
20599
 
 
20600
/*-------------------------------------------/
 
20601
/ igraph_get_isomorphisms_vf2                /
 
20602
/-------------------------------------------*/
 
20603
void shell_igraph_get_isomorphisms_vf2_usage(char **argv) {
 
20604
  printf("%s --graph1=<graph1> --graph2=<graph2> --maps=<maps>\n", basename(argv[0]));
 
20605
  exit(1);
 
20606
}
 
20607
 
 
20608
int shell_igraph_get_isomorphisms_vf2(int argc, char **argv) {
 
20609
 
 
20610
  igraph_t graph1;
 
20611
  igraph_t graph2;
 
20612
  igraph_vector_ptr_t maps;
 
20613
  char* shell_arg_maps=0;
 
20614
  int shell_result;
 
20615
 
 
20616
 
 
20617
  int shell_seen[3];
 
20618
  int shell_index=-1;
 
20619
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20620
                                   { "graph2",required_argument,0,1 },
 
20621
                                   { "maps",required_argument,0,2 },
 
20622
                                   { "help",no_argument,0,3 },
 
20623
                                   { 0,0,0,0 }
 
20624
                                 };
 
20625
 
 
20626
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20627
  memset(shell_seen, 0, 3*sizeof(int));
 
20628
 
 
20629
  
 
20630
  /* Parse arguments and read input */
 
20631
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20632
 
 
20633
    if (shell_index==-1) {
 
20634
      exit(1);
 
20635
    }
 
20636
 
 
20637
    if (shell_seen[shell_index]==1) {
 
20638
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20639
              shell_options[shell_index].name);
 
20640
      exit(1);
 
20641
    }
 
20642
    shell_seen[shell_index]=1;  
 
20643
 
 
20644
    switch (shell_index) {
 
20645
    case 0: /* graph1 */
 
20646
      shell_read_graph(&graph1, optarg);
 
20647
      break;
 
20648
    case 1: /* graph2 */
 
20649
      shell_read_graph(&graph2, optarg);
 
20650
      break;
 
20651
    case 2: /* maps */
 
20652
      igraph_vector_ptr_init(&maps, 0);
 
20653
      break;
 
20654
    case 3:
 
20655
      shell_igraph_get_isomorphisms_vf2_usage(argv);
 
20656
      break;
 
20657
    default:
 
20658
      break;
 
20659
    }
 
20660
 
 
20661
    shell_index=-1;
 
20662
  }
 
20663
 
 
20664
  /* Check that we have all arguments */
 
20665
  for (shell_index=0; shell_index<3; shell_index++) {
 
20666
    if (!shell_seen[shell_index]) {
 
20667
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20668
              shell_options[shell_index].name);
 
20669
      exit(1);
 
20670
    }
 
20671
  }
 
20672
 
 
20673
  /* Do the operation */
 
20674
  shell_result=igraph_get_isomorphisms_vf2(&graph1, &graph2, &maps);
 
20675
 
 
20676
  /* Write the result */
 
20677
  igraph_destroy(&graph1);
 
20678
  igraph_destroy(&graph2);
 
20679
  shell_write_vectorlist(&maps, shell_arg_maps); 
 
20680
  shell_free_vectorlist(&maps); 
 
20681
  igraph_vector_ptr_destroy(&maps);
 
20682
 
 
20683
  return 0;
 
20684
}
 
20685
 
 
20686
/*-------------------------------------------/
 
20687
/ igraph_subisomorphic_vf2                   /
 
20688
/-------------------------------------------*/
 
20689
void shell_igraph_subisomorphic_vf2_usage(char **argv) {
 
20690
  printf("%s --graph1=<graph1> --graph2=<graph2> --iso=<iso> --map12=<map12> --map21=<map21>\n", basename(argv[0]));
 
20691
  exit(1);
 
20692
}
 
20693
 
 
20694
int shell_igraph_subisomorphic_vf2(int argc, char **argv) {
 
20695
 
 
20696
  igraph_t graph1;
 
20697
  igraph_t graph2;
 
20698
  igraph_bool_t iso;
 
20699
  igraph_vector_t v_map12; igraph_vector_t *map12=0;
 
20700
  igraph_vector_t v_map21; igraph_vector_t *map21=0;
 
20701
  char* shell_arg_iso=0;
 
20702
  char* shell_arg_map12=0;
 
20703
  char* shell_arg_map21=0;
 
20704
  int shell_result;
 
20705
 
 
20706
 
 
20707
  int shell_seen[5];
 
20708
  int shell_index=-1;
 
20709
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20710
                                   { "graph2",required_argument,0,1 },
 
20711
                                   { "iso",required_argument,0,2 },
 
20712
                                   { "map12",required_argument,0,3 },
 
20713
                                   { "map21",required_argument,0,4 },
 
20714
                                   { "help",no_argument,0,5 },
 
20715
                                   { 0,0,0,0 }
 
20716
                                 };
 
20717
 
 
20718
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20719
  memset(shell_seen, 0, 5*sizeof(int));
 
20720
 
 
20721
  
 
20722
  /* Parse arguments and read input */
 
20723
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20724
 
 
20725
    if (shell_index==-1) {
 
20726
      exit(1);
 
20727
    }
 
20728
 
 
20729
    if (shell_seen[shell_index]==1) {
 
20730
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20731
              shell_options[shell_index].name);
 
20732
      exit(1);
 
20733
    }
 
20734
    shell_seen[shell_index]=1;  
 
20735
 
 
20736
    switch (shell_index) {
 
20737
    case 0: /* graph1 */
 
20738
      shell_read_graph(&graph1, optarg);
 
20739
      break;
 
20740
    case 1: /* graph2 */
 
20741
      shell_read_graph(&graph2, optarg);
 
20742
      break;
 
20743
    case 2: /* iso */
 
20744
      
 
20745
      break;
 
20746
    case 3: /* map12 */
 
20747
      map12=&v_map12; igraph_vector_init(map12, 0); 
 
20748
  shell_arg_map12=strdup(optarg);
 
20749
      break;
 
20750
    case 4: /* map21 */
 
20751
      map21=&v_map21; igraph_vector_init(map21, 0); 
 
20752
  shell_arg_map21=strdup(optarg);
 
20753
      break;
 
20754
    case 5:
 
20755
      shell_igraph_subisomorphic_vf2_usage(argv);
 
20756
      break;
 
20757
    default:
 
20758
      break;
 
20759
    }
 
20760
 
 
20761
    shell_index=-1;
 
20762
  }
 
20763
 
 
20764
  /* Check that we have all arguments */
 
20765
  for (shell_index=0; shell_index<5; shell_index++) {
 
20766
    if (!shell_seen[shell_index]) {
 
20767
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20768
              shell_options[shell_index].name);
 
20769
      exit(1);
 
20770
    }
 
20771
  }
 
20772
 
 
20773
  /* Do the operation */
 
20774
  shell_result=igraph_subisomorphic_vf2(&graph1, &graph2, &iso, map12, map21);
 
20775
 
 
20776
  /* Write the result */
 
20777
  igraph_destroy(&graph1);
 
20778
  igraph_destroy(&graph2);
 
20779
  shell_write_boolean(iso, shell_arg_iso);
 
20780
  if (map12) { shell_write_vector(map12, shell_arg_map12); 
 
20781
  igraph_vector_destroy(map12); }
 
20782
  if (map21) { shell_write_vector(map21, shell_arg_map21); 
 
20783
  igraph_vector_destroy(map21); }
 
20784
 
 
20785
  return 0;
 
20786
}
 
20787
 
 
20788
/*-------------------------------------------/
 
20789
/ igraph_count_subisomorphisms_vf2           /
 
20790
/-------------------------------------------*/
 
20791
void shell_igraph_count_subisomorphisms_vf2_usage(char **argv) {
 
20792
  printf("%s --graph1=<graph1> --graph2=<graph2> --count=<count>\n", basename(argv[0]));
 
20793
  exit(1);
 
20794
}
 
20795
 
 
20796
int shell_igraph_count_subisomorphisms_vf2(int argc, char **argv) {
 
20797
 
 
20798
  igraph_t graph1;
 
20799
  igraph_t graph2;
 
20800
  igraph_integer_t count;
 
20801
  char* shell_arg_count=0;
 
20802
  int shell_result;
 
20803
 
 
20804
 
 
20805
  int shell_seen[3];
 
20806
  int shell_index=-1;
 
20807
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20808
                                   { "graph2",required_argument,0,1 },
 
20809
                                   { "count",required_argument,0,2 },
 
20810
                                   { "help",no_argument,0,3 },
 
20811
                                   { 0,0,0,0 }
 
20812
                                 };
 
20813
 
 
20814
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20815
  memset(shell_seen, 0, 3*sizeof(int));
 
20816
 
 
20817
  
 
20818
  /* Parse arguments and read input */
 
20819
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20820
 
 
20821
    if (shell_index==-1) {
 
20822
      exit(1);
 
20823
    }
 
20824
 
 
20825
    if (shell_seen[shell_index]==1) {
 
20826
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20827
              shell_options[shell_index].name);
 
20828
      exit(1);
 
20829
    }
 
20830
    shell_seen[shell_index]=1;  
 
20831
 
 
20832
    switch (shell_index) {
 
20833
    case 0: /* graph1 */
 
20834
      shell_read_graph(&graph1, optarg);
 
20835
      break;
 
20836
    case 1: /* graph2 */
 
20837
      shell_read_graph(&graph2, optarg);
 
20838
      break;
 
20839
    case 2: /* count */
 
20840
      shell_arg_count=strdup(optarg);
 
20841
      break;
 
20842
    case 3:
 
20843
      shell_igraph_count_subisomorphisms_vf2_usage(argv);
 
20844
      break;
 
20845
    default:
 
20846
      break;
 
20847
    }
 
20848
 
 
20849
    shell_index=-1;
 
20850
  }
 
20851
 
 
20852
  /* Check that we have all arguments */
 
20853
  for (shell_index=0; shell_index<3; shell_index++) {
 
20854
    if (!shell_seen[shell_index]) {
 
20855
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20856
              shell_options[shell_index].name);
 
20857
      exit(1);
 
20858
    }
 
20859
  }
 
20860
 
 
20861
  /* Do the operation */
 
20862
  shell_result=igraph_count_subisomorphisms_vf2(&graph1, &graph2, &count);
 
20863
 
 
20864
  /* Write the result */
 
20865
  igraph_destroy(&graph1);
 
20866
  igraph_destroy(&graph2);
 
20867
  shell_write_integer(count, shell_arg_count);
 
20868
 
 
20869
  return 0;
 
20870
}
 
20871
 
 
20872
/*-------------------------------------------/
 
20873
/ igraph_get_subisomorphisms_vf2             /
 
20874
/-------------------------------------------*/
 
20875
void shell_igraph_get_subisomorphisms_vf2_usage(char **argv) {
 
20876
  printf("%s --graph1=<graph1> --graph2=<graph2> --maps=<maps>\n", basename(argv[0]));
 
20877
  exit(1);
 
20878
}
 
20879
 
 
20880
int shell_igraph_get_subisomorphisms_vf2(int argc, char **argv) {
 
20881
 
 
20882
  igraph_t graph1;
 
20883
  igraph_t graph2;
 
20884
  igraph_vector_ptr_t maps;
 
20885
  char* shell_arg_maps=0;
 
20886
  int shell_result;
 
20887
 
 
20888
 
 
20889
  int shell_seen[3];
 
20890
  int shell_index=-1;
 
20891
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20892
                                   { "graph2",required_argument,0,1 },
 
20893
                                   { "maps",required_argument,0,2 },
 
20894
                                   { "help",no_argument,0,3 },
 
20895
                                   { 0,0,0,0 }
 
20896
                                 };
 
20897
 
 
20898
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20899
  memset(shell_seen, 0, 3*sizeof(int));
 
20900
 
 
20901
  
 
20902
  /* Parse arguments and read input */
 
20903
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20904
 
 
20905
    if (shell_index==-1) {
 
20906
      exit(1);
 
20907
    }
 
20908
 
 
20909
    if (shell_seen[shell_index]==1) {
 
20910
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20911
              shell_options[shell_index].name);
 
20912
      exit(1);
 
20913
    }
 
20914
    shell_seen[shell_index]=1;  
 
20915
 
 
20916
    switch (shell_index) {
 
20917
    case 0: /* graph1 */
 
20918
      shell_read_graph(&graph1, optarg);
 
20919
      break;
 
20920
    case 1: /* graph2 */
 
20921
      shell_read_graph(&graph2, optarg);
 
20922
      break;
 
20923
    case 2: /* maps */
 
20924
      igraph_vector_ptr_init(&maps, 0);
 
20925
      break;
 
20926
    case 3:
 
20927
      shell_igraph_get_subisomorphisms_vf2_usage(argv);
 
20928
      break;
 
20929
    default:
 
20930
      break;
 
20931
    }
 
20932
 
 
20933
    shell_index=-1;
 
20934
  }
 
20935
 
 
20936
  /* Check that we have all arguments */
 
20937
  for (shell_index=0; shell_index<3; shell_index++) {
 
20938
    if (!shell_seen[shell_index]) {
 
20939
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
20940
              shell_options[shell_index].name);
 
20941
      exit(1);
 
20942
    }
 
20943
  }
 
20944
 
 
20945
  /* Do the operation */
 
20946
  shell_result=igraph_get_subisomorphisms_vf2(&graph1, &graph2, &maps);
 
20947
 
 
20948
  /* Write the result */
 
20949
  igraph_destroy(&graph1);
 
20950
  igraph_destroy(&graph2);
 
20951
  shell_write_vectorlist(&maps, shell_arg_maps); 
 
20952
  shell_free_vectorlist(&maps); 
 
20953
  igraph_vector_ptr_destroy(&maps);
 
20954
 
 
20955
  return 0;
 
20956
}
 
20957
 
 
20958
/*-------------------------------------------/
 
20959
/ igraph_isomorphic_34                       /
 
20960
/-------------------------------------------*/
 
20961
void shell_igraph_isomorphic_34_usage(char **argv) {
 
20962
  printf("%s --graph1=<graph1> --graph2=<graph2> --iso=<iso>\n", basename(argv[0]));
 
20963
  exit(1);
 
20964
}
 
20965
 
 
20966
int shell_igraph_isomorphic_34(int argc, char **argv) {
 
20967
 
 
20968
  igraph_t graph1;
 
20969
  igraph_t graph2;
 
20970
  igraph_bool_t iso;
 
20971
  char* shell_arg_iso=0;
 
20972
  int shell_result;
 
20973
 
 
20974
 
 
20975
  int shell_seen[3];
 
20976
  int shell_index=-1;
 
20977
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
20978
                                   { "graph2",required_argument,0,1 },
 
20979
                                   { "iso",required_argument,0,2 },
 
20980
                                   { "help",no_argument,0,3 },
 
20981
                                   { 0,0,0,0 }
 
20982
                                 };
 
20983
 
 
20984
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
20985
  memset(shell_seen, 0, 3*sizeof(int));
 
20986
 
 
20987
  
 
20988
  /* Parse arguments and read input */
 
20989
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
20990
 
 
20991
    if (shell_index==-1) {
 
20992
      exit(1);
 
20993
    }
 
20994
 
 
20995
    if (shell_seen[shell_index]==1) {
 
20996
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
20997
              shell_options[shell_index].name);
 
20998
      exit(1);
 
20999
    }
 
21000
    shell_seen[shell_index]=1;  
 
21001
 
 
21002
    switch (shell_index) {
 
21003
    case 0: /* graph1 */
 
21004
      shell_read_graph(&graph1, optarg);
 
21005
      break;
 
21006
    case 1: /* graph2 */
 
21007
      shell_read_graph(&graph2, optarg);
 
21008
      break;
 
21009
    case 2: /* iso */
 
21010
      
 
21011
      break;
 
21012
    case 3:
 
21013
      shell_igraph_isomorphic_34_usage(argv);
 
21014
      break;
 
21015
    default:
 
21016
      break;
 
21017
    }
 
21018
 
 
21019
    shell_index=-1;
 
21020
  }
 
21021
 
 
21022
  /* Check that we have all arguments */
 
21023
  for (shell_index=0; shell_index<3; shell_index++) {
 
21024
    if (!shell_seen[shell_index]) {
 
21025
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21026
              shell_options[shell_index].name);
 
21027
      exit(1);
 
21028
    }
 
21029
  }
 
21030
 
 
21031
  /* Do the operation */
 
21032
  shell_result=igraph_isomorphic_34(&graph1, &graph2, &iso);
 
21033
 
 
21034
  /* Write the result */
 
21035
  igraph_destroy(&graph1);
 
21036
  igraph_destroy(&graph2);
 
21037
  shell_write_boolean(iso, shell_arg_iso);
 
21038
 
 
21039
  return 0;
 
21040
}
 
21041
 
 
21042
/*-------------------------------------------/
 
21043
/ igraph_canonical_permutation               /
 
21044
/-------------------------------------------*/
 
21045
void shell_igraph_canonical_permutation_usage(char **argv) {
 
21046
  printf("%s --graph=<graph> --labeling=<labeling>\n", basename(argv[0]));
 
21047
  exit(1);
 
21048
}
 
21049
 
 
21050
int shell_igraph_canonical_permutation(int argc, char **argv) {
 
21051
 
 
21052
  igraph_t graph;
 
21053
  igraph_vector_t labeling;
 
21054
 
 
21055
 
 
21056
  char* shell_arg_labeling=0;
 
21057
  char* shell_arg_info=0;
 
21058
  int shell_result;
 
21059
 
 
21060
 
 
21061
  int shell_seen[2];
 
21062
  int shell_index=-1;
 
21063
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
21064
                                   { "labeling",required_argument,0,1 },
 
21065
                                   { "help",no_argument,0,2 },
 
21066
                                   { 0,0,0,0 }
 
21067
                                 };
 
21068
 
 
21069
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21070
  memset(shell_seen, 0, 2*sizeof(int));
 
21071
 
 
21072
  
 
21073
  /* Parse arguments and read input */
 
21074
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21075
 
 
21076
    if (shell_index==-1) {
 
21077
      exit(1);
 
21078
    }
 
21079
 
 
21080
    if (shell_seen[shell_index]==1) {
 
21081
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21082
              shell_options[shell_index].name);
 
21083
      exit(1);
 
21084
    }
 
21085
    shell_seen[shell_index]=1;  
 
21086
 
 
21087
    switch (shell_index) {
 
21088
    case 0: /* graph */
 
21089
      shell_read_graph(&graph, optarg);
 
21090
      break;
 
21091
    case 1: /* labeling */
 
21092
      shell_arg_labeling=strdup(optarg); 
 
21093
  igraph_vector_init(&labeling, 0);
 
21094
      break;
 
21095
    case 2:
 
21096
      shell_igraph_canonical_permutation_usage(argv);
 
21097
      break;
 
21098
    default:
 
21099
      break;
 
21100
    }
 
21101
 
 
21102
    shell_index=-1;
 
21103
  }
 
21104
 
 
21105
  /* Check that we have all arguments */
 
21106
  for (shell_index=0; shell_index<2; shell_index++) {
 
21107
    if (!shell_seen[shell_index]) {
 
21108
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21109
              shell_options[shell_index].name);
 
21110
      exit(1);
 
21111
    }
 
21112
  }
 
21113
 
 
21114
  /* Do the operation */
 
21115
  shell_result=igraph_canonical_permutation(&graph, &labeling, 0, 0);
 
21116
 
 
21117
  /* Write the result */
 
21118
  igraph_destroy(&graph);
 
21119
  shell_write_vector(&labeling, shell_arg_labeling); 
 
21120
  igraph_vector_destroy(&labeling);
 
21121
 
 
21122
  return 0;
 
21123
}
 
21124
 
 
21125
/*-------------------------------------------/
 
21126
/ igraph_permute_vertices                    /
 
21127
/-------------------------------------------*/
 
21128
void shell_igraph_permute_vertices_usage(char **argv) {
 
21129
  printf("%s --graph=<graph> --res=<res> --permutation=<permutation>\n", basename(argv[0]));
 
21130
  exit(1);
 
21131
}
 
21132
 
 
21133
int shell_igraph_permute_vertices(int argc, char **argv) {
 
21134
 
 
21135
  igraph_t graph;
 
21136
  igraph_t res;
 
21137
  igraph_vector_t permutation;
 
21138
  char* shell_arg_res=0;
 
21139
  int shell_result;
 
21140
 
 
21141
 
 
21142
  int shell_seen[3];
 
21143
  int shell_index=-1;
 
21144
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
21145
                                   { "res",required_argument,0,1 },
 
21146
                                   { "permutation",required_argument,0,2 },
 
21147
                                   { "help",no_argument,0,3 },
 
21148
                                   { 0,0,0,0 }
 
21149
                                 };
 
21150
 
 
21151
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21152
  memset(shell_seen, 0, 3*sizeof(int));
 
21153
 
 
21154
  
 
21155
  /* Parse arguments and read input */
 
21156
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21157
 
 
21158
    if (shell_index==-1) {
 
21159
      exit(1);
 
21160
    }
 
21161
 
 
21162
    if (shell_seen[shell_index]==1) {
 
21163
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21164
              shell_options[shell_index].name);
 
21165
      exit(1);
 
21166
    }
 
21167
    shell_seen[shell_index]=1;  
 
21168
 
 
21169
    switch (shell_index) {
 
21170
    case 0: /* graph */
 
21171
      shell_read_graph(&graph, optarg);
 
21172
      break;
 
21173
    case 1: /* res */
 
21174
      shell_arg_res=strdup(optarg);
 
21175
      break;
 
21176
    case 2: /* permutation */
 
21177
      shell_read_vector(&permutation, optarg);
 
21178
      break;
 
21179
    case 3:
 
21180
      shell_igraph_permute_vertices_usage(argv);
 
21181
      break;
 
21182
    default:
 
21183
      break;
 
21184
    }
 
21185
 
 
21186
    shell_index=-1;
 
21187
  }
 
21188
 
 
21189
  /* Check that we have all arguments */
 
21190
  for (shell_index=0; shell_index<3; shell_index++) {
 
21191
    if (!shell_seen[shell_index]) {
 
21192
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21193
              shell_options[shell_index].name);
 
21194
      exit(1);
 
21195
    }
 
21196
  }
 
21197
 
 
21198
  /* Do the operation */
 
21199
  shell_result=igraph_permute_vertices(&graph, &res, &permutation);
 
21200
 
 
21201
  /* Write the result */
 
21202
  igraph_destroy(&graph);
 
21203
  shell_write_graph(&res, shell_arg_res); 
 
21204
  igraph_destroy(&res);
 
21205
  igraph_vector_destroy(&permutation);
 
21206
 
 
21207
  return 0;
 
21208
}
 
21209
 
 
21210
/*-------------------------------------------/
 
21211
/ igraph_isomorphic_bliss                    /
 
21212
/-------------------------------------------*/
 
21213
void shell_igraph_isomorphic_bliss_usage(char **argv) {
 
21214
  printf("%s --graph1=<graph1> --graph2=<graph2> --iso=<iso> --map12=<map12> --map21=<map21>\n", basename(argv[0]));
 
21215
  exit(1);
 
21216
}
 
21217
 
 
21218
int shell_igraph_isomorphic_bliss(int argc, char **argv) {
 
21219
 
 
21220
  igraph_t graph1;
 
21221
  igraph_t graph2;
 
21222
  igraph_bool_t iso;
 
21223
  igraph_vector_t v_map12; igraph_vector_t *map12=0;
 
21224
  igraph_vector_t v_map21; igraph_vector_t *map21=0;
 
21225
 
 
21226
 
 
21227
 
 
21228
 
 
21229
  char* shell_arg_iso=0;
 
21230
  char* shell_arg_map12=0;
 
21231
  char* shell_arg_map21=0;
 
21232
  char* shell_arg_info1=0;
 
21233
  char* shell_arg_info2=0;
 
21234
  int shell_result;
 
21235
 
 
21236
 
 
21237
  int shell_seen[5];
 
21238
  int shell_index=-1;
 
21239
  struct option shell_options[]= { { "graph1",required_argument,0,0 },
 
21240
                                   { "graph2",required_argument,0,1 },
 
21241
                                   { "iso",required_argument,0,2 },
 
21242
                                   { "map12",required_argument,0,3 },
 
21243
                                   { "map21",required_argument,0,4 },
 
21244
                                   { "help",no_argument,0,5 },
 
21245
                                   { 0,0,0,0 }
 
21246
                                 };
 
21247
 
 
21248
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21249
  memset(shell_seen, 0, 5*sizeof(int));
 
21250
 
 
21251
  
 
21252
  /* Parse arguments and read input */
 
21253
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21254
 
 
21255
    if (shell_index==-1) {
 
21256
      exit(1);
 
21257
    }
 
21258
 
 
21259
    if (shell_seen[shell_index]==1) {
 
21260
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21261
              shell_options[shell_index].name);
 
21262
      exit(1);
 
21263
    }
 
21264
    shell_seen[shell_index]=1;  
 
21265
 
 
21266
    switch (shell_index) {
 
21267
    case 0: /* graph1 */
 
21268
      shell_read_graph(&graph1, optarg);
 
21269
      break;
 
21270
    case 1: /* graph2 */
 
21271
      shell_read_graph(&graph2, optarg);
 
21272
      break;
 
21273
    case 2: /* iso */
 
21274
      
 
21275
      break;
 
21276
    case 3: /* map12 */
 
21277
      map12=&v_map12; igraph_vector_init(map12, 0); 
 
21278
  shell_arg_map12=strdup(optarg);
 
21279
      break;
 
21280
    case 4: /* map21 */
 
21281
      map21=&v_map21; igraph_vector_init(map21, 0); 
 
21282
  shell_arg_map21=strdup(optarg);
 
21283
      break;
 
21284
    case 5:
 
21285
      shell_igraph_isomorphic_bliss_usage(argv);
 
21286
      break;
 
21287
    default:
 
21288
      break;
 
21289
    }
 
21290
 
 
21291
    shell_index=-1;
 
21292
  }
 
21293
 
 
21294
  /* Check that we have all arguments */
 
21295
  for (shell_index=0; shell_index<5; shell_index++) {
 
21296
    if (!shell_seen[shell_index]) {
 
21297
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21298
              shell_options[shell_index].name);
 
21299
      exit(1);
 
21300
    }
 
21301
  }
 
21302
 
 
21303
  /* Do the operation */
 
21304
  shell_result=igraph_isomorphic_bliss(&graph1, &graph2, &iso, map12, map21, 0, 0, 0, 0);
 
21305
 
 
21306
  /* Write the result */
 
21307
  igraph_destroy(&graph1);
 
21308
  igraph_destroy(&graph2);
 
21309
  shell_write_boolean(iso, shell_arg_iso);
 
21310
  if (map12) { shell_write_vector(map12, shell_arg_map12); 
 
21311
  igraph_vector_destroy(map12); }
 
21312
  if (map21) { shell_write_vector(map21, shell_arg_map21); 
 
21313
  igraph_vector_destroy(map21); }
 
21314
 
 
21315
  return 0;
 
21316
}
 
21317
 
 
21318
/*-------------------------------------------/
 
21319
/ igraph_automorphisms                       /
 
21320
/-------------------------------------------*/
 
21321
void shell_igraph_automorphisms_usage(char **argv) {
 
21322
  printf("%s --graph=<graph>\n", basename(argv[0]));
 
21323
  exit(1);
 
21324
}
 
21325
 
 
21326
int shell_igraph_automorphisms(int argc, char **argv) {
 
21327
 
 
21328
  igraph_t graph;
 
21329
 
 
21330
 
 
21331
  char* shell_arg_info=0;
 
21332
  int shell_result;
 
21333
 
 
21334
 
 
21335
  int shell_seen[1];
 
21336
  int shell_index=-1;
 
21337
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
21338
                                   { "help",no_argument,0,1 },
 
21339
                                   { 0,0,0,0 }
 
21340
                                 };
 
21341
 
 
21342
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21343
  memset(shell_seen, 0, 1*sizeof(int));
 
21344
 
 
21345
  
 
21346
  /* Parse arguments and read input */
 
21347
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21348
 
 
21349
    if (shell_index==-1) {
 
21350
      exit(1);
 
21351
    }
 
21352
 
 
21353
    if (shell_seen[shell_index]==1) {
 
21354
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21355
              shell_options[shell_index].name);
 
21356
      exit(1);
 
21357
    }
 
21358
    shell_seen[shell_index]=1;  
 
21359
 
 
21360
    switch (shell_index) {
 
21361
    case 0: /* graph */
 
21362
      shell_read_graph(&graph, optarg);
 
21363
      break;
 
21364
    case 1:
 
21365
      shell_igraph_automorphisms_usage(argv);
 
21366
      break;
 
21367
    default:
 
21368
      break;
 
21369
    }
 
21370
 
 
21371
    shell_index=-1;
 
21372
  }
 
21373
 
 
21374
  /* Check that we have all arguments */
 
21375
  for (shell_index=0; shell_index<1; shell_index++) {
 
21376
    if (!shell_seen[shell_index]) {
 
21377
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21378
              shell_options[shell_index].name);
 
21379
      exit(1);
 
21380
    }
 
21381
  }
 
21382
 
 
21383
  /* Do the operation */
 
21384
  shell_result=igraph_automorphisms(&graph, 0, 0);
 
21385
 
 
21386
  /* Write the result */
 
21387
  igraph_destroy(&graph);
 
21388
 
 
21389
  return 0;
 
21390
}
 
21391
 
 
21392
/*-------------------------------------------/
 
21393
/ igraph_running_mean                        /
 
21394
/-------------------------------------------*/
 
21395
void shell_igraph_running_mean_usage(char **argv) {
 
21396
  printf("%s --data=<data> --res=<res> --binwidth=<binwidth>\n", basename(argv[0]));
 
21397
  exit(1);
 
21398
}
 
21399
 
 
21400
int shell_igraph_running_mean(int argc, char **argv) {
 
21401
 
 
21402
  igraph_vector_t data;
 
21403
  igraph_vector_t res;
 
21404
  igraph_integer_t binwidth;
 
21405
  char* shell_arg_res=0;
 
21406
  int shell_result;
 
21407
 
 
21408
 
 
21409
  int shell_seen[3];
 
21410
  int shell_index=-1;
 
21411
  struct option shell_options[]= { { "data",required_argument,0,0 },
 
21412
                                   { "res",required_argument,0,1 },
 
21413
                                   { "binwidth",required_argument,0,2 },
 
21414
                                   { "help",no_argument,0,3 },
 
21415
                                   { 0,0,0,0 }
 
21416
                                 };
 
21417
 
 
21418
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21419
  memset(shell_seen, 0, 3*sizeof(int));
 
21420
 
 
21421
  
 
21422
  /* Parse arguments and read input */
 
21423
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21424
 
 
21425
    if (shell_index==-1) {
 
21426
      exit(1);
 
21427
    }
 
21428
 
 
21429
    if (shell_seen[shell_index]==1) {
 
21430
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21431
              shell_options[shell_index].name);
 
21432
      exit(1);
 
21433
    }
 
21434
    shell_seen[shell_index]=1;  
 
21435
 
 
21436
    switch (shell_index) {
 
21437
    case 0: /* data */
 
21438
      shell_read_vector(&data, optarg);
 
21439
      break;
 
21440
    case 1: /* res */
 
21441
      shell_arg_res=strdup(optarg); 
 
21442
  igraph_vector_init(&res, 0);
 
21443
      break;
 
21444
    case 2: /* binwidth */
 
21445
      shell_read_integer(&binwidth, optarg);
 
21446
      break;
 
21447
    case 3:
 
21448
      shell_igraph_running_mean_usage(argv);
 
21449
      break;
 
21450
    default:
 
21451
      break;
 
21452
    }
 
21453
 
 
21454
    shell_index=-1;
 
21455
  }
 
21456
 
 
21457
  /* Check that we have all arguments */
 
21458
  for (shell_index=0; shell_index<3; shell_index++) {
 
21459
    if (!shell_seen[shell_index]) {
 
21460
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21461
              shell_options[shell_index].name);
 
21462
      exit(1);
 
21463
    }
 
21464
  }
 
21465
 
 
21466
  /* Do the operation */
 
21467
  shell_result=igraph_running_mean(&data, &res, binwidth);
 
21468
 
 
21469
  /* Write the result */
 
21470
  igraph_vector_destroy(&data);
 
21471
  shell_write_vector(&res, shell_arg_res); 
 
21472
  igraph_vector_destroy(&res);
 
21473
 
 
21474
  return 0;
 
21475
}
 
21476
 
 
21477
/*-------------------------------------------/
 
21478
/ igraph_random_sample                       /
 
21479
/-------------------------------------------*/
 
21480
void shell_igraph_random_sample_usage(char **argv) {
 
21481
  printf("%s --res=<res> --l=<l> --h=<h> --length=<length>\n", basename(argv[0]));
 
21482
  exit(1);
 
21483
}
 
21484
 
 
21485
int shell_igraph_random_sample(int argc, char **argv) {
 
21486
 
 
21487
  igraph_vector_t res;
 
21488
  igraph_integer_t l;
 
21489
  igraph_integer_t h;
 
21490
  igraph_integer_t length;
 
21491
  char* shell_arg_res=0;
 
21492
  int shell_result;
 
21493
 
 
21494
 
 
21495
  int shell_seen[4];
 
21496
  int shell_index=-1;
 
21497
  struct option shell_options[]= { { "res",required_argument,0,0 },
 
21498
                                   { "l",required_argument,0,1 },
 
21499
                                   { "h",required_argument,0,2 },
 
21500
                                   { "length",required_argument,0,3 },
 
21501
                                   { "help",no_argument,0,4 },
 
21502
                                   { 0,0,0,0 }
 
21503
                                 };
 
21504
 
 
21505
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21506
  memset(shell_seen, 0, 4*sizeof(int));
 
21507
 
 
21508
  
 
21509
  /* Parse arguments and read input */
 
21510
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21511
 
 
21512
    if (shell_index==-1) {
 
21513
      exit(1);
 
21514
    }
 
21515
 
 
21516
    if (shell_seen[shell_index]==1) {
 
21517
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21518
              shell_options[shell_index].name);
 
21519
      exit(1);
 
21520
    }
 
21521
    shell_seen[shell_index]=1;  
 
21522
 
 
21523
    switch (shell_index) {
 
21524
    case 0: /* res */
 
21525
      shell_arg_res=strdup(optarg); 
 
21526
  igraph_vector_init(&res, 0);
 
21527
      break;
 
21528
    case 1: /* l */
 
21529
      shell_read_integer(&l, optarg);
 
21530
      break;
 
21531
    case 2: /* h */
 
21532
      shell_read_integer(&h, optarg);
 
21533
      break;
 
21534
    case 3: /* length */
 
21535
      shell_read_integer(&length, optarg);
 
21536
      break;
 
21537
    case 4:
 
21538
      shell_igraph_random_sample_usage(argv);
 
21539
      break;
 
21540
    default:
 
21541
      break;
 
21542
    }
 
21543
 
 
21544
    shell_index=-1;
 
21545
  }
 
21546
 
 
21547
  /* Check that we have all arguments */
 
21548
  for (shell_index=0; shell_index<4; shell_index++) {
 
21549
    if (!shell_seen[shell_index]) {
 
21550
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21551
              shell_options[shell_index].name);
 
21552
      exit(1);
 
21553
    }
 
21554
  }
 
21555
 
 
21556
  /* Do the operation */
 
21557
  shell_result=igraph_random_sample(&res, l, h, length);
 
21558
 
 
21559
  /* Write the result */
 
21560
  shell_write_vector(&res, shell_arg_res); 
 
21561
  igraph_vector_destroy(&res);
 
21562
 
 
21563
  return 0;
 
21564
}
 
21565
 
 
21566
/*-------------------------------------------/
 
21567
/ igraph_convex_hull                         /
 
21568
/-------------------------------------------*/
 
21569
void shell_igraph_convex_hull_usage(char **argv) {
 
21570
  printf("%s --data=<data> --resverts=<resverts> --rescoords=<rescoords>\n", basename(argv[0]));
 
21571
  exit(1);
 
21572
}
 
21573
 
 
21574
int shell_igraph_convex_hull(int argc, char **argv) {
 
21575
 
 
21576
  igraph_matrix_t data;
 
21577
  igraph_vector_t resverts;
 
21578
  igraph_matrix_t rescoords;
 
21579
  char* shell_arg_resverts=0;
 
21580
  char* shell_arg_rescoords=0;
 
21581
  int shell_result;
 
21582
 
 
21583
 
 
21584
  int shell_seen[3];
 
21585
  int shell_index=-1;
 
21586
  struct option shell_options[]= { { "data",required_argument,0,0 },
 
21587
                                   { "resverts",required_argument,0,1 },
 
21588
                                   { "rescoords",required_argument,0,2 },
 
21589
                                   { "help",no_argument,0,3 },
 
21590
                                   { 0,0,0,0 }
 
21591
                                 };
 
21592
 
 
21593
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21594
  memset(shell_seen, 0, 3*sizeof(int));
 
21595
 
 
21596
  
 
21597
  /* Parse arguments and read input */
 
21598
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21599
 
 
21600
    if (shell_index==-1) {
 
21601
      exit(1);
 
21602
    }
 
21603
 
 
21604
    if (shell_seen[shell_index]==1) {
 
21605
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21606
              shell_options[shell_index].name);
 
21607
      exit(1);
 
21608
    }
 
21609
    shell_seen[shell_index]=1;  
 
21610
 
 
21611
    switch (shell_index) {
 
21612
    case 0: /* data */
 
21613
      shell_read_matrix(&data, optarg);
 
21614
      break;
 
21615
    case 1: /* resverts */
 
21616
      shell_arg_resverts=strdup(optarg); 
 
21617
  igraph_vector_init(&resverts, 0);
 
21618
      break;
 
21619
    case 2: /* rescoords */
 
21620
      shell_arg_rescoords=strdup(optarg); 
 
21621
  igraph_matrix_init(&rescoords, 0, 0);
 
21622
      break;
 
21623
    case 3:
 
21624
      shell_igraph_convex_hull_usage(argv);
 
21625
      break;
 
21626
    default:
 
21627
      break;
 
21628
    }
 
21629
 
 
21630
    shell_index=-1;
 
21631
  }
 
21632
 
 
21633
  /* Check that we have all arguments */
 
21634
  for (shell_index=0; shell_index<3; shell_index++) {
 
21635
    if (!shell_seen[shell_index]) {
 
21636
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21637
              shell_options[shell_index].name);
 
21638
      exit(1);
 
21639
    }
 
21640
  }
 
21641
 
 
21642
  /* Do the operation */
 
21643
  shell_result=igraph_convex_hull(&data, &resverts, &rescoords);
 
21644
 
 
21645
  /* Write the result */
 
21646
  igraph_matrix_destroy(&data);
 
21647
  shell_write_vector(&resverts, shell_arg_resverts); 
 
21648
  igraph_vector_destroy(&resverts);
 
21649
  shell_write_matrix(&rescoords, shell_arg_rescoords); 
 
21650
  igraph_matrix_destroy(&rescoords);
 
21651
 
 
21652
  return 0;
 
21653
}
 
21654
 
 
21655
/*-------------------------------------------/
 
21656
/ igraph_revolver_ml_d                       /
 
21657
/-------------------------------------------*/
 
21658
void shell_igraph_revolver_ml_d_usage(char **argv) {
 
21659
  printf("%s --graph=<graph> --niter=<niter> --kernel=<kernel> --cites=<cites> --delta=<delta> --filter=<filter> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
21660
  exit(1);
 
21661
}
 
21662
 
 
21663
int shell_igraph_revolver_ml_d(int argc, char **argv) {
 
21664
 
 
21665
  igraph_t graph;
 
21666
  igraph_integer_t niter;
 
21667
  igraph_vector_t kernel;
 
21668
  igraph_vector_t v_cites; igraph_vector_t *cites=0;
 
21669
  igraph_real_t delta=1e-10;
 
21670
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
21671
  igraph_real_t logprob;
 
21672
  igraph_real_t logmax;
 
21673
  char* shell_arg_kernel=0;
 
21674
  char* shell_arg_cites=0;
 
21675
  char* shell_arg_logprob=0;
 
21676
  char* shell_arg_logmax=0;
 
21677
  int shell_result;
 
21678
 
 
21679
 
 
21680
  int shell_seen[8];
 
21681
  int shell_index=-1;
 
21682
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
21683
                                   { "niter",required_argument,0,1 },
 
21684
                                   { "kernel",required_argument,0,2 },
 
21685
                                   { "cites",required_argument,0,3 },
 
21686
                                   { "delta",required_argument,0,4 },
 
21687
                                   { "filter",required_argument,0,5 },
 
21688
                                   { "logprob",required_argument,0,6 },
 
21689
                                   { "logmax",required_argument,0,7 },
 
21690
                                   { "help",no_argument,0,8 },
 
21691
                                   { 0,0,0,0 }
 
21692
                                 };
 
21693
 
 
21694
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21695
  memset(shell_seen, 0, 8*sizeof(int));
 
21696
  shell_seen[4]=2;
 
21697
  shell_seen[5]=2;
 
21698
  
 
21699
  /* Parse arguments and read input */
 
21700
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21701
 
 
21702
    if (shell_index==-1) {
 
21703
      exit(1);
 
21704
    }
 
21705
 
 
21706
    if (shell_seen[shell_index]==1) {
 
21707
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21708
              shell_options[shell_index].name);
 
21709
      exit(1);
 
21710
    }
 
21711
    shell_seen[shell_index]=1;  
 
21712
 
 
21713
    switch (shell_index) {
 
21714
    case 0: /* graph */
 
21715
      shell_read_graph(&graph, optarg);
 
21716
      break;
 
21717
    case 1: /* niter */
 
21718
      shell_read_integer(&niter, optarg);
 
21719
      break;
 
21720
    case 2: /* kernel */
 
21721
      shell_arg_kernel=strdup(optarg); 
 
21722
  igraph_vector_init(&kernel, 0);
 
21723
      break;
 
21724
    case 3: /* cites */
 
21725
      cites=&v_cites; igraph_vector_init(cites, 0); 
 
21726
  shell_arg_cites=strdup(optarg);
 
21727
      break;
 
21728
    case 4: /* delta */
 
21729
      shell_read_real(&delta, optarg);
 
21730
      break;
 
21731
    case 5: /* filter */
 
21732
      filter=&v_filter; shell_read_vector(filter, optarg);
 
21733
      break;
 
21734
    case 6: /* logprob */
 
21735
      shell_arg_logprob=strdup(optarg);
 
21736
      break;
 
21737
    case 7: /* logmax */
 
21738
      shell_arg_logmax=strdup(optarg);
 
21739
      break;
 
21740
    case 8:
 
21741
      shell_igraph_revolver_ml_d_usage(argv);
 
21742
      break;
 
21743
    default:
 
21744
      break;
 
21745
    }
 
21746
 
 
21747
    shell_index=-1;
 
21748
  }
 
21749
 
 
21750
  /* Check that we have all arguments */
 
21751
  for (shell_index=0; shell_index<8; shell_index++) {
 
21752
    if (!shell_seen[shell_index]) {
 
21753
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21754
              shell_options[shell_index].name);
 
21755
      exit(1);
 
21756
    }
 
21757
  }
 
21758
 
 
21759
  /* Do the operation */
 
21760
  shell_result=igraph_revolver_ml_d(&graph, niter, &kernel, cites, delta, filter, &logprob, &logmax);
 
21761
 
 
21762
  /* Write the result */
 
21763
  igraph_destroy(&graph);
 
21764
  shell_write_vector(&kernel, shell_arg_kernel); 
 
21765
  igraph_vector_destroy(&kernel);
 
21766
  if (cites) { shell_write_vector(cites, shell_arg_cites); 
 
21767
  igraph_vector_destroy(cites); }
 
21768
  if (filter) { igraph_vector_destroy(filter); }
 
21769
  shell_write_real(logprob, shell_arg_logprob);
 
21770
  shell_write_real(logmax, shell_arg_logmax);
 
21771
 
 
21772
  return 0;
 
21773
}
 
21774
 
 
21775
/*-------------------------------------------/
 
21776
/ igraph_revolver_probs_d                    /
 
21777
/-------------------------------------------*/
 
21778
void shell_igraph_revolver_probs_d_usage(char **argv) {
 
21779
  printf("%s --graph=<graph> --kernel=<kernel> --probs=<probs> --citedprobs=<citedprobs> --citingprobs=<citingprobs> --ntk=<ntk>\n", basename(argv[0]));
 
21780
  exit(1);
 
21781
}
 
21782
 
 
21783
int shell_igraph_revolver_probs_d(int argc, char **argv) {
 
21784
 
 
21785
  igraph_t graph;
 
21786
  igraph_vector_t kernel;
 
21787
  igraph_vector_t v_probs; igraph_vector_t *probs=0;
 
21788
  igraph_vector_t v_citedprobs; igraph_vector_t *citedprobs=0;
 
21789
  igraph_vector_t v_citingprobs; igraph_vector_t *citingprobs=0;
 
21790
  igraph_bool_t ntk=0;
 
21791
  char* shell_arg_probs=0;
 
21792
  char* shell_arg_citedprobs=0;
 
21793
  char* shell_arg_citingprobs=0;
 
21794
  int shell_result;
 
21795
 
 
21796
 
 
21797
  int shell_seen[6];
 
21798
  int shell_index=-1;
 
21799
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
21800
                                   { "kernel",required_argument,0,1 },
 
21801
                                   { "probs",required_argument,0,2 },
 
21802
                                   { "citedprobs",required_argument,0,3 },
 
21803
                                   { "citingprobs",required_argument,0,4 },
 
21804
                                   { "ntk",required_argument,0,5 },
 
21805
                                   { "help",no_argument,0,6 },
 
21806
                                   { 0,0,0,0 }
 
21807
                                 };
 
21808
 
 
21809
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21810
  memset(shell_seen, 0, 6*sizeof(int));
 
21811
  shell_seen[5]=2;
 
21812
  
 
21813
  /* Parse arguments and read input */
 
21814
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21815
 
 
21816
    if (shell_index==-1) {
 
21817
      exit(1);
 
21818
    }
 
21819
 
 
21820
    if (shell_seen[shell_index]==1) {
 
21821
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21822
              shell_options[shell_index].name);
 
21823
      exit(1);
 
21824
    }
 
21825
    shell_seen[shell_index]=1;  
 
21826
 
 
21827
    switch (shell_index) {
 
21828
    case 0: /* graph */
 
21829
      shell_read_graph(&graph, optarg);
 
21830
      break;
 
21831
    case 1: /* kernel */
 
21832
      shell_read_vector(&kernel, optarg);
 
21833
      break;
 
21834
    case 2: /* probs */
 
21835
      probs=&v_probs; igraph_vector_init(probs, 0); 
 
21836
  shell_arg_probs=strdup(optarg);
 
21837
      break;
 
21838
    case 3: /* citedprobs */
 
21839
      citedprobs=&v_citedprobs; igraph_vector_init(citedprobs, 0); 
 
21840
  shell_arg_citedprobs=strdup(optarg);
 
21841
      break;
 
21842
    case 4: /* citingprobs */
 
21843
      citingprobs=&v_citingprobs; igraph_vector_init(citingprobs, 0); 
 
21844
  shell_arg_citingprobs=strdup(optarg);
 
21845
      break;
 
21846
    case 5: /* ntk */
 
21847
      shell_read_boolean(&ntk, optarg);
 
21848
      break;
 
21849
    case 6:
 
21850
      shell_igraph_revolver_probs_d_usage(argv);
 
21851
      break;
 
21852
    default:
 
21853
      break;
 
21854
    }
 
21855
 
 
21856
    shell_index=-1;
 
21857
  }
 
21858
 
 
21859
  /* Check that we have all arguments */
 
21860
  for (shell_index=0; shell_index<6; shell_index++) {
 
21861
    if (!shell_seen[shell_index]) {
 
21862
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21863
              shell_options[shell_index].name);
 
21864
      exit(1);
 
21865
    }
 
21866
  }
 
21867
 
 
21868
  /* Do the operation */
 
21869
  shell_result=igraph_revolver_probs_d(&graph, &kernel, probs, citedprobs, citingprobs, ntk);
 
21870
 
 
21871
  /* Write the result */
 
21872
  igraph_destroy(&graph);
 
21873
  igraph_vector_destroy(&kernel);
 
21874
  if (probs) { shell_write_vector(probs, shell_arg_probs); 
 
21875
  igraph_vector_destroy(probs); }
 
21876
  if (citedprobs) { shell_write_vector(citedprobs, shell_arg_citedprobs); 
 
21877
  igraph_vector_destroy(citedprobs); }
 
21878
  if (citingprobs) { shell_write_vector(citingprobs, shell_arg_citingprobs); 
 
21879
  igraph_vector_destroy(citingprobs); }
 
21880
 
 
21881
  return 0;
 
21882
}
 
21883
 
 
21884
/*-------------------------------------------/
 
21885
/ igraph_revolver_ml_de                      /
 
21886
/-------------------------------------------*/
 
21887
void shell_igraph_revolver_ml_de_usage(char **argv) {
 
21888
  printf("%s --graph=<graph> --niter=<niter> --kernel=<kernel> --cats=<cats> --delta=<delta> --filter=<filter> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
21889
  exit(1);
 
21890
}
 
21891
 
 
21892
int shell_igraph_revolver_ml_de(int argc, char **argv) {
 
21893
 
 
21894
  igraph_t graph;
 
21895
  igraph_integer_t niter;
 
21896
  igraph_matrix_t kernel;
 
21897
  igraph_vector_t cats;
 
21898
 
 
21899
  igraph_real_t delta=1e-10;
 
21900
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
21901
  igraph_real_t logprob;
 
21902
  igraph_real_t logmax;
 
21903
  char* shell_arg_kernel=0;
 
21904
  char* shell_arg_cites=0;
 
21905
  char* shell_arg_logprob=0;
 
21906
  char* shell_arg_logmax=0;
 
21907
  int shell_result;
 
21908
 
 
21909
 
 
21910
  int shell_seen[8];
 
21911
  int shell_index=-1;
 
21912
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
21913
                                   { "niter",required_argument,0,1 },
 
21914
                                   { "kernel",required_argument,0,2 },
 
21915
                                   { "cats",required_argument,0,3 },
 
21916
                                   { "delta",required_argument,0,4 },
 
21917
                                   { "filter",required_argument,0,5 },
 
21918
                                   { "logprob",required_argument,0,6 },
 
21919
                                   { "logmax",required_argument,0,7 },
 
21920
                                   { "help",no_argument,0,8 },
 
21921
                                   { 0,0,0,0 }
 
21922
                                 };
 
21923
 
 
21924
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
21925
  memset(shell_seen, 0, 8*sizeof(int));
 
21926
  shell_seen[4]=2;
 
21927
  shell_seen[5]=2;
 
21928
  
 
21929
  /* Parse arguments and read input */
 
21930
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
21931
 
 
21932
    if (shell_index==-1) {
 
21933
      exit(1);
 
21934
    }
 
21935
 
 
21936
    if (shell_seen[shell_index]==1) {
 
21937
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
21938
              shell_options[shell_index].name);
 
21939
      exit(1);
 
21940
    }
 
21941
    shell_seen[shell_index]=1;  
 
21942
 
 
21943
    switch (shell_index) {
 
21944
    case 0: /* graph */
 
21945
      shell_read_graph(&graph, optarg);
 
21946
      break;
 
21947
    case 1: /* niter */
 
21948
      shell_read_integer(&niter, optarg);
 
21949
      break;
 
21950
    case 2: /* kernel */
 
21951
      shell_arg_kernel=strdup(optarg); 
 
21952
  igraph_matrix_init(&kernel, 0, 0);
 
21953
      break;
 
21954
    case 3: /* cats */
 
21955
      shell_read_vector(&cats, optarg);
 
21956
      break;
 
21957
    case 4: /* delta */
 
21958
      shell_read_real(&delta, optarg);
 
21959
      break;
 
21960
    case 5: /* filter */
 
21961
      filter=&v_filter; shell_read_vector(filter, optarg);
 
21962
      break;
 
21963
    case 6: /* logprob */
 
21964
      shell_arg_logprob=strdup(optarg);
 
21965
      break;
 
21966
    case 7: /* logmax */
 
21967
      shell_arg_logmax=strdup(optarg);
 
21968
      break;
 
21969
    case 8:
 
21970
      shell_igraph_revolver_ml_de_usage(argv);
 
21971
      break;
 
21972
    default:
 
21973
      break;
 
21974
    }
 
21975
 
 
21976
    shell_index=-1;
 
21977
  }
 
21978
 
 
21979
  /* Check that we have all arguments */
 
21980
  for (shell_index=0; shell_index<8; shell_index++) {
 
21981
    if (!shell_seen[shell_index]) {
 
21982
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
21983
              shell_options[shell_index].name);
 
21984
      exit(1);
 
21985
    }
 
21986
  }
 
21987
 
 
21988
  /* Do the operation */
 
21989
  shell_result=igraph_revolver_ml_de(&graph, niter, &kernel, &cats, 0, delta, filter, &logprob, &logmax);
 
21990
 
 
21991
  /* Write the result */
 
21992
  igraph_destroy(&graph);
 
21993
  shell_write_matrix(&kernel, shell_arg_kernel); 
 
21994
  igraph_matrix_destroy(&kernel);
 
21995
  igraph_vector_destroy(&cats);
 
21996
  if (filter) { igraph_vector_destroy(filter); }
 
21997
  shell_write_real(logprob, shell_arg_logprob);
 
21998
  shell_write_real(logmax, shell_arg_logmax);
 
21999
 
 
22000
  return 0;
 
22001
}
 
22002
 
 
22003
/*-------------------------------------------/
 
22004
/ igraph_revolver_probs_de                   /
 
22005
/-------------------------------------------*/
 
22006
void shell_igraph_revolver_probs_de_usage(char **argv) {
 
22007
  printf("%s --graph=<graph> --kernel=<kernel> --cats=<cats> --logprobs=<logprobs> --logcited=<logcited> --logciting=<logciting>\n", basename(argv[0]));
 
22008
  exit(1);
 
22009
}
 
22010
 
 
22011
int shell_igraph_revolver_probs_de(int argc, char **argv) {
 
22012
 
 
22013
  igraph_t graph;
 
22014
  igraph_matrix_t kernel;
 
22015
  igraph_vector_t cats;
 
22016
  igraph_vector_t v_logprobs; igraph_vector_t *logprobs=0;
 
22017
  igraph_vector_t v_logcited; igraph_vector_t *logcited=0;
 
22018
  igraph_vector_t v_logciting; igraph_vector_t *logciting=0;
 
22019
  char* shell_arg_logprobs=0;
 
22020
  char* shell_arg_logcited=0;
 
22021
  char* shell_arg_logciting=0;
 
22022
  int shell_result;
 
22023
 
 
22024
 
 
22025
  int shell_seen[6];
 
22026
  int shell_index=-1;
 
22027
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22028
                                   { "kernel",required_argument,0,1 },
 
22029
                                   { "cats",required_argument,0,2 },
 
22030
                                   { "logprobs",required_argument,0,3 },
 
22031
                                   { "logcited",required_argument,0,4 },
 
22032
                                   { "logciting",required_argument,0,5 },
 
22033
                                   { "help",no_argument,0,6 },
 
22034
                                   { 0,0,0,0 }
 
22035
                                 };
 
22036
 
 
22037
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22038
  memset(shell_seen, 0, 6*sizeof(int));
 
22039
 
 
22040
  
 
22041
  /* Parse arguments and read input */
 
22042
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22043
 
 
22044
    if (shell_index==-1) {
 
22045
      exit(1);
 
22046
    }
 
22047
 
 
22048
    if (shell_seen[shell_index]==1) {
 
22049
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22050
              shell_options[shell_index].name);
 
22051
      exit(1);
 
22052
    }
 
22053
    shell_seen[shell_index]=1;  
 
22054
 
 
22055
    switch (shell_index) {
 
22056
    case 0: /* graph */
 
22057
      shell_read_graph(&graph, optarg);
 
22058
      break;
 
22059
    case 1: /* kernel */
 
22060
      shell_read_matrix(&kernel, optarg);
 
22061
      break;
 
22062
    case 2: /* cats */
 
22063
      shell_read_vector(&cats, optarg);
 
22064
      break;
 
22065
    case 3: /* logprobs */
 
22066
      logprobs=&v_logprobs; igraph_vector_init(logprobs, 0); 
 
22067
  shell_arg_logprobs=strdup(optarg);
 
22068
      break;
 
22069
    case 4: /* logcited */
 
22070
      logcited=&v_logcited; igraph_vector_init(logcited, 0); 
 
22071
  shell_arg_logcited=strdup(optarg);
 
22072
      break;
 
22073
    case 5: /* logciting */
 
22074
      logciting=&v_logciting; igraph_vector_init(logciting, 0); 
 
22075
  shell_arg_logciting=strdup(optarg);
 
22076
      break;
 
22077
    case 6:
 
22078
      shell_igraph_revolver_probs_de_usage(argv);
 
22079
      break;
 
22080
    default:
 
22081
      break;
 
22082
    }
 
22083
 
 
22084
    shell_index=-1;
 
22085
  }
 
22086
 
 
22087
  /* Check that we have all arguments */
 
22088
  for (shell_index=0; shell_index<6; shell_index++) {
 
22089
    if (!shell_seen[shell_index]) {
 
22090
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22091
              shell_options[shell_index].name);
 
22092
      exit(1);
 
22093
    }
 
22094
  }
 
22095
 
 
22096
  /* Do the operation */
 
22097
  shell_result=igraph_revolver_probs_de(&graph, &kernel, &cats, logprobs, logcited, logciting);
 
22098
 
 
22099
  /* Write the result */
 
22100
  igraph_destroy(&graph);
 
22101
  igraph_matrix_destroy(&kernel);
 
22102
  igraph_vector_destroy(&cats);
 
22103
  if (logprobs) { shell_write_vector(logprobs, shell_arg_logprobs); 
 
22104
  igraph_vector_destroy(logprobs); }
 
22105
  if (logcited) { shell_write_vector(logcited, shell_arg_logcited); 
 
22106
  igraph_vector_destroy(logcited); }
 
22107
  if (logciting) { shell_write_vector(logciting, shell_arg_logciting); 
 
22108
  igraph_vector_destroy(logciting); }
 
22109
 
 
22110
  return 0;
 
22111
}
 
22112
 
 
22113
/*-------------------------------------------/
 
22114
/ igraph_revolver_ml_ade                     /
 
22115
/-------------------------------------------*/
 
22116
void shell_igraph_revolver_ml_ade_usage(char **argv) {
 
22117
  printf("%s --graph=<graph> --niter=<niter> --cats=<cats> --agebins=<agebins> --delta=<delta> --filter=<filter> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
22118
  exit(1);
 
22119
}
 
22120
 
 
22121
int shell_igraph_revolver_ml_ade(int argc, char **argv) {
 
22122
 
 
22123
  igraph_t graph;
 
22124
  igraph_integer_t niter;
 
22125
 
 
22126
  igraph_vector_t cats;
 
22127
 
 
22128
  igraph_integer_t agebins=300;
 
22129
  igraph_real_t delta=1e-10;
 
22130
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
22131
  igraph_real_t logprob;
 
22132
  igraph_real_t logmax;
 
22133
  char* shell_arg_kernel=0;
 
22134
  char* shell_arg_cites=0;
 
22135
  char* shell_arg_logprob=0;
 
22136
  char* shell_arg_logmax=0;
 
22137
  int shell_result;
 
22138
 
 
22139
 
 
22140
  int shell_seen[8];
 
22141
  int shell_index=-1;
 
22142
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22143
                                   { "niter",required_argument,0,1 },
 
22144
                                   { "cats",required_argument,0,2 },
 
22145
                                   { "agebins",required_argument,0,3 },
 
22146
                                   { "delta",required_argument,0,4 },
 
22147
                                   { "filter",required_argument,0,5 },
 
22148
                                   { "logprob",required_argument,0,6 },
 
22149
                                   { "logmax",required_argument,0,7 },
 
22150
                                   { "help",no_argument,0,8 },
 
22151
                                   { 0,0,0,0 }
 
22152
                                 };
 
22153
 
 
22154
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22155
  memset(shell_seen, 0, 8*sizeof(int));
 
22156
  shell_seen[3]=2;
 
22157
  shell_seen[4]=2;
 
22158
  shell_seen[5]=2;
 
22159
  
 
22160
  /* Parse arguments and read input */
 
22161
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22162
 
 
22163
    if (shell_index==-1) {
 
22164
      exit(1);
 
22165
    }
 
22166
 
 
22167
    if (shell_seen[shell_index]==1) {
 
22168
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22169
              shell_options[shell_index].name);
 
22170
      exit(1);
 
22171
    }
 
22172
    shell_seen[shell_index]=1;  
 
22173
 
 
22174
    switch (shell_index) {
 
22175
    case 0: /* graph */
 
22176
      shell_read_graph(&graph, optarg);
 
22177
      break;
 
22178
    case 1: /* niter */
 
22179
      shell_read_integer(&niter, optarg);
 
22180
      break;
 
22181
    case 2: /* cats */
 
22182
      shell_read_vector(&cats, optarg);
 
22183
      break;
 
22184
    case 3: /* agebins */
 
22185
      shell_read_integer(&agebins, optarg);
 
22186
      break;
 
22187
    case 4: /* delta */
 
22188
      shell_read_real(&delta, optarg);
 
22189
      break;
 
22190
    case 5: /* filter */
 
22191
      filter=&v_filter; shell_read_vector(filter, optarg);
 
22192
      break;
 
22193
    case 6: /* logprob */
 
22194
      shell_arg_logprob=strdup(optarg);
 
22195
      break;
 
22196
    case 7: /* logmax */
 
22197
      shell_arg_logmax=strdup(optarg);
 
22198
      break;
 
22199
    case 8:
 
22200
      shell_igraph_revolver_ml_ade_usage(argv);
 
22201
      break;
 
22202
    default:
 
22203
      break;
 
22204
    }
 
22205
 
 
22206
    shell_index=-1;
 
22207
  }
 
22208
 
 
22209
  /* Check that we have all arguments */
 
22210
  for (shell_index=0; shell_index<8; shell_index++) {
 
22211
    if (!shell_seen[shell_index]) {
 
22212
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22213
              shell_options[shell_index].name);
 
22214
      exit(1);
 
22215
    }
 
22216
  }
 
22217
 
 
22218
  /* Do the operation */
 
22219
  shell_result=igraph_revolver_ml_ade(&graph, niter, 0, &cats, 0, agebins, delta, filter, &logprob, &logmax);
 
22220
 
 
22221
  /* Write the result */
 
22222
  igraph_destroy(&graph);
 
22223
  igraph_vector_destroy(&cats);
 
22224
  if (filter) { igraph_vector_destroy(filter); }
 
22225
  shell_write_real(logprob, shell_arg_logprob);
 
22226
  shell_write_real(logmax, shell_arg_logmax);
 
22227
 
 
22228
  return 0;
 
22229
}
 
22230
 
 
22231
/*-------------------------------------------/
 
22232
/ igraph_revolver_probs_ade                  /
 
22233
/-------------------------------------------*/
 
22234
void shell_igraph_revolver_probs_ade_usage(char **argv) {
 
22235
  printf("%s --graph=<graph> --cats=<cats> --logprobs=<logprobs> --logcited=<logcited> --logciting=<logciting>\n", basename(argv[0]));
 
22236
  exit(1);
 
22237
}
 
22238
 
 
22239
int shell_igraph_revolver_probs_ade(int argc, char **argv) {
 
22240
 
 
22241
  igraph_t graph;
 
22242
 
 
22243
  igraph_vector_t cats;
 
22244
  igraph_vector_t v_logprobs; igraph_vector_t *logprobs=0;
 
22245
  igraph_vector_t v_logcited; igraph_vector_t *logcited=0;
 
22246
  igraph_vector_t v_logciting; igraph_vector_t *logciting=0;
 
22247
  char* shell_arg_logprobs=0;
 
22248
  char* shell_arg_logcited=0;
 
22249
  char* shell_arg_logciting=0;
 
22250
  int shell_result;
 
22251
 
 
22252
 
 
22253
  int shell_seen[5];
 
22254
  int shell_index=-1;
 
22255
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22256
                                   { "cats",required_argument,0,1 },
 
22257
                                   { "logprobs",required_argument,0,2 },
 
22258
                                   { "logcited",required_argument,0,3 },
 
22259
                                   { "logciting",required_argument,0,4 },
 
22260
                                   { "help",no_argument,0,5 },
 
22261
                                   { 0,0,0,0 }
 
22262
                                 };
 
22263
 
 
22264
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22265
  memset(shell_seen, 0, 5*sizeof(int));
 
22266
 
 
22267
  
 
22268
  /* Parse arguments and read input */
 
22269
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22270
 
 
22271
    if (shell_index==-1) {
 
22272
      exit(1);
 
22273
    }
 
22274
 
 
22275
    if (shell_seen[shell_index]==1) {
 
22276
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22277
              shell_options[shell_index].name);
 
22278
      exit(1);
 
22279
    }
 
22280
    shell_seen[shell_index]=1;  
 
22281
 
 
22282
    switch (shell_index) {
 
22283
    case 0: /* graph */
 
22284
      shell_read_graph(&graph, optarg);
 
22285
      break;
 
22286
    case 1: /* cats */
 
22287
      shell_read_vector(&cats, optarg);
 
22288
      break;
 
22289
    case 2: /* logprobs */
 
22290
      logprobs=&v_logprobs; igraph_vector_init(logprobs, 0); 
 
22291
  shell_arg_logprobs=strdup(optarg);
 
22292
      break;
 
22293
    case 3: /* logcited */
 
22294
      logcited=&v_logcited; igraph_vector_init(logcited, 0); 
 
22295
  shell_arg_logcited=strdup(optarg);
 
22296
      break;
 
22297
    case 4: /* logciting */
 
22298
      logciting=&v_logciting; igraph_vector_init(logciting, 0); 
 
22299
  shell_arg_logciting=strdup(optarg);
 
22300
      break;
 
22301
    case 5:
 
22302
      shell_igraph_revolver_probs_ade_usage(argv);
 
22303
      break;
 
22304
    default:
 
22305
      break;
 
22306
    }
 
22307
 
 
22308
    shell_index=-1;
 
22309
  }
 
22310
 
 
22311
  /* Check that we have all arguments */
 
22312
  for (shell_index=0; shell_index<5; shell_index++) {
 
22313
    if (!shell_seen[shell_index]) {
 
22314
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22315
              shell_options[shell_index].name);
 
22316
      exit(1);
 
22317
    }
 
22318
  }
 
22319
 
 
22320
  /* Do the operation */
 
22321
  shell_result=igraph_revolver_probs_ade(&graph, 0, &cats, logprobs, logcited, logciting);
 
22322
 
 
22323
  /* Write the result */
 
22324
  igraph_destroy(&graph);
 
22325
  igraph_vector_destroy(&cats);
 
22326
  if (logprobs) { shell_write_vector(logprobs, shell_arg_logprobs); 
 
22327
  igraph_vector_destroy(logprobs); }
 
22328
  if (logcited) { shell_write_vector(logcited, shell_arg_logcited); 
 
22329
  igraph_vector_destroy(logcited); }
 
22330
  if (logciting) { shell_write_vector(logciting, shell_arg_logciting); 
 
22331
  igraph_vector_destroy(logciting); }
 
22332
 
 
22333
  return 0;
 
22334
}
 
22335
 
 
22336
/*-------------------------------------------/
 
22337
/ igraph_revolver_ml_f                       /
 
22338
/-------------------------------------------*/
 
22339
void shell_igraph_revolver_ml_f_usage(char **argv) {
 
22340
  printf("%s --graph=<graph> --niter=<niter> --kernel=<kernel> --cites=<cites> --delta=<delta> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
22341
  exit(1);
 
22342
}
 
22343
 
 
22344
int shell_igraph_revolver_ml_f(int argc, char **argv) {
 
22345
 
 
22346
  igraph_t graph;
 
22347
  igraph_integer_t niter;
 
22348
  igraph_vector_t kernel;
 
22349
  igraph_vector_t v_cites; igraph_vector_t *cites=0;
 
22350
  igraph_real_t delta=1e-10;
 
22351
  igraph_real_t logprob;
 
22352
  igraph_real_t logmax;
 
22353
  char* shell_arg_kernel=0;
 
22354
  char* shell_arg_cites=0;
 
22355
  char* shell_arg_logprob=0;
 
22356
  char* shell_arg_logmax=0;
 
22357
  int shell_result;
 
22358
 
 
22359
 
 
22360
  int shell_seen[7];
 
22361
  int shell_index=-1;
 
22362
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22363
                                   { "niter",required_argument,0,1 },
 
22364
                                   { "kernel",required_argument,0,2 },
 
22365
                                   { "cites",required_argument,0,3 },
 
22366
                                   { "delta",required_argument,0,4 },
 
22367
                                   { "logprob",required_argument,0,5 },
 
22368
                                   { "logmax",required_argument,0,6 },
 
22369
                                   { "help",no_argument,0,7 },
 
22370
                                   { 0,0,0,0 }
 
22371
                                 };
 
22372
 
 
22373
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22374
  memset(shell_seen, 0, 7*sizeof(int));
 
22375
  shell_seen[4]=2;
 
22376
  
 
22377
  /* Parse arguments and read input */
 
22378
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22379
 
 
22380
    if (shell_index==-1) {
 
22381
      exit(1);
 
22382
    }
 
22383
 
 
22384
    if (shell_seen[shell_index]==1) {
 
22385
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22386
              shell_options[shell_index].name);
 
22387
      exit(1);
 
22388
    }
 
22389
    shell_seen[shell_index]=1;  
 
22390
 
 
22391
    switch (shell_index) {
 
22392
    case 0: /* graph */
 
22393
      shell_read_graph(&graph, optarg);
 
22394
      break;
 
22395
    case 1: /* niter */
 
22396
      shell_read_integer(&niter, optarg);
 
22397
      break;
 
22398
    case 2: /* kernel */
 
22399
      shell_arg_kernel=strdup(optarg); 
 
22400
  igraph_vector_init(&kernel, 0);
 
22401
      break;
 
22402
    case 3: /* cites */
 
22403
      cites=&v_cites; igraph_vector_init(cites, 0); 
 
22404
  shell_arg_cites=strdup(optarg);
 
22405
      break;
 
22406
    case 4: /* delta */
 
22407
      shell_read_real(&delta, optarg);
 
22408
      break;
 
22409
    case 5: /* logprob */
 
22410
      shell_arg_logprob=strdup(optarg);
 
22411
      break;
 
22412
    case 6: /* logmax */
 
22413
      shell_arg_logmax=strdup(optarg);
 
22414
      break;
 
22415
    case 7:
 
22416
      shell_igraph_revolver_ml_f_usage(argv);
 
22417
      break;
 
22418
    default:
 
22419
      break;
 
22420
    }
 
22421
 
 
22422
    shell_index=-1;
 
22423
  }
 
22424
 
 
22425
  /* Check that we have all arguments */
 
22426
  for (shell_index=0; shell_index<7; shell_index++) {
 
22427
    if (!shell_seen[shell_index]) {
 
22428
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22429
              shell_options[shell_index].name);
 
22430
      exit(1);
 
22431
    }
 
22432
  }
 
22433
 
 
22434
  /* Do the operation */
 
22435
  shell_result=igraph_revolver_ml_f(&graph, niter, &kernel, cites, delta, &logprob, &logmax);
 
22436
 
 
22437
  /* Write the result */
 
22438
  igraph_destroy(&graph);
 
22439
  shell_write_vector(&kernel, shell_arg_kernel); 
 
22440
  igraph_vector_destroy(&kernel);
 
22441
  if (cites) { shell_write_vector(cites, shell_arg_cites); 
 
22442
  igraph_vector_destroy(cites); }
 
22443
  shell_write_real(logprob, shell_arg_logprob);
 
22444
  shell_write_real(logmax, shell_arg_logmax);
 
22445
 
 
22446
  return 0;
 
22447
}
 
22448
 
 
22449
/*-------------------------------------------/
 
22450
/ igraph_revolver_ml_df                      /
 
22451
/-------------------------------------------*/
 
22452
void shell_igraph_revolver_ml_df_usage(char **argv) {
 
22453
  printf("%s --graph=<graph> --niter=<niter> --kernel=<kernel> --delta=<delta> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
22454
  exit(1);
 
22455
}
 
22456
 
 
22457
int shell_igraph_revolver_ml_df(int argc, char **argv) {
 
22458
 
 
22459
  igraph_t graph;
 
22460
  igraph_integer_t niter;
 
22461
  igraph_matrix_t kernel;
 
22462
 
 
22463
  igraph_real_t delta=1e-10;
 
22464
  igraph_real_t logprob;
 
22465
  igraph_real_t logmax;
 
22466
  char* shell_arg_kernel=0;
 
22467
  char* shell_arg_cites=0;
 
22468
  char* shell_arg_logprob=0;
 
22469
  char* shell_arg_logmax=0;
 
22470
  int shell_result;
 
22471
 
 
22472
 
 
22473
  int shell_seen[6];
 
22474
  int shell_index=-1;
 
22475
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22476
                                   { "niter",required_argument,0,1 },
 
22477
                                   { "kernel",required_argument,0,2 },
 
22478
                                   { "delta",required_argument,0,3 },
 
22479
                                   { "logprob",required_argument,0,4 },
 
22480
                                   { "logmax",required_argument,0,5 },
 
22481
                                   { "help",no_argument,0,6 },
 
22482
                                   { 0,0,0,0 }
 
22483
                                 };
 
22484
 
 
22485
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22486
  memset(shell_seen, 0, 6*sizeof(int));
 
22487
  shell_seen[3]=2;
 
22488
  
 
22489
  /* Parse arguments and read input */
 
22490
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22491
 
 
22492
    if (shell_index==-1) {
 
22493
      exit(1);
 
22494
    }
 
22495
 
 
22496
    if (shell_seen[shell_index]==1) {
 
22497
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22498
              shell_options[shell_index].name);
 
22499
      exit(1);
 
22500
    }
 
22501
    shell_seen[shell_index]=1;  
 
22502
 
 
22503
    switch (shell_index) {
 
22504
    case 0: /* graph */
 
22505
      shell_read_graph(&graph, optarg);
 
22506
      break;
 
22507
    case 1: /* niter */
 
22508
      shell_read_integer(&niter, optarg);
 
22509
      break;
 
22510
    case 2: /* kernel */
 
22511
      shell_arg_kernel=strdup(optarg); 
 
22512
  igraph_matrix_init(&kernel, 0, 0);
 
22513
      break;
 
22514
    case 3: /* delta */
 
22515
      shell_read_real(&delta, optarg);
 
22516
      break;
 
22517
    case 4: /* logprob */
 
22518
      shell_arg_logprob=strdup(optarg);
 
22519
      break;
 
22520
    case 5: /* logmax */
 
22521
      shell_arg_logmax=strdup(optarg);
 
22522
      break;
 
22523
    case 6:
 
22524
      shell_igraph_revolver_ml_df_usage(argv);
 
22525
      break;
 
22526
    default:
 
22527
      break;
 
22528
    }
 
22529
 
 
22530
    shell_index=-1;
 
22531
  }
 
22532
 
 
22533
  /* Check that we have all arguments */
 
22534
  for (shell_index=0; shell_index<6; shell_index++) {
 
22535
    if (!shell_seen[shell_index]) {
 
22536
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22537
              shell_options[shell_index].name);
 
22538
      exit(1);
 
22539
    }
 
22540
  }
 
22541
 
 
22542
  /* Do the operation */
 
22543
  shell_result=igraph_revolver_ml_df(&graph, niter, &kernel, 0, delta, &logprob, &logmax);
 
22544
 
 
22545
  /* Write the result */
 
22546
  igraph_destroy(&graph);
 
22547
  shell_write_matrix(&kernel, shell_arg_kernel); 
 
22548
  igraph_matrix_destroy(&kernel);
 
22549
  shell_write_real(logprob, shell_arg_logprob);
 
22550
  shell_write_real(logmax, shell_arg_logmax);
 
22551
 
 
22552
  return 0;
 
22553
}
 
22554
 
 
22555
/*-------------------------------------------/
 
22556
/ igraph_revolver_ml_l                       /
 
22557
/-------------------------------------------*/
 
22558
void shell_igraph_revolver_ml_l_usage(char **argv) {
 
22559
  printf("%s --graph=<graph> --niter=<niter> --kernel=<kernel> --cites=<cites> --agebins=<agebins> --delta=<delta> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
22560
  exit(1);
 
22561
}
 
22562
 
 
22563
int shell_igraph_revolver_ml_l(int argc, char **argv) {
 
22564
 
 
22565
  igraph_t graph;
 
22566
  igraph_integer_t niter;
 
22567
  igraph_vector_t kernel;
 
22568
  igraph_vector_t v_cites; igraph_vector_t *cites=0;
 
22569
  igraph_integer_t agebins=300;
 
22570
  igraph_real_t delta=1e-10;
 
22571
  igraph_real_t logprob;
 
22572
  igraph_real_t logmax;
 
22573
  char* shell_arg_kernel=0;
 
22574
  char* shell_arg_cites=0;
 
22575
  char* shell_arg_logprob=0;
 
22576
  char* shell_arg_logmax=0;
 
22577
  int shell_result;
 
22578
 
 
22579
 
 
22580
  int shell_seen[8];
 
22581
  int shell_index=-1;
 
22582
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22583
                                   { "niter",required_argument,0,1 },
 
22584
                                   { "kernel",required_argument,0,2 },
 
22585
                                   { "cites",required_argument,0,3 },
 
22586
                                   { "agebins",required_argument,0,4 },
 
22587
                                   { "delta",required_argument,0,5 },
 
22588
                                   { "logprob",required_argument,0,6 },
 
22589
                                   { "logmax",required_argument,0,7 },
 
22590
                                   { "help",no_argument,0,8 },
 
22591
                                   { 0,0,0,0 }
 
22592
                                 };
 
22593
 
 
22594
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22595
  memset(shell_seen, 0, 8*sizeof(int));
 
22596
  shell_seen[4]=2;
 
22597
  shell_seen[5]=2;
 
22598
  
 
22599
  /* Parse arguments and read input */
 
22600
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22601
 
 
22602
    if (shell_index==-1) {
 
22603
      exit(1);
 
22604
    }
 
22605
 
 
22606
    if (shell_seen[shell_index]==1) {
 
22607
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22608
              shell_options[shell_index].name);
 
22609
      exit(1);
 
22610
    }
 
22611
    shell_seen[shell_index]=1;  
 
22612
 
 
22613
    switch (shell_index) {
 
22614
    case 0: /* graph */
 
22615
      shell_read_graph(&graph, optarg);
 
22616
      break;
 
22617
    case 1: /* niter */
 
22618
      shell_read_integer(&niter, optarg);
 
22619
      break;
 
22620
    case 2: /* kernel */
 
22621
      shell_arg_kernel=strdup(optarg); 
 
22622
  igraph_vector_init(&kernel, 0);
 
22623
      break;
 
22624
    case 3: /* cites */
 
22625
      cites=&v_cites; igraph_vector_init(cites, 0); 
 
22626
  shell_arg_cites=strdup(optarg);
 
22627
      break;
 
22628
    case 4: /* agebins */
 
22629
      shell_read_integer(&agebins, optarg);
 
22630
      break;
 
22631
    case 5: /* delta */
 
22632
      shell_read_real(&delta, optarg);
 
22633
      break;
 
22634
    case 6: /* logprob */
 
22635
      shell_arg_logprob=strdup(optarg);
 
22636
      break;
 
22637
    case 7: /* logmax */
 
22638
      shell_arg_logmax=strdup(optarg);
 
22639
      break;
 
22640
    case 8:
 
22641
      shell_igraph_revolver_ml_l_usage(argv);
 
22642
      break;
 
22643
    default:
 
22644
      break;
 
22645
    }
 
22646
 
 
22647
    shell_index=-1;
 
22648
  }
 
22649
 
 
22650
  /* Check that we have all arguments */
 
22651
  for (shell_index=0; shell_index<8; shell_index++) {
 
22652
    if (!shell_seen[shell_index]) {
 
22653
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22654
              shell_options[shell_index].name);
 
22655
      exit(1);
 
22656
    }
 
22657
  }
 
22658
 
 
22659
  /* Do the operation */
 
22660
  shell_result=igraph_revolver_ml_l(&graph, niter, &kernel, cites, agebins, delta, &logprob, &logmax);
 
22661
 
 
22662
  /* Write the result */
 
22663
  igraph_destroy(&graph);
 
22664
  shell_write_vector(&kernel, shell_arg_kernel); 
 
22665
  igraph_vector_destroy(&kernel);
 
22666
  if (cites) { shell_write_vector(cites, shell_arg_cites); 
 
22667
  igraph_vector_destroy(cites); }
 
22668
  shell_write_real(logprob, shell_arg_logprob);
 
22669
  shell_write_real(logmax, shell_arg_logmax);
 
22670
 
 
22671
  return 0;
 
22672
}
 
22673
 
 
22674
/*-------------------------------------------/
 
22675
/ igraph_revolver_ml_ad                      /
 
22676
/-------------------------------------------*/
 
22677
void shell_igraph_revolver_ml_ad_usage(char **argv) {
 
22678
  printf("%s --graph=<graph> --niter=<niter> --kernel=<kernel> --agebins=<agebins> --delta=<delta> --filter=<filter> --logprob=<logprob> --logmax=<logmax>\n", basename(argv[0]));
 
22679
  exit(1);
 
22680
}
 
22681
 
 
22682
int shell_igraph_revolver_ml_ad(int argc, char **argv) {
 
22683
 
 
22684
  igraph_t graph;
 
22685
  igraph_integer_t niter;
 
22686
  igraph_matrix_t kernel;
 
22687
 
 
22688
  igraph_integer_t agebins=300;
 
22689
  igraph_real_t delta=1e-10;
 
22690
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
22691
  igraph_real_t logprob;
 
22692
  igraph_real_t logmax;
 
22693
  char* shell_arg_kernel=0;
 
22694
  char* shell_arg_cites=0;
 
22695
  char* shell_arg_logprob=0;
 
22696
  char* shell_arg_logmax=0;
 
22697
  int shell_result;
 
22698
 
 
22699
 
 
22700
  int shell_seen[8];
 
22701
  int shell_index=-1;
 
22702
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22703
                                   { "niter",required_argument,0,1 },
 
22704
                                   { "kernel",required_argument,0,2 },
 
22705
                                   { "agebins",required_argument,0,3 },
 
22706
                                   { "delta",required_argument,0,4 },
 
22707
                                   { "filter",required_argument,0,5 },
 
22708
                                   { "logprob",required_argument,0,6 },
 
22709
                                   { "logmax",required_argument,0,7 },
 
22710
                                   { "help",no_argument,0,8 },
 
22711
                                   { 0,0,0,0 }
 
22712
                                 };
 
22713
 
 
22714
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22715
  memset(shell_seen, 0, 8*sizeof(int));
 
22716
  shell_seen[3]=2;
 
22717
  shell_seen[4]=2;
 
22718
  shell_seen[5]=2;
 
22719
  
 
22720
  /* Parse arguments and read input */
 
22721
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22722
 
 
22723
    if (shell_index==-1) {
 
22724
      exit(1);
 
22725
    }
 
22726
 
 
22727
    if (shell_seen[shell_index]==1) {
 
22728
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22729
              shell_options[shell_index].name);
 
22730
      exit(1);
 
22731
    }
 
22732
    shell_seen[shell_index]=1;  
 
22733
 
 
22734
    switch (shell_index) {
 
22735
    case 0: /* graph */
 
22736
      shell_read_graph(&graph, optarg);
 
22737
      break;
 
22738
    case 1: /* niter */
 
22739
      shell_read_integer(&niter, optarg);
 
22740
      break;
 
22741
    case 2: /* kernel */
 
22742
      shell_arg_kernel=strdup(optarg); 
 
22743
  igraph_matrix_init(&kernel, 0, 0);
 
22744
      break;
 
22745
    case 3: /* agebins */
 
22746
      shell_read_integer(&agebins, optarg);
 
22747
      break;
 
22748
    case 4: /* delta */
 
22749
      shell_read_real(&delta, optarg);
 
22750
      break;
 
22751
    case 5: /* filter */
 
22752
      filter=&v_filter; shell_read_vector(filter, optarg);
 
22753
      break;
 
22754
    case 6: /* logprob */
 
22755
      shell_arg_logprob=strdup(optarg);
 
22756
      break;
 
22757
    case 7: /* logmax */
 
22758
      shell_arg_logmax=strdup(optarg);
 
22759
      break;
 
22760
    case 8:
 
22761
      shell_igraph_revolver_ml_ad_usage(argv);
 
22762
      break;
 
22763
    default:
 
22764
      break;
 
22765
    }
 
22766
 
 
22767
    shell_index=-1;
 
22768
  }
 
22769
 
 
22770
  /* Check that we have all arguments */
 
22771
  for (shell_index=0; shell_index<8; shell_index++) {
 
22772
    if (!shell_seen[shell_index]) {
 
22773
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22774
              shell_options[shell_index].name);
 
22775
      exit(1);
 
22776
    }
 
22777
  }
 
22778
 
 
22779
  /* Do the operation */
 
22780
  shell_result=igraph_revolver_ml_ad(&graph, niter, &kernel, 0, agebins, delta, filter, &logprob, &logmax);
 
22781
 
 
22782
  /* Write the result */
 
22783
  igraph_destroy(&graph);
 
22784
  shell_write_matrix(&kernel, shell_arg_kernel); 
 
22785
  igraph_matrix_destroy(&kernel);
 
22786
  if (filter) { igraph_vector_destroy(filter); }
 
22787
  shell_write_real(logprob, shell_arg_logprob);
 
22788
  shell_write_real(logmax, shell_arg_logmax);
 
22789
 
 
22790
  return 0;
 
22791
}
 
22792
 
 
22793
/*-------------------------------------------/
 
22794
/ igraph_revolver_probs_ad                   /
 
22795
/-------------------------------------------*/
 
22796
void shell_igraph_revolver_probs_ad_usage(char **argv) {
 
22797
  printf("%s --graph=<graph> --kernel=<kernel> --probs=<probs> --citedprobs=<citedprobs> --citingprobs=<citingprobs> --ntk=<ntk>\n", basename(argv[0]));
 
22798
  exit(1);
 
22799
}
 
22800
 
 
22801
int shell_igraph_revolver_probs_ad(int argc, char **argv) {
 
22802
 
 
22803
  igraph_t graph;
 
22804
  igraph_matrix_t kernel;
 
22805
  igraph_vector_t v_probs; igraph_vector_t *probs=0;
 
22806
  igraph_vector_t v_citedprobs; igraph_vector_t *citedprobs=0;
 
22807
  igraph_vector_t v_citingprobs; igraph_vector_t *citingprobs=0;
 
22808
  igraph_bool_t ntk=0;
 
22809
  char* shell_arg_probs=0;
 
22810
  char* shell_arg_citedprobs=0;
 
22811
  char* shell_arg_citingprobs=0;
 
22812
  int shell_result;
 
22813
 
 
22814
 
 
22815
  int shell_seen[6];
 
22816
  int shell_index=-1;
 
22817
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22818
                                   { "kernel",required_argument,0,1 },
 
22819
                                   { "probs",required_argument,0,2 },
 
22820
                                   { "citedprobs",required_argument,0,3 },
 
22821
                                   { "citingprobs",required_argument,0,4 },
 
22822
                                   { "ntk",required_argument,0,5 },
 
22823
                                   { "help",no_argument,0,6 },
 
22824
                                   { 0,0,0,0 }
 
22825
                                 };
 
22826
 
 
22827
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22828
  memset(shell_seen, 0, 6*sizeof(int));
 
22829
  shell_seen[5]=2;
 
22830
  
 
22831
  /* Parse arguments and read input */
 
22832
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22833
 
 
22834
    if (shell_index==-1) {
 
22835
      exit(1);
 
22836
    }
 
22837
 
 
22838
    if (shell_seen[shell_index]==1) {
 
22839
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22840
              shell_options[shell_index].name);
 
22841
      exit(1);
 
22842
    }
 
22843
    shell_seen[shell_index]=1;  
 
22844
 
 
22845
    switch (shell_index) {
 
22846
    case 0: /* graph */
 
22847
      shell_read_graph(&graph, optarg);
 
22848
      break;
 
22849
    case 1: /* kernel */
 
22850
      shell_read_matrix(&kernel, optarg);
 
22851
      break;
 
22852
    case 2: /* probs */
 
22853
      probs=&v_probs; igraph_vector_init(probs, 0); 
 
22854
  shell_arg_probs=strdup(optarg);
 
22855
      break;
 
22856
    case 3: /* citedprobs */
 
22857
      citedprobs=&v_citedprobs; igraph_vector_init(citedprobs, 0); 
 
22858
  shell_arg_citedprobs=strdup(optarg);
 
22859
      break;
 
22860
    case 4: /* citingprobs */
 
22861
      citingprobs=&v_citingprobs; igraph_vector_init(citingprobs, 0); 
 
22862
  shell_arg_citingprobs=strdup(optarg);
 
22863
      break;
 
22864
    case 5: /* ntk */
 
22865
      shell_read_boolean(&ntk, optarg);
 
22866
      break;
 
22867
    case 6:
 
22868
      shell_igraph_revolver_probs_ad_usage(argv);
 
22869
      break;
 
22870
    default:
 
22871
      break;
 
22872
    }
 
22873
 
 
22874
    shell_index=-1;
 
22875
  }
 
22876
 
 
22877
  /* Check that we have all arguments */
 
22878
  for (shell_index=0; shell_index<6; shell_index++) {
 
22879
    if (!shell_seen[shell_index]) {
 
22880
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
22881
              shell_options[shell_index].name);
 
22882
      exit(1);
 
22883
    }
 
22884
  }
 
22885
 
 
22886
  /* Do the operation */
 
22887
  shell_result=igraph_revolver_probs_ad(&graph, &kernel, probs, citedprobs, citingprobs, ntk);
 
22888
 
 
22889
  /* Write the result */
 
22890
  igraph_destroy(&graph);
 
22891
  igraph_matrix_destroy(&kernel);
 
22892
  if (probs) { shell_write_vector(probs, shell_arg_probs); 
 
22893
  igraph_vector_destroy(probs); }
 
22894
  if (citedprobs) { shell_write_vector(citedprobs, shell_arg_citedprobs); 
 
22895
  igraph_vector_destroy(citedprobs); }
 
22896
  if (citingprobs) { shell_write_vector(citingprobs, shell_arg_citingprobs); 
 
22897
  igraph_vector_destroy(citingprobs); }
 
22898
 
 
22899
  return 0;
 
22900
}
 
22901
 
 
22902
/*-------------------------------------------/
 
22903
/ igraph_revolver_ml_D_alpha                 /
 
22904
/-------------------------------------------*/
 
22905
void shell_igraph_revolver_ml_D_alpha_usage(char **argv) {
 
22906
  printf("%s --graph=<graph> --alpha=<alpha> --alpha-out=<alpha-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
22907
  exit(1);
 
22908
}
 
22909
 
 
22910
int shell_igraph_revolver_ml_D_alpha(int argc, char **argv) {
 
22911
 
 
22912
  igraph_t graph;
 
22913
  igraph_real_t alpha;
 
22914
  igraph_real_t Fmin;
 
22915
  igraph_real_t abstol=1e-8;
 
22916
  igraph_real_t reltol=1e-8;
 
22917
  int maxit=1000;
 
22918
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
22919
  igraph_integer_t fncount;
 
22920
  igraph_integer_t grcount;
 
22921
  char* shell_arg_alpha=0;
 
22922
  char* shell_arg_Fmin=0;
 
22923
  char* shell_arg_fncount=0;
 
22924
  char* shell_arg_grcount=0;
 
22925
  int shell_result;
 
22926
 
 
22927
 
 
22928
  int shell_seen[10];
 
22929
  int shell_index=-1;
 
22930
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
22931
                                   { "alpha",required_argument,0,1 },
 
22932
                                   { "alpha-out",required_argument,0,2 },
 
22933
                                   { "Fmin",required_argument,0,3 },
 
22934
                                   { "abstol",required_argument,0,4 },
 
22935
                                   { "reltol",required_argument,0,5 },
 
22936
                                   { "maxit",required_argument,0,6 },
 
22937
                                   { "filter",required_argument,0,7 },
 
22938
                                   { "fncount",required_argument,0,8 },
 
22939
                                   { "grcount",required_argument,0,9 },
 
22940
                                   { "help",no_argument,0,10 },
 
22941
                                   { 0,0,0,0 }
 
22942
                                 };
 
22943
 
 
22944
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
22945
  memset(shell_seen, 0, 10*sizeof(int));
 
22946
  shell_seen[4]=2;
 
22947
  shell_seen[5]=2;
 
22948
  shell_seen[6]=2;
 
22949
  shell_seen[7]=2;
 
22950
  
 
22951
  /* Parse arguments and read input */
 
22952
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
22953
 
 
22954
    if (shell_index==-1) {
 
22955
      exit(1);
 
22956
    }
 
22957
 
 
22958
    if (shell_seen[shell_index]==1) {
 
22959
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
22960
              shell_options[shell_index].name);
 
22961
      exit(1);
 
22962
    }
 
22963
    shell_seen[shell_index]=1;  
 
22964
 
 
22965
    switch (shell_index) {
 
22966
    case 0: /* graph */
 
22967
      shell_read_graph(&graph, optarg);
 
22968
      break;
 
22969
    case 1: /* alpha */
 
22970
      shell_read_real(&alpha, optarg);
 
22971
      break;
 
22972
    case 2: /* alpha-out */
 
22973
      shell_arg_alpha=strdup(optarg);
 
22974
      break;
 
22975
    case 3: /* Fmin */
 
22976
      shell_arg_Fmin=strdup(optarg);
 
22977
      break;
 
22978
    case 4: /* abstol */
 
22979
      shell_read_real(&abstol, optarg);
 
22980
      break;
 
22981
    case 5: /* reltol */
 
22982
      shell_read_real(&reltol, optarg);
 
22983
      break;
 
22984
    case 6: /* maxit */
 
22985
      shell_read_int(&maxit, optarg);
 
22986
      break;
 
22987
    case 7: /* filter */
 
22988
      filter=&v_filter; shell_read_vector(filter, optarg);
 
22989
      break;
 
22990
    case 8: /* fncount */
 
22991
      shell_arg_fncount=strdup(optarg);
 
22992
      break;
 
22993
    case 9: /* grcount */
 
22994
      shell_arg_grcount=strdup(optarg);
 
22995
      break;
 
22996
    case 10:
 
22997
      shell_igraph_revolver_ml_D_alpha_usage(argv);
 
22998
      break;
 
22999
    default:
 
23000
      break;
 
23001
    }
 
23002
 
 
23003
    shell_index=-1;
 
23004
  }
 
23005
 
 
23006
  /* Check that we have all arguments */
 
23007
  for (shell_index=0; shell_index<10; shell_index++) {
 
23008
    if (!shell_seen[shell_index]) {
 
23009
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23010
              shell_options[shell_index].name);
 
23011
      exit(1);
 
23012
    }
 
23013
  }
 
23014
 
 
23015
  /* Do the operation */
 
23016
  shell_result=igraph_revolver_ml_D_alpha(&graph, &alpha, &Fmin, abstol, reltol, maxit, filter, &fncount, &grcount);
 
23017
 
 
23018
  /* Write the result */
 
23019
  igraph_destroy(&graph);
 
23020
  shell_write_real(alpha, shell_arg_alpha);
 
23021
  shell_write_real(Fmin, shell_arg_Fmin);
 
23022
  if (filter) { igraph_vector_destroy(filter); }
 
23023
  shell_write_integer(fncount, shell_arg_fncount);
 
23024
  shell_write_integer(grcount, shell_arg_grcount);
 
23025
 
 
23026
  return 0;
 
23027
}
 
23028
 
 
23029
/*-------------------------------------------/
 
23030
/ igraph_revolver_ml_D_alpha_a               /
 
23031
/-------------------------------------------*/
 
23032
void shell_igraph_revolver_ml_D_alpha_a_usage(char **argv) {
 
23033
  printf("%s --graph=<graph> --alpha=<alpha> --alpha-out=<alpha-out> --a=<a> --a-out=<a-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
23034
  exit(1);
 
23035
}
 
23036
 
 
23037
int shell_igraph_revolver_ml_D_alpha_a(int argc, char **argv) {
 
23038
 
 
23039
  igraph_t graph;
 
23040
  igraph_real_t alpha;
 
23041
  igraph_real_t a;
 
23042
  igraph_real_t Fmin;
 
23043
  igraph_real_t abstol=1e-8;
 
23044
  igraph_real_t reltol=1e-8;
 
23045
  int maxit=1000;
 
23046
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23047
  igraph_integer_t fncount;
 
23048
  igraph_integer_t grcount;
 
23049
  char* shell_arg_alpha=0;
 
23050
  char* shell_arg_a=0;
 
23051
  char* shell_arg_Fmin=0;
 
23052
  char* shell_arg_fncount=0;
 
23053
  char* shell_arg_grcount=0;
 
23054
  int shell_result;
 
23055
 
 
23056
 
 
23057
  int shell_seen[12];
 
23058
  int shell_index=-1;
 
23059
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23060
                                   { "alpha",required_argument,0,1 },
 
23061
                                   { "alpha-out",required_argument,0,2 },
 
23062
                                   { "a",required_argument,0,3 },
 
23063
                                   { "a-out",required_argument,0,4 },
 
23064
                                   { "Fmin",required_argument,0,5 },
 
23065
                                   { "abstol",required_argument,0,6 },
 
23066
                                   { "reltol",required_argument,0,7 },
 
23067
                                   { "maxit",required_argument,0,8 },
 
23068
                                   { "filter",required_argument,0,9 },
 
23069
                                   { "fncount",required_argument,0,10 },
 
23070
                                   { "grcount",required_argument,0,11 },
 
23071
                                   { "help",no_argument,0,12 },
 
23072
                                   { 0,0,0,0 }
 
23073
                                 };
 
23074
 
 
23075
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
23076
  memset(shell_seen, 0, 12*sizeof(int));
 
23077
  shell_seen[6]=2;
 
23078
  shell_seen[7]=2;
 
23079
  shell_seen[8]=2;
 
23080
  shell_seen[9]=2;
 
23081
  
 
23082
  /* Parse arguments and read input */
 
23083
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
23084
 
 
23085
    if (shell_index==-1) {
 
23086
      exit(1);
 
23087
    }
 
23088
 
 
23089
    if (shell_seen[shell_index]==1) {
 
23090
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
23091
              shell_options[shell_index].name);
 
23092
      exit(1);
 
23093
    }
 
23094
    shell_seen[shell_index]=1;  
 
23095
 
 
23096
    switch (shell_index) {
 
23097
    case 0: /* graph */
 
23098
      shell_read_graph(&graph, optarg);
 
23099
      break;
 
23100
    case 1: /* alpha */
 
23101
      shell_read_real(&alpha, optarg);
 
23102
      break;
 
23103
    case 2: /* alpha-out */
 
23104
      shell_arg_alpha=strdup(optarg);
 
23105
      break;
 
23106
    case 3: /* a */
 
23107
      shell_read_real(&a, optarg);
 
23108
      break;
 
23109
    case 4: /* a-out */
 
23110
      shell_arg_a=strdup(optarg);
 
23111
      break;
 
23112
    case 5: /* Fmin */
 
23113
      shell_arg_Fmin=strdup(optarg);
 
23114
      break;
 
23115
    case 6: /* abstol */
 
23116
      shell_read_real(&abstol, optarg);
 
23117
      break;
 
23118
    case 7: /* reltol */
 
23119
      shell_read_real(&reltol, optarg);
 
23120
      break;
 
23121
    case 8: /* maxit */
 
23122
      shell_read_int(&maxit, optarg);
 
23123
      break;
 
23124
    case 9: /* filter */
 
23125
      filter=&v_filter; shell_read_vector(filter, optarg);
 
23126
      break;
 
23127
    case 10: /* fncount */
 
23128
      shell_arg_fncount=strdup(optarg);
 
23129
      break;
 
23130
    case 11: /* grcount */
 
23131
      shell_arg_grcount=strdup(optarg);
 
23132
      break;
 
23133
    case 12:
 
23134
      shell_igraph_revolver_ml_D_alpha_a_usage(argv);
 
23135
      break;
 
23136
    default:
 
23137
      break;
 
23138
    }
 
23139
 
 
23140
    shell_index=-1;
 
23141
  }
 
23142
 
 
23143
  /* Check that we have all arguments */
 
23144
  for (shell_index=0; shell_index<12; shell_index++) {
 
23145
    if (!shell_seen[shell_index]) {
 
23146
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23147
              shell_options[shell_index].name);
 
23148
      exit(1);
 
23149
    }
 
23150
  }
 
23151
 
 
23152
  /* Do the operation */
 
23153
  shell_result=igraph_revolver_ml_D_alpha_a(&graph, &alpha, &a, &Fmin, abstol, reltol, maxit, filter, &fncount, &grcount);
 
23154
 
 
23155
  /* Write the result */
 
23156
  igraph_destroy(&graph);
 
23157
  shell_write_real(alpha, shell_arg_alpha);
 
23158
  shell_write_real(a, shell_arg_a);
 
23159
  shell_write_real(Fmin, shell_arg_Fmin);
 
23160
  if (filter) { igraph_vector_destroy(filter); }
 
23161
  shell_write_integer(fncount, shell_arg_fncount);
 
23162
  shell_write_integer(grcount, shell_arg_grcount);
 
23163
 
 
23164
  return 0;
 
23165
}
 
23166
 
 
23167
/*-------------------------------------------/
 
23168
/ igraph_revolver_ml_DE_alpha_a              /
 
23169
/-------------------------------------------*/
 
23170
void shell_igraph_revolver_ml_DE_alpha_a_usage(char **argv) {
 
23171
  printf("%s --graph=<graph> --cats=<cats> --alpha=<alpha> --alpha-out=<alpha-out> --a=<a> --a-out=<a-out> --coeffs=<coeffs> --coeffs-out=<coeffs-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
23172
  exit(1);
 
23173
}
 
23174
 
 
23175
int shell_igraph_revolver_ml_DE_alpha_a(int argc, char **argv) {
 
23176
 
 
23177
  igraph_t graph;
 
23178
  igraph_vector_t cats;
 
23179
  igraph_real_t alpha;
 
23180
  igraph_real_t a;
 
23181
  igraph_vector_t coeffs;
 
23182
  igraph_real_t Fmin;
 
23183
  igraph_real_t abstol=1e-8;
 
23184
  igraph_real_t reltol=1e-8;
 
23185
  int maxit=1000;
 
23186
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23187
  igraph_integer_t fncount;
 
23188
  igraph_integer_t grcount;
 
23189
  char* shell_arg_alpha=0;
 
23190
  char* shell_arg_a=0;
 
23191
  char* shell_arg_coeffs=0;
 
23192
  char* shell_arg_Fmin=0;
 
23193
  char* shell_arg_fncount=0;
 
23194
  char* shell_arg_grcount=0;
 
23195
  int shell_result;
 
23196
 
 
23197
 
 
23198
  int shell_seen[15];
 
23199
  int shell_index=-1;
 
23200
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23201
                                   { "cats",required_argument,0,1 },
 
23202
                                   { "alpha",required_argument,0,2 },
 
23203
                                   { "alpha-out",required_argument,0,3 },
 
23204
                                   { "a",required_argument,0,4 },
 
23205
                                   { "a-out",required_argument,0,5 },
 
23206
                                   { "coeffs",required_argument,0,6 },
 
23207
                                   { "coeffs-out",required_argument,0,7 },
 
23208
                                   { "Fmin",required_argument,0,8 },
 
23209
                                   { "abstol",required_argument,0,9 },
 
23210
                                   { "reltol",required_argument,0,10 },
 
23211
                                   { "maxit",required_argument,0,11 },
 
23212
                                   { "filter",required_argument,0,12 },
 
23213
                                   { "fncount",required_argument,0,13 },
 
23214
                                   { "grcount",required_argument,0,14 },
 
23215
                                   { "help",no_argument,0,15 },
 
23216
                                   { 0,0,0,0 }
 
23217
                                 };
 
23218
 
 
23219
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
23220
  memset(shell_seen, 0, 15*sizeof(int));
 
23221
  shell_seen[9]=2;
 
23222
  shell_seen[10]=2;
 
23223
  shell_seen[11]=2;
 
23224
  shell_seen[12]=2;
 
23225
  
 
23226
  /* Parse arguments and read input */
 
23227
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
23228
 
 
23229
    if (shell_index==-1) {
 
23230
      exit(1);
 
23231
    }
 
23232
 
 
23233
    if (shell_seen[shell_index]==1) {
 
23234
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
23235
              shell_options[shell_index].name);
 
23236
      exit(1);
 
23237
    }
 
23238
    shell_seen[shell_index]=1;  
 
23239
 
 
23240
    switch (shell_index) {
 
23241
    case 0: /* graph */
 
23242
      shell_read_graph(&graph, optarg);
 
23243
      break;
 
23244
    case 1: /* cats */
 
23245
      shell_read_vector(&cats, optarg);
 
23246
      break;
 
23247
    case 2: /* alpha */
 
23248
      shell_read_real(&alpha, optarg);
 
23249
      break;
 
23250
    case 3: /* alpha-out */
 
23251
      shell_arg_alpha=strdup(optarg);
 
23252
      break;
 
23253
    case 4: /* a */
 
23254
      shell_read_real(&a, optarg);
 
23255
      break;
 
23256
    case 5: /* a-out */
 
23257
      shell_arg_a=strdup(optarg);
 
23258
      break;
 
23259
    case 6: /* coeffs */
 
23260
      shell_read_vector(&coeffs, optarg);
 
23261
      break;
 
23262
    case 7: /* coeffs-out */
 
23263
      shell_arg_coeffs=strdup(optarg); 
 
23264
  igraph_vector_init(&coeffs, 0);
 
23265
      break;
 
23266
    case 8: /* Fmin */
 
23267
      shell_arg_Fmin=strdup(optarg);
 
23268
      break;
 
23269
    case 9: /* abstol */
 
23270
      shell_read_real(&abstol, optarg);
 
23271
      break;
 
23272
    case 10: /* reltol */
 
23273
      shell_read_real(&reltol, optarg);
 
23274
      break;
 
23275
    case 11: /* maxit */
 
23276
      shell_read_int(&maxit, optarg);
 
23277
      break;
 
23278
    case 12: /* filter */
 
23279
      filter=&v_filter; shell_read_vector(filter, optarg);
 
23280
      break;
 
23281
    case 13: /* fncount */
 
23282
      shell_arg_fncount=strdup(optarg);
 
23283
      break;
 
23284
    case 14: /* grcount */
 
23285
      shell_arg_grcount=strdup(optarg);
 
23286
      break;
 
23287
    case 15:
 
23288
      shell_igraph_revolver_ml_DE_alpha_a_usage(argv);
 
23289
      break;
 
23290
    default:
 
23291
      break;
 
23292
    }
 
23293
 
 
23294
    shell_index=-1;
 
23295
  }
 
23296
 
 
23297
  /* Check that we have all arguments */
 
23298
  for (shell_index=0; shell_index<15; shell_index++) {
 
23299
    if (!shell_seen[shell_index]) {
 
23300
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23301
              shell_options[shell_index].name);
 
23302
      exit(1);
 
23303
    }
 
23304
  }
 
23305
 
 
23306
  /* Do the operation */
 
23307
  shell_result=igraph_revolver_ml_DE_alpha_a(&graph, &cats, &alpha, &a, &coeffs, &Fmin, abstol, reltol, maxit, filter, &fncount, &grcount);
 
23308
 
 
23309
  /* Write the result */
 
23310
  igraph_destroy(&graph);
 
23311
  igraph_vector_destroy(&cats);
 
23312
  shell_write_real(alpha, shell_arg_alpha);
 
23313
  shell_write_real(a, shell_arg_a);
 
23314
  igraph_vector_destroy(&coeffs);
 
23315
  shell_write_vector(&coeffs, shell_arg_coeffs); 
 
23316
  igraph_vector_destroy(&coeffs);
 
23317
  shell_write_real(Fmin, shell_arg_Fmin);
 
23318
  if (filter) { igraph_vector_destroy(filter); }
 
23319
  shell_write_integer(fncount, shell_arg_fncount);
 
23320
  shell_write_integer(grcount, shell_arg_grcount);
 
23321
 
 
23322
  return 0;
 
23323
}
 
23324
 
 
23325
/*-------------------------------------------/
 
23326
/ igraph_revolver_ml_AD_alpha_a_beta         /
 
23327
/-------------------------------------------*/
 
23328
void shell_igraph_revolver_ml_AD_alpha_a_beta_usage(char **argv) {
 
23329
  printf("%s --graph=<graph> --alpha=<alpha> --alpha-out=<alpha-out> --a=<a> --a-out=<a-out> --beta=<beta> --beta-out=<beta-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --agebins=<agebins> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
23330
  exit(1);
 
23331
}
 
23332
 
 
23333
int shell_igraph_revolver_ml_AD_alpha_a_beta(int argc, char **argv) {
 
23334
 
 
23335
  igraph_t graph;
 
23336
  igraph_real_t alpha;
 
23337
  igraph_real_t a;
 
23338
  igraph_real_t beta;
 
23339
  igraph_real_t Fmin;
 
23340
  igraph_real_t abstol=1e-8;
 
23341
  igraph_real_t reltol=1e-8;
 
23342
  int maxit=1000;
 
23343
  int agebins=300;
 
23344
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23345
  igraph_integer_t fncount;
 
23346
  igraph_integer_t grcount;
 
23347
  char* shell_arg_alpha=0;
 
23348
  char* shell_arg_a=0;
 
23349
  char* shell_arg_beta=0;
 
23350
  char* shell_arg_Fmin=0;
 
23351
  char* shell_arg_fncount=0;
 
23352
  char* shell_arg_grcount=0;
 
23353
  int shell_result;
 
23354
 
 
23355
 
 
23356
  int shell_seen[15];
 
23357
  int shell_index=-1;
 
23358
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23359
                                   { "alpha",required_argument,0,1 },
 
23360
                                   { "alpha-out",required_argument,0,2 },
 
23361
                                   { "a",required_argument,0,3 },
 
23362
                                   { "a-out",required_argument,0,4 },
 
23363
                                   { "beta",required_argument,0,5 },
 
23364
                                   { "beta-out",required_argument,0,6 },
 
23365
                                   { "Fmin",required_argument,0,7 },
 
23366
                                   { "abstol",required_argument,0,8 },
 
23367
                                   { "reltol",required_argument,0,9 },
 
23368
                                   { "maxit",required_argument,0,10 },
 
23369
                                   { "agebins",required_argument,0,11 },
 
23370
                                   { "filter",required_argument,0,12 },
 
23371
                                   { "fncount",required_argument,0,13 },
 
23372
                                   { "grcount",required_argument,0,14 },
 
23373
                                   { "help",no_argument,0,15 },
 
23374
                                   { 0,0,0,0 }
 
23375
                                 };
 
23376
 
 
23377
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
23378
  memset(shell_seen, 0, 15*sizeof(int));
 
23379
  shell_seen[8]=2;
 
23380
  shell_seen[9]=2;
 
23381
  shell_seen[10]=2;
 
23382
  shell_seen[11]=2;
 
23383
  shell_seen[12]=2;
 
23384
  
 
23385
  /* Parse arguments and read input */
 
23386
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
23387
 
 
23388
    if (shell_index==-1) {
 
23389
      exit(1);
 
23390
    }
 
23391
 
 
23392
    if (shell_seen[shell_index]==1) {
 
23393
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
23394
              shell_options[shell_index].name);
 
23395
      exit(1);
 
23396
    }
 
23397
    shell_seen[shell_index]=1;  
 
23398
 
 
23399
    switch (shell_index) {
 
23400
    case 0: /* graph */
 
23401
      shell_read_graph(&graph, optarg);
 
23402
      break;
 
23403
    case 1: /* alpha */
 
23404
      shell_read_real(&alpha, optarg);
 
23405
      break;
 
23406
    case 2: /* alpha-out */
 
23407
      shell_arg_alpha=strdup(optarg);
 
23408
      break;
 
23409
    case 3: /* a */
 
23410
      shell_read_real(&a, optarg);
 
23411
      break;
 
23412
    case 4: /* a-out */
 
23413
      shell_arg_a=strdup(optarg);
 
23414
      break;
 
23415
    case 5: /* beta */
 
23416
      shell_read_real(&beta, optarg);
 
23417
      break;
 
23418
    case 6: /* beta-out */
 
23419
      shell_arg_beta=strdup(optarg);
 
23420
      break;
 
23421
    case 7: /* Fmin */
 
23422
      shell_arg_Fmin=strdup(optarg);
 
23423
      break;
 
23424
    case 8: /* abstol */
 
23425
      shell_read_real(&abstol, optarg);
 
23426
      break;
 
23427
    case 9: /* reltol */
 
23428
      shell_read_real(&reltol, optarg);
 
23429
      break;
 
23430
    case 10: /* maxit */
 
23431
      shell_read_int(&maxit, optarg);
 
23432
      break;
 
23433
    case 11: /* agebins */
 
23434
      shell_read_int(&agebins, optarg);
 
23435
      break;
 
23436
    case 12: /* filter */
 
23437
      filter=&v_filter; shell_read_vector(filter, optarg);
 
23438
      break;
 
23439
    case 13: /* fncount */
 
23440
      shell_arg_fncount=strdup(optarg);
 
23441
      break;
 
23442
    case 14: /* grcount */
 
23443
      shell_arg_grcount=strdup(optarg);
 
23444
      break;
 
23445
    case 15:
 
23446
      shell_igraph_revolver_ml_AD_alpha_a_beta_usage(argv);
 
23447
      break;
 
23448
    default:
 
23449
      break;
 
23450
    }
 
23451
 
 
23452
    shell_index=-1;
 
23453
  }
 
23454
 
 
23455
  /* Check that we have all arguments */
 
23456
  for (shell_index=0; shell_index<15; shell_index++) {
 
23457
    if (!shell_seen[shell_index]) {
 
23458
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23459
              shell_options[shell_index].name);
 
23460
      exit(1);
 
23461
    }
 
23462
  }
 
23463
 
 
23464
  /* Do the operation */
 
23465
  shell_result=igraph_revolver_ml_AD_alpha_a_beta(&graph, &alpha, &a, &beta, &Fmin, abstol, reltol, maxit, agebins, filter, &fncount, &grcount);
 
23466
 
 
23467
  /* Write the result */
 
23468
  igraph_destroy(&graph);
 
23469
  shell_write_real(alpha, shell_arg_alpha);
 
23470
  shell_write_real(a, shell_arg_a);
 
23471
  shell_write_real(beta, shell_arg_beta);
 
23472
  shell_write_real(Fmin, shell_arg_Fmin);
 
23473
  if (filter) { igraph_vector_destroy(filter); }
 
23474
  shell_write_integer(fncount, shell_arg_fncount);
 
23475
  shell_write_integer(grcount, shell_arg_grcount);
 
23476
 
 
23477
  return 0;
 
23478
}
 
23479
 
 
23480
/*-------------------------------------------/
 
23481
/ igraph_revolver_ml_AD_dpareto              /
 
23482
/-------------------------------------------*/
 
23483
void shell_igraph_revolver_ml_AD_dpareto_usage(char **argv) {
 
23484
  printf("%s --graph=<graph> --alpha=<alpha> --alpha-out=<alpha-out> --a=<a> --a-out=<a-out> --paralpha=<paralpha> --paralpha-out=<paralpha-out> --parbeta=<parbeta> --parbeta-out=<parbeta-out> --parscale=<parscale> --parscale-out=<parscale-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --agebins=<agebins> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
23485
  exit(1);
 
23486
}
 
23487
 
 
23488
int shell_igraph_revolver_ml_AD_dpareto(int argc, char **argv) {
 
23489
 
 
23490
  igraph_t graph;
 
23491
  igraph_real_t alpha;
 
23492
  igraph_real_t a;
 
23493
  igraph_real_t paralpha;
 
23494
  igraph_real_t parbeta;
 
23495
  igraph_real_t parscale;
 
23496
  igraph_real_t Fmin;
 
23497
  igraph_real_t abstol=1e-8;
 
23498
  igraph_real_t reltol=1e-8;
 
23499
  int maxit=1000;
 
23500
  int agebins=300;
 
23501
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23502
  igraph_integer_t fncount;
 
23503
  igraph_integer_t grcount;
 
23504
  char* shell_arg_alpha=0;
 
23505
  char* shell_arg_a=0;
 
23506
  char* shell_arg_paralpha=0;
 
23507
  char* shell_arg_parbeta=0;
 
23508
  char* shell_arg_parscale=0;
 
23509
  char* shell_arg_Fmin=0;
 
23510
  char* shell_arg_fncount=0;
 
23511
  char* shell_arg_grcount=0;
 
23512
  int shell_result;
 
23513
 
 
23514
 
 
23515
  int shell_seen[19];
 
23516
  int shell_index=-1;
 
23517
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23518
                                   { "alpha",required_argument,0,1 },
 
23519
                                   { "alpha-out",required_argument,0,2 },
 
23520
                                   { "a",required_argument,0,3 },
 
23521
                                   { "a-out",required_argument,0,4 },
 
23522
                                   { "paralpha",required_argument,0,5 },
 
23523
                                   { "paralpha-out",required_argument,0,6 },
 
23524
                                   { "parbeta",required_argument,0,7 },
 
23525
                                   { "parbeta-out",required_argument,0,8 },
 
23526
                                   { "parscale",required_argument,0,9 },
 
23527
                                   { "parscale-out",required_argument,0,10 },
 
23528
                                   { "Fmin",required_argument,0,11 },
 
23529
                                   { "abstol",required_argument,0,12 },
 
23530
                                   { "reltol",required_argument,0,13 },
 
23531
                                   { "maxit",required_argument,0,14 },
 
23532
                                   { "agebins",required_argument,0,15 },
 
23533
                                   { "filter",required_argument,0,16 },
 
23534
                                   { "fncount",required_argument,0,17 },
 
23535
                                   { "grcount",required_argument,0,18 },
 
23536
                                   { "help",no_argument,0,19 },
 
23537
                                   { 0,0,0,0 }
 
23538
                                 };
 
23539
 
 
23540
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
23541
  memset(shell_seen, 0, 19*sizeof(int));
 
23542
  shell_seen[12]=2;
 
23543
  shell_seen[13]=2;
 
23544
  shell_seen[14]=2;
 
23545
  shell_seen[15]=2;
 
23546
  shell_seen[16]=2;
 
23547
  
 
23548
  /* Parse arguments and read input */
 
23549
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
23550
 
 
23551
    if (shell_index==-1) {
 
23552
      exit(1);
 
23553
    }
 
23554
 
 
23555
    if (shell_seen[shell_index]==1) {
 
23556
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
23557
              shell_options[shell_index].name);
 
23558
      exit(1);
 
23559
    }
 
23560
    shell_seen[shell_index]=1;  
 
23561
 
 
23562
    switch (shell_index) {
 
23563
    case 0: /* graph */
 
23564
      shell_read_graph(&graph, optarg);
 
23565
      break;
 
23566
    case 1: /* alpha */
 
23567
      shell_read_real(&alpha, optarg);
 
23568
      break;
 
23569
    case 2: /* alpha-out */
 
23570
      shell_arg_alpha=strdup(optarg);
 
23571
      break;
 
23572
    case 3: /* a */
 
23573
      shell_read_real(&a, optarg);
 
23574
      break;
 
23575
    case 4: /* a-out */
 
23576
      shell_arg_a=strdup(optarg);
 
23577
      break;
 
23578
    case 5: /* paralpha */
 
23579
      shell_read_real(&paralpha, optarg);
 
23580
      break;
 
23581
    case 6: /* paralpha-out */
 
23582
      shell_arg_paralpha=strdup(optarg);
 
23583
      break;
 
23584
    case 7: /* parbeta */
 
23585
      shell_read_real(&parbeta, optarg);
 
23586
      break;
 
23587
    case 8: /* parbeta-out */
 
23588
      shell_arg_parbeta=strdup(optarg);
 
23589
      break;
 
23590
    case 9: /* parscale */
 
23591
      shell_read_real(&parscale, optarg);
 
23592
      break;
 
23593
    case 10: /* parscale-out */
 
23594
      shell_arg_parscale=strdup(optarg);
 
23595
      break;
 
23596
    case 11: /* Fmin */
 
23597
      shell_arg_Fmin=strdup(optarg);
 
23598
      break;
 
23599
    case 12: /* abstol */
 
23600
      shell_read_real(&abstol, optarg);
 
23601
      break;
 
23602
    case 13: /* reltol */
 
23603
      shell_read_real(&reltol, optarg);
 
23604
      break;
 
23605
    case 14: /* maxit */
 
23606
      shell_read_int(&maxit, optarg);
 
23607
      break;
 
23608
    case 15: /* agebins */
 
23609
      shell_read_int(&agebins, optarg);
 
23610
      break;
 
23611
    case 16: /* filter */
 
23612
      filter=&v_filter; shell_read_vector(filter, optarg);
 
23613
      break;
 
23614
    case 17: /* fncount */
 
23615
      shell_arg_fncount=strdup(optarg);
 
23616
      break;
 
23617
    case 18: /* grcount */
 
23618
      shell_arg_grcount=strdup(optarg);
 
23619
      break;
 
23620
    case 19:
 
23621
      shell_igraph_revolver_ml_AD_dpareto_usage(argv);
 
23622
      break;
 
23623
    default:
 
23624
      break;
 
23625
    }
 
23626
 
 
23627
    shell_index=-1;
 
23628
  }
 
23629
 
 
23630
  /* Check that we have all arguments */
 
23631
  for (shell_index=0; shell_index<19; shell_index++) {
 
23632
    if (!shell_seen[shell_index]) {
 
23633
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23634
              shell_options[shell_index].name);
 
23635
      exit(1);
 
23636
    }
 
23637
  }
 
23638
 
 
23639
  /* Do the operation */
 
23640
  shell_result=igraph_revolver_ml_AD_dpareto(&graph, &alpha, &a, &paralpha, &parbeta, &parscale, &Fmin, abstol, reltol, maxit, agebins, filter, &fncount, &grcount);
 
23641
 
 
23642
  /* Write the result */
 
23643
  igraph_destroy(&graph);
 
23644
  shell_write_real(alpha, shell_arg_alpha);
 
23645
  shell_write_real(a, shell_arg_a);
 
23646
  shell_write_real(paralpha, shell_arg_paralpha);
 
23647
  shell_write_real(parbeta, shell_arg_parbeta);
 
23648
  shell_write_real(parscale, shell_arg_parscale);
 
23649
  shell_write_real(Fmin, shell_arg_Fmin);
 
23650
  if (filter) { igraph_vector_destroy(filter); }
 
23651
  shell_write_integer(fncount, shell_arg_fncount);
 
23652
  shell_write_integer(grcount, shell_arg_grcount);
 
23653
 
 
23654
  return 0;
 
23655
}
 
23656
 
 
23657
/*-------------------------------------------/
 
23658
/ igraph_revolver_ml_AD_dpareto_eval         /
 
23659
/-------------------------------------------*/
 
23660
void shell_igraph_revolver_ml_AD_dpareto_eval_usage(char **argv) {
 
23661
  printf("%s --graph=<graph> --alpha=<alpha> --a=<a> --paralpha=<paralpha> --parbeta=<parbeta> --parscale=<parscale> --value=<value> --deriv=<deriv> --agebins=<agebins> --filter=<filter>\n", basename(argv[0]));
 
23662
  exit(1);
 
23663
}
 
23664
 
 
23665
int shell_igraph_revolver_ml_AD_dpareto_eval(int argc, char **argv) {
 
23666
 
 
23667
  igraph_t graph;
 
23668
  igraph_real_t alpha;
 
23669
  igraph_real_t a;
 
23670
  igraph_real_t paralpha;
 
23671
  igraph_real_t parbeta;
 
23672
  igraph_real_t parscale;
 
23673
  igraph_real_t value;
 
23674
  igraph_vector_t deriv;
 
23675
  int agebins=300;
 
23676
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23677
  char* shell_arg_value=0;
 
23678
  char* shell_arg_deriv=0;
 
23679
  int shell_result;
 
23680
 
 
23681
 
 
23682
  int shell_seen[10];
 
23683
  int shell_index=-1;
 
23684
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23685
                                   { "alpha",required_argument,0,1 },
 
23686
                                   { "a",required_argument,0,2 },
 
23687
                                   { "paralpha",required_argument,0,3 },
 
23688
                                   { "parbeta",required_argument,0,4 },
 
23689
                                   { "parscale",required_argument,0,5 },
 
23690
                                   { "value",required_argument,0,6 },
 
23691
                                   { "deriv",required_argument,0,7 },
 
23692
                                   { "agebins",required_argument,0,8 },
 
23693
                                   { "filter",required_argument,0,9 },
 
23694
                                   { "help",no_argument,0,10 },
 
23695
                                   { 0,0,0,0 }
 
23696
                                 };
 
23697
 
 
23698
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
23699
  memset(shell_seen, 0, 10*sizeof(int));
 
23700
  shell_seen[8]=2;
 
23701
  shell_seen[9]=2;
 
23702
  
 
23703
  /* Parse arguments and read input */
 
23704
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
23705
 
 
23706
    if (shell_index==-1) {
 
23707
      exit(1);
 
23708
    }
 
23709
 
 
23710
    if (shell_seen[shell_index]==1) {
 
23711
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
23712
              shell_options[shell_index].name);
 
23713
      exit(1);
 
23714
    }
 
23715
    shell_seen[shell_index]=1;  
 
23716
 
 
23717
    switch (shell_index) {
 
23718
    case 0: /* graph */
 
23719
      shell_read_graph(&graph, optarg);
 
23720
      break;
 
23721
    case 1: /* alpha */
 
23722
      shell_read_real(&alpha, optarg);
 
23723
      break;
 
23724
    case 2: /* a */
 
23725
      shell_read_real(&a, optarg);
 
23726
      break;
 
23727
    case 3: /* paralpha */
 
23728
      shell_read_real(&paralpha, optarg);
 
23729
      break;
 
23730
    case 4: /* parbeta */
 
23731
      shell_read_real(&parbeta, optarg);
 
23732
      break;
 
23733
    case 5: /* parscale */
 
23734
      shell_read_real(&parscale, optarg);
 
23735
      break;
 
23736
    case 6: /* value */
 
23737
      shell_arg_value=strdup(optarg);
 
23738
      break;
 
23739
    case 7: /* deriv */
 
23740
      shell_arg_deriv=strdup(optarg); 
 
23741
  igraph_vector_init(&deriv, 0);
 
23742
      break;
 
23743
    case 8: /* agebins */
 
23744
      shell_read_int(&agebins, optarg);
 
23745
      break;
 
23746
    case 9: /* filter */
 
23747
      filter=&v_filter; shell_read_vector(filter, optarg);
 
23748
      break;
 
23749
    case 10:
 
23750
      shell_igraph_revolver_ml_AD_dpareto_eval_usage(argv);
 
23751
      break;
 
23752
    default:
 
23753
      break;
 
23754
    }
 
23755
 
 
23756
    shell_index=-1;
 
23757
  }
 
23758
 
 
23759
  /* Check that we have all arguments */
 
23760
  for (shell_index=0; shell_index<10; shell_index++) {
 
23761
    if (!shell_seen[shell_index]) {
 
23762
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23763
              shell_options[shell_index].name);
 
23764
      exit(1);
 
23765
    }
 
23766
  }
 
23767
 
 
23768
  /* Do the operation */
 
23769
  shell_result=igraph_revolver_ml_AD_dpareto_eval(&graph, alpha, a, paralpha, parbeta, parscale, &value, &deriv, agebins, filter);
 
23770
 
 
23771
  /* Write the result */
 
23772
  igraph_destroy(&graph);
 
23773
  shell_write_real(value, shell_arg_value);
 
23774
  shell_write_vector(&deriv, shell_arg_deriv); 
 
23775
  igraph_vector_destroy(&deriv);
 
23776
  if (filter) { igraph_vector_destroy(filter); }
 
23777
 
 
23778
  return 0;
 
23779
}
 
23780
 
 
23781
/*-------------------------------------------/
 
23782
/ igraph_revolver_ml_ADE_alpha_a_beta        /
 
23783
/-------------------------------------------*/
 
23784
void shell_igraph_revolver_ml_ADE_alpha_a_beta_usage(char **argv) {
 
23785
  printf("%s --graph=<graph> --cats=<cats> --alpha=<alpha> --alpha-out=<alpha-out> --a=<a> --a-out=<a-out> --beta=<beta> --beta-out=<beta-out> --coeffs=<coeffs> --coeffs-out=<coeffs-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --agebins=<agebins> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
23786
  exit(1);
 
23787
}
 
23788
 
 
23789
int shell_igraph_revolver_ml_ADE_alpha_a_beta(int argc, char **argv) {
 
23790
 
 
23791
  igraph_t graph;
 
23792
  igraph_vector_t cats;
 
23793
  igraph_real_t alpha;
 
23794
  igraph_real_t a;
 
23795
  igraph_real_t beta;
 
23796
  igraph_vector_t coeffs;
 
23797
  igraph_real_t Fmin;
 
23798
  igraph_real_t abstol=1e-8;
 
23799
  igraph_real_t reltol=1e-8;
 
23800
  int maxit=1000;
 
23801
  int agebins=300;
 
23802
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23803
  igraph_integer_t fncount;
 
23804
  igraph_integer_t grcount;
 
23805
  char* shell_arg_alpha=0;
 
23806
  char* shell_arg_a=0;
 
23807
  char* shell_arg_beta=0;
 
23808
  char* shell_arg_coeffs=0;
 
23809
  char* shell_arg_Fmin=0;
 
23810
  char* shell_arg_fncount=0;
 
23811
  char* shell_arg_grcount=0;
 
23812
  int shell_result;
 
23813
 
 
23814
 
 
23815
  int shell_seen[18];
 
23816
  int shell_index=-1;
 
23817
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23818
                                   { "cats",required_argument,0,1 },
 
23819
                                   { "alpha",required_argument,0,2 },
 
23820
                                   { "alpha-out",required_argument,0,3 },
 
23821
                                   { "a",required_argument,0,4 },
 
23822
                                   { "a-out",required_argument,0,5 },
 
23823
                                   { "beta",required_argument,0,6 },
 
23824
                                   { "beta-out",required_argument,0,7 },
 
23825
                                   { "coeffs",required_argument,0,8 },
 
23826
                                   { "coeffs-out",required_argument,0,9 },
 
23827
                                   { "Fmin",required_argument,0,10 },
 
23828
                                   { "abstol",required_argument,0,11 },
 
23829
                                   { "reltol",required_argument,0,12 },
 
23830
                                   { "maxit",required_argument,0,13 },
 
23831
                                   { "agebins",required_argument,0,14 },
 
23832
                                   { "filter",required_argument,0,15 },
 
23833
                                   { "fncount",required_argument,0,16 },
 
23834
                                   { "grcount",required_argument,0,17 },
 
23835
                                   { "help",no_argument,0,18 },
 
23836
                                   { 0,0,0,0 }
 
23837
                                 };
 
23838
 
 
23839
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
23840
  memset(shell_seen, 0, 18*sizeof(int));
 
23841
  shell_seen[11]=2;
 
23842
  shell_seen[12]=2;
 
23843
  shell_seen[13]=2;
 
23844
  shell_seen[14]=2;
 
23845
  shell_seen[15]=2;
 
23846
  
 
23847
  /* Parse arguments and read input */
 
23848
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
23849
 
 
23850
    if (shell_index==-1) {
 
23851
      exit(1);
 
23852
    }
 
23853
 
 
23854
    if (shell_seen[shell_index]==1) {
 
23855
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
23856
              shell_options[shell_index].name);
 
23857
      exit(1);
 
23858
    }
 
23859
    shell_seen[shell_index]=1;  
 
23860
 
 
23861
    switch (shell_index) {
 
23862
    case 0: /* graph */
 
23863
      shell_read_graph(&graph, optarg);
 
23864
      break;
 
23865
    case 1: /* cats */
 
23866
      shell_read_vector(&cats, optarg);
 
23867
      break;
 
23868
    case 2: /* alpha */
 
23869
      shell_read_real(&alpha, optarg);
 
23870
      break;
 
23871
    case 3: /* alpha-out */
 
23872
      shell_arg_alpha=strdup(optarg);
 
23873
      break;
 
23874
    case 4: /* a */
 
23875
      shell_read_real(&a, optarg);
 
23876
      break;
 
23877
    case 5: /* a-out */
 
23878
      shell_arg_a=strdup(optarg);
 
23879
      break;
 
23880
    case 6: /* beta */
 
23881
      shell_read_real(&beta, optarg);
 
23882
      break;
 
23883
    case 7: /* beta-out */
 
23884
      shell_arg_beta=strdup(optarg);
 
23885
      break;
 
23886
    case 8: /* coeffs */
 
23887
      shell_read_vector(&coeffs, optarg);
 
23888
      break;
 
23889
    case 9: /* coeffs-out */
 
23890
      shell_arg_coeffs=strdup(optarg); 
 
23891
  igraph_vector_init(&coeffs, 0);
 
23892
      break;
 
23893
    case 10: /* Fmin */
 
23894
      shell_arg_Fmin=strdup(optarg);
 
23895
      break;
 
23896
    case 11: /* abstol */
 
23897
      shell_read_real(&abstol, optarg);
 
23898
      break;
 
23899
    case 12: /* reltol */
 
23900
      shell_read_real(&reltol, optarg);
 
23901
      break;
 
23902
    case 13: /* maxit */
 
23903
      shell_read_int(&maxit, optarg);
 
23904
      break;
 
23905
    case 14: /* agebins */
 
23906
      shell_read_int(&agebins, optarg);
 
23907
      break;
 
23908
    case 15: /* filter */
 
23909
      filter=&v_filter; shell_read_vector(filter, optarg);
 
23910
      break;
 
23911
    case 16: /* fncount */
 
23912
      shell_arg_fncount=strdup(optarg);
 
23913
      break;
 
23914
    case 17: /* grcount */
 
23915
      shell_arg_grcount=strdup(optarg);
 
23916
      break;
 
23917
    case 18:
 
23918
      shell_igraph_revolver_ml_ADE_alpha_a_beta_usage(argv);
 
23919
      break;
 
23920
    default:
 
23921
      break;
 
23922
    }
 
23923
 
 
23924
    shell_index=-1;
 
23925
  }
 
23926
 
 
23927
  /* Check that we have all arguments */
 
23928
  for (shell_index=0; shell_index<18; shell_index++) {
 
23929
    if (!shell_seen[shell_index]) {
 
23930
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
23931
              shell_options[shell_index].name);
 
23932
      exit(1);
 
23933
    }
 
23934
  }
 
23935
 
 
23936
  /* Do the operation */
 
23937
  shell_result=igraph_revolver_ml_ADE_alpha_a_beta(&graph, &cats, &alpha, &a, &beta, &coeffs, &Fmin, abstol, reltol, maxit, agebins, filter, &fncount, &grcount);
 
23938
 
 
23939
  /* Write the result */
 
23940
  igraph_destroy(&graph);
 
23941
  igraph_vector_destroy(&cats);
 
23942
  shell_write_real(alpha, shell_arg_alpha);
 
23943
  shell_write_real(a, shell_arg_a);
 
23944
  shell_write_real(beta, shell_arg_beta);
 
23945
  igraph_vector_destroy(&coeffs);
 
23946
  shell_write_vector(&coeffs, shell_arg_coeffs); 
 
23947
  igraph_vector_destroy(&coeffs);
 
23948
  shell_write_real(Fmin, shell_arg_Fmin);
 
23949
  if (filter) { igraph_vector_destroy(filter); }
 
23950
  shell_write_integer(fncount, shell_arg_fncount);
 
23951
  shell_write_integer(grcount, shell_arg_grcount);
 
23952
 
 
23953
  return 0;
 
23954
}
 
23955
 
 
23956
/*-------------------------------------------/
 
23957
/ igraph_revolver_ml_ADE_dpareto             /
 
23958
/-------------------------------------------*/
 
23959
void shell_igraph_revolver_ml_ADE_dpareto_usage(char **argv) {
 
23960
  printf("%s --graph=<graph> --cats=<cats> --alpha=<alpha> --alpha-out=<alpha-out> --a=<a> --a-out=<a-out> --paralpha=<paralpha> --paralpha-out=<paralpha-out> --parbeta=<parbeta> --parbeta-out=<parbeta-out> --parscale=<parscale> --parscale-out=<parscale-out> --coeffs=<coeffs> --coeffs-out=<coeffs-out> --Fmin=<Fmin> --abstol=<abstol> --reltol=<reltol> --maxit=<maxit> --agebins=<agebins> --filter=<filter> --fncount=<fncount> --grcount=<grcount>\n", basename(argv[0]));
 
23961
  exit(1);
 
23962
}
 
23963
 
 
23964
int shell_igraph_revolver_ml_ADE_dpareto(int argc, char **argv) {
 
23965
 
 
23966
  igraph_t graph;
 
23967
  igraph_vector_t cats;
 
23968
  igraph_real_t alpha;
 
23969
  igraph_real_t a;
 
23970
  igraph_real_t paralpha;
 
23971
  igraph_real_t parbeta;
 
23972
  igraph_real_t parscale;
 
23973
  igraph_vector_t coeffs;
 
23974
  igraph_real_t Fmin;
 
23975
  igraph_real_t abstol=1e-8;
 
23976
  igraph_real_t reltol=1e-8;
 
23977
  int maxit=1000;
 
23978
  int agebins=300;
 
23979
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
23980
  igraph_integer_t fncount;
 
23981
  igraph_integer_t grcount;
 
23982
  char* shell_arg_alpha=0;
 
23983
  char* shell_arg_a=0;
 
23984
  char* shell_arg_paralpha=0;
 
23985
  char* shell_arg_parbeta=0;
 
23986
  char* shell_arg_parscale=0;
 
23987
  char* shell_arg_coeffs=0;
 
23988
  char* shell_arg_Fmin=0;
 
23989
  char* shell_arg_fncount=0;
 
23990
  char* shell_arg_grcount=0;
 
23991
  int shell_result;
 
23992
 
 
23993
 
 
23994
  int shell_seen[22];
 
23995
  int shell_index=-1;
 
23996
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
23997
                                   { "cats",required_argument,0,1 },
 
23998
                                   { "alpha",required_argument,0,2 },
 
23999
                                   { "alpha-out",required_argument,0,3 },
 
24000
                                   { "a",required_argument,0,4 },
 
24001
                                   { "a-out",required_argument,0,5 },
 
24002
                                   { "paralpha",required_argument,0,6 },
 
24003
                                   { "paralpha-out",required_argument,0,7 },
 
24004
                                   { "parbeta",required_argument,0,8 },
 
24005
                                   { "parbeta-out",required_argument,0,9 },
 
24006
                                   { "parscale",required_argument,0,10 },
 
24007
                                   { "parscale-out",required_argument,0,11 },
 
24008
                                   { "coeffs",required_argument,0,12 },
 
24009
                                   { "coeffs-out",required_argument,0,13 },
 
24010
                                   { "Fmin",required_argument,0,14 },
 
24011
                                   { "abstol",required_argument,0,15 },
 
24012
                                   { "reltol",required_argument,0,16 },
 
24013
                                   { "maxit",required_argument,0,17 },
 
24014
                                   { "agebins",required_argument,0,18 },
 
24015
                                   { "filter",required_argument,0,19 },
 
24016
                                   { "fncount",required_argument,0,20 },
 
24017
                                   { "grcount",required_argument,0,21 },
 
24018
                                   { "help",no_argument,0,22 },
 
24019
                                   { 0,0,0,0 }
 
24020
                                 };
 
24021
 
 
24022
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
24023
  memset(shell_seen, 0, 22*sizeof(int));
 
24024
  shell_seen[15]=2;
 
24025
  shell_seen[16]=2;
 
24026
  shell_seen[17]=2;
 
24027
  shell_seen[18]=2;
 
24028
  shell_seen[19]=2;
 
24029
  
 
24030
  /* Parse arguments and read input */
 
24031
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
24032
 
 
24033
    if (shell_index==-1) {
 
24034
      exit(1);
 
24035
    }
 
24036
 
 
24037
    if (shell_seen[shell_index]==1) {
 
24038
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
24039
              shell_options[shell_index].name);
 
24040
      exit(1);
 
24041
    }
 
24042
    shell_seen[shell_index]=1;  
 
24043
 
 
24044
    switch (shell_index) {
 
24045
    case 0: /* graph */
 
24046
      shell_read_graph(&graph, optarg);
 
24047
      break;
 
24048
    case 1: /* cats */
 
24049
      shell_read_vector(&cats, optarg);
 
24050
      break;
 
24051
    case 2: /* alpha */
 
24052
      shell_read_real(&alpha, optarg);
 
24053
      break;
 
24054
    case 3: /* alpha-out */
 
24055
      shell_arg_alpha=strdup(optarg);
 
24056
      break;
 
24057
    case 4: /* a */
 
24058
      shell_read_real(&a, optarg);
 
24059
      break;
 
24060
    case 5: /* a-out */
 
24061
      shell_arg_a=strdup(optarg);
 
24062
      break;
 
24063
    case 6: /* paralpha */
 
24064
      shell_read_real(&paralpha, optarg);
 
24065
      break;
 
24066
    case 7: /* paralpha-out */
 
24067
      shell_arg_paralpha=strdup(optarg);
 
24068
      break;
 
24069
    case 8: /* parbeta */
 
24070
      shell_read_real(&parbeta, optarg);
 
24071
      break;
 
24072
    case 9: /* parbeta-out */
 
24073
      shell_arg_parbeta=strdup(optarg);
 
24074
      break;
 
24075
    case 10: /* parscale */
 
24076
      shell_read_real(&parscale, optarg);
 
24077
      break;
 
24078
    case 11: /* parscale-out */
 
24079
      shell_arg_parscale=strdup(optarg);
 
24080
      break;
 
24081
    case 12: /* coeffs */
 
24082
      shell_read_vector(&coeffs, optarg);
 
24083
      break;
 
24084
    case 13: /* coeffs-out */
 
24085
      shell_arg_coeffs=strdup(optarg); 
 
24086
  igraph_vector_init(&coeffs, 0);
 
24087
      break;
 
24088
    case 14: /* Fmin */
 
24089
      shell_arg_Fmin=strdup(optarg);
 
24090
      break;
 
24091
    case 15: /* abstol */
 
24092
      shell_read_real(&abstol, optarg);
 
24093
      break;
 
24094
    case 16: /* reltol */
 
24095
      shell_read_real(&reltol, optarg);
 
24096
      break;
 
24097
    case 17: /* maxit */
 
24098
      shell_read_int(&maxit, optarg);
 
24099
      break;
 
24100
    case 18: /* agebins */
 
24101
      shell_read_int(&agebins, optarg);
 
24102
      break;
 
24103
    case 19: /* filter */
 
24104
      filter=&v_filter; shell_read_vector(filter, optarg);
 
24105
      break;
 
24106
    case 20: /* fncount */
 
24107
      shell_arg_fncount=strdup(optarg);
 
24108
      break;
 
24109
    case 21: /* grcount */
 
24110
      shell_arg_grcount=strdup(optarg);
 
24111
      break;
 
24112
    case 22:
 
24113
      shell_igraph_revolver_ml_ADE_dpareto_usage(argv);
 
24114
      break;
 
24115
    default:
 
24116
      break;
 
24117
    }
 
24118
 
 
24119
    shell_index=-1;
 
24120
  }
 
24121
 
 
24122
  /* Check that we have all arguments */
 
24123
  for (shell_index=0; shell_index<22; shell_index++) {
 
24124
    if (!shell_seen[shell_index]) {
 
24125
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
24126
              shell_options[shell_index].name);
 
24127
      exit(1);
 
24128
    }
 
24129
  }
 
24130
 
 
24131
  /* Do the operation */
 
24132
  shell_result=igraph_revolver_ml_ADE_dpareto(&graph, &cats, &alpha, &a, &paralpha, &parbeta, &parscale, &coeffs, &Fmin, abstol, reltol, maxit, agebins, filter, &fncount, &grcount);
 
24133
 
 
24134
  /* Write the result */
 
24135
  igraph_destroy(&graph);
 
24136
  igraph_vector_destroy(&cats);
 
24137
  shell_write_real(alpha, shell_arg_alpha);
 
24138
  shell_write_real(a, shell_arg_a);
 
24139
  shell_write_real(paralpha, shell_arg_paralpha);
 
24140
  shell_write_real(parbeta, shell_arg_parbeta);
 
24141
  shell_write_real(parscale, shell_arg_parscale);
 
24142
  igraph_vector_destroy(&coeffs);
 
24143
  shell_write_vector(&coeffs, shell_arg_coeffs); 
 
24144
  igraph_vector_destroy(&coeffs);
 
24145
  shell_write_real(Fmin, shell_arg_Fmin);
 
24146
  if (filter) { igraph_vector_destroy(filter); }
 
24147
  shell_write_integer(fncount, shell_arg_fncount);
 
24148
  shell_write_integer(grcount, shell_arg_grcount);
 
24149
 
 
24150
  return 0;
 
24151
}
 
24152
 
 
24153
/*-------------------------------------------/
 
24154
/ igraph_revolver_ml_ADE_dpareto_eval        /
 
24155
/-------------------------------------------*/
 
24156
void shell_igraph_revolver_ml_ADE_dpareto_eval_usage(char **argv) {
 
24157
  printf("%s --graph=<graph> --cats=<cats> --alpha=<alpha> --a=<a> --paralpha=<paralpha> --parbeta=<parbeta> --parscale=<parscale> --coeffs=<coeffs> --value=<value> --deriv=<deriv> --agebins=<agebins> --filter=<filter>\n", basename(argv[0]));
 
24158
  exit(1);
 
24159
}
 
24160
 
 
24161
int shell_igraph_revolver_ml_ADE_dpareto_eval(int argc, char **argv) {
 
24162
 
 
24163
  igraph_t graph;
 
24164
  igraph_vector_t cats;
 
24165
  igraph_real_t alpha;
 
24166
  igraph_real_t a;
 
24167
  igraph_real_t paralpha;
 
24168
  igraph_real_t parbeta;
 
24169
  igraph_real_t parscale;
 
24170
  igraph_vector_t coeffs;
 
24171
  igraph_real_t value;
 
24172
  igraph_vector_t deriv;
 
24173
  int agebins=300;
 
24174
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
24175
  char* shell_arg_value=0;
 
24176
  char* shell_arg_deriv=0;
 
24177
  int shell_result;
 
24178
 
 
24179
 
 
24180
  int shell_seen[12];
 
24181
  int shell_index=-1;
 
24182
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
24183
                                   { "cats",required_argument,0,1 },
 
24184
                                   { "alpha",required_argument,0,2 },
 
24185
                                   { "a",required_argument,0,3 },
 
24186
                                   { "paralpha",required_argument,0,4 },
 
24187
                                   { "parbeta",required_argument,0,5 },
 
24188
                                   { "parscale",required_argument,0,6 },
 
24189
                                   { "coeffs",required_argument,0,7 },
 
24190
                                   { "value",required_argument,0,8 },
 
24191
                                   { "deriv",required_argument,0,9 },
 
24192
                                   { "agebins",required_argument,0,10 },
 
24193
                                   { "filter",required_argument,0,11 },
 
24194
                                   { "help",no_argument,0,12 },
 
24195
                                   { 0,0,0,0 }
 
24196
                                 };
 
24197
 
 
24198
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
24199
  memset(shell_seen, 0, 12*sizeof(int));
 
24200
  shell_seen[10]=2;
 
24201
  shell_seen[11]=2;
 
24202
  
 
24203
  /* Parse arguments and read input */
 
24204
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
24205
 
 
24206
    if (shell_index==-1) {
 
24207
      exit(1);
 
24208
    }
 
24209
 
 
24210
    if (shell_seen[shell_index]==1) {
 
24211
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
24212
              shell_options[shell_index].name);
 
24213
      exit(1);
 
24214
    }
 
24215
    shell_seen[shell_index]=1;  
 
24216
 
 
24217
    switch (shell_index) {
 
24218
    case 0: /* graph */
 
24219
      shell_read_graph(&graph, optarg);
 
24220
      break;
 
24221
    case 1: /* cats */
 
24222
      shell_read_vector(&cats, optarg);
 
24223
      break;
 
24224
    case 2: /* alpha */
 
24225
      shell_read_real(&alpha, optarg);
 
24226
      break;
 
24227
    case 3: /* a */
 
24228
      shell_read_real(&a, optarg);
 
24229
      break;
 
24230
    case 4: /* paralpha */
 
24231
      shell_read_real(&paralpha, optarg);
 
24232
      break;
 
24233
    case 5: /* parbeta */
 
24234
      shell_read_real(&parbeta, optarg);
 
24235
      break;
 
24236
    case 6: /* parscale */
 
24237
      shell_read_real(&parscale, optarg);
 
24238
      break;
 
24239
    case 7: /* coeffs */
 
24240
      shell_read_vector(&coeffs, optarg);
 
24241
      break;
 
24242
    case 8: /* value */
 
24243
      shell_arg_value=strdup(optarg);
 
24244
      break;
 
24245
    case 9: /* deriv */
 
24246
      shell_arg_deriv=strdup(optarg); 
 
24247
  igraph_vector_init(&deriv, 0);
 
24248
      break;
 
24249
    case 10: /* agebins */
 
24250
      shell_read_int(&agebins, optarg);
 
24251
      break;
 
24252
    case 11: /* filter */
 
24253
      filter=&v_filter; shell_read_vector(filter, optarg);
 
24254
      break;
 
24255
    case 12:
 
24256
      shell_igraph_revolver_ml_ADE_dpareto_eval_usage(argv);
 
24257
      break;
 
24258
    default:
 
24259
      break;
 
24260
    }
 
24261
 
 
24262
    shell_index=-1;
 
24263
  }
 
24264
 
 
24265
  /* Check that we have all arguments */
 
24266
  for (shell_index=0; shell_index<12; shell_index++) {
 
24267
    if (!shell_seen[shell_index]) {
 
24268
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
24269
              shell_options[shell_index].name);
 
24270
      exit(1);
 
24271
    }
 
24272
  }
 
24273
 
 
24274
  /* Do the operation */
 
24275
  shell_result=igraph_revolver_ml_ADE_dpareto_eval(&graph, &cats, alpha, a, paralpha, parbeta, parscale, &coeffs, &value, &deriv, agebins, filter);
 
24276
 
 
24277
  /* Write the result */
 
24278
  igraph_destroy(&graph);
 
24279
  igraph_vector_destroy(&cats);
 
24280
  igraph_vector_destroy(&coeffs);
 
24281
  shell_write_real(value, shell_arg_value);
 
24282
  shell_write_vector(&deriv, shell_arg_deriv); 
 
24283
  igraph_vector_destroy(&deriv);
 
24284
  if (filter) { igraph_vector_destroy(filter); }
 
24285
 
 
24286
  return 0;
 
24287
}
 
24288
 
 
24289
/*-------------------------------------------/
 
24290
/ igraph_revolver_ml_ADE_dpareto_evalf       /
 
24291
/-------------------------------------------*/
 
24292
void shell_igraph_revolver_ml_ADE_dpareto_evalf_usage(char **argv) {
 
24293
  printf("%s --graph=<graph> --cats=<cats> --par=<par> --value=<value> --agebins=<agebins> --filter=<filter>\n", basename(argv[0]));
 
24294
  exit(1);
 
24295
}
 
24296
 
 
24297
int shell_igraph_revolver_ml_ADE_dpareto_evalf(int argc, char **argv) {
 
24298
 
 
24299
  igraph_t graph;
 
24300
  igraph_vector_t cats;
 
24301
  igraph_matrix_t par;
 
24302
  igraph_vector_t value;
 
24303
  int agebins;
 
24304
  igraph_vector_t v_filter; igraph_vector_t *filter=0=NULL;
 
24305
  char* shell_arg_value=0;
 
24306
  int shell_result;
 
24307
 
 
24308
 
 
24309
  int shell_seen[6];
 
24310
  int shell_index=-1;
 
24311
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
24312
                                   { "cats",required_argument,0,1 },
 
24313
                                   { "par",required_argument,0,2 },
 
24314
                                   { "value",required_argument,0,3 },
 
24315
                                   { "agebins",required_argument,0,4 },
 
24316
                                   { "filter",required_argument,0,5 },
 
24317
                                   { "help",no_argument,0,6 },
 
24318
                                   { 0,0,0,0 }
 
24319
                                 };
 
24320
 
 
24321
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
24322
  memset(shell_seen, 0, 6*sizeof(int));
 
24323
  shell_seen[5]=2;
 
24324
  
 
24325
  /* Parse arguments and read input */
 
24326
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
24327
 
 
24328
    if (shell_index==-1) {
 
24329
      exit(1);
 
24330
    }
 
24331
 
 
24332
    if (shell_seen[shell_index]==1) {
 
24333
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
24334
              shell_options[shell_index].name);
 
24335
      exit(1);
 
24336
    }
 
24337
    shell_seen[shell_index]=1;  
 
24338
 
 
24339
    switch (shell_index) {
 
24340
    case 0: /* graph */
 
24341
      shell_read_graph(&graph, optarg);
 
24342
      break;
 
24343
    case 1: /* cats */
 
24344
      shell_read_vector(&cats, optarg);
 
24345
      break;
 
24346
    case 2: /* par */
 
24347
      shell_read_matrix(&par, optarg);
 
24348
      break;
 
24349
    case 3: /* value */
 
24350
      shell_arg_value=strdup(optarg); 
 
24351
  igraph_vector_init(&value, 0);
 
24352
      break;
 
24353
    case 4: /* agebins */
 
24354
      shell_read_int(&agebins, optarg);
 
24355
      break;
 
24356
    case 5: /* filter */
 
24357
      filter=&v_filter; shell_read_vector(filter, optarg);
 
24358
      break;
 
24359
    case 6:
 
24360
      shell_igraph_revolver_ml_ADE_dpareto_evalf_usage(argv);
 
24361
      break;
 
24362
    default:
 
24363
      break;
 
24364
    }
 
24365
 
 
24366
    shell_index=-1;
 
24367
  }
 
24368
 
 
24369
  /* Check that we have all arguments */
 
24370
  for (shell_index=0; shell_index<6; shell_index++) {
 
24371
    if (!shell_seen[shell_index]) {
 
24372
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
24373
              shell_options[shell_index].name);
 
24374
      exit(1);
 
24375
    }
 
24376
  }
 
24377
 
 
24378
  /* Do the operation */
 
24379
  shell_result=igraph_revolver_ml_ADE_dpareto_evalf(&graph, &cats, &par, &value, agebins, filter);
 
24380
 
 
24381
  /* Write the result */
 
24382
  igraph_destroy(&graph);
 
24383
  igraph_vector_destroy(&cats);
 
24384
  igraph_matrix_destroy(&par);
 
24385
  shell_write_vector(&value, shell_arg_value); 
 
24386
  igraph_vector_destroy(&value);
 
24387
  if (filter) { igraph_vector_destroy(filter); }
 
24388
 
 
24389
  return 0;
 
24390
}
 
24391
 
 
24392
/*-------------------------------------------/
 
24393
/ igraph_revolver_probs_ADE_dpareto          /
 
24394
/-------------------------------------------*/
 
24395
void shell_igraph_revolver_probs_ADE_dpareto_usage(char **argv) {
 
24396
  printf("%s --graph=<graph> --par=<par> --cats=<cats> --gcats=<gcats> --agebins=<agebins> --logprobs=<logprobs> --logcited=<logcited> --logciting=<logciting>\n", basename(argv[0]));
 
24397
  exit(1);
 
24398
}
 
24399
 
 
24400
int shell_igraph_revolver_probs_ADE_dpareto(int argc, char **argv) {
 
24401
 
 
24402
  igraph_t graph;
 
24403
  igraph_matrix_t par;
 
24404
  igraph_vector_t cats;
 
24405
  igraph_vector_t gcats;
 
24406
  int agebins;
 
24407
  igraph_vector_t v_logprobs; igraph_vector_t *logprobs=0;
 
24408
  igraph_vector_t v_logcited; igraph_vector_t *logcited=0;
 
24409
  igraph_vector_t v_logciting; igraph_vector_t *logciting=0;
 
24410
  char* shell_arg_logprobs=0;
 
24411
  char* shell_arg_logcited=0;
 
24412
  char* shell_arg_logciting=0;
 
24413
  int shell_result;
 
24414
 
 
24415
 
 
24416
  int shell_seen[8];
 
24417
  int shell_index=-1;
 
24418
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
24419
                                   { "par",required_argument,0,1 },
 
24420
                                   { "cats",required_argument,0,2 },
 
24421
                                   { "gcats",required_argument,0,3 },
 
24422
                                   { "agebins",required_argument,0,4 },
 
24423
                                   { "logprobs",required_argument,0,5 },
 
24424
                                   { "logcited",required_argument,0,6 },
 
24425
                                   { "logciting",required_argument,0,7 },
 
24426
                                   { "help",no_argument,0,8 },
 
24427
                                   { 0,0,0,0 }
 
24428
                                 };
 
24429
 
 
24430
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
24431
  memset(shell_seen, 0, 8*sizeof(int));
 
24432
 
 
24433
  
 
24434
  /* Parse arguments and read input */
 
24435
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
24436
 
 
24437
    if (shell_index==-1) {
 
24438
      exit(1);
 
24439
    }
 
24440
 
 
24441
    if (shell_seen[shell_index]==1) {
 
24442
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
24443
              shell_options[shell_index].name);
 
24444
      exit(1);
 
24445
    }
 
24446
    shell_seen[shell_index]=1;  
 
24447
 
 
24448
    switch (shell_index) {
 
24449
    case 0: /* graph */
 
24450
      shell_read_graph(&graph, optarg);
 
24451
      break;
 
24452
    case 1: /* par */
 
24453
      shell_read_matrix(&par, optarg);
 
24454
      break;
 
24455
    case 2: /* cats */
 
24456
      shell_read_vector(&cats, optarg);
 
24457
      break;
 
24458
    case 3: /* gcats */
 
24459
      shell_read_vector(&gcats, optarg);
 
24460
      break;
 
24461
    case 4: /* agebins */
 
24462
      shell_read_int(&agebins, optarg);
 
24463
      break;
 
24464
    case 5: /* logprobs */
 
24465
      logprobs=&v_logprobs; igraph_vector_init(logprobs, 0); 
 
24466
  shell_arg_logprobs=strdup(optarg);
 
24467
      break;
 
24468
    case 6: /* logcited */
 
24469
      logcited=&v_logcited; igraph_vector_init(logcited, 0); 
 
24470
  shell_arg_logcited=strdup(optarg);
 
24471
      break;
 
24472
    case 7: /* logciting */
 
24473
      logciting=&v_logciting; igraph_vector_init(logciting, 0); 
 
24474
  shell_arg_logciting=strdup(optarg);
 
24475
      break;
 
24476
    case 8:
 
24477
      shell_igraph_revolver_probs_ADE_dpareto_usage(argv);
 
24478
      break;
 
24479
    default:
 
24480
      break;
 
24481
    }
 
24482
 
 
24483
    shell_index=-1;
 
24484
  }
 
24485
 
 
24486
  /* Check that we have all arguments */
 
24487
  for (shell_index=0; shell_index<8; shell_index++) {
 
24488
    if (!shell_seen[shell_index]) {
 
24489
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
24490
              shell_options[shell_index].name);
 
24491
      exit(1);
 
24492
    }
 
24493
  }
 
24494
 
 
24495
  /* Do the operation */
 
24496
  shell_result=igraph_revolver_probs_ADE_dpareto(&graph, &par, &cats, &gcats, agebins, logprobs, logcited, logciting);
 
24497
 
 
24498
  /* Write the result */
 
24499
  igraph_destroy(&graph);
 
24500
  igraph_matrix_destroy(&par);
 
24501
  igraph_vector_destroy(&cats);
 
24502
  igraph_vector_destroy(&gcats);
 
24503
  if (logprobs) { shell_write_vector(logprobs, shell_arg_logprobs); 
 
24504
  igraph_vector_destroy(logprobs); }
 
24505
  if (logcited) { shell_write_vector(logcited, shell_arg_logcited); 
 
24506
  igraph_vector_destroy(logcited); }
 
24507
  if (logciting) { shell_write_vector(logciting, shell_arg_logciting); 
 
24508
  igraph_vector_destroy(logciting); }
 
24509
 
 
24510
  return 0;
 
24511
}
 
24512
 
 
24513
/*-------------------------------------------/
 
24514
/ igraph_convergence_degree                  /
 
24515
/-------------------------------------------*/
 
24516
void shell_igraph_convergence_degree_usage(char **argv) {
 
24517
  printf("%s --graph=<graph> --result=<result>\n", basename(argv[0]));
 
24518
  exit(1);
 
24519
}
 
24520
 
 
24521
int shell_igraph_convergence_degree(int argc, char **argv) {
 
24522
 
 
24523
  igraph_t graph;
 
24524
  igraph_vector_t result;
 
24525
  char* shell_arg_result=0;
 
24526
  int shell_result;
 
24527
 
 
24528
 
 
24529
  int shell_seen[2];
 
24530
  int shell_index=-1;
 
24531
  struct option shell_options[]= { { "graph",required_argument,0,0 },
 
24532
                                   { "result",required_argument,0,1 },
 
24533
                                   { "help",no_argument,0,2 },
 
24534
                                   { 0,0,0,0 }
 
24535
                                 };
 
24536
 
 
24537
  /* 0 - not seen, 1 - seen as argument, 2 - seen as default */
 
24538
  memset(shell_seen, 0, 2*sizeof(int));
 
24539
 
 
24540
  
 
24541
  /* Parse arguments and read input */
 
24542
  while (getopt_long(argc, argv, "", shell_options, &shell_index) != -1) {
 
24543
 
 
24544
    if (shell_index==-1) {
 
24545
      exit(1);
 
24546
    }
 
24547
 
 
24548
    if (shell_seen[shell_index]==1) {
 
24549
      fprintf(stderr, "Error, `--%s' argument given twice.\n",
 
24550
              shell_options[shell_index].name);
 
24551
      exit(1);
 
24552
    }
 
24553
    shell_seen[shell_index]=1;  
 
24554
 
 
24555
    switch (shell_index) {
 
24556
    case 0: /* graph */
 
24557
      shell_read_graph(&graph, optarg);
 
24558
      break;
 
24559
    case 1: /* result */
 
24560
      shell_arg_result=strdup(optarg); 
 
24561
  igraph_vector_init(&result, 0);
 
24562
      break;
 
24563
    case 2:
 
24564
      shell_igraph_convergence_degree_usage(argv);
 
24565
      break;
 
24566
    default:
 
24567
      break;
 
24568
    }
 
24569
 
 
24570
    shell_index=-1;
 
24571
  }
 
24572
 
 
24573
  /* Check that we have all arguments */
 
24574
  for (shell_index=0; shell_index<2; shell_index++) {
 
24575
    if (!shell_seen[shell_index]) {
 
24576
      fprintf(stderr, "Error, argument missing: `--%s'.\n",
 
24577
              shell_options[shell_index].name);
 
24578
      exit(1);
 
24579
    }
 
24580
  }
 
24581
 
 
24582
  /* Do the operation */
 
24583
  shell_result=igraph_convergence_degree(&graph, &result);
 
24584
 
 
24585
  /* Write the result */
 
24586
  igraph_destroy(&graph);
 
24587
  shell_write_vector(&result, shell_arg_result); 
 
24588
  igraph_vector_destroy(&result);
 
24589
 
 
24590
  return 0;
 
24591
}