-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhex2bin.c
More file actions
112 lines (107 loc) · 3.74 KB
/
hex2bin.c
File metadata and controls
112 lines (107 loc) · 3.74 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
# include <stdio.h>
# include <math.h>
# include <ctype.h>
# include <stdlib.h>
# include <string.h>
# define MAXCHAR 2560
# define COLORTEXT "YES"
//this program standlize pdb file*/
char ifilename[MAXCHAR];
char ofilename[MAXCHAR];
char line[MAXCHAR];
char name[MAXCHAR];
char fs[MAXCHAR];
FILE *fpin, *fpout;
void convert() {
int i;
fprintf(fpout, "%s\t", name);
for(i=0; i<strlen(fs); i++) {
if(fs[i] == '0') fprintf(fpout, "%c %c %c %c ", '0','0','0','0');
if(fs[i] == '1') fprintf(fpout, "%c %c %c %c ", '0','0','0','1');
if(fs[i] == '2') fprintf(fpout, "%c %c %c %c ", '0','0','1','0');
if(fs[i] == '3') fprintf(fpout, "%c %c %c %c ", '0','0','1','1');
if(fs[i] == '4') fprintf(fpout, "%c %c %c %c ", '0','1','0','0');
if(fs[i] == '5') fprintf(fpout, "%c %c %c %c ", '0','1','0','1');
if(fs[i] == '6') fprintf(fpout, "%c %c %c %c ", '0','1','1','0');
if(fs[i] == '7') fprintf(fpout, "%c %c %c %c ", '0','1','1','1');
if(fs[i] == '8') fprintf(fpout, "%c %c %c %c ", '1','0','0','0');
if(fs[i] == '9') fprintf(fpout, "%c %c %c %c ", '1','0','0','1');
if(fs[i] == 'a') fprintf(fpout, "%c %c %c %c ", '1','0','1','0');
if(fs[i] == 'b') fprintf(fpout, "%c %c %c %c ", '1','0','1','1');
if(fs[i] == 'c') fprintf(fpout, "%c %c %c %c ", '1','1','0','0');
if(fs[i] == 'd') fprintf(fpout, "%c %c %c %c ", '1','1','0','1');
if(fs[i] == 'e') fprintf(fpout, "%c %c %c %c ", '1','1','1','0');
if(fs[i] == 'f') fprintf(fpout, "%c %c %c %c ", '1','1','1','1');
if(fs[i] == 'A') fprintf(fpout, "%c %c %c %c ", '1','0','1','0');
if(fs[i] == 'B') fprintf(fpout, "%c %c %c %c ", '1','0','1','1');
if(fs[i] == 'C') fprintf(fpout, "%c %c %c %c ", '1','1','0','0');
if(fs[i] == 'D') fprintf(fpout, "%c %c %c %c ", '1','1','0','1');
if(fs[i] == 'E') fprintf(fpout, "%c %c %c %c ", '1','1','1','0');
if(fs[i] == 'F') fprintf(fpout, "%c %c %c %c ", '1','1','1','1');
}
fprintf(fpout, "\n");
}
int main(int argc, char *argv[]) {
int i;
int count = 0;
int atomnum;
double x, y, z;
if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) {
if (argc == 2
&& (strcmp(argv[1], "-h") == 0
|| strcmp(argv[1], "-H") == 0)) {
printf
("[31mUsage: hex2bin -i[0m input file name in hex fingerprint format \n"
"[31m -o[0m output file name in binary descriptor format\n");
exit(0);
}
if (argc != 5) {
printf
("[31mUsage: hex2bin -i[0m input file name in hex fingerprint format \n"
"[31m -o[0m output file name in binary descriptor format\n");
exit(0);
}
} else {
if (argc == 2
&& (strcmp(argv[1], "-h") == 0
|| strcmp(argv[1], "-H") == 0)) {
printf
("Usage: hex2bin -i input file name in hex fingerprint format \n"
" -o output file name in binary descriptor format\n");
exit(0);
}
if (argc != 5) {
printf
("Usage: hex2bin -i input file name in hex fingerprint format \n"
" -o output file name in binary descriptor format\n");
exit(0);
}
}
for (i = 1; i < argc; i += 2) {
if (strcmp(argv[i], "-i") == 0)
strcpy(ifilename, argv[i + 1]);
if (strcmp(argv[i], "-o") == 0)
strcpy(ofilename, argv[i + 1]);
}
if ((fpin = fopen(ifilename, "r")) == NULL) {
fprintf(stderr, "Cannot open file %s, exit\n", ifilename);
exit(1);
}
if ((fpout = fopen(ofilename, "w")) == NULL) {
fprintf(stderr, "Cannot open file %s, exit\n", ofilename);
exit(1);
}
for (;;) {
if (fgets(line, MAXCHAR, fpin) == NULL) break;
if (line[0] == '#') continue;
if (strlen(line) <= 1) break;
strcpy(fs, "#######");
strcpy(name, "#######");
sscanf(line, "%s%s", fs, name);
if(strcmp(name, "#######") == 0) continue;
convert();
}
fclose(fpin);
fclose(fpout);
return 0;
}