about summary refs log tree commit diff
path: root/sourcecodes/print_structure/structure.c
blob: cc893a35c06f429c95adb0372d9e2962b773f5c1 (plain)
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

struct st{
char *name;	
double *data;	
}*st_tab;

main(int argc,char *argv[])
{
FILE *fp1,*fp2,*fp3;
char line[2500];
int i,j,rd;
double d,row;
double thr=atof(argv[5]);

fp1=fopen(argv[2],"r");
fp2=fopen(argv[3],"w");

fp3=fopen(argv[4],"w");


row=0.0;
while(fgets(line,2500,fp1)!=NULL)
   row++;

rd=(int)sqrt(row);

printf("%d\n",rd);

fclose(fp1);
fp1=fopen(argv[1],"r");

st_tab=(struct st *)malloc(sizeof(struct st)*rd);

for(i=0;i<rd;i++)
{
   fscanf(fp1,"%s",line);	
   st_tab[i].name=(char *)malloc(sizeof(char)*(sizeof(line)+1));
   strcpy(st_tab[i].name,line);
   st_tab[i].data=(double *)calloc(rd,sizeof(double));
}

fclose(fp1);
fp1=fopen(argv[2],"r");

for(i=0;i<rd;i++)
{
    for(j=0;j<rd;j++)
    {
          fscanf(fp1,"%s",line);
	   fscanf(fp1,"%s",line);
	   fscanf(fp1,"%s",line);		
   	   fscanf(fp1,"%lf",&d);
          st_tab[i].data[j]=d;
    
    }
}

/*
for(i=0;i<rd;i++)
{
    for(j=0;j<rd;j++)
    {
         if(st_tab[i].data[j]>=st_tab[j].data[i])
                 st_tab[j].data[i]=0.0;
    
    }
}
*/

for(i=0;i<rd;i++)
{ 
    fprintf(fp2,"%s\t",st_tab[i].name);
    fprintf(fp3,"%s\t",st_tab[i].name);
}

fprintf(fp2,"\n");
fprintf(fp3,"\n");

for(i=0;i<rd;i++)
{ 
    for(j=0;j<rd;j++)
    {
   	   fprintf(fp2,"%lf\t",st_tab[j].data[i]);
          if(st_tab[j].data[i]>thr)	
   	     fprintf(fp3,"1\t");
          else 	
   	     fprintf(fp3,"0\t");
    }
    fprintf(fp2,"\n");
    fprintf(fp3,"\n");
}

}