-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvfile2.c
More file actions
140 lines (118 loc) · 2.23 KB
/
Copy pathconvfile2.c
File metadata and controls
140 lines (118 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright: Tatsuya Akutsu, Kyoto University
* This program can be used only for acamemic purposes.
* The author does not have any responsibility on problems caused by this program.
* */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXNODES 5000
double NODEX[MAXNODES];
double NODEY[MAXNODES];
#define MAXEDGES 2000000
int EDGES[MAXEDGES][2];
int CONNECTEDID[MAXNODES];
int CONNECTEDSIZE[MAXNODES];
char ADJ[MAXNODES][MAXNODES];
int delcomma(char infile[], char outfile[]);
char BIGBUF[1000000];
int main(int argc, char *argv[])
{
FILE *fp;
int i,j,k,m,n,cnt,zcnt;
double x;
char buf[100];
if (argc != 2) {
printf("Usage: convfile2 pdfXXX.txt\n");
exit(0);
}
delcomma(argv[1],"pdf2.txt");
if ((fp = fopen("pdf2.txt","r"))==NULL) {
printf("Cannnot open pdf2.txt\n");
exit(0);
}
n = 0;
while(fgets(BIGBUF,1000000,fp)!=NULL) {
n++;
}
fclose(fp);
printf("#Nodes = %d\n",n);
if ((fp = fopen("pdf2.txt","r"))==NULL) {
printf("Error4\n");
exit(0);
}
m = 0;
zcnt = 0;
for(i = 0;i < n;i++) {
for(j = 0;j < n;j++) {
if (fscanf(fp,"%d",&k)!=1) {
printf("Error5: %d %d\n",i,j);
exit(0);
}
ADJ[i][j] = k;
if (k == 1) {
EDGES[m][0] = i;
EDGES[m][1] = j;
m++;
}
if (k == 0) {
zcnt++;
}
}
}
fclose(fp);
cnt = 0;
for(k = 0;k < m;k++) {
i = EDGES[k][0];
j = EDGES[k][1];
if (ADJ[i][j] != ADJ[j][i]) {
cnt++;
}
}
fp = fopen("neuroedges.txt","w");
fprintf(fp,"source\tweight\ttarget\n");
for(i = 0;i < n;i++) {
for(j = 0;j < n;j++) {
if (ADJ[i][j]==1) {
fprintf(fp,"Node%d\t1.0\tNode%d\n",i+1,j+1);
}
}
}
fclose(fp);
fp = fopen("neuronodes.txt","w");
fprintf(fp,"NodeID\tAttributes\n");
for(i = 0;i < n;i++) {
if (i > n/2) {
j = 1;
}
else {
j = 2;
}
fprintf(fp,"Node%d\t%d\n",i+1,j);
}
fclose(fp);
}
int delcomma(char infile[], char outfile[])
{
FILE *fp1,*fp2;
char ch;
int cnt;
if ((fp1 = fopen(infile,"r"))==NULL) {
printf("Cannot open %s\n",infile);
exit(0);
}
if ((fp2 = fopen(outfile,"w"))==NULL) {
printf("Cannot open %s\n",outfile);
exit(0);
}
cnt = 0;
while((ch=fgetc(fp1)) != EOF) {
if (ch == ',') {
ch = ' ';
cnt++;
}
fputc(ch,fp2);
}
fclose(fp1);
fclose(fp2);
}