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

📄 atmosctl.cpp

📁 大气透过率计算软件
💻 CPP
字号:
// AtmosCtl.cpp : Implementation of the CAtmosCtrl ActiveX Control class.

#include "stdafx.h"
#include "atmos.h"
#include "AtmosCtl.h"
#include "AtmosPpg.h"
#include "math.h"
#include "matlib.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CAtmosCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CAtmosCtrl, COleControl)
	//{{AFX_MSG_MAP(CAtmosCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CAtmosCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CAtmosCtrl)
	DISP_FUNCTION(CAtmosCtrl, "leveltrans", leveltrans, VT_R8, VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8)
	DISP_FUNCTION(CAtmosCtrl, "inclinedtrans", inclinedtrans, VT_R8, VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CAtmosCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CAtmosCtrl, COleControl)
	//{{AFX_EVENT_MAP(CAtmosCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CAtmosCtrl, 1)
	PROPPAGEID(CAtmosPropPage::guid)
END_PROPPAGEIDS(CAtmosCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CAtmosCtrl, "ATMOS.AtmosCtrl.1",
	0x47d5f507, 0xb394, 0x4d56, 0x83, 0x4, 0x1f, 0x2b, 0xc1, 0x34, 0x33, 0xba)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CAtmosCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DAtmos =
		{ 0x5db30f1b, 0xa8d1, 0x4842, { 0x8f, 0x9e, 0x9f, 0x10, 0x7, 0x6b, 0x1a, 0xae } };
const IID BASED_CODE IID_DAtmosEvents =
		{ 0xff507b18, 0xb3c5, 0x43bf, { 0xbe, 0xd3, 0xcf, 0x2e, 0x66, 0xbb, 0x59, 0x73 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwAtmosOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CAtmosCtrl, IDS_ATMOS, _dwAtmosOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::CAtmosCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CAtmosCtrl

BOOL CAtmosCtrl::CAtmosCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_ATMOS,
			IDB_ATMOS,
			afxRegApartmentThreading,
			_dwAtmosOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::CAtmosCtrl - Constructor

CAtmosCtrl::CAtmosCtrl()
{
	InitializeIIDs(&IID_DAtmos, &IID_DAtmosEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::~CAtmosCtrl - Destructor

CAtmosCtrl::~CAtmosCtrl()
{
	// TODO: Cleanup your control's instance data here.

}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::OnDraw - Drawing function

void CAtmosCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	pdc->Ellipse(rcBounds);
}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::DoPropExchange - Persistence support

void CAtmosCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::OnResetState - Reset control to default state

void CAtmosCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl::AboutBox - Display an "About" box to the user

void CAtmosCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_ATMOS);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CAtmosCtrl message handlers
double CAtmosCtrl::inclinedtrans(double lamda, double vdlamda/*能见距离对应波长*/, double startheight, double endheight, double zenith, double relehum, double temperature, double visibledistance, double snow, double rain) 
{
	// TODO: Add your dispatch handler code here
/*	lamda=10.6;
	vdlamda=0.555;
	startheight=0;
	endheight=2;
	zenith=30;
	relehum=0.5;
	temperature=10;
	visibledistance=15;
	rain=0;
	snow=0;*/
    initM(MATCOM_VERSION);
	double vaporx[61];
	for(int i=-30;i<=30;i++)
     vaporx[i+30]=(double)i;	
    double vapory[61]={0.046,0.050,0.054,0.059,0.065,0.070,0.076,0.084,0.091,0.099,0.108,0.117,0.127,0.137,0.149,0.161,0.174,
    0.188,0.203,0.219,0.237,0.255,0.274,0.295,0.318,0.341,0.367,0.394,0.423,0.453,0.486,0.521,0.557,0.596,0.637,
    0.681,0.728,0.778,0.828,0.885,0.941,1.002,1.068,1.136,1.208,1.283,1.365,1.449,1.539,1.632,1.732,1.835,1.945,
    2.059,2.181,2.305,2.440,2.577,2.725,2.876,3.038};
	Mm m_vaporx=zeros(1,61);
    memcpy(m_vaporx.addr(),vaporx,61*sizeof(double));
	Mm m_vapory=zeros(1,61);
    memcpy(m_vapory.addr(),vapory,61*sizeof(double));

//	if(lamda==10.6)
//	{
     double h2otranstablex[11]={0,0.2,0.5,1,2,5,10,20,50,100,200};
     double h2otranstabley[11]={1,0.998,0.994,0.988,0.976,0.942,0.887,0.786,0.546,0.300,0.089};
     Mm m_h2otranstablex=zeros(1,11);
	 memcpy(m_h2otranstablex.addr(),h2otranstablex,11*sizeof(double));
	 Mm m_h2otranstabley=zeros(1,11);
	 memcpy(m_h2otranstabley.addr(),h2otranstabley,11*sizeof(double));
	 double co2transtablex[11]={0,0.2,0.5,1,2,5,10,20,50,100,200};
	 double co2transtabley[11]={1,1,1,0.999,0.999,0.998,0.995,0.991,0.978,0.955,0.914};
     Mm m_co2transtablex=zeros(1,11);
	 Mm m_co2transtabley=zeros(1,11);
     memcpy(m_co2transtablex.addr(),co2transtablex,11*sizeof(double));
     memcpy(m_co2transtabley.addr(),co2transtabley,11*sizeof(double));

//	}*/
/*	//if(lamda=2.0)
	//{
	double h2otranstablex[13]={0.1,0.2,0.5,1,2,5,10,20,50,100,200,500,1000};
    double h2otranstabley[13]={0.985,0.979,0.966,0.953,0.933,0.894,0.851,0.790,0.674,0.552,0.401,0.184,0.006};
    Mm m_h2otranstablex=zeros(1,13);
    memcpy(m_h2otranstablex.addr(),h2otranstablex,10*sizeof(double));
    Mm m_h2otranstabley=zeros(1,13);
    memcpy(m_h2otranstabley.addr(),h2otranstabley,10*sizeof(double));
	//}*/


	double omiga0,omigae,re,h2otrans,co2trans,difftrans,trans;
	Mm m_temperature=zeros(1,1);
    memcpy(m_temperature.addr(),&temperature,1*sizeof(double));
	Mm m_omiga0=zeros(1,1);
	m_omiga0=interp1(m_vaporx,m_vapory,m_temperature,TM("spline"));
    memcpy(&omiga0,m_omiga0.addr(),1*sizeof(double));
	omigae=omiga0*relehum*(exp(-0.5154*startheight)-exp(-0.5154*endheight))/(0.5154*cos(zenith*3.1415926/180));
    omigae=omigae*10;
	Mm m_omigae=zeros(1,1);
	memcpy(m_omigae.addr(),&omigae,1*sizeof(double));
	Mm m_h2otrans=zeros(1,1);
    m_h2otrans=interp1(m_h2otranstablex,m_h2otranstabley,m_omigae,TM("spline"));
	memcpy(&h2otrans,m_h2otrans.addr(),1*sizeof(double));
	re=(exp(-0.313*startheight)-exp(-0.313*endheight))/(0.313*cos(zenith*3.1415926/180));
	Mm m_re=zeros(1,1);
	memcpy(m_re.addr(),&re,1*sizeof(double));
	Mm m_co2trans=zeros(1,1);
	m_co2trans=interp1(m_co2transtablex,m_co2transtabley,m_re,TM("spline"));/////////
	memcpy(&co2trans,m_co2trans.addr(),1*sizeof(double));
    double length=(endheight-startheight)/cos(zenith*3.1415926/180);
	if(visibledistance!=0)
	difftrans=exp(-3.912*length*pow((vdlamda/lamda),1.3)/visibledistance);
	else
	difftrans=1;
	double alpharain,alphasnow,snowtrans,raintrans;
	alpharain=1.9*pow(rain,0.63);
	alphasnow=2*pow(snow,0.75);
	snowtrans=exp(-alphasnow*length);
	raintrans=exp(-alpharain*length);
	trans=h2otrans*co2trans*difftrans*raintrans*snowtrans;
	exitM();

	return trans;

}


double CAtmosCtrl::leveltrans(double lamda, double vdlamda, double height, double length, double relehum, double temperature, double visibledistance, double snow, double rain) 
{
	// TODO: Add your dispatch handler code here
/*	lamda=10.6;
	vdlamda=0.555;
	height=2;
	length=1.8;
	//zenith=30;
	relehum=0.5;
	temperature=10;
	visibledistance=15;
	rain=0;
	snow=0;*/

	double vaporx[61];
	for(int i=-30;i<=30;i++)
     vaporx[i+30]=(double)i;	
    double vapory[61]={0.046,0.050,0.054,0.059,0.065,0.070,0.076,0.084,0.091,0.099,0.108,0.117,0.127,0.137,0.149,0.161,0.174,
    0.188,0.203,0.219,0.237,0.255,0.274,0.295,0.318,0.341,0.367,0.394,0.423,0.453,0.486,0.521,0.557,0.596,0.637,
    0.681,0.728,0.778,0.828,0.885,0.941,1.002,1.068,1.136,1.208,1.283,1.365,1.449,1.539,1.632,1.732,1.835,1.945,
    2.059,2.181,2.305,2.440,2.577,2.725,2.876,3.038};
    initM(MATCOM_VERSION);
	Mm m_vaporx=zeros(1,61);
    memcpy(m_vaporx.addr(),vaporx,61*sizeof(double));
	Mm m_vapory=zeros(1,61);
    memcpy(m_vapory.addr(),vapory,61*sizeof(double));



//*	if(lamda==10.6)
	//{
	 double h2otranstablex[11]={0,0.2,0.5,1,2,5,10,20,50,100,200};
     double h2otranstabley[11]={1,0.998,0.994,0.988,0.976,0.942,0.887,0.786,0.546,0.300,0.089};
     Mm m_h2otranstablex=zeros(1,11);
	 memcpy(m_h2otranstablex.addr(),h2otranstablex,11*sizeof(double));
	 Mm m_h2otranstabley=zeros(1,11);
	 memcpy(m_h2otranstabley.addr(),h2otranstabley,11*sizeof(double));
	 double co2transtablex[11]={0,0.2,0.5,1,2,5,10,20,50,100,200};
	 double co2transtabley[11]={1,1,1,0.999,0.999,0.998,0.995,0.991,0.978,0.955,0.914};
     Mm m_co2transtablex=zeros(1,11);
	 Mm m_co2transtabley=zeros(1,11);
     memcpy(m_co2transtablex.addr(),co2transtablex,11*sizeof(double));
     memcpy(m_co2transtabley.addr(),co2transtabley,11*sizeof(double));

//	}*/
	//if(lamda=2.0)
	//{
	/*double h2otranstablex[13]={0.1,0.2,0.5,1,2,5,10,20,50,100,200,500,1000};
    double h2otranstabley[13]={0.985,0.979,0.966,0.953,0.933,0.894,0.851,0.790,0.674,0.552,0.401,0.184,0.006};
    Mm m_h2otranstablex=zeros(1,13);
    memcpy(m_h2otranstablex.addr(),h2otranstablex,13*sizeof(double));
    Mm m_h2otranstabley=zeros(1,13);
    memcpy(m_h2otranstabley.addr(),h2otranstabley,13*sizeof(double));
	double co2transtablex[13]={0.1,0.2,0.5,1,2,5,10,20,50,100,200,500,1000};
    double co2transtabley[13]={0.978,0.969,0.951,0.931,0.903,0.847,0.785,0.699,0.541,0.387,0.221,0.053,0.006};
    Mm m_co2transtablex=zeros(1,13);
	Mm m_co2transtabley=zeros(1,13);
    memcpy(m_co2transtablex.addr(),co2transtablex,13*sizeof(double));
    memcpy(m_co2transtabley.addr(),co2transtabley,13*sizeof(double));
	//}*/


    double omiga0,omigae,re,h2otrans,co2trans,difftrans,trans;
	Mm m_temperature=zeros(1,1);
    memcpy(m_temperature.addr(),&temperature,1*sizeof(double));
	Mm m_omiga0=zeros(1,1);
	m_omiga0=interp1(m_vaporx,m_vapory,m_temperature,TM("spline"));///////////
    memcpy(&omiga0,m_omiga0.addr(),1*sizeof(double));
	omigae=omiga0*length*relehum*exp(-0.5154*height);
    omigae=omigae*10;
	Mm m_omigae=zeros(1,1);
	memcpy(m_omigae.addr(),&omigae,1*sizeof(double));
	Mm m_h2otrans=zeros(1,1);
    m_h2otrans=interp1(m_h2otranstablex,m_h2otranstabley,m_omigae,TM("spline"));///////////
	memcpy(&h2otrans,m_h2otrans.addr(),1*sizeof(double));

	re=length*exp(-0.313*height);
	Mm m_re=zeros(1,1);
	memcpy(m_re.addr(),&re,1*sizeof(double));
	Mm m_co2trans=zeros(1,1);
	m_co2trans=interp1(m_co2transtablex,m_co2transtabley,m_re,TM("spline"));/////////
	memcpy(&co2trans,m_co2trans.addr(),1*sizeof(double));
	if(visibledistance!=0)
	difftrans=exp(-3.912*length*pow((vdlamda/lamda),1.3)/visibledistance);
	else 
	difftrans=1;
	
	double alpharain,alphasnow,snowtrans,raintrans;
	alpharain=1.9*pow(rain,0.63);
	alphasnow=2*pow(snow,0.75);
	snowtrans=exp(-alphasnow*length);
	raintrans=exp(-alpharain*length);
	
	trans=h2otrans*co2trans*difftrans*raintrans*snowtrans;

	exitM();
	return trans;
}



⌨️ 快捷键说明

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