#include
#include
#include
#include
#include
static int maxnum = 3600;
void main(int argc,char **argv[])
{
int now=0, start=0;
FILE *fd, *fd1;
fd = fopen("test", "r");
fd1 = fopen("test.zip", "w");
float E=10.01;
float mem, mem_old;
float upgate; /*定义上门*/
float downgate; /*定义下门*/
float k1; /*k1表示上门和过程数据间的斜率*/
float k2; /*k2表示下门和过程数据间的斜率*/
fread(&mem, sizeof(float), 1, fd);
mem_old = mem;
for(;;) {
if(now == maxnum-1) {
fwrite(&mem, sizeof(float), 1, fd1);
break;
}
fwrite(&mem, sizeof(float), 1, fd1);
start = now;
upgate=mem+E;
downgate=mem-E;
k1=-10000;
k2=-10000;
for(;;) {
now++;
mem_old = mem;
fread(&mem, sizeof(float), 1, fd);
if(fabs(mem-upgate)>0.001){
if((mem-upgate)/(now -start)>k1) k1=(mem-upgate)/(now-start);
else {
now=now++;
fwrite(&mem_old, sizeof(float), 1, fd1);
break;
}
}
if(fabs(mem-downgate)>0.001){
if((downgate-mem)/(now-start)>k2) k2=(downgate-mem)/(now-start);
else {
now=now++;
fwrite(&mem_old, sizeof(float), 1, fd1);
break;
}
}
if(now == maxnum-1) {
break;
}
}
}
fclose(fd);
fclose(fd1);
}
程序的目的是要实现一个3600大小的float数组的压缩。
做这个测试的目的,完全源于偶然,看到上面所描述的算法,所以,自己简单实现后,想看看最终性能,请勿用于商业用途,毕竟,人家有版权的。。。
阅读(3771) | 评论(1) | 转发(0) |