main.cpp
来自「利用相关法计算物体的移动」· C++ 代码 · 共 229 行
CPP
229 行
#include "math.h"
#include "stdio.h"
#include "io.h"
#include "CorrCoff.h"
#include "memory.h"
int Z11[1000][1000];
int Z22[1000][1000];
void main()
{
float theta[3];
int i,j,k;
//////////////////////纪录两个时刻三公里高度上的风场资料////////////////////
FILE *ResFile1,*ResFile2;
ResFile1=fopen("F:\\result1.txt","wt");
ResFile2=fopen("F:\\result2.txt","wt");
//////////////////打开三个文件进行插值/////////////////////////////////////////
FILE *fp1, *fp2;
FILE *fp3;
/////调试用////////////////////
FILE *fp=fopen("f:\\ddd.dat","wt");
CCorrCoff *m_Corr=new CCorrCoff(2,2,64,64);
////////////////////////对两个时次的资料进行插值///////////////////////////////////////
for(k=0;k<2;k++)
{
if(k==0)
{
unsigned char (*Z1)[1000]=new unsigned char[1000][1000]; ///定义一个全局变量
unsigned char (*Z2)[1000]=new unsigned char[1000][1000];
unsigned char (*Z3)[1000]=new unsigned char[1000][1000];
unsigned char *theta1=new unsigned char[6];
fp1=fopen("F:\\资料\\要用的资料\\凤台1\\98P7131518.48I","rb"); ///打开读入数据文件
fp2=fopen("F:\\资料\\要用的资料\\凤台1\\98P7131519.14I","rb");
fp3=fopen("F:\\资料\\要用的资料\\凤台1\\98P7131519.40I","rb");
if(fp1==NULL||fp2==NULL||fp3==NULL)
return;
fseek(fp1,384L,0);///////////////////////////跳过文件头////////////////////////////////////////////
fseek(fp2,384L,0);
fseek(fp3,384L,0);
/* memset(Z1,0,sizeof(Z1));
memset(Z2,0,sizeof(Z2));
memset(Z3,0,sizeof(Z3));*/
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++)
{
Z1[i][j]=Z2[i][j]=Z3[i][j]=0;}
}
for(i=0;i<360;i++)
{
/////////////////////////////////////////
////跳过方位、仰角
char buff[2];
fread(buff,1,2,fp1);
fread(buff,1,2,fp2);
fread(buff,1,2,fp3);
fread(&theta1[0],sizeof(unsigned char),1,fp1);
fread(&theta1[1],sizeof(unsigned char),1,fp1);
theta[0]=(theta1[0]*256+theta1[1])*360.0f/4096-90; ///记录仰角
//////////////////////////////////////////////////////
fread(&theta1[2],sizeof(unsigned char),1,fp2);
fread(&theta1[3],sizeof(unsigned char),1,fp2);
theta[1]=(theta1[2]*256+theta1[3])*360.0f/4096-90;
/////////////////////////////////////////////////////
fread(&theta1[4],sizeof(unsigned char),1,fp3);
fread(&theta1[5],sizeof(unsigned char),1,fp3);
theta[2]=(theta1[4]*256+theta1[5])*360.0f/4096-90;
fprintf(fp,"%6.2f %6.2f %6.2f\n",theta[0],theta[1],theta[2]);
for(j=0;j<256;j++)
{
fread(&Z1[i][j],1L,1,fp1);
if(Z1[i][j]>80)Z1[i][j]=0;
fread(&Z2[i][j],1L,1,fp2);
if(Z2[i][j]>80)Z2[i][j]=0;
fread(&Z3[i][j],1L,1,fp3);
if(Z3[i][j]>80)Z3[i][j]=0;
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
m_Corr->Intervence(Z1,Z2,Z3,theta,ResFile1);
delete []Z1;
delete []Z2;
delete []Z3;
delete []theta1;
}
else if(k==1)
{
unsigned char (*Z1)[1000]=new unsigned char[1000][1000]; ///定义一个全局变量
unsigned char (*Z2)[1000]=new unsigned char[1000][1000];
unsigned char (*Z3)[1000]=new unsigned char[1000][1000];
unsigned char *theta1=new unsigned char[6];
fp1=fopen("F:\\资料\\要用的资料\\凤台1\\98P7131525.48I","rb"); ///打开读入数据文件
fp2=fopen("F:\\资料\\要用的资料\\凤台1\\98P7131526.13I","rb");
fp3=fopen("F:\\资料\\要用的资料\\凤台1\\98P7131526.39I","rb");
if(fp1==NULL||fp2==NULL||fp3==NULL)
return;
fseek(fp1,384L,0);///////////////////////////跳过文件头////////////////////////////////////////////
fseek(fp2,384L,0);
fseek(fp3,384L,0);
/* memset(Z1,0,sizeof(Z1));
memset(Z2,0,sizeof(Z2));
memset(Z3,0,sizeof(Z3));*/
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++)
{
Z1[i][j]=Z2[i][j]=Z3[i][j]=0;}
}
for(i=0;i<360;i++)
{
/////////////////////////////////////////
////跳过方位、仰角
char buff[2];
fread(buff,1,2,fp1);
fread(buff,1,2,fp2);
fread(buff,1,2,fp3);
fread(&theta1[0],sizeof(unsigned char),1,fp1);
fread(&theta1[1],sizeof(unsigned char),1,fp1);
theta[0]=(theta1[0]*256+theta1[1])*360.0f/4096-90; ///记录仰角
//////////////////////////////////////////////////////
fread(&theta1[2],sizeof(unsigned char),1,fp2);
fread(&theta1[3],sizeof(unsigned char),1,fp2);
theta[1]=(theta1[2]*256+theta1[3])*360.0f/4096-90;
/////////////////////////////////////////////////////
fread(&theta1[4],sizeof(unsigned char),1,fp3);
fread(&theta1[5],sizeof(unsigned char),1,fp3);
theta[2]=(theta1[4]*256+theta1[5])*360.0f/4096-90;
for(j=0;j<256;j++)
{
fread(&Z1[i][j],sizeof(unsigned char),1,fp1);
if(Z1[i][j]>80)Z1[i][j]=0;
fread(&Z2[i][j],sizeof(unsigned char),1,fp2);
if(Z2[i][j]>80)Z2[i][j]=0;
fread(&Z3[i][j],sizeof(unsigned char),1,fp3);
if(Z3[i][j]>80)Z3[i][j]=0;
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
m_Corr->Intervence(Z1,Z2,Z3,theta,ResFile2);
delete []Z1;
delete []Z2;
delete []Z3;
delete []theta1;
}
}
fclose(fp);
fclose(ResFile1);
fclose(ResFile2);
/////////////////以上完成插值过程////////////////////////////////////////////////
FILE *fileold;
FILE *filenew;
if((fileold=fopen("F:\\result1.txt","rt"))==NULL) ////打开第一时刻,某一高度平面上的值
return;
if((filenew=fopen("F:\\result2.txt","rt"))==NULL) ////打开第二时刻,对应高度上的值
return;
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++)
{
Z11[i][j]=Z22[i][j]=0;
}
}
for(i=0;i<=512;i++)
{
for(j=0;j<=512;j++)
{
fscanf(fileold,"%d",&Z11[i][j]);
fscanf(filenew,"%d",&Z22[i][j]);
}
}
fclose(fileold);
fclose(filenew);
m_Corr->Compute_Coff(Z11,Z22,513,513,7*60);
FILE*fp4=fopen("F:\\wave\\wind.dat","wt");
if(fp4==NULL)
return;
for( i=0;i<512/2;i++)
{
for(j=0;j<512/2;j++)
{
fprintf(fp4,"%5.1f ",m_Corr->m_U[i][j]);
}
fprintf(fp4,"\n");
}
for( i=0;i<512/2;i++)
{
for(j=0;j<512/2;j++)
{
fprintf(fp4,"%5.1f ",m_Corr->m_V[i][j]);
}
fprintf(fp4,"\n");
}
delete m_Corr;
return;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?