代码内容:
1)文件读取
2)文件写入输出
3)矩阵逆时针旋转90度
4)矩阵顺时针旋转90度
#include<stdio.h>
#include "su.h"
#include "segy.h"
int main()
{
//input
//read the file (binary)
FILE *fp,*fp1;
float **buffer;
float **buffer_input;
int nx=1051,nz=2301,iz,ix;//矩阵横纵自己对应上
buffer_input=alloc2float(nz,nx);
buffer=alloc2float(nx,nz);//su自带函数,申明二维数组的空间
//读取二进制文件
fp=fopen("wenjian.bin","rb+");
//find the beginning of the file
fseek(fp, 0, sizeof(float));
//read the data
for(ix=0;ix<nx;ix++)
for(iz=0;iz<nz;iz++)
{
fread(&buffer_input[ix][iz],sizeof(float),1,fp);
}
fclose(fp);
//对矩阵做旋转操作并用另一个数组存储,这边注意对应矩阵的纵横
for(ix=0;ix<nx;ix++)
for(iz=0;iz<nz;iz++)
{
//顺时针
buffer[nz-1-iz][ix]=buffer_input[ix][iz];
//逆时针
//buffer[iz][nx-1-ix]=buffer_input[ix][iz];
}
// output(the value of the arrary of the binary)
fp1=fopen("after.bin","wb+");
//find the beginning of the file
fseek(fp1, 0, sizeof(float));
for(iz=0;iz<nz;iz++){
fseek(fp1,iz*4*nx,0);
for(ix=0;ix<nx;ix++)
{
fwrite(&buffer[iz][ix],4,1,fp1);
}
}
fclose(fp1);
//printf("hello\n");
free2float(buffer);
free2float(buffer_input);//释放空间
return 0;
}