⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typhooncls.cpp

📁 解析中央气象局下发的台风报文
💻 CPP
📖 第 1 页 / 共 3 页
字号:
							{
								strLine.Trim ();
								pTd->Date_Time =ChackDateTime (dtFile.GetYear (),dtFile.GetMonth (),atoi(strLine.Mid (0,2)),atoi(strLine.Mid (2,2)),atoi(strLine.Mid (4,2)),0,dtFile);

							}
						}
						else if(strLine.Find ("HRS")>0)
						{
							
	NEXTFORCAST_WTPN3PGTW:
							
							TYPHOONFORCAST *pTf=new TYPHOONFORCAST();
							while(file.ReadString (strLine))
							{
								strLine.TrimRight ();
								strLine.TrimLeft ();
								if(strLine=="")
									continue;
								if(strLine.Find ("Z ---")>0)
								{
									I=strLine.Find ("Z ---");
									strtemp=strLine.Left (I);
									strtemp.Trim ();
									pTf->Predict_Time =ChackDateTime (dtFile.GetYear (),dtFile.GetMonth (),atoi(strtemp.Mid (0,2)),atoi(strtemp.Mid (2,2)),atoi(strtemp.Mid (4,2)),0,dtFile);
									I=strLine.Find ("---");
									J=strLine.Find ("N");
									pTf->Latitude =atof(strLine.Mid (I+3,J-I-3));
									I=strLine.Find ("E");
									pTf->Longitude =atof(strLine.Mid (J+1,I-J-1));
								
								}
								if(strLine.Find ("MAX SUSTAINED WINDS")>=0)
								{
									I=strLine.Find ("WINDS -");
									J=strLine.Find ("KT");
									pTf->Wind_Power=atof(strLine.Mid (I+7,J-I-7))/3.6;

								}
								if(strLine.Find ("RADIUS OF 050 KT")>=0)
								{
									I=strLine.Find ("WINDS -");
									J=strLine.Find ("NM");
									pTf->Radius_10=atof(strLine.Mid (I+7,J-I-7))*1.852;

								}
								if(strLine.Find ("RADIUS OF 034 KT")>=0)
								{
									I=strLine.Find ("WINDS -");
									J=strLine.Find ("NM");
									pTf->Radius_7=atof(strLine.Mid (I+7,J-I-7))*1.852;

								}
								if(strLine.Find ("NNNN")>=0)
								{
									break;
								}
								if(strLine.Find ("HRS")>0)
								{
									pTd->AddForcast (pTf);
									goto NEXTFORCAST_WTPN3PGTW;

								}
								
							}
							pTd->AddForcast (pTf);
						}
					}
					this->m_tdArray.Add (pTd);
						
				}
			}
			catch(...)
			{
			}
		
		}
		file.Close ();
	}
	catch(...)
	{
		
	}
	this->SaveTyphoon ();
	return true;
}
CString CTyphoonCls::GetTyphoonID(CString strId,CString strName)
{
	CString strLastTyphoon=CParam::GetParam ("台风资料","LASTTYPHOON",",,");
	vector<CString>vecOut;
	CParam::Split (strLastTyphoon,",",vecOut);
	if(strId.Left (2)==vecOut[0].Left (2)&&strName==vecOut[1])
	{
		return vecOut[0];
	}
	else
	{
		CString cmdText="select typhoon_id from typhoondata where SUBSTRING(convert(char(6),typhoon_id),3,4)='"+strId+"' and Title_EN='"+strName+"'";
		_RecordsetPtr pSet;
		pSet.CreateInstance (_uuidof(Recordset));
		cn.Execute (pSet,cmdText);
		try
		{
			if(pSet->adoEOF )
			{
				pSet->Close ();
				return "";
			}
			else
			{
				CString strtemp=CParam::ToString (pSet->GetCollect (0).lVal).Mid (2) ;
				pSet->Close ();
				return strtemp;
			}
		}
		catch(...)
		{
			return "";
		}
	}
	return "";
}
CString CTyphoonCls::GetCnName(CString strEnName)
{
	CString cmdText="select Title_CN from TyphoonName where  Title_EN='"+strEnName+"'";
	_RecordsetPtr pSet;
	pSet.CreateInstance (_uuidof(Recordset));
	cn.Execute (pSet,cmdText);
	try
	{
		if(pSet->adoEOF )
		{
				pSet->Close ();
				return "";
		}
		else
		{
		    _variant_t var=pSet->GetCollect ("Title_CN");
			CString strtemp=(_bstr_t)var.bstrVal ;
			pSet->Close ();
			return strtemp;
		}
	}
	catch(...)
	{
			return "";
	}

}
CString CTyphoonCls::GetIntensityCnName(CString strEnName)
{
	CString cmdText="select Intensity_CN from TyphoonGrade where  Intensity_ID ='"+strEnName+"'";
	_RecordsetPtr pSet;
	pSet.CreateInstance (_uuidof(Recordset));
	cn.Execute (pSet,cmdText);
	try
	{
		if(pSet->adoEOF )
		{
				pSet->Close ();
				return "";
		}
		else
		{
			    _variant_t var=pSet->GetCollect ("Intensity_CN");
				CString strtemp=(_bstr_t)var.bstrVal ;
				pSet->Close ();
				return strtemp;
		}
	}
	catch(...)
	{
			return "";
	}
}
void CTyphoonCls::SaveTempData(TYPHOONDATA *pTd)
{
	if(pTd==NULL)
		return;
	CString strPath=CParam::GetModulePath ()+"\\temptyphoon.ini";

	int nCount=atoi(CParam::GetParam ("TYPHOON","COUNT","0",strPath));
	try
	{
		
		CString strTemp=pTd->Typhoon_ID+","+pTd->Title_EN +","+pTd->Date_Time.Format ("%Y-%m-%d %H:%M:%S")+","+pTd->Station_Name+",";			
		CString strLine;
		for(int i=0;i<pTd->m_tfArray.GetCount ();i++)
		{
			TYPHOONFORCAST*pTf=pTd->m_tfArray [i];
			nCount++;
			strLine=strTemp;
			strLine+=pTf->Predict_Time.Format ("%Y-%m-%d %H:%M:%S")+",";
			strLine+=CParam::ToString (pTf->Longitude)+",";
			strLine+=CParam::ToString (pTf->Latitude)+",";
			strLine+=CParam::ToString (pTf->Pressure)+",";
			strLine+=CParam::ToString (pTf->Wind_Power)+",";
			strLine+=CParam::ToString (pTf->Radius_7)+",";
			strLine+=CParam::ToString (pTf->Radius_10)+",";
			strLine+=CParam::ToString (pTf->Move_Speed)+",";
			strLine+=pTf->Direction+",";
			strLine+=pTf->Affect_affect+",";
			CParam::WriteParam  ("TYPHOON","COUNT",CParam::ToString (nCount),strPath);
			CParam::WriteParam  ("TYPHOON",CParam::ToString (nCount),strLine,strPath);


		}
	

	}
	catch(...)
	{

	}
}
void CTyphoonCls::ReadTempData()
{
	CString strPath=CParam::GetModulePath ()+"\\temptyphoon.ini";
	CStdioFile file;
	if(!::PathFileExists (strPath))
		return;
	
		CString strLine;
		vector<CString>vecOut;

		int nCount=atoi(CParam::GetParam ("TYPHOON","COUNT","0",strPath));
		for(int i=0;i<nCount;i++)
		{
			strLine=CParam::GetParam ("TYPHOON",CParam::ToString (i+1),"",strPath);

			CParam::Split (strLine,",",vecOut);
			if(vecOut.size ()<14)
				continue;
			
			TYPHOONDATA *pTd=new TYPHOONDATA();
			pTd->Typhoon_ID =vecOut[0];
			pTd->Title_EN  =vecOut[1];
			pTd->Date_Time.ParseDateTime (vecOut[2]);
			pTd->Station_Name =vecOut[3];
			TYPHOONFORCAST*pTf=new TYPHOONFORCAST();

			pTf->Predict_Time .ParseDateTime (vecOut[4]);
			pTf->Longitude=atof(vecOut[6]);
			pTf->Latitude=atof(vecOut[6]);
			pTf->Pressure=atof(vecOut[7]);
			pTf->Wind_Power=atof(vecOut[8]);
			pTf->Radius_7=atof(vecOut[9]);
			pTf->Radius_10=atof(vecOut[10]);
			pTf->Move_Speed=atof(vecOut[11]);
			pTf->Direction=vecOut[12];
			pTf->Affect_affect=vecOut[13];
			pTd->AddForcast (pTf);
			this->m_tdArray .Add (pTd);
		}
		CParam::WriteParam ("TYPHOON","COUNT","0",strPath);
		MyDeleteFile(strPath);


}
BOOL  CTyphoonCls::SaveTyphoon()
{

	if(this->m_tdArray.GetCount ()<=0)
		return true;
	::CoInitialize (NULL);
	try
	{
		
		
		_RecordsetPtr pSet,pSet1,pSet2;
		pSet.CreateInstance (_uuidof(Recordset));
		pSet1.CreateInstance (_uuidof(Recordset));
		
		_variant_t var;
		CString cmdText="select * from TyphoonLocation where 1<>1";
		cn.Execute (pSet,cmdText);
		cmdText="select * from TyphoonForecast where 1<>1";
		cn.Execute (pSet1,cmdText);
		for(int i=0;i<this->m_tdArray .GetCount ();i++)
		{	
			TYPHOONDATA *pTd= this->m_tdArray [i];
			if(pTd->Station_Name =="中央")
			{
				CString strLastTyphoon=GetTyphoonID(pTd->Typhoon_ID ,pTd->Title_EN );
				if(strLastTyphoon=="")
				{
					pSet2.CreateInstance (_uuidof(Recordset));
					cmdText="select * from typhoondata where SUBSTRING(convert(char(6),typhoon_id),3,4)='"+pTd->Typhoon_ID+"'";
					cn.Execute (pSet2,cmdText);
					
					try
					{
						if(pSet2->adoEOF)
							pSet2->AddNew ();
						else
							pSet2->MoveFirst();
						
						pSet2->GetFields ()->GetItem ("Typhoon_ID")->put_Value (_variant_t(CParam::ToYear (pTd->Typhoon_ID)));
						pSet2->GetFields ()->GetItem ("Title_EN")->put_Value (_variant_t(pTd->Title_EN));
						pSet2->GetFields ()->GetItem ("Title_CN")->put_Value (_variant_t(GetCnName(pTd->Title_EN)));
						pSet2->GetFields ()->GetItem ("Intensity_CN")->put_Value (_variant_t(GetIntensityCnName(pTd->Intensity_EN) ));
						pSet2->Update ();
						pSet2->Close ();
						CParam::WriteParam ("台风资料","LASTTYPHOON",pTd->Typhoon_ID+","+pTd->Title_EN);
						ReadTempData();
					
						
					}
					catch(...)
					{
					}

				}
				
				cmdText="select typhoon_id from TyphoonLocation where Typhoon_ID="+CParam::ToString (CParam::ToYear (pTd->Typhoon_ID))+" and Station_Name='中央' and Date_Time='"+pTd->Date_Time.Format ("%Y-%m-%d %H:%M:%S")+"'";
				if(!cn.IsExits (cmdText))
				{

					try
					{
						pSet->AddNew ();
						pSet->GetFields ()->GetItem ("Typhoon_ID")->put_Value (_variant_t(CParam::ToYear (pTd->Typhoon_ID) ));
						pSet->GetFields ()->GetItem ("Date_Time")->put_Value (_variant_t(pTd->Date_Time ));
						pSet->GetFields ()->GetItem ("Intensity_CN")->put_Value (_variant_t(GetIntensityCnName(pTd->Intensity_EN) ));
						if(pTd->Latitude!=INVALID_VALUE)
						pSet->GetFields ()->GetItem ("Latitude")->put_Value (_variant_t(pTd->Latitude ));
						if(pTd->Longitude!=INVALID_VALUE)
						pSet->GetFields ()->GetItem ("Longitude")->put_Value (_variant_t(pTd->Longitude ));
						if(pTd->Pressure!=INVALID_VALUE)
						pSet->GetFields ()->GetItem ("Pressure")->put_Value (_variant_t(pTd->Pressure ));
						if(pTd->Move_Speed!=INVALID_VALUE)
						pSet->GetFields ()->GetItem ("Wind_Power")->put_Value (_variant_t(pTd->Move_Speed ));
						if(pTd->Radius_7!=INVALID_VALUE)
						pSet->GetFields ()->GetItem ("Radius_7")->put_Value (_variant_t(pTd->Radius_7 ));
						if(pTd->Radius_10!=INVALID_VALUE)
						pSet->GetFields ()->GetItem ("Radius_10")->put_Value (_variant_t(pTd->Radius_10 ));
						pSet->Update ();
					}
					catch(...)
					{

					}
				}
			}
			else if(pTd->Station_Name =="关岛"||pTd->Station_Name=="香港"||pTd->Station_Name=="日本")
			{
				CString strTyphoonId=this->GetTyphoonID (pTd->Typhoon_ID ,pTd->Title_EN );
			
				if(strTyphoonId!="")
				{
					pTd->Typhoon_ID=strTyphoonId;
				}
				else//保存临时数据
				{
					SaveTempData(pTd);
					continue;

				}
			}
			for(int j=0;j<pTd->m_tfArray .GetCount ();j++)
			{	
				try
				{
					
					TYPHOONFORCAST*pTf=pTd->m_tfArray [j];

					cmdText="select typhoon_id from TyphoonForecast where Typhoon_ID="+CParam::ToString (CParam::ToYear (pTd->Typhoon_ID))+" and Station_Name='"+pTd->Station_Name+"' and [Current_Time]='"+pTd->Date_Time.Format ("%Y-%m-%d %H:%M:%S")+"' and Predict_Time='"+pTf->Predict_Time.Format ("%Y-%m-%d %H:%M:%S")+"'";

					if(!cn.IsExits (cmdText))
					{

						pSet1->AddNew ();
						pSet1->GetFields ()->GetItem ("Typhoon_ID")->put_Value (_variant_t(CParam::ToYear (pTd->Typhoon_ID) ));
						pSet1->GetFields ()->GetItem ("Station_Name")->put_Value (_variant_t(pTd->Station_Name ));
						pSet1->GetFields ()->GetItem ("Current_Time")->put_Value (_variant_t(pTd->Date_Time ));
						pSet1->GetFields ()->GetItem ("Predict_Time")->put_Value (_variant_t(pTf->Predict_Time));
						if(pTf->Longitude!=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Longitude")->put_Value (_variant_t(pTf->Longitude ));
						if(pTf->Latitude!=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Latitude")->put_Value (_variant_t(pTf->Latitude ));
						if(pTf->Pressure!=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Pressure")->put_Value (_variant_t(pTf->Pressure ));
						if(pTf->Wind_Power!=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Wind_Power")->put_Value (_variant_t(pTf->Wind_Power ));
						if(pTf->Radius_7!=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Radius_7")->put_Value (_variant_t(pTf->Radius_7 ));
						if(pTf->Radius_10!=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Radius_10")->put_Value (_variant_t(pTf->Radius_10 ));
						if(pTf->Move_Speed !=INVALID_VALUE)
						pSet1->GetFields ()->GetItem ("Move_Speed")->put_Value (_variant_t(pTf->Move_Speed ));
						pSet1->GetFields ()->GetItem ("Direction")->put_Value (_variant_t(pTf->Direction ));
						pSet1->GetFields ()->GetItem ("Affect_affect")->put_Value (_variant_t(pTf->Affect_affect ));
						
						pSet1->Update ();
					}
				}
				catch(...)
				{
				}
				
			}
				
		}
		pSet->Close ();
		pSet1->Close ();

	}
	catch(...)
	{
	}

	cn.Close ();
	::CoUninitialize ();
	this->Clear ();
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -