www.pudn.com > RADAR-ALARM.rar > ReadRadarBaseData.cpp, change:2011-07-30,size:5563b


#include "StdAfx.h" 
#include "ReadRadarBaseData.h" 
 
CReadRadarBaseData::CReadRadarBaseData(void) 
: NumValidCuts(0) 
{ 
	 RData=new float[MaxCuts*MaxRads*RGates]; 
	 VData=new float[MaxCuts*MaxRads*VGates]; 
	 WData=new float[MaxCuts*MaxRads*WGates]; 
	 pOneRadial = (RADIALDATA*)malloc(sizeof(RADIALDATA)); 
} 
 
CReadRadarBaseData::~CReadRadarBaseData(void) 
{ 
	delete[] RData; 
	delete[] VData; 
	delete[] WData; 
	free(pOneRadial); 
} 
 
// ȡ 
bool CReadRadarBaseData::ReadBaseData(CString filename) 
{ 
	  
	FILE *fp=0; 
 
	int FstBin,LstBin,BinNum; 
	float CurAz,CurEl; 
	int ElIndex,AzIndex,BnIndex; 
	int ptrPos; 
 
	size_t readSize; 
	int fileEndFlag; 
	int j=0; 
 
	bool VolBeg=false; 
	bool VolEnd=false; 
 
	bool RFlag,VFlag,WFlag; 
 
	fp = _tfopen(filename,_T("rb")); 
	if(fp==0) return false;	 
	if(pOneRadial==0) return false; 
 
	//Initialize array 
	for(ElIndex=0; ElIndex<MaxCuts; ElIndex++) 
	{ 
		for(AzIndex=0; AzIndex<MaxRads; AzIndex++) 
		{ 
			for(BnIndex=0; BnIndex<RGates; BnIndex++) 
				RData[ElIndex*MaxRads*RGates+AzIndex*RGates+BnIndex] = VALUE_INVALID; 
			for(BnIndex=0; BnIndex<VGates; BnIndex++) 
				VData[ElIndex*MaxRads*VGates+AzIndex*VGates+BnIndex] = VALUE_INVALID; 
			for(BnIndex=0; BnIndex<WGates; BnIndex++) 
				WData[ElIndex*MaxRads*WGates+AzIndex*WGates+BnIndex] = VALUE_INVALID; 
		}//end az 
 
		Elevation[ElIndex]=VALUE_INVALID; 
	}//end el 
 
	do 
	{ 
		//Initialize flags 
		RFlag=VFlag=WFlag=false; 
 
		readSize = fread(pOneRadial,sizeof(RADIALDATA),1,fp); 
		{ 
			int i=0; 
		    CurAz = float((pOneRadial->Az/8.)*(180./4096.));	   
		     if(CurAz >= 360.) CurAz = float(CurAz-360.); 
		    AzIndex = int(CurAz+0.5); 
 
		   
		} 
		 
	 
		fileEndFlag = feof(fp); 
 
		//Start a volume scan 
		if(pOneRadial->RadialStatus == VOL_BEG)  
		{ 
			ElIndex=0; 
			CurEl = float((pOneRadial->El/8.)*(180./4096.)); 
			Elevation[ElIndex] = CurEl; 
 
			VolBeg = true; 
		} 
		//Find the beginning of the volume scan 
		if(!VolBeg) continue;		 
 
		//Start an elevation 
		if(pOneRadial->RadialStatus == ELV_BEG) 
		{ 
			CurEl = float((pOneRadial->El/8.)*(180./4096.)); 
			if(CurEl-Elevation[ElIndex] > 0.4)  
			{//different elevation angle 
				ElIndex++; 
				Elevation[ElIndex] = CurEl; 
 
			} 
		} 
 
		//Start an elevation 
		if(pOneRadial->RadialStatus == VOL_END) 
			VolEnd=true; 
 
 
 
		//what kind of data in this cut 
		if(pOneRadial->PtrOfReflectivity !=0)	RFlag=true; 
		if(pOneRadial->PtrOfVelocity !=0)		VFlag=true; 
		if(pOneRadial->PtrOfSpectrumWidth !=0)	WFlag=true; 
 
		//Save reflectivity data into the array 
		if(RFlag) 
		{ 
			//Get first bin, last bin, and number of bins 
			FstBin = int(pOneRadial->RangeToFirstGateOfRef/pOneRadial->GateSizeOfReflectivity+0.5); 
			BinNum = pOneRadial->GatesNumberOfReflectivity; 
			if(FstBin<0) 
			{ 
				BinNum = FstBin+BinNum; 
				FstBin = -1*FstBin; 
			} 
			LstBin = FstBin + BinNum; 
			ptrPos = pOneRadial->PtrOfReflectivity; 
 
			//Save data 
			for(BnIndex=FstBin; BnIndex<LstBin; BnIndex++) 
			{ 
				RData[ElIndex*MaxRads*RGates+AzIndex*RGates+BnIndex] = DecodeRef(pOneRadial->Echodata[BnIndex]); 
//                 for(int k=0;k<j;k++) 
// 				RDatatwo[ElIndex][AzIndex][BnIndex] = DecodeRef(pRadial[j].Echodata[BnIndex]); 
			} 
		} 
 
		//Save velocity data into the array 
		if(VFlag) 
		{ 
			//Get first bin, last bin, and number of bins 
			FstBin = int(pOneRadial->RangeToFirstGateOfDop/pOneRadial->GateSizeOfDoppler+0.5); 
			BinNum = pOneRadial->GatesNumberOfDoppler; 
			if(FstBin<0) 
			{ 
				BinNum = FstBin+BinNum; 
				FstBin = -1*FstBin; 
			} 
			LstBin = FstBin + BinNum; 
			ptrPos = pOneRadial->PtrOfVelocity-100; 
			//Save data 
			for(BnIndex=FstBin; BnIndex<LstBin; BnIndex++) 
			{ 
				VData[ElIndex*MaxRads*VGates+AzIndex*VGates+BnIndex] =  
				DecodeVel(pOneRadial->Echodata[ptrPos+BnIndex],pOneRadial->ResolutionOfVelocity); 
			} 
		} 
 
		//Save spectrum width data into the array 
		if(WFlag) 
		{ 
			//Get first bin, last bin, and number of bins 
			FstBin = int(pOneRadial->RangeToFirstGateOfDop/pOneRadial->GateSizeOfDoppler+0.5); 
			BinNum = pOneRadial->GatesNumberOfDoppler; 
			if(FstBin<0) 
			{ 
				BinNum = FstBin+BinNum; 
				FstBin = -1*FstBin; 
			} 
			LstBin = FstBin + BinNum; 
			ptrPos = pOneRadial->PtrOfSpectrumWidth-100; 
			//Save data 
			for(BnIndex=FstBin; BnIndex<LstBin; BnIndex++) 
				WData[ElIndex*MaxRads*WGates+AzIndex*WGates+BnIndex] = DecodeSpw(pOneRadial->Echodata[ptrPos+BnIndex]); 
			int k=0; 
		} 
	}while(fileEndFlag==0 && !VolEnd && !(readSize<1)); 
	 
	if(!VolEnd && !VolBeg) 
	{ 
		fclose(fp); 
		return false; 
	} 
 
	NumValidCuts = ElIndex+1; 
	fclose(fp); 
 
	return true; 
} 
 
float CReadRadarBaseData::DecodeRef(unsigned char code) 
{ 
	if(code==CODE_INVALID)		return VALUE_INVALID; 
	else if(code==CODE_RANFOLD)	return VALUE_RANFOLD; 
	else						 
		return (float((code-2.)/2.-32.5)); 
} 
 
float CReadRadarBaseData::DecodeVel(unsigned char code, short ResType) 
{ 
	if(code==CODE_INVALID)		return VALUE_INVALID; 
	else if(code==CODE_RANFOLD)	return VALUE_RANFOLD; 
	else						 
	{ 
		if(ResType==RES_POINT_FIVE) //0.5 m/s  
			return (float((code-2.)/2.-63.5)); 
		else 
			return (float((code-2)-127.)); 
	} 
} 
 
float CReadRadarBaseData::DecodeSpw(unsigned char code) 
{ 
	if(code==CODE_INVALID)		return VALUE_INVALID; 
	else if(code==CODE_RANFOLD)	return VALUE_RANFOLD; 
	else						 
		return (float((code-2.)/2.-63.5)); 
} 
void CReadRadarBaseData::Delate(void) 
{ 
	delete[] RData; 
	delete[] VData; 
	delete[] WData; 
}