读取二进制文件 矩阵旋转90度 写二进制文件

代码内容:
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值