/* -*- mode: C -*- */
/*
IGraph library.
Copyright (C) 2007 Gabor Csardi <csardi@rmki.kfki.hu>
MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#define _GNU_SOURCE
#include <libgen.h>
#include <string.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
#include "igraph.h"
/* ------------------------------------------------------------------------ */
/* Conversion & other common functions first */
/* ------------------------------------------------------------------------ */
int shell_igraph_usage(int argc, char **argv) {
printf("Command line interface to igraph\n");
return 0;
}
int shell_skip_whitespace(FILE *fin) {
int c;
c=fgetc(fin);
while (isspace(c)) {
c=fgetc(fin);
}
if (c!=EOF) { ungetc(c, fin); }
return 0;
}
FILE *shell_open_file(const char *where, const char *mode) {
static const char *input="input";
static const char *output="output";
FILE *f;
if (!strcmp(where, "-")) {
if (!strcmp(mode, "r")) {
return stdin;
} else if (!strcmp(mode, "w")) {
return stdout;
}
}
f=fopen(where, mode);
if (!f) {
fprintf(stderr, "Cannot open %s file: `%s'\n",
!strcmp(mode, "r") ? input : output, where);
exit(1);
}
return f;
}
int shell_read_graph(igraph_t *graph, const char *where) {
FILE *fin=shell_open_file(where, "r");
igraph_read_graph_graphml(graph, fin, 0);
fclose(fin);
return 0;
}
int shell_write_graph(const igraph_t *graph, const char *where) {
FILE *fout=shell_open_file(where, "w");
igraph_write_graph_graphml(graph, fout);
fclose(fout);
return 0;
}
int shell_read_vector(igraph_vector_t *v, const char *where) {
FILE *fin=shell_open_file(where, "r");
igraph_real_t n;
int ret=1;
igraph_vector_init(v, 0);
while (ret > 0) {
ret=fscanf(fin, "%lf", &n);
if (ret > 0) {
igraph_vector_push_back(v, n);
}
}
fclose(fin);
if (ret != EOF) {
fprintf(stderr, "Error reading vector from file: `%s'\n", where);
exit(1);
}
return 0;
}
int shell_write_a_vector(const igraph_vector_t *v, FILE *fout, const char *where) {
int ret=1;
long int i, n=igraph_vector_size(v);
if (n>0) { ret=fprintf(fout, "%g", VECTOR(*v)[0]); }
if (ret <= 0) {
fprintf(stderr, "Cannot write vector to `%s'\n", where);
fclose(fout);
exit(1);
}
for (i=1; i<n; i++) {
ret=fprintf(fout, " %g", VECTOR(*v)[i]);
if (ret <= 0) {
fprintf(stderr, "Cannot write vector to `%s'\n", where);
fclose(fout);
exit(1);
}
}
fprintf(fout, "\n");
return 0;
}
int shell_write_vector(const igraph_vector_t *v, const char *where) {
FILE *fout=shell_open_file(where, "w");
shell_write_a_vector(v, fout, where);
fclose(fout);
return 0;
}
int shell_read_a_matrix(igraph_matrix_t *m, FILE *fin, const char *where) {
long int ncol, nrow, i, j;
igraph_real_t n;
int ret;
if (2 != fscanf(fin, "%li %li", &nrow, &ncol)) {
fprintf(stderr, "Error reading matrix from file '%s'\n", where);
fclose(fin);
exit(1);
}
igraph_matrix_init(m,nrow,ncol);
for (i=0; i<nrow; i++) {
for (j=0; j<ncol; j++) {
ret=fscanf(fin, "%lf", &n);
if (ret <= 0) {
fprintf(stderr, "Error reading matrix from file '%s'\n", where);
fclose(fin);
exit(1);
}
MATRIX(*m, i, j)=n;
}
}
return 0;
}
int shell_read_matrix(igraph_matrix_t *m, const char *where) {
FILE *fin=shell_open_file(where, "r");
shell_read_a_matrix(m, fin, where);
fclose(fin);
return 0;
}
int shell_write_matrix(const igraph_matrix_t *m, const char *where) {
FILE *fout=shell_open_file(where, "w");
long int nrow=igraph_matrix_nrow(m);
long int ncol=igraph_matrix_ncol(m);
long int i, j;
if (0>fprintf(fout, "%li %li\n", nrow, ncol)) {
fprintf(stderr, "Error writing matrix to file '%s'.\n", where);
fclose(fout);
exit(1);
}
for (i=0; i<nrow; i++) {
for (j=0; j<ncol; j++) {
if (j!=0) { fprintf(fout, " "); }
if (0>fprintf(fout, "%g", MATRIX(*m, i, j))) {
fprintf(stderr, "Error writing matrix to file '%s'.\n", where);
fclose(fout);
exit(1);
}
}
fprintf(fout, "\n");
}
fclose(fout);
return 0;
}
int shell_read_integer(igraph_integer_t *n, const char *where) {
long int nn;
int ret=sscanf(where, "%li", &nn);
if (ret == EOF || ret == 0) {
fprintf(stderr, "Error, cannot interpret '%s' as integer\n", where);
exit(1);
}
*n=nn;
return 0;
}
int shell_write_integer(igraph_integer_t n, const char *where) {
FILE *fout=shell_open_file(where, "w");
int ret=fprintf(fout, "%li\n", (long int)n);
if (ret <= 0) {
fprintf(stderr, "Cannot write integer to '%s'\n", where);
fclose(fout);
exit(1);
}
return 0;
}
int shell_read_boolean(igraph_bool_t *b, const char *where) {
if (strlen(where)==0 ||
where[0]=='0' ||
where[0]=='F' ||
where[0]=='f') {
*b=0;
} else {
*b=1;
}
return 0;
}
int shell_write_boolean(igraph_bool_t b, const char *where) {
int bb= b==0 ? 0 : 1;
FILE *fout=shell_open_file(where, "w");
int ret=fprintf(fout, "%i\n", bb);
if (ret <= 0) {
fprintf(stderr, "Cannot write integer to '%s'\n", where);
fclose(fout);
exit(1);
}
return 0;
}
int shell_read_real(igraph_real_t *b, const char *where) {
int ret=sscanf(where, "%lf", b);
if (ret == EOF || ret == 0) {
fprintf(stderr, "Error, cannot interpret '%s' as real\n", where);
exit(1);
}
return 0;
}
int shell_write_real(igraph_real_t b, const char *where) {
FILE *fout=shell_open_file(where, "w");
int ret=fprintf(fout, "%g\n", (double)b);
if (ret <= 0) {
fprintf(stderr, "Cannot write real to `%s'\n", where);
fclose(fout);
exit(1);
}
return 0;
}
int shell_read_enum(void* value, const char *where, ...) {
int result=-1, *p=value;
va_list args;
va_start(args, where);
while (1) {
char *name=va_arg(args, char*);
int code;
if (name) {
code=va_arg(args, int);
if (!strcmp(optarg, name)) {
result=code;
break;
}
} else {
break;
}
}
if (result==-1) {
fprintf(stderr, "Cannot interpret argument: '%s'.\n", where);
exit(1);
}
*p=result;
return 0;
}
int shell_read_int(int *value, const char *where) {
long int li=strtol(where, 0, 10);
if (errno || li<INT_MIN || li>INT_MAX) {
fprintf(stderr, "Integer too small/big: '%s'.\n", where);
}
*value=li;
return 0;
}
int shell_read_longint(long int *value, const char *where) {
long int li=strtol(where, 0, 10);
if (errno) {
fprintf(stderr, "Long integer too small/big: '%s'.\n", where);
}
*value=li;
return 0;
}
int shell_read_file(FILE **file, const char *where, const char *mode) {
*file=fopen(where, mode);
if (!*file) {
fprintf(stderr, "Cannot open file '%s'\n", where);
}
return 0;
}
int shell_read_matrixlist(igraph_vector_ptr_t *list, const char *where) {
FILE *fin=shell_open_file(where, "r");
igraph_vector_ptr_init(list, 0);
shell_skip_whitespace(fin);
while (!feof(fin)) {
igraph_matrix_t *m=malloc(sizeof(igraph_matrix_t));
shell_read_a_matrix(m,
没有合适的资源?快使用搜索试试~ 我知道了~
igraph-c语言写的复杂网络分析库
4星 · 超过85%的资源 需积分: 46 209 下载量 53 浏览量
2010-07-14
14:43:18
上传
评论 4
收藏 1.65MB GZ 举报
温馨提示
共541个文件
c:270个
out:73个
h:65个
igraph是一个建立和操纵无向图、有向图的开源C程序库,它既包含经典图论里的各种算法(例如最小支撑树、网络流等),也包含了最近的出现的一些网络分析算法(如社团结构搜索等) 版本0.5.3
资源推荐
资源详情
资源评论
收起资源包目录
igraph-c语言写的复杂网络分析库 (541个子文件)
igraph.3 2KB
iso_b03_m1000.A00 5KB
Makefile.am 5KB
Makefile.am 3KB
Makefile.am 1KB
Makefile.am 663B
Makefile.am 213B
structural_properties.at 5KB
structure_generators.at 4KB
types.at 3KB
foreign.at 3KB
basic.at 3KB
community.at 2KB
iterators.at 2KB
operators.at 2KB
testsuite.at 2KB
layout.at 2KB
cliques.at 1KB
bipartite.at 1KB
attributes.at 1KB
conversion.at 1KB
flow.at 1KB
other.at 1KB
arpack.at 1KB
components.at 1KB
topology.at 1KB
visitors.at 1KB
motifs.at 1KB
eigen.at 946B
AUTHORS 70B
interface.c 704KB
revolver_cit.c 176KB
structural_properties.c 165KB
revolver_ml_cit.c 101KB
topology.c 97KB
foreign.c 90KB
games.c 81KB
foreign-pajek-parser.c 78KB
layout.c 70KB
structure_generators.c 69KB
measure_dynamics.c 67KB
foreign-pajek-lexer.c 66KB
cattributes.c 62KB
community.c 60KB
iterators.c 51KB
flow.c 50KB
foreign-gml-lexer.c 49KB
foreign-ncol-lexer.c 48KB
dneupd.c 48KB
foreign-lgl-lexer.c 48KB
foreign-gml-parser.c 47KB
centrality.c 46KB
foreign-lgl-parser.c 43KB
foreign-ncol-parser.c 42KB
foreign-graphml.c 42KB
type_indexededgelist.c 40KB
revolver_grow.c 39KB
dseupd.c 39KB
dsaup2.c 36KB
dtrsyl.c 36KB
dnaup2.c 36KB
dtrevc.c 35KB
dnaupd.c 34KB
dnaitr.c 34KB
fast_community.c 34KB
dsaitr.c 33KB
dsaupd.c 33KB
random.c 31KB
dlamch.c 29KB
cliques.c 29KB
dnapps.c 28KB
operators.c 28KB
motifs.c 26KB
bipartite.c 24KB
arpack.c 24KB
spmatrix.c 24KB
dsapps.c 23KB
components.c 21KB
heap.c 21KB
dlaqrb.c 20KB
dlarfx.c 18KB
dstqrb.c 18KB
dtrsen.c 17KB
dlaln2.c 16KB
adjlist.c 16KB
dlahqr.c 16KB
cocitation.c 16KB
dgetv0.c 16KB
conversion.c 15KB
dsteqr.c 15KB
vector_ptr.c 15KB
dlasy2.c 14KB
igraph_strvector.c 14KB
igraph_grid.c 14KB
dneigh.c 14KB
dlaexc.c 13KB
dmout.c 13KB
dlasr.c 11KB
dtrmm.c 11KB
dngets.c 11KB
共 541 条
- 1
- 2
- 3
- 4
- 5
- 6
phoenix05056
- 粉丝: 2
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页