#include<stdio.h>
#include<stdlib.h>
#define H 200
#define V 301
main (){
int i, j, p, q, a, c, sum[168][237],**mem;
char s[256];
FILE *fp;
//memの確保
mem=(int **)malloc(sizeof(int *)*H*V);
if(mem==NULL){
printf("please put any key to stop program ");
exit(1);
}
for(i=0;i<V;i++){
mem[i]=(int *)malloc(sizeof(int)*V);
if(mem[i]==NULL){
printf("Plz put any key to stop program ");
exit(1);
}
}
// sumの初期化
for(j=0;j<237;j++){
for(i=0;i<168;i++){
sum[i][j]=0;
}
}
//fileの読み込み
fp=fopen("morikawa.pbm","r");
if(fp==NULL){
printf("Can not open file ");
exit(1);
}
for(i=0; i<3; i++){
fgets(s, 256, fp);
}
for(j=0;j<V;j++){
for(i=0;i<H;i++){
fscanf(fp,"%d", &mem[i][j]);
}
}
fclose(fp);
for(j=0;j<237;j++){
for(i=0;i<168;i++){
a=0;
c=0;
for(q=0;q<64;q++){
for(p=0;p<32;p++){
a=mem[i+p][j+q];
c=c+a;
}
}
sum[i][j]=c;
}
}
fp=fopen("sum51.txt","w");
if(fp==NULL){
printf("Can not open file ");
exit(1);
}
for(j=0;j<237;j++){
for(i=0;i<168;i++){
fprintf(fp,"%d ",sum[i][j]);
}
fprintf(fp," ");
}
fclose(fp);
}