-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUniQuantizer.cpp
103 lines (79 loc) · 2.06 KB
/
UniQuantizer.cpp
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
int UniQuantizer (char *argv[])
{
char tmp;
char str[200];
char tmpFileName[400];
fpos_t position1;
long unsigned int Location=0;
double Exp=0;
int flag=0;
long unsigned int PreLocation = 0;
char Prestr[200];
strcpy(Prestr,"empty");
long unsigned int PreExp = 0;
int i;
char stri[100];
char FileName[400];//name of processed Wig file 1
strcpy(FileName, argv[1]);
FILE *fpRead = fopen(FileName, "r");
if (fpRead == NULL) {
fprintf(stderr, "Can't open file %s!\n",FileName);
exit(1);
}
long int TotalNumbers;
float Max;
float Min;
strcpy(FileName, argv[1]);
strcat(FileName, "Maximum");
FILE *fpReadMax;
fpReadMax = fopen(FileName, "r");
if (fpReadMax == NULL) {
fprintf(stderr, "Can't open input file %s!\n",FileName);
exit(1);
}
fgets(stri, sizeof(stri), fpReadMax);
fscanf(fpReadMax,"%ld %f %f ", &TotalNumbers, &Max , &Min);
fclose(fpReadMax);
// printf("%ld %f %f ", TotalNumbers, Max ,Min);
strcpy(FileName, argv[1]);
strcat(FileName,"Uniform_Quantized");
FILE *fpWrite = fopen(FileName, "w");
if (fpWrite == NULL) {
fprintf(stderr, "Can't open file %s!\n",FileName);
exit(1);
}
float Quantized2 = 0;
float d = Threshold/Number_Levels;
//double FixLargeValue = 0.8 * Max;
double FixLargeValue = 960;
//double FixLargeValue = 1000.0;
//printf(" %lf %lf ",Threshold, FixLargeValue);
if(Threshold > FixLargeValue){
printf("Threshold is greater than FixLargeValue, either increase the FixLargeValue or decrease the threshold");
exit(1);
}
while (!feof(fpRead))
{
tmp = fgetc(fpRead);
if (tmp >= '0' && tmp <= '9')
{
ungetc(tmp,fpRead);
fscanf(fpRead,"%lu %lf\n", &Location,&Exp);
if(Exp <= Threshold)
Quantized2 = d* floor(Exp/d)+ d/2;
else
Quantized2 = FixLargeValue;
fprintf(fpWrite, "%lu \t %.2f\n", Location, Quantized2);
}
else
{
ungetc(tmp,fpRead);
fgets(str,sizeof(str),fpRead);
strcpy(Prestr,str);
fputs(str,fpWrite);
}
}
fclose(fpRead);
fclose(fpWrite);
return 1;
}