好久没有在这里放文章了,今天灌点水,自己写的小程序。
#define frows 128
#define fcols 128
#define mrows 5
#define mcols 5
float fdem[frows][fcols];
float mdem[mrows][mcols];
#define PRINT_TEST \
printf("\n\n --------mdem array---------"); \
printf("\n frr=%d, fcc=%d", frr, fcc); \
printf("\n mrr=%d, mcc=%d", mrr, mcc); \
for(i=mrr; i<mrr+mrows; i++){ \
int r = i % mrows; \
printf("\n "); \
for(j=mcc; j<mcc+mcols; j++){ \
int c = j % mcols; \
printf("%0.3f\t ", mdem[r][c]); \
} \
}
int main(int argc, char* argv[])
{
int i,j;
int step=0; //在mem中跳过的格子数
int steplen=2; //mem中一个格子对应在file跳过的格子数
//初始化
for(i=0; i<frows; i++){
for(j=0; j<fcols; j++){
fdem[i][j] = i + j*0.001f;
}
}
int frr=0; int fcc=0; int mrr=0; int mcc=0;
for(i=mrr; i<mrr+mrows; i++){
int r = i % mrows;
for(j=mcc; j<mcc+mcols; j++){
int c = j % mcols;
mdem[r][c] = fdem[frr + (i-mrr)*steplen][fcc+ (j-mcc)*steplen];
}
}
PRINT_TEST;
//向右平移
step=3;
for(j=mcc; j<mcc+step; j++){
int c = j % mcols;
for(i=mrr; i<mrr+mrows; i++){
int r = i % mrows;
int rr = frr + (i-mrr) * steplen;
int cc = fcc + (mcols + j-mcc) * steplen;
mdem[r][c] = fdem[rr][cc];
}
}
fcc += step * steplen;
mcc += step;
PRINT_TEST;
//向左平移
step=3;
for(j=mcc-1; j>=mcc-step; j--){
int c = (j + mcols) % mcols;
for(i=mrr; i<mrr+mrows; i++){
int r = i % mrows;
int rr = frr + (i-mrr) * steplen;
int cc = fcc - (mcc-j) * steplen;
mdem[r][c] = fdem[rr][cc];
}
}
fcc -= step * steplen;
mcc -= step;
PRINT_TEST;
//向下平移
step=3;
for(i=mrr; i<mrr+step; i++){
int r = i % mrows;
for(j=mcc; j<mcc+mcols; j++){
int c = j % mcols;
int cc = fcc + (j-mcc) * steplen;
int rr = frr + (mrows + i-mrr) * steplen;
mdem[r][c] = fdem[rr][cc];
}
}
frr += step * steplen;
mrr += step;
PRINT_TEST;
//向上平移
step=3;
for(i=mrr-1; i>=mrr-step; i--){
int r = (i + mrows) % mrows;
for(j=mcc; j<mcc+mcols; j++){
int c = j % mcols;
int cc = fcc + (j-mcc) * steplen;
int rr = frr - (mrr-i) * steplen;
mdem[r][c] = fdem[rr][cc];
}
}
frr -= step * steplen;
mrr -= step;
PRINT_TEST;
return 0;
}