/**************************************************************************** oper.cc Various operation on convolutions files of the same dimension convolutions files are text arrays (with tab); the first 3 numbers caracterise the convolution the first one is the width the second one is the height the third one is the total of the number in the array (if you don't know, put 0) ex : oper a 10000 file1 file2 add the convoltion matrix in the two files and normalize the total of values to 10000 limitations : only deal with integer values arno@salk.edu, Arnaud Delorme, CNL / Salk Institute, 2001 This program is free software; you can redistribute it and/or modify it. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ****************************************************************************/ #include #include #include int result[100][100]; int somme; void lirecrire(FILE *fpe,FILE *fps) { int i; while (fscanf(fpe,"%d",&i) != EOF) fprintf(fps," %d",i); } void operation(char oper,int dim,FILE *fp1,FILE *fp2) { int int1,int2; int i,j; somme = 0; for (i=0;iint2) ? (int1-int2) : 0 ; break; case 'm' : result[i][j] = (int1int2) ? int1 : int2 ; break; default : printf("erreur dans l'option choisie\n"); exit(-1); } somme += result[i][j]; } } int main(int argc,char *argv[]){ FILE *fp1,*fp2; char oper; /* operation a effectuer */ int dimention; /* dimention des tableau */ int poids_total; /* poids total approximatif du tableau retourne */ int somme2; /* poids fimal du tableau retourne */ int i,j,k1,k2; if (argc < 5) { printf("oper [a|s|m|M] TOT file1 file2\n"); printf("\tfile1 : name of the first file which contains the first convolution\n"); printf("\tfile2 : name of the second file which contains the second convolution\n"); printf("\tconvolutions files are text arrays (with tab); the first 3 numbers caracterise the convolution\n"); printf("\t the first one is the width\n"); printf("\t the second one is the height\n"); printf("\t the third one is the total of the number in the array (if you don't know, put 0)\n"); printf("\ta : add two convolutions\n"); printf("\tS : subtract two convolutions\n"); printf("\ts : subtract two convolutions and then compute the absolute value\n"); printf("\tm : minimum of the values at each place for the two comvolutions\n"); printf("\tM : Maximum of the values at each place for the two comvolutions\n"); printf("\tTOT : normalization parameter (0 no renormalization)\n"); exit(-1); } /* saisie des arguments */ oper = *argv[1]; poids_total = atoi(argv[2]); if ((fp1 = fopen(argv[3], "r")) == NULL) { printf("unable to open %s\n",argv[3]); exit(-1); } if ((fp2 = fopen(argv[4], "r")) == NULL) { printf("unable to open %s\n",argv[4]); exit(-1); } /* lecture des entetes */ fscanf(fp1,"%d%d%d",&k1,&i,&j); fscanf(fp2,"%d%d%d",&k2,&i,&j); if (k1!=k2) { printf("les fichier n'ont pas la meme dimention\n"); exit(-1); } else dimention =k1; /* operation sur les deux tableaux */ operation(oper,dimention,fp1,fp2); /* recalcul des poids */ if (poids_total != 0) { if (somme==0) somme=1; somme2=0; for (i=0;i