// SAPP1Dlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include "Form1.h"
#include "Form2.h"

#include "Dlg_BuiltForm.h"
#include "Dlg_JobDetails.h"
#include "Dlg_Ventilation.h"
#include "Dlg_MainHeating.h"
#include "Dlg_MainHeatingDetails.h"
#include "Dlg_SecHeating.h"
#include "Dlg_WaterHeating.h"
#include "Dlg_Renewables.h"
#include "Dlg_Renewables1.h"
#include "Dlg_ThermalBridging.h"
#include "Dlg_Results.h"
#include "Dlg_Windows.h"
#include "Dlg_AreaAndUvalues.h"
#include "Dlg_AddToEstate.h"
#include "Dlg_Estate.h"
#include <vector>

using namespace std;

// CSAPP1Dlg dialog
class CSAPP1Dlg : public CDialog
{
// Construction
public:
	CSAPP1Dlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_SAPP1_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void SaveProjectFile_2();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult);
	// Main tab control variable
	CTabCtrl m_tabCtrl;

// Declare dialog variables for tabs
	CForm1* m_Dialog_Form1;
	CForm2* m_Dialog_Form2;

	CDlg_BuiltForm* m_BuiltForm;
	CDlg_JobDetails* m_JobDetails;
	CDlg_Ventilation* m_Ventilation;
	CDlg_MainHeating* m_MainHeating;
	CDlg_MainHeatingDetails *m_MainHeatingDetails;
	CDlg_SecHeating* m_SecHeating;
	CDlg_WaterHeating* m_WaterHeating;
	CDlg_Renewables* m_Renewables;
	CDlg_Renewables1* m_Renewables1;
	CDlg_ThermalBridging* m_ThermalBridging;
	CDlg_Results* m_Results;
	CDlg_Windows* m_Windows;
	CDlg_AreaAndUvalues* m_AreaAndUvalues;
	CDlg_AreaAndUvalues* m_AreaUvalues;

	CTabCtrl m_tabCtrlProjects;
	CTabCtrl m_tabCtrlEstate;

	BOOL DestroyModlessDialogs();

	afx_msg void OnFileSave();
	afx_msg void OnFileOpen();
	afx_msg void OpenProjectFile();
	afx_msg void OnFileNew();
	afx_msg void ReadSecHtEffFile();
	afx_msg void ReadsSAPboilers();
	afx_msg void ReadsSAPcostTable();
	afx_msg void ReadSAPandClimateDataFile();
	afx_msg void ReadClimateDataFile();
	afx_msg void ReadFDBRFile();
	afx_msg void ReadWWHRSDataFile();
	afx_msg void ReadFGHRScombiDataFile();
	afx_msg void ReadWindDataFile();
	afx_msg void RecreateAllDialogs();
	afx_msg void OpenNewTabForProjectFile();
	afx_msg void DeleteUntitledTab();
	afx_msg void ReadDataFromSHCSFile();

	afx_msg void OnClose();
	afx_msg void OnFileExit();
	afx_msg void OnFileSaveas();
	afx_msg void OnHelpAbout();
	
	afx_msg void OnClickProjectsTab(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnFileClose();
	afx_msg void OnFileAddToEstate();
	afx_msg void DisplayAddToEstateDialog();
	afx_msg void AddPropertyToEstate();
	
	afx_msg void OnFileOpenEstate();
	afx_msg void OnTcnSelchangeTab3(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMClickTab3(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnEstateAddToEstate();
	afx_msg void OnEstateViewEstate();
	afx_msg void OnExportToEspr();
	afx_msg void OnExportExporttosapinformation();

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnFileReadFromSHCS();
	afx_msg void OnEstateSaveEstate();
	afx_msg void OnEstateOpenEstate();
	afx_msg void OnFileMenuOpenEstate();
};

#define MAX_CHARS_IN_A_ROW_2 500
#define MAX_CHARS_IN_A_ROW_CLIMATE_FILE 5000

#define PATH_TO_REGIONS_WEATHER_FILE "..\\data\\clmsummarydata.csv"
#define PATH_TO_SAP_CLIMATE_FILE "..\\data\\SAPclmsummarydata.csv"
#define PATH_TO_TOWNS_WEATHER_FILE "..\\data\\townsclmsummarydata.csv"
#define PATH_TO_DATA_FILE "..\\data\\FRDB.csv"

typedef struct
{
	char entryLabel[MAX_CHARS_IN_A_ROW_2];
	char entryString[MAX_CHARS_IN_A_ROW_2];
	char entryStringImp1[MAX_CHARS_IN_A_ROW_2];
	char entryStringImp2[MAX_CHARS_IN_A_ROW_2];
	char entryStringImp3[MAX_CHARS_IN_A_ROW_2];
	char entryStringImp4[MAX_CHARS_IN_A_ROW_2];
	char entryStringImp5[MAX_CHARS_IN_A_ROW_2];
	char entryStringBase[MAX_CHARS_IN_A_ROW_2];
}LineEntryInfo;

extern vector <LineEntryInfo> stringsWithValues;

typedef struct
{
	int tabNumber;
	CString projectFileName;
	CString projectFileNameNoPath;
	CString projectFileNameNoExt;
}OpenProjectInfo;
extern vector <OpenProjectInfo> projectInfo;

typedef struct
{
	CString nameWithPath;
	CString nameNoPath;
}projectFileNamesInTabs;

extern vector <projectFileNamesInTabs> projectFileNamesInTabs_1;


struct MonthlyValues
{
	double Jan;
	double Feb;
	double Mar;
	double Apr;
	double May;
	double Jun;
	double Jul;
	double Aug;
	double Sep;
	double Oct;
	double Nov;
	double Dec;
	double total;
};

extern struct MonthlyValues effectiveInfiltrationRate;
extern struct MonthlyValues WindFactor;
extern struct MonthlyValues averageWindSpeed;
extern struct MonthlyValues monthlyNumOfDays;
extern struct MonthlyValues DHW_monthlyUsage;
extern struct MonthlyValues DHW_monthlyFactorsForHotWaterUse;
extern struct MonthlyValues DHW_coldWaterTemp;
extern struct MonthlyValues DHW_monthlyTempRise;
extern struct MonthlyValues IfBalancedMVHR;      // If balanced mechanical ventilation with heat recovery (MVHR)
extern struct MonthlyValues IfBalancedMVnoHR;    // If balanced mechanical ventilation without heat recovery (MV)
extern struct MonthlyValues IfWholeHouseExractVentilationOrInputVentFromOutside; // If whole house extract ventilation or positive input ventilation from outside
extern struct MonthlyValues IfNaturalVentilationOrInputVentFromLoft;             // If natural ventilation or whole house positive input ventilation from loft
extern struct MonthlyValues IfPositiveInputFromOutside;
extern struct MonthlyValues EffectiveAirChangeRate;
extern struct MonthlyValues DSMResults;
extern struct MonthlyValues DSMResults1;
extern struct MonthlyValues DSMResults2;

typedef struct
{
	char FGHRSname[MAX_CHARS_IN_A_ROW_2];
	double Qsp_1, Qsp1a_keepHot, Qsp1b_keepHot, Qsp1c_keepHot, Qsp1a_otherCombi, Qsp1b_otherCombi, Qsp1c_otherCombi;
	double Qsp_2, Qsp2a_keepHot, Qsp2b_keepHot, Qsp2c_keepHot, Qsp2a_otherCombi, Qsp2b_otherCombi, Qsp2c_otherCombi;
	double Qsp_3, Qsp3a_keepHot, Qsp3b_keepHot, Qsp3c_keepHot, Qsp3a_otherCombi, Qsp3b_otherCombi, Qsp3c_otherCombi;
	double Qsp_4, Qsp4a_keepHot, Qsp4b_keepHot, Qsp4c_keepHot, Qsp4a_otherCombi, Qsp4b_otherCombi, Qsp4c_otherCombi;
	double Qsp_5, Qsp5a_keepHot, Qsp5b_keepHot, Qsp5c_keepHot, Qsp5a_otherCombi, Qsp5b_otherCombi, Qsp5c_otherCombi;
	double Qsp_6, Qsp6a_keepHot, Qsp6b_keepHot, Qsp6c_keepHot, Qsp6a_otherCombi, Qsp6b_otherCombi, Qsp6c_otherCombi;
}FGHRS_Data;
extern vector <FGHRS_Data> FGHRS_combiData;

typedef struct
{
	char type[MAX_CHARS_IN_A_ROW_2];
	char make[MAX_CHARS_IN_A_ROW_2];
	char model[MAX_CHARS_IN_A_ROW_2];
	char modelQualifier[MAX_CHARS_IN_A_ROW_2];
	double effeciencyMixer;
	double effeciencyInstElec;
	double UfMixer;
	double UfinstElec;
}WWHRSData;
extern vector <WWHRSData> WWHRSData_1;

typedef struct
{
	char locationName[MAX_CHARS_IN_A_ROW_2];
	int s3;
}WindData;

extern vector <WindData> WindData_1;

typedef struct
{
	char locationName[100];
	double Jan1, Jan2, Jan3, Jan4, Jan5, Jan6, Jan7, Jan8, Jan9;	
	double Feb1, Feb2, Feb3, Feb4, Feb5, Feb6, Feb7, Feb8, Feb9;
	double Mar1, Mar2, Mar3, Mar4, Mar5, Mar6, Mar7, Mar8, Mar9;
	double Apr1, Apr2, Apr3, Apr4, Apr5, Apr6, Apr7, Apr8, Apr9;
	double May1, May2, May3, May4, May5, May6, May7, May8, May9;
	double Jun1, Jun2, Jun3, Jun4, Jun5, Jun6, Jun7, Jun8, Jun9;
	double Jul1, Jul2, Jul3, Jul4, Jul5, Jul6, Jul7, Jul8, Jul9;
	double Aug1, Aug2, Aug3, Aug4, Aug5, Aug6, Aug7, Aug8, Aug9;
	double Sep1, Sep2, Sep3, Sep4, Sep5, Sep6, Sep7, Sep8, Sep9;
	double Oct1, Oct2, Oct3, Oct4, Oct5, Oct6, Oct7, Oct8, Oct9;
	double Nov1, Nov2, Nov3, Nov4, Nov5, Nov6, Nov7, Nov8, Nov9;
	double Dec1, Dec2, Dec3, Dec4, Dec5, Dec6, Dec7, Dec8, Dec9;
}ClimateData;

extern vector <ClimateData> ClimateData_1;
extern vector <ClimateData> ClimateData_towns;

typedef struct
{
	char index[15];
	char month1[15],month2[15],month3[15],month4[15],month5[15],month6[15],month7[15],month8[15],month9[15],month10[15],month11[15],month12[15];
	double Jan1, Jan2, Jan3, Jan4, Jan5, Jan6, Jan7, Jan8, Jan9, Jan10, Jan11;	
	double Feb1, Feb2, Feb3, Feb4, Feb5, Feb6, Feb7, Feb8, Feb9, Feb10, Feb11;
	double Mar1, Mar2, Mar3, Mar4, Mar5, Mar6, Mar7, Mar8, Mar9, Mar10, Mar11;
	double Apr1, Apr2, Apr3, Apr4, Apr5, Apr6, Apr7, Apr8, Apr9, Apr10, Apr11;
	double May1, May2, May3, May4, May5, May6, May7, May8, May9, May10, May11;
	double Jun1, Jun2, Jun3, Jun4, Jun5, Jun6, Jun7, Jun8, Jun9, Jun10, Jun11;
	double Jul1, Jul2, Jul3, Jul4, Jul5, Jul6, Jul7, Jul8, Jul9, Jul10, Jul11;
	double Aug1, Aug2, Aug3, Aug4, Aug5, Aug6, Aug7, Aug8, Aug9, Aug10, Aug11;
	double Sep1, Sep2, Sep3, Sep4, Sep5, Sep6, Sep7, Sep8, Sep9, Sep10, Sep11;
	double Oct1, Oct2, Oct3, Oct4, Oct5, Oct6, Oct7, Oct8, Oct9, Oct10, Oct11;
	double Nov1, Nov2, Nov3, Nov4, Nov5, Nov6, Nov7, Nov8, Nov9, Nov10, Nov11;
	double Dec1, Dec2, Dec3, Dec4, Dec5, Dec6, Dec7, Dec8, Dec9, Dec10, Dec11;
}IndexDataNew;

extern vector <IndexDataNew> IndexDataNew_1;

typedef struct
{
	// Line 01 data
	char houseTypeName[25];     // 1
	char yearOfBuild[25];       // 2
	double frequencyOfOccurence;   // 3
	char builtForm[25];			// 4
	char detachment[25];		// 5
	char flatPosition[25];		// 6
	int numOfFloors;			// 7
	//double floorAreaPerFloor;	
	//double heightPerFloor;	   

	double floorArea1stFloor;	// 8
	double floorArea2ndFloor;	// 9
	double floorArea3rdFloor;	// 10
	double floorArea4thFloor;	// 11
	double floorArea5thFloor;	// 12
	double floorArea6thFloor;	// 13

	double height1stFloor;		// 14
	double height2ndFloor;		// 15
	double height3rdFloor;		// 16
	double height4thFloor;		// 17
	double height5thFloor;		// 18
	double height6thFloor;		// 19

	// Line 02 data
	double TFA;					// 1
	double thermBridgeyValue;   // 2
	double totalExtWalArea;     // 3
	double uValueXextArea;		// 4
	double ach;					// 5
	double LEL;					// 6
	double TMP;					// 7
	char overshading[25];		// 8
	char glazing[25];			// 9
    double livingAreaFraction;	// 10

	// Line 03 data
	char mainFuel[25];			// 1
	char heatGenerator[25];		// 2
	char bolerType[25];			// 3
	double boilerEff;			// 4
	int controls;			    // 5 control is associated to a control number
	char isFanFlue[5];			// 6	
	char interlock[5];			// 7
	char isPumpInHeatedSpace[5];// 8

	// Line 04 data
	char DHWfuel[25];			// 1
	double DHWeff;				// 2
	char isCylWithinDwelling[5];// 3
	char isCylSepTimed[5];		// 4
	double cylMaufacturerLossFactor;// 5
	double cylVolume;			// 6
	char cylInsType[25];		// 7
	double cylInsThickness;		// 8
	char isThereThermostat[5];	// 9
	char isCylInHeaterSpace[5];	// 10
	char isPrimPipeworkInsulated[5];// 11
	char isPumpedSystem[5];		// 12
	char waterHtType[25];		// 13

	// Line 05 data
	double winNArea;            // 1
	double winNEArea;			// 2
	double winEArea;			// 3
	double winSEArea;			// 4
	double winSArea;			// 5
	double winSWArea;			// 6
	double winWArea;			// 7
	double winNWArea;			// 8
	double rooflightsArea;		// 9

	double winNSolTrans;		// 10
	double winNESolTrans;		// 11
	double winESolTrans;		// 12
	double winSESolTrans;		// 13
	double winSSolTrans;		// 14
	double winSWSolTrans;		// 15
	double winWSolTrans;		// 16
	double winNWSolTrans;		// 17
	double rooflightsSolTrans;	// 18

	double winNFrameFactor;		// 19
	double winNEFrameFactor;	// 20
	double winEFrameFactor;		// 21
	double winSEFrameFactor;	// 22
	double winSFrameFactor;		// 23
	double winSWFrameFactor;	// 24
	double winWFrameFactor;		// 25
	double winNWFrameFactor;	// 26
	double rooflightsFrameFactor;	// 27
	
	// Line 06 data
	double doorArea;			// 1
	double GFnetArea;			// 2
	double expFloorNetArea;		// 3
	double wallType1GrossArea;	// 4
	double wallType2NetArea;	// 5
	double roofType1GrossArea;	// 6
	double roofType2NetArea;  // 7
	double partyWallArea;		// 8
	double partyFloorArea;		// 9
	double partyCeilingArea;	// 10
	double intWallArea;			// 11
	double intFloorArea;		// 12
	double intCeilingArea;		// 13

	// Line 07 data
	double doorUvalue;			// 1
	double windowsUvalue;		// 2
	double rooflightsUvalue;	// 3
	double GFUvalue;			// 4
	double exposedFloorUvalue;  // 5
	double wallType1Uvalue;		// 6
	double wallType2Uvalue;		// 7
	double roofType1Uvalue;		// 8
	double roofType2Uvalue;		// 9
	double partyWallUvalue;		// 10

	// Line 08 data
	double GFkValue;			// 1
	double exposedFloorkValue;	// 2
	double wallType1kValue;		// 3
	double wallType2kValue;		// 4
	double roofType1kValue;		// 5
	double roofType2kValue;		// 6
	double partyWallkValue;		// 7
	double partyFloorkValue;	// 8
	double partyCeilingkValue;  // 9
	double intWallkValue;	    // 10
	double intFloorkValue;		// 11
	double intCeilingkValue;	// 12
	
	// Line 09 data	
	int numOfFirePlaces;		// 1
	int numOfFlues;				// 2
	int numOfFluelessGasFires;	// 3
	int numOfExtractFans;		// 4
	int numOfPasiveVents;		// 5
	char ventilationType[25];	// 6
	int numOfShelteredSides;	// 7
}SHCSfileRead;

extern vector <SHCSfileRead> SHCSfileRead1;

typedef struct
{
	char openingName[30];
	char openingFromSource[25];
	char openingDescription[25];
	char openingGlzType[25];
	char openingLowECoating[25];
	char openingUsedDefEmissivity[25];
	char openingEmissivty[5];

	char openingArgonFilled[25];
	char openingGap[25];
	char openingPitch[5]; // ???unknown
	char openingOrientation[500];
	char openingOvershading[25];

	char openingWidth[5];
	char openingHeight[5];
	char openingLocationName[25];
	char openingOverhangDepth[5];
	char openingOverhangWidth[5];

	char openingRef[25];
	char openingLinkageMaster[25];
	char openingLinkedTo[25];

	char openingFrame[25];
	char openingThermalBreak[25];
	char openingDraughtProofing[25];
	char openingMetalLintel[25];

	char openingTransmittanceSelected[25];
	char openingTransmittanceFactor[5];

	char openingFrameSelected[25];
	char openingFrameFactor[5];

	char openingUvalueSelected[25];
	char openingUvalue[5];
}openingsForDlg;


//--------------------------------------------------------
// JOB DETAILS GLOBAL VARIABLES
//--------------------------------------------------------
extern CString JobDetRefNum;
extern CString assessorName;
extern CString JobDetComments;
extern CString propertyFlatNameorNum;
extern CString propertyLetter;
extern CString propertyHouseNum;
extern CString propertyStreet;
extern CString propertyLocality;
extern CString propertyDistrict;
extern CString propertyTown;
extern CString propertyCounty;
extern CString propertyPostCode;
extern CString clientFlatNameorNum;
extern CString clientLetter;
extern CString clientHouseorBlockNum;
extern CString clientStreet;
extern CString clientLocality;
extern CString clientDistrict;
extern CString clientTown;
extern CString clientCounty;
extern CString clientPostCode;

//----------------------------------------
// BUILT FORM GLOBAL VARIABLES
//----------------------------------------
extern CString dwellingType;
extern CString builtForm;
extern CString Detachment;
extern CString FlatPosition;
extern CString yearPropertBuilt; 

extern bool is_locationString_changed;
extern bool is_hemHouseType_changed;
extern bool is_hemYearOfBuild_changed;

extern CString locationString;
extern int dwellingShelteredSides;
extern CString dwellingTerrain;
extern CString dwellingExposure;

extern CString storey1;
extern CString storey2;
extern CString storey3;
extern CString storey4;
extern CString storey5;
extern CString storey6;

extern CString storey1Level;
extern CString storey2Level;
extern CString storey3Level;
extern CString storey4Level;
extern CString storey5Level;
extern CString storey6Level;

extern CString storey1Basement;
extern CString storey2Basement;
extern CString storey3Basement;
extern CString storey4Basement;
extern CString storey5Basement;
extern CString storey6Basement;

extern double storey1Area;
extern double storey2Area;
extern double storey3Area;
extern double storey4Area;
extern double storey5Area;
extern double storey6Area;

extern double storey1Height;
extern double storey2Height;
extern double storey3Height;
extern double storey4Height;
extern double storey5Height;
extern double storey6Height;

extern double multipleLinearRegCoeff;
extern double multipleLinearRegCoeff1;
extern double multipleLinearRegCoeff2;

extern double thermBridgeYvalue_grossArea;
extern double hem_yValueEntry;
extern double hem_sigmaUA;

//-----------------------------------------------------
// FLOORS GLOBAL VARIABLES
//-----------------------------------------------------
extern CString floor1Selected;
extern CString floor2Selected;
extern CString floor3Selected;
extern CString floor4Selected;
extern CString floor5Selected;
extern CString floor6Selected;
extern CString floor7Selected;
extern CString floor8Selected;
extern CString floor9Selected;
extern CString floor10Selected;

extern CString floor1Name;
extern CString floor2Name;
extern CString floor3Name;
extern CString floor4Name;
extern CString floor5Name;
extern CString floor6Name;
extern CString floor7Name;
extern CString floor8Name;
extern CString floor9Name;
extern CString floor10Name;

extern CString floor1Type;
extern CString floor2Type;
extern CString floor3Type;
extern CString floor4Type;
extern CString floor5Type;
extern CString floor6Type;
extern CString floor7Type;
extern CString floor8Type;
extern CString floor9Type;
extern CString floor10Type;

extern CString floor1Construction;
extern CString floor2Construction;
extern CString floor3Construction;
extern CString floor4Construction;
extern CString floor5Construction;
extern CString floor6Construction;
extern CString floor7Construction;
extern CString floor8Construction;
extern CString floor9Construction;
extern CString floor10Construction;

extern CString isfloor1Sealed;
extern CString isfloor2Sealed;
extern CString isfloor3Sealed;
extern CString isfloor4Sealed;
extern CString isfloor5Sealed;
extern CString isfloor6Sealed;
extern CString isfloor7Sealed;
extern CString isfloor8Sealed;
extern CString isfloor9Sealed;
extern CString isfloor10Sealed;

extern double floor1Area;
extern double floor2Area;
extern double floor3Area;
extern double floor4Area;
extern double floor5Area;
extern double floor6Area;
extern double floor7Area;
extern double floor8Area;
extern double floor9Area;
extern double floor10Area;

extern double floor1Uvalue;
extern double floor2Uvalue;
extern double floor3Uvalue;
extern double floor4Uvalue;
extern double floor5Uvalue;
extern double floor6Uvalue;
extern double floor7Uvalue;
extern double floor8Uvalue;
extern double floor9Uvalue;
extern double floor10Uvalue;

//----------------------------------
// WALLS GLOBAL VARIABLES
//----------------------------------
extern CString wall1Selected;
extern CString wall2Selected;
extern CString wall3Selected;
extern CString wall4Selected;
extern CString wall5Selected;
extern CString wall6Selected;
extern CString wall7Selected;
extern CString wall8Selected;
extern CString wall9Selected;
extern CString wall10Selected;

extern CString wall1Name;
extern CString wall2Name;
extern CString wall3Name;
extern CString wall4Name;
extern CString wall5Name;
extern CString wall6Name;
extern CString wall7Name;
extern CString wall8Name;
extern CString wall9Name;
extern CString wall10Name;

extern CString wall1Construction;
extern CString wall2Construction;
extern CString wall3Construction;
extern CString wall4Construction;
extern CString wall5Construction;
extern CString wall6Construction;
extern CString wall7Construction;
extern CString wall8Construction;
extern CString wall9Construction;
extern CString wall10Construction;

extern CString wall1Basement;
extern CString wall2Basement;
extern CString wall3Basement;
extern CString wall4Basement;
extern CString wall5Basement;
extern CString wall6Basement;
extern CString wall7Basement;
extern CString wall8Basement;
extern CString wall9Basement;
extern CString wall10Basement;

extern double wall1Area;
extern double wall2Area;
extern double wall3Area;
extern double wall4Area;
extern double wall5Area;
extern double wall6Area;
extern double wall7Area;
extern double wall8Area;
extern double wall9Area;
extern double wall10Area;

extern double wall1Uvalue;
extern double wall2Uvalue;
extern double wall3Uvalue;
extern double wall4Uvalue;
extern double wall5Uvalue;
extern double wall6Uvalue;
extern double wall7Uvalue;
extern double wall8Uvalue;
extern double wall9Uvalue;
extern double wall10Uvalue;

//---------------------------------------------
// ROOFS GLOBAL VARIABLES
//---------------------------------------------
extern CString isRoof1Selected;
extern CString isRoof2Selected;
extern CString isRoof3Selected;
extern CString isRoof4Selected;
extern CString isRoof5Selected;
extern CString isRoof6Selected;
extern CString isRoof7Selected;
extern CString isRoof8Selected;
extern CString isRoof9Selected;
extern CString isRoof10Selected;

extern CString roof1Name;
extern CString roof2Name;
extern CString roof3Name;
extern CString roof4Name;
extern CString roof5Name;
extern CString roof6Name;
extern CString roof7Name;
extern CString roof8Name;
extern CString roof9Name;
extern CString roof10Name;

extern CString roof1Construction;
extern CString roof2Construction;
extern CString roof3Construction;
extern CString roof4Construction;
extern CString roof5Construction;
extern CString roof6Construction;
extern CString roof7Construction;
extern CString roof8Construction;
extern CString roof9Construction;
extern CString roof10Construction;

extern double roof1Area;
extern double roof2Area;
extern double roof3Area;
extern double roof4Area;
extern double roof5Area;
extern double roof6Area;
extern double roof7Area;
extern double roof8Area;
extern double roof9Area;
extern double roof10Area;

extern double roof1Uvalue;
extern double roof2Uvalue;
extern double roof3Uvalue;
extern double roof4Uvalue;
extern double roof5Uvalue;
extern double roof6Uvalue;
extern double roof7Uvalue;
extern double roof8Uvalue;
extern double roof9Uvalue;
extern double roof10Uvalue;

//---------------------------------------------------
// VENTILATION GLOBAL VARIABLES
//---------------------------------------------------
extern CString designAirPermeability;
extern CString pressureTestScotland;
extern CString accreditedDetailsScotland;
extern CString seekExemptionForLT3Dwellings;

extern double designAirPermRate;
extern double asBuiltAirPermRate;

extern CString airPermMeasuredInDwelling;
extern CString asBuiltRef;
extern CString asBuiltTestDate;

extern CString mechVentType;
extern CString mechVentValuesFrom;
extern CString numsWetRooms;
extern CString ductInsulation;

extern int numsOpenFirePlaces;
extern int numsOpenFlues;
extern int numsFluelessGasFires;

extern int numsExtractFans;
extern int numsPassiveVents ;

extern CString isACPresent;
extern double ACEnergyUse;

extern CString pressureTestYN;
extern double measuredQ50;
extern int numOfStoreys;
extern double structInf;
extern double floorInf;
extern CString draughtLobby;
extern int perWindowDraughtStripped;

extern double dewllingVolume;
extern double infiltration_rate;
extern double infiltration_rate18;
extern double shelterFactor;
extern double infiltrationRateWithshelterFactor;
extern double infliltrationOpenings;
extern double additionalInfiltration;
extern double windowInfiltration;
extern int numOfShelteredSides;
extern double totalWindSpeed;
extern double totalWindFactor;
extern double effInfiltrationRate;
extern double achThrougSystem;
extern double valueIfExhaustAirHP;
extern double valueIfBalancedHR;
extern double effectiveACH;
extern double effectiveACH_MVHR ;
extern double achMVHR1;
extern double achMVHR2;

extern double spaceHeatingDemandMVHR1;
extern double spaceHeatingDemandMVHR2;
//---------------------------------------------------------
// MAIN HEATING GLOBAL VARIABLES
//---------------------------------------------------------
extern CString electricityTarrif;
extern CString mainHtType;
extern CString mainHtEffFrom;
extern CString boilerRef;
extern CString boilerModel;
extern CString boilerType;
extern CString mainFuel;
extern CString isSecBoilerFuelPresent;
extern CString isFanFluePresent;
extern CString mainHtSystem;
extern CString mainHtControls;
extern CString mainHtEmitter;
extern CString isIterlockPresent;
extern CString mainHtCompensator;
extern CString isPumpInHeatedSpace;
extern CString mainHtManufacturerDesc;
extern CString mainHtTestMethod;
extern double mainHtEff;

extern double mainHtEffNominal; //edit by min 20140303

extern double mainHtEffAdj;
extern double mainHtTempAdj;
extern double mainHtFractionSupplied;
extern bool is_enhanced_load_compensator;
extern bool is_under_floor_system;

//--------------------------------------------------------
// MAIN HEATING DETAILS GLOBAL VARIABLES
//--------------------------------------------------------
extern CString oilPumpInHeatedSpace;
extern CString oilBoilerInstalled;

extern double CPSUoperatingTemp;
extern double heatEmmFromCase;
extern double heatTransferredToWater;

extern CString smokeControlledArea;
extern CString isThereCHP;
extern CString CHPfuel;

extern double fractOfHtFromCHP;
extern double elecEffOfCHP;
extern double heatingEffOfCHP;

extern CString secComBoilerFuel;
extern CString secComBoilerSystem;

extern double secComBoilerEff;
extern double secComBoilerFractOfHtFromBoiler2;
extern CString secComBoilerManufactDesc;

//------------------------------------------------------
// SEC HEATING GLOBAL VARIABLES
//------------------------------------------------------
extern CString isThereSecHeating;
extern CString secHtOpenFlueChimney;
extern CString secHtUnconnectedGasPoint;
extern CString secHtEffFrom;
extern CString secHtFuel;
extern CString secHtSystem;
extern CString secHtManufactDesc;
extern CString secHtTestMethod;
extern double secHtEff;
extern double secHtFraction;

extern double spaceHeatingEffAdj;
extern double waterHeatingEffAdj;


//----------------------------------------------
// WATER HEATING GLOBAL VARIABLES
//----------------------------------------------
extern CString WHtype;
extern CString WHtCylinderWithinDwelling;
extern CString WHtFuel;
extern CString WHtWaterSepTimed;

extern CString WHtCylManufactLossFactor;
extern double WHtCylDeclaredFactor;
extern double WHtCylVolume;

extern CString WHtCylInsType;
extern double WHtCylInsThickness;
extern CString WHtCylThermostat;
extern CString WHtCylInHeatedSpace;
extern CString WHtCylPrimaryPipeworkInsulated;
extern CString WHtCylPumpedPrimarySystem;
extern double WHtEff;
extern double WHtEffAdj;

extern CString WHtTSnCPSUinSingleUnit;
extern CString WHtTSnCPSUPrimaryPipeworkLT1_5m;
extern CString WHtTSnCPSUstoreInAirCupbrd;

extern CString WHtCombiKeepHotYN;
extern CString WHtCombiKeepHotUsesElec;
extern double WHtCombiPowerRating;

extern CString DHWfromCommunityScheme;
extern CString DHWComSchemeProvidedFrom;
extern double DHWComSchemeCHP2PowerRatio;
extern CString DHWComSchemeSystem;
extern double DHWComSchemeEff;

extern CString WHtHeatPumpUsesImmer;
extern CString WHtUsesSummerImmer;

//---------------------------------------------------------
// GLOBAL VARIABLES FOR MULTISCALING
//---------------------------------------------------------
extern int numOfDwellings;
extern CString caseOfDwellings;

//---------------------------------------------------------
// RENEWABLES GLOBAL VARIABLES
//---------------------------------------------------------
extern CString isSHWPresent;
extern CString SHWCollectorType;
extern CString SHWCollectorOrientation;
extern CString SHWCollectorTilt;
extern CString SHWOvershading;
extern CString isSHWAreaGross;

extern double SHW_overshadingFactor;
extern double SHWApertureArea;
extern double SHW_ZLCE;
extern double SHW_HeatLossCoefficient;
extern double SHW_annualSolarRadiation_pm2 ;
extern double SHW_collectorPerformanceRatio;
extern double SHW_solarEnergyAvailable;
extern double SHW_apertureArea;
extern double SHW_solarToLoadRatio;
extern double SHW_collectorPerformanceFactor;
extern double SHW_utilizationFactor;
extern double N_OCC;
extern double SHW_annualHotWaterUsage;
extern double SHW_dailyHotWaterDemand_litres;
extern double SHW_volumeRatio;
extern double SHW_dedicatedSolarStorageVolumeFactor;
extern double SHW_annualSolarInput;

extern CString isSHWSolarStoreCombined;
extern double SHWDedSolStoreVol;
extern double SHW_effectiveSolarVolume;
extern CString SHWSolarCircPump;


extern CString isRENAdditionalElectGenerated;

extern double RENAddiationalElecGenerated;
extern double REN_TFA;

extern CString isPVPresent;

extern double installedPVPeakPower;

extern CString PVCollectorOrientation;
extern CString PVCollectorTilt;
extern CString PVOvershading;
extern double PV_overshadingFactor;
extern double PV_annualSolarRadiation_pm2;
extern CString isWTPresent;

extern int WTNumOf;
extern double WTDiameter;
extern double WTHeight;
extern double WTs3;

extern CString uHydroyn;
extern CString uCHPyn;
extern CString MVHRyn;

extern double uHydroAnnualAvgHead;
extern double uHydroAnnualAvgFlow;
extern double uHydroEff;
extern double uHydroAnnualEnergy;

extern double uCHPheatToPowerRatio;
extern double uCHPElectricEff;
extern CString CHPFuel;
extern double uCHPHeatingEff;
extern double uCHPHeatingFraction;
extern double uCHPAnnualElectricity;

extern CString FGHRSpresent;
extern CString FGHRSstore;
extern double  FGHRSstoreVolume;
extern double  FGHRSusefulFracHtRec_kf1;
extern CString FGHRSfittedMain;
extern CString FGHRSfittedSec;
extern CString FGHRStype;
extern CString determineFGHRStype;
extern double  FGHRStotFracHeatRec_kf2;
extern double  FGHRSauxelec;
extern CString FGHRSpvPoweredHt;
extern double  FGHRSpvPkPower;
extern CString FGHRSpvOrientation;
extern CString FGHRSpvTilt;
extern CString FGHRSpvOvershading;
extern double  FGHRScableLoss;

extern CString WWHRSpresent;
extern CString WWHRS1Make;
extern CString WWHRS1Model;
extern CString WWHRS1ModelQualifier;

extern int WWHRSnumOfRooms;
extern int WWHRSnumMixerShowersWithBath1;
extern int WWHRSnumMixerShowersWithoutBath1;

extern CString WWHRS2Make;
extern CString WWHRS2Model;
extern CString WWHRS2ModelQualifier;
extern int WWHRSnumMixerShowersWithBath2;
extern int WWHRSnumMixerShowersWithoutBath2;


// Misc variables used in calculations
extern double WWHRS_savings;
extern double FGHRS_saving;
extern double FGHRS_PVinput;

extern CString versionText;
extern CString titleBarText;

extern double MVHRThermalEff;
extern double lambda;
extern bool is_mvhr_eff_changed;
extern bool is_spf_changed;

// Factor for LZCT
extern double B_PV;
extern double B_WT;
extern double B_uHydro;
extern double B_uCHP;
extern double annualEnergy_PV;
extern double WTsupplyInput;
extern double uHydrosupplyInput;
extern double uCHPsupplyInput;

extern double LZCT_elecDisplaced;
extern double LZCT_elecSold;
extern double totalElectricalSupply;
//-------------------------------------------------------
// LIGHTS GLOBAL VARIABLES
//-------------------------------------------------------
extern double fractionLEL;
extern int IntLightsStdFittings;
extern int IntLightsDedicatedLowEnergy;
extern int IntLightsNonDedicatedLowEnergy;
extern int IntLightsTotal;

extern CString ExtLightsAssess;
extern CString ExtLightsFittingGT40Lumens;
extern CString ExtLightsLampsNGT150W;


//-------------------------------------------------
// THERMAL BRIDGES Global Variables
//-------------------------------------------------
extern double ThermBGFPerimeter;
extern double ThermBFloorWithingDwellinPerimeter;
extern double ThermBFloorBetweenDwellinPerimeter;
extern double ThermBBalconyWithingDwellingLength;
extern double ThermBBalconyBetweenDwellingLength;
extern double ThermBEavesAtCeiling;
extern double ThermBEavesAtRafter;
extern double ThermBGableAtCeiling;
extern double ThermBGableAtRafter;
extern double ThermBLengthNormalCorners;
extern double ThermBLengthInvertedCorners;
extern double ThermBPartWallBetweenDwelling;
extern double yValueEntry;

extern CString ThermBMetalBoxLintelUserDef;
extern CString ThermBOtherLintelUserDef;
extern CString ThermBSillUserDef;
extern CString ThermBJambUserDef;
extern CString ThermBGFPerimeterUserDef;
extern CString ThermBFloorWithinDwellingUserDef;
extern CString ThermBFloorBwDwellingUserDef;
extern CString ThermBBalcWithinDwellingLengthUserDef;
extern CString ThermBBalcBwDwellingLengthUserDef;
extern CString ThermBEavesInsAtCeilingUserDef;
extern CString ThermBEavesInsAtRafterUserDef;
extern CString ThermBGableInsAtCeilingUserDef;
extern CString ThermBGableInsAtRafetUserDef;
extern CString ThermBLengthOfNormalCornersUserDef;
extern CString ThermBLengthOfInvertedCornersUserDef;
extern CString ThermBPartWallBetweenDwellingUserDef;

extern double ThermBMetalBoxLintelSiValue;
extern double ThermBOtherLintelsSiValue;
extern double ThermBSillSiValue;
extern double ThermBJambSiValue;
extern double ThermBGFPerimeterSiValue;
extern double ThermBFloorWithinDwellingSiValue;
extern double ThermBFloorBetweenDwellingSiValue;
extern double ThermBBalconyWithinDwellingSiValue;
extern double ThermBBalconyBwDwellingSiValue;
extern double ThermBEavesInsAtCelingSiValue;
extern double ThermBEavesInsAtRafterSiValue;
extern double ThermBGableInsAtCeilingSiValue;
extern double ThermBGableInsAtRafterSiValue;
extern double ThermBLengthOfNormalCornersSiValue;
extern double ThermBLengthOfInvertedCornersSiValue;
extern double ThermBPartBwDwellingLengthSiValue;

extern double ThermBMetalBoxLintelResult;
extern double ThermBOtherLintelsResult;
extern double ThermBSillResult;
extern double ThermBJambResult;
extern double ThermBGFPerimeterResult;
extern double ThermBFloorWithinDwellingPerimeterResult;
extern double ThermBFloorBetweenDwellingPerimeterResult;
extern double ThermBBalcWithDwellingLengthResult;
extern double ThermBBalconyBwDwellingLengthResult;
extern double ThermBEavesInsCeilingResult;
extern double ThermBEavesInsRafterResult;
extern double ThermBGableInsCeilingResult;
extern double ThermBGableInsRafterResult;
extern double ThermBLengthNormalCornersResult;
extern double ThermBLengthInvertedCornersResult;
extern double ThermBPartyWallBwDwellingResult;

//---------------------------------------------
// SUMMER OVERHEATING GLOBAL VARIABLES
//---------------------------------------------
extern CString isTMPUserDef;
extern double TMPvalue;
extern CString TMPIntPartConstruction;
extern CString TMPPartyWallConstruction;
extern CString isVentUserDefined;
extern double airChangeRate;
extern CString isCrossVentOnMostFloors;
extern CString windowVentilation;
extern CString areCurtainsClosedDuringDay;
extern double fractCurtainsClosed;
extern CString blindCurtainType;
extern CString sourceUserDefValues;

//----------------------------
//WINDOWS
//----------------------------

extern double totalGlzArea;
extern double winNArea;
extern double winNEArea;
extern double winEArea;
extern double winSEArea;
extern double winSArea;
extern double winSWArea;
extern double winWArea;
extern double winNWArea;

extern double winNSolTrans;
extern double winNESolTrans;
extern double winESolTrans;
extern double winSESolTrans;
extern double winSSolTrans;
extern double winSWSolTrans;
extern double winWSolTrans;
extern double winNWSolTrans;
extern double rooflightsSolTrans;

extern double winNFrameFactor;
extern double winNEFrameFactor;
extern double winEFrameFactor;
extern double winSEFrameFactor;
extern double winSFrameFactor;
extern double winSWFrameFactor;
extern double winWFrameFactor;
extern double winNWFrameFactor;
extern double rooflightsFrameFactor;

extern double rooflightsArea ;
extern CString winOvershading;
extern CString winGlazing;

//---------------------------------------------
// RESULTS
//---------------------------------------------
extern int chkInsulation;
extern int chkAirtightness;
extern int chkCapacity;
extern int chkSolarIngress;
extern int chkOccupancy;
extern int chkControlledSpace;
extern int chkHeatingEff;
extern int chkDHWEff;

extern int chkSDHW;
extern int chkPV;
extern int chkWT;
extern int chkuCHP;
extern int chkuHydro;
extern int chkPCM;
extern int chkMVHR;
extern int chkFGHRS;
extern int chkWWHRS;

extern int chkActual;
extern int	chkperm2;
extern int	chkEnergy;
extern int	chkCost;
extern int	chkEmissions;

extern CString hemHouseType;
extern CString hemYearOfBuild;
extern double propertyFreqOfOccurence;

extern CString hemCoolingFuel;
extern double hemCoolingEff;

extern CString hemX_exposure;
extern CString hemI_insulation;
extern CString hemI_insulation1;
extern CString hemI_insulation2;
extern CString hemA_ach;
extern CString hemC_capacity;
extern CString hemS_solarGains;
extern CString hemO_occupantDensity;
extern CString hemL_livingAreaFraction;
extern CString hemXIACSOL_string;
extern CString hemXIACSOL_string1;
extern CString hemXIACSOL_string2;
extern double hemx_1;
extern double hemx_2;
extern double hemy_1;
extern double hemy_2;
extern double hemTFA;

extern int hemI_insulationSliderPos;
extern int hemA_achSliderPos;
extern int hemC_capacitySliderPos;
extern int hemS_solarGainsSliderPos;
extern int hemO_OCCDensitySliderPos;
extern int hemL_LAFracSliderPos;
extern int hem_HeffSliderPos;
extern int hem_DHWeffSliderPos;

extern double iStat;
extern double dwellingVoulme;
extern double SFP;
extern double auxillaryElectricity;

extern double numOfOccupants;
extern double TFA;
extern double TFAfromHEM;
extern double EB;
extern double C1;
extern double ZL;
extern double gL;
extern double GL_total;
extern double C2;
extern double lightElectricity;

extern double Vd_avg;
extern double DHW_energy;
extern double distributionLoss;
extern double winterOpTemp;
extern double tempFactor;
extern double storageLoss;
extern double lossFactor;
extern double tankVolume;
extern double volumeFacor;
extern double heatLossFactor;
extern double srorageLoss;
extern double primaryCircuitLoss;
extern double F_u;
extern double combiLoss;
extern double solarDHWInput;
extern double pvSupplyInput;
extern double DHWspaceHeatingGain;
extern double usefulStorageLoss;
extern bool isCylinderPresent;
extern double domesticHotWaterSupply;
extern double spaceHeatingDemand;
extern int btnWaterHtFromMainState;
extern double totalRenElecSupply;
extern double totalRenElecSupply_fuelCost;
extern double totalRenElecSupply_Emm;
extern double totalRenElecSupply_PrimEnergyFactor;

extern bool display_msg_only_once;
extern bool display_CPSUmsg_only_once;
extern int enterYValue;

extern double mainSpaceHtSupply;
extern double secSpaceHtSupply;
extern double totalSpaceHtSupply;
extern double totalSpaceCoolingSupply;

extern double totalEnergy;
extern double totalCost;
extern double totalEmissions;
extern double totalPrimaryEnergy;

extern double mainSpaceHtSupply_fuelCost;
extern double secSpaceHtSupply_fuelCost;
extern double domesticHotWaterSupply_fuelCost;
extern double auxillaryElectricity_fuelCost;
extern double lightElectricity_fuelCost;
extern double totalSpaceCoolingSupply_fuelCost;
extern double  LZCT_elecSold_fuelCost;
extern double  LZCT_elecDisp_fuelCost;
extern double primaryFuelUsed_fuelCost;
extern double secFuelUsed_fuelCost;

extern double mainSpaceHtSupply_Emm;
extern double secSpaceHtSupply_Emm;
extern double domesticHotWaterSupply_Emm;
extern double auxillaryElectricity_Emm;
extern double lightElectricity_Emm;
extern double totalSpaceCoolingSupply_Emm;
extern double  LZCT_elecSold_Emm;
extern double  LZCT_elecDisp_Emm;
extern double primaryFuelUsed_Emm;
extern double secFuelUsed_Emm;


extern double mainSpaceHtSupply_PrimEnergyFactor;
extern double secSpaceHtSupply_PrimEnergyFactor;
extern double domesticHotWaterSupply_PrimEnergyFactor;
extern double auxillaryElectricity_PrimEnergyFactor;
extern double lightElectricity_PrimEnergyFactor;
extern double totalSpaceCoolingSupply_PrimEnergyFactor;
extern double  LZCT_elecSold_PrimEnergyFactor;
extern double  LZCT_elecDisp_PrimEnergyFactor;

extern double totalSpaceHtSupply_Disp;
extern double totalSpaceCoolingSupply_Disp;
extern double domesticHotWaterSupply_Disp;
extern double lightElectricity_Disp;
extern double auxillaryElectricity_Disp;
extern double totalElectricalSupply_Disp;
extern double mainSpaceHtSupply_Disp;
extern double secSpaceHtSupply_Disp;
extern double LZCTelecSold_Disp;
extern double LZCTelecDisp_Disp;
extern double primaryFuelUsed_Disp;
extern double secFuelUsed_Disp;

//---------------------------------------------
// GLOBAL VARIABLES FOR TC ID
//---------------------------------------------
extern bool ifReadFRDBfile;
extern bool fReadSAPcalcsFile;

// Create index number to read data from frdb.csv file
extern CString X_exposure;
extern CString I_insulation;
extern CString I_insulation1;
extern CString I_insulation2;
extern CString A_ach;
extern CString A_ach_MVHR1;
extern CString A_ach_MVHR2;
extern CString C_capacity;
extern CString S_solarGains;
extern CString O_occupantDensity;
extern CString L_livingAreaFraction;
extern CString XIACSOL_string;
extern CString XIACSOL_string1;
extern CString XIACSOL_string2;
extern double x_1;
extern double x_2;
extern double y_1;
extern double y_2;

// String for user display
extern CString XIACSOL_string_disp;
extern CString XIACSOL_string_disp1;
extern CString XIACSOL_string_disp2;

//---------------------------------
// Living room fraction limits
extern double L_limit1;
extern double L_limit2;
extern double L_limit3;
extern double L_limit4;
extern double L_limit5;

//---------------------------------
// Living room fraction range
extern double L_range1;
extern double L_range2;
extern double L_range3;
extern double L_range4;
extern double L_range5;

//---------------------------------
// Occupant density limits
extern double O_limit1;
extern double O_limit2;
extern double O_limit3;
extern double O_limit4;
extern double O_limit5;

//---------------------------------
// Occupant density range
extern double O_range1;
extern double O_range2;
extern double O_range3;
extern double O_range4;
extern double O_range5;

//---------------------------------
// Solar gains limits
extern double S_limit1;
extern double S_limit2;
extern double S_limit3;

//---------------------------------
// Solar gains range
extern double S_range1;
extern double S_range2;
extern double S_range3;

//---------------------------------
// Capacity limit
extern double C_limit;

//---------------------------------
// Air change per hour limits
extern double A_limit1;
extern double A_limit2;
extern double A_limit3;
extern double A_limit4;
extern double A_limit5;

//---------------------------------
// Air change per hour range
extern double A_range1;
extern double A_range2;
extern double A_range3;
extern double A_range4;
extern double A_range5;

//---------------------------------
// Insulation limits // DUMMY VALUES USED
extern double I_limit1;
extern double I_limit2;
extern double I_limit3;
extern double I_limit4;
extern double I_limit5;

//---------------------------------
// Insulation range 
extern double I_range1;
extern double I_range2;
extern double I_range3;
extern double I_range4;
extern double I_range5;

//---------------------------------
// Exposure limits 
extern double X_limit1;
extern double X_limit2;
extern double X_limit3;
extern double X_limit4;
extern double X_limit5;

//---------------------------------
// Exposure range 
extern double X_range1;
extern double X_range2;
extern double X_range3;
extern double X_range4;
extern double X_range5;

//---------------------------------
// Misc variables used in ach calc
extern int numOfChimneys_multip;
extern int numOfFlues_multip;  
extern int numOfFansPassVents_multip; 
extern int numOfFluelessGasFires_multip;

extern int numOfChimneys_m3perh;
extern int	numOfFlues_m3perh;
extern int	numOfFansPassVents_m3perh;
extern int	numOfFluelessGasFires_m3perh;

extern double total_solarGains;

//---------------------------------------------
// VIEW OPENINGS FOR WALL ROOF
//---------------------------------------------
extern CString WallRoofOpeningName;

//---------------------------------------------
// AREAS & U-VALUES
//---------------------------------------------

extern double grossAreaWall1;
extern double groosAreaRoof1;
extern double netAreaDoors;
extern double netAreaWindows;
extern double netAreaRoofLights;
extern double netAreaGF;
extern double netAreaExFloor;
extern double netAreaWallType1;
extern double netAreaWallType2;
extern double netAreaRoofType1;
extern double netAreaRoofType2;
extern double netAreaPartyWall;
extern double netAreaPartyFloor;
extern double netAreaPartyCeiling;
extern double netAreaInternalWall;
extern double netAreaInternalFloor;
extern double netAreaInternalCeiling;

extern double UvalueDoors;
extern double UvalueWindows;
extern double UvalueRooflights;
extern double UvalueGF;
extern double UvalueExposedFloor;
extern double UvalueWallType1;
extern double UvalueWallType2;
extern double UvalueRoofTYpe1;
extern double UvalueRoofType2;
extern double UvaluePartyWall;

extern double kValueGF;
extern double kValueExpFloor;
extern double kValueWallType1;
extern double kValueWallType2;
extern double kValueRoofType1;
extern double kValueRoofType2;
extern double kValuePartyWall;
extern double kValuePartyFloor;
extern double kValuePartyCeiling;
extern double kValueIntWall;
extern double kValueIntFloor;
extern double kValueIntCeiling;


extern bool is_climate_changed_from_results;
extern bool is_house_type_changed_from_results;
extern bool is_year_of_build_changed;
extern bool is_make_eff_adjustments_slider_insulation;
extern bool is_make_eff_adjustments_slider_exposure;
extern bool is_make_eff_adjustments_slider_airChanges;
extern bool is_make_eff_adjustments_slider_capacity;
extern bool is_make_eff_adjustments_slider_occupancy;
extern bool is_make_eff_adjustments_slider_livingArea;
extern bool is_make_eff_adjustments_slider_solarIngress;
extern double thermalMassParameter;
extern double livingRoomFraction;
extern double extAreaSum;
extern double exposureValue;
extern double extInsulationValue;
extern double extUvalueXareaSum;
extern double hem_extInsulationValue;
extern double hem_extAreaSum;
extern double hem_extUvalueXareaSum;

extern int addOpening;
extern CString newOpeningName;
extern bool enable_user_to_change_tab;
extern bool is_new_opeing_added;
extern bool file_new_selected;
extern bool TFA_from_HEM;
extern bool yValue_from_HEM;

typedef struct
{
	char openingName[500];
	char openingFromSource[500];
	char openingDescription[500];
	char openingGlzType[500];
	char openingLowECoating[500];
	char openingUsedDefEmissivity[500];
	double openingEmissivty; //7

	char openingArgonFilled[500];
	char openingGap[500];
	double openingPitch; 
	char openingOrientation[500];
	char openingOvershading[500]; //12

	double openingWidth;
	double openingHeight;
	char openingLocationName[500];
	double openingOverhangDepth;
	double openingOverhangWidth; //17

	char openingRef[500];
	char openingLinkageMaster[500];
	char openingLinkedTo[500]; //20

	char openingFrame[500];
	char openingThermalBreak[500];
	char openingDraughtProofing[500];
	char openingMetalLintel[500];//24

	char openingTransmittanceSelected[500];
	double openingTransmittanceFactor;//26

	char openingFrameSelected[500];
	double openingFrameFactor; // 28

	char openingUvalueSelected[500];
	double openingUvalue; //30
}openingListData;

typedef struct
{
	char openingName[500];
	char parentSurface[500];
	int multipier;
}openingsData;


typedef struct
{
	char fuelType[50];
	char systemType[500];
	int effeciency;
}secHtSysData;


typedef struct
{
	char boilerRef[15];
	char boilerModel[500];
	double effeciency;
}SAPboilers;

typedef struct
{
	char fuelType[50];
	char tariff[15];
	double unitPrice;
	double emissions;
	double primaryEnergyFactor;
}SAPcostTable;


extern vector <openingsData> openingsData_New;
extern vector <openingListData> openingListData_New;
extern vector <secHtSysData> secHtSysData_New;
extern vector <SAPboilers> SAPboilers_db;
extern vector <SAPcostTable> SAPcostTable_New;

// CO2 emission factors (SAP2009)
#define CO2_MAIN_GAS		 0.198
#define CO2_LPG				 0.254
#define CO2_OIL				 0.274
#define CO2_HOUSE_COAL		 0.301
#define CO2_ANTHRACITE		 0.318
#define CO2_WASTE_COMBUSTION 0.040
#define CO2_WOOD_LOGS		 0.008
#define CO2_WOOD_CHIPS		 0.009
#define CO2_WOOD_PALLETS	 0.028
#define CO2_BIOGAS			 0.018
#define CO2_WASTE_HEAT		 0.058
#define CO2_GEO_HEAT_SOURCE  0.036
#define CO2_UNKNOWN			 0.198

extern bool results_dialog_read_first_time;
extern bool if_change_house_type;
extern bool if_change_flat_type;

extern CString projectFileName;
extern CString projectFileNameNoPath;
extern CString projectFileNameNoExt;

extern int fileFound;
extern int baseSelected;
extern int imp1Selected;
extern int imp2Selected;
extern int imp3Selected;
extern int imp4Selected;
extern int imp5Selected;

extern bool is_file_opened_if_changing_tabs;
extern bool is_file_opened;
extern bool is_results_values_read_first_time;
extern bool is_base_selected;
extern bool is_imp1_selected;
extern bool is_imp2_selected;
extern bool is_imp3_selected;
extern bool is_imp4_selected;
extern bool is_imp5_selected;

extern bool is_base_changed;
extern bool is_imp1_changed;
extern bool is_imp2_changed;
extern bool is_imp3_changed;
extern bool is_imp4_changed;
extern bool is_imp5_changed;

extern bool is_base_saved;
extern bool is_imp1_saved;
extern bool is_imp2_saved;
extern bool is_imp3_saved;
extern bool is_imp4_saved;
extern bool is_imp5_saved;


extern bool display_base_results;
extern bool display_imp1_results;
extern bool display_imp2_results;
extern bool display_imp3_results;
extern bool display_imp4_results;
extern bool display_imp5_results;

extern int tabCtrlProjects;
extern int currentProjectTabPosition;

extern bool is_ins_slider_moved_due_to_house_type_change;
extern bool is_ins_slider_moved_due_to_year_bilud_change;

//--------------------------------------------------------
// Create a structure that holds all variables Estate data
//--------------------------------------------------------
typedef struct 
{
	//---------------------------------------------------------
	// VARIABLES FOR MULTISCALING
	//---------------------------------------------------------
	int numOfDwellings;
	CString caseOfDwellings;
	CString projectFileNameNoPath;
	CString	projectFileName;
	CString projectFileNameNoExt;
	CString XIACSOL_string1;
	CString XIACSOL_string2;

	double TFA;

	double DHWspaceHeatingGain;
	double usefulStorageLoss;

	double totalSpaceHtSupply;
	double totalSpaceCoolingSupply;
	double domesticHotWaterSupply;
	double lightElectricity;
	double auxillaryElectricity ;
	double totalElectricalSupply;
	double mainSpaceHtSupply;
	double secSpaceHtSupply;
	double LZCT_elecSold;
	double LZCT_elecDisplaced;
	double primaryFuelUsed;
	double secFuelUsed;	

	double mainSpaceHtSupply_Emm ;
	double secSpaceHtSupply_Emm;
	double totalSpaceCoolingSupply_Emm;
	double domesticHotWaterSupply_Emm;
	double lightElectricity_Emm;
	double auxillaryElectricity_Emm;
	double LZCTelecSold_Emm;
	double LZCTelecDisp_Emm;
	double primaryFuelUsed_Emm;
	double secFuelUsed_Emm;

	double mainSpaceHtSupply_fuelCost;
	double secSpaceHtSupply_fuelCost;
	double totalSpaceCoolingSupply_fuelCost;
	double domesticHotWaterSupply_fuelCost;
	double lightElectricity_fuelCost;
	double auxillaryElectricity_fuelCost;
	double LZCTelecSold_fuelCost;
	double LZCTelecDisp_fuelCost;
	double primaryFuelUsed_fuelCost;
	double secFuelUsed_fuelCost;
}EstateData;

extern vector <EstateData> EstateDataValues;
extern vector <EstateData> EstateDataValuesBase;
extern vector <EstateData> EstateDataValuesImp1;
extern vector <EstateData> EstateDataValuesImp2;
extern vector <EstateData> EstateDataValuesImp3;
extern vector <EstateData> EstateDataValuesImp4;
extern vector <EstateData> EstateDataValuesImp5;

extern bool add_dwelling_to_estate;
extern bool chk_if_project_saved;
extern bool file_already_opened;
extern bool is_save_dialg_called;

// These variables wil be used to calculate primary fuel
extern double primaryFuelUsed;
extern double secFuelUsed;
extern double mainGasTotalFuel;
extern double LPGTotalFuel;
extern double botGasTotalFuel;
extern double oilTotalFuel;
extern double houseCoalTotalFuel;
extern double smokelessTotalFuel;
extern double anthraciteTotalFuel;
extern double woodLogsTotalFuel;
extern double woodchipsTotalFuel;
extern double woodPelletsTotalFuel;
extern double dualFuelTotalFuel;
extern double electricityTotalFuel;
extern CString primaryFuelUsedString;
extern CString secFuelUsedString;
extern int lastTabNumber;
extern void SetAllValuesToDefault();
extern void WriteSHCSDataToDialogs();
extern void RangeCheckFunction(double lowerLimit, double upperLimit, double number);
extern void DisplayWarningMessages();

// Flags for RangeCheckFunction

// Overview dilaog
extern bool isCheckRange_TFA;
extern bool isCheckRange_costOfImprovement;

// Built form dialog
extern bool isCheckRange_areaStorey1;
extern bool isCheckRange_areaStorey2;
extern bool isCheckRange_areaStorey3;
extern bool isCheckRange_areaStorey4;
extern bool isCheckRange_areaStorey5;
extern bool isCheckRange_areaStorey6;

extern bool isCheckRange_heightStorey1;
extern bool isCheckRange_heightStorey2;
extern bool isCheckRange_heightStorey3;
extern bool isCheckRange_heightStorey4;
extern bool isCheckRange_heightStorey5;
extern bool isCheckRange_heightStorey6;

// Windows dialog
extern bool isCheckRange_winNArea;
extern bool isCheckRange_winNEArea;
extern bool isCheckRange_winEArea;
extern bool isCheckRange_winSEArea;
extern bool isCheckRange_winSArea;
extern bool isCheckRange_winSWArea;
extern bool isCheckRange_winWArea;
extern bool isCheckRange_winNWArea;
extern bool isCheckRange_rooflightsArea;

extern bool isCheckRange_winNSolTrans;
extern bool isCheckRange_winNESolTrans;
extern bool isCheckRange_winESolTrans;
extern bool isCheckRange_winSESolTrans;
extern bool isCheckRange_winSSolTrans;
extern bool isCheckRange_winSWSolTrans;
extern bool isCheckRange_winWSolTrans;
extern bool isCheckRange_winNWSolTrans;
extern bool isCheckRange_rooflightsSolTrans;

extern bool isCheckRange_winNFrameFactor;
extern bool isCheckRange_winNEFrameFactor;
extern bool isCheckRange_winEFrameFactor;
extern bool isCheckRange_winSEFrameFactor;
extern bool isCheckRange_winSFrameFactor;
extern bool isCheckRange_winSWFrameFactor;
extern bool isCheckRange_winWFrameFactor;
extern bool isCheckRange_winNWFrameFactor;
extern bool isCheckRange_rooflightsFrameFactor;

extern bool isCheckRange_fractionLEL;

// Area and u-Value dialog
extern bool isCheckRange_grossAreaWall1;
extern bool isCheckRange_groosAreaRoof1;
extern bool isCheckRange_netAreaDoors;
extern bool isCheckRange_netAreaWindows;
extern bool isCheckRange_netAreaRoofLights;
extern bool isCheckRange_netAreaGF;
extern bool isCheckRange_netAreaExFloor;
extern bool isCheckRange_netAreaWallType1;
extern bool isCheckRange_netAreaWallType2;
extern bool isCheckRange_netAreaRoofType1;
extern bool isCheckRange_netAreaRoofType2;
extern bool isCheckRange_netAreaPartyWall;
extern bool isCheckRange_netAreaPartyFloor;
extern bool isCheckRange_netAreaPartyCeiling;
extern bool isCheckRange_netAreaInternalWall;
extern bool isCheckRange_netAreaInternalFloor;
extern bool isCheckRange_netAreaInternalCeiling;

extern bool isCheckRange_UvalueDoors;
extern bool isCheckRange_UvalueWindows;
extern bool isCheckRange_UvalueRooflights;
extern bool isCheckRange_UvalueGF;
extern bool isCheckRange_UvalueExposedFloor;
extern bool isCheckRange_UvalueWallType1;
extern bool isCheckRange_UvalueWallType2;
extern bool isCheckRange_UvalueRoofTYpe1;
extern bool isCheckRange_UvalueRoofType2;
extern bool isCheckRange_UvaluePartyWall;

extern bool isCheckRange_kValueGF;
extern bool isCheckRange_kValueExpFloor;
extern bool isCheckRange_kValueWallType1;
extern bool isCheckRange_kValueWallType2;
extern bool isCheckRange_kValueRoofType1;
extern bool isCheckRange_kValueRoofType2;
extern bool isCheckRange_kValuePartyWall;
extern bool isCheckRange_kValuePartyFloor;
extern bool isCheckRange_kValuePartyCeiling;
extern bool isCheckRange_kValueIntWall;
extern bool isCheckRange_kValueIntFloor;
extern bool isCheckRange_kValueIntCeiling;

// Thermal bridge dialog
extern bool isCheckRange_yValueEntry;
extern bool isCheckRange_ThermBGFPerimeter;
extern bool isCheckRange_ThermBFloorWithingDwellinPerimeter;
extern bool isCheckRange_ThermBFloorBetweenDwellinPerimeter;
extern bool isCheckRange_ThermBBalconyWithingDwellingLength;
extern bool isCheckRange_ThermBBalconyBetweenDwellingLength;
extern bool isCheckRange_ThermBEavesAtCeiling;
extern bool isCheckRange_ThermBEavesAtRafter;
extern bool isCheckRange_ThermBGableAtCeiling;
extern bool isCheckRange_ThermBGableAtRafter;
extern bool isCheckRange_ThermBLengthNormalCorners;
extern bool isCheckRange_ThermBLengthInvertedCorners;
extern bool isCheckRange_ThermBPartWallBetweenDwelling;

extern bool isCheckRange_ThermBMetalBoxLintelSiValue;
extern bool isCheckRange_ThermBOtherLintelsSiValue;
extern bool isCheckRange_ThermBSillSiValue;
extern bool isCheckRange_ThermBJambSiValue;
extern bool isCheckRange_ThermBGFPerimeterSiValue;
extern bool isCheckRange_ThermBFloorWithinDwellingSiValue;
extern bool isCheckRange_ThermBFloorBetweenDwellingSiValue;
extern bool isCheckRange_ThermBBalconyWithinDwellingSiValue;
extern bool isCheckRange_ThermBBalconyBwDwellingSiValue;
extern bool isCheckRange_ThermBEavesInsAtCelingSiValue;
extern bool isCheckRange_ThermBEavesInsAtRafterSiValue;
extern bool isCheckRange_ThermBGableInsAtCeilingSiValue;
extern bool isCheckRange_ThermBGableInsAtRafterSiValue;
extern bool isCheckRange_ThermBLengthOfNormalCornersSiValue;
extern bool isCheckRange_ThermBLengthOfInvertedCornersSiValue;
extern bool isCheckRange_ThermBPartBwDwellingLengthSiValue;

// Ventilation dialog
extern bool isCheckRange_numsOpenFirePlaces;
extern bool isCheckRange_numsOpenFlues; 
extern bool isCheckRange_numsFluelessGasFires;
extern bool isCheckRange_numsExtractFans;
extern bool isCheckRange_numsPassiveVents;

extern bool isCheckRange_measuredQ50;
extern bool isCheckRange_numOfStoreys;
extern bool isCheckRange_SFP;

// Main heating dialog
extern bool isCheckRange_mainHtEff;
extern bool isCheckRange_mainHtFractionSupplied;

// Secondary heating dilaog
extern bool isCheckRange_secHtEff;
extern bool isCheckRange_secHtFraction;

// Water heating dialog
extern bool isCheckRange_WHtCylDeclaredFactor;
extern bool isCheckRange_WHtCylVolume;
extern bool isCheckRange_WHtCylInsThickness;
extern bool isCheckRange_WHtEff;

// Renewables 1
// SDHW
extern bool isCheckRange_SHWApertureArea;
extern bool isCheckRange_SHW_ZLCE;
extern bool isCheckRange_SHW_HeatLossCoefficient;
extern bool isCheckRange_SHWDedSolStoreVol;

// PV
extern bool isCheckRange_installedPVPeakPower;

// WT
extern bool isCheckRange_WTNumOf;
extern bool isCheckRange_WTDiameter;
extern bool isCheckRange_WTHeight;

// Renewables 2
// uHydro
extern bool isCheckRange_uHydroAnnualAvgHead;
extern bool isCheckRange_uHydroAnnualAvgFlow;
extern bool isCheckRange_uHydroEff;

// uCHP
extern bool isCheckRange_uCHPheatToPowerRatio;
extern bool isCheckRange_uCHPElectricEff;
extern bool isCheckRange_uCHPHeatingEff;
extern bool isCheckRange_uCHPHeatingFraction;

// MVHR
extern bool isCheckRange_MVHRThermalEff;