// SAPP1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "SAPP1Dlg.h"
#include "string.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <vector>

using namespace std;


vector <LineEntryInfo> stringsWithValues;
vector <openingsData> openingsData_New;
vector <openingListData> openingListData_New;
vector <secHtSysData> secHtSysData_New;
vector <SAPboilers> SAPboilers_db;

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

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

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

#define PATH_TO_SEC_HT_EFF_FILE "..\\data\\SecHtEfficiencies.csv"
#define PATH_TO_SAP_BOILER_DB_FILE "SAPBoilers.csv"
//#define PATH_TO_SAP_BOILER_DB_FILE "..\\data\\SAPBoilers.csv"

// CSAPP1Dlg dialog

CSAPP1Dlg::CSAPP1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSAPP1Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSAPP1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TAB1, m_c_TabCtrl);
}

BEGIN_MESSAGE_MAP(CSAPP1Dlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTcnSelchangeTab1)
	ON_COMMAND(ID_FILE_SAVE142, OnFileSave)
	ON_COMMAND(ID_FILE_OPEN143, OnFileOpen)
	ON_COMMAND(ID_FILE_NEW148, OnFileNew)
END_MESSAGE_MAP()


// CSAPP1Dlg message handlers
CString projectFileName;

vector <openingsForDlg> openingsForDlg1;

struct MonthlyValues monthlyNumOfDays;
struct MonthlyValues DHW_monthlyUsage;
struct MonthlyValues DHW_monthlyTempRise;

int addOpening = 0;
CString newOpeningName;
bool is_new_opeing_added = false;

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

//----------------------------------------
// BUILT FORM GLOBAL VARIABLES
//----------------------------------------
CString dwellingType;
CString propertyType;
CString BuiltForm;
CString FlatType;
CString yearPropertBuilt; 

CString degreeDayLocation;
int dwellingShelteredSides = 0;
CString dwellingTerrain;
CString dwellingExposure;

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

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

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

double storey1Area = 0.0;
double storey2Area = 0.0;
double storey3Area = 0.0;
double storey4Area = 0.0;
double storey5Area = 0.0;
double storey6Area = 0.0;

double storey1Height = 0.0;
double storey2Height = 0.0;
double storey3Height = 0.0;
double storey4Height = 0.0;
double storey5Height = 0.0;
double storey6Height = 0.0;

//-----------------------------------------------------
// FLOORS GLOBAL VARIABLES
//-----------------------------------------------------

CString floor1Selected;
CString floor2Selected;
CString floor3Selected;
CString floor4Selected;
CString floor5Selected;
CString floor6Selected;
CString floor7Selected;
CString floor8Selected;
CString floor9Selected;
CString floor10Selected;

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

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

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

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


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

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

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

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

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

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

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

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


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

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

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

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

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

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

double designAirPermRate = 0.0;
double asBuiltAirPermRate = 0.0;

CString airPermMeasuredInDwelling;
CString asBuiltRef;
CString asBuiltTestDate;


CString mechVentType;
double mechVentEff = 0;
CString mechVentValuesFrom;
CString numsWetRooms;
CString ductInsulation;

int numsOpenFirePlaces   = 0;
int numsOpenFlues        = 0;
int numsFluelessGasFires = 0;

int numsExtractFans = 0;
int numsPassiveVents = 0;

CString isACPresent;
double ACEnergyUse = 0.0;

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


//---------------------------------------------------------
// MAIN HEATING GLOBAL VARIABLES
//---------------------------------------------------------
CString electricityTarrif;
CString mainHtType;
CString mainHtEffFrom;
CString boilerRef;
CString boilerModel;
CString boilerType;
CString mainFuel;
CString isSecBoilerFuelPresent;
CString isFanFluePresent;
CString mainHtSystem;
CString mainHtControls;
CString mainHtEmitter;
CString isIterlockPresent;
CString mainHtCompensator;
CString isPumpInHeatedSpace;
CString mainHtManufacturerDesc;
CString mainHtTestMethod;
double mainHtEff = 0.0;
bool is_sec_ht_fraction_from_main = false;


//--------------------------------------------------------
// MAIN HEATING DETAILS GLOBAL VARIABLES
//--------------------------------------------------------
CString oilPumpInHeatedSpace;
CString oilBoilerInstalled;
double CPSUoperatingTemp = 0.0;

double heatEmmFromCase   = 0.0;
double heatTransferredToWater = 0.0;
CString smokeControlledArea;

CString isThereCHP;
CString CHPfuel;
double fractOfHtFromCHP = 0.0;
double elecEffOfCHP = 0.0;
double heatingEffOfCHP = 0.0;

CString secComBoilerFuel;
CString secComBoilerSystem;
double secComBoilerEff = 0.0;
double secComBoilerFractOfHtFromBoiler2 = 0.0;
CString secComBoilerManufactDesc;

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

double spaceHeatingEffAdj;
double waterHeatingEffAdj;

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

CString WHtCylManufactLossFactor;
double WHtCylDeclaredFactor= 0.0;
double WHtCylVolume= 0.0;

CString WHtCylInsType;
double WHtCylInsThickness= 0.0;
CString WHtCylThermostat;
CString WHtCylInHeatedSpace;
CString WHtCylPrimaryPipeworkInsulated;
CString WHtCylPumpedPrimarySystem;

double WHtEff = 0;

CString WHtTSnCPSUinSingleUnit;
CString WHtTSnCPSUPrimaryPipeworkLT1_5m;
CString WHtTSnCPSUstoreInAirCupbrd;

CString WHtCombiKeepHotYN;
CString WHtCombiKeepHotUsesElec;
double WHtCombiPowerRating= 0.0;

CString DHWfromCommunityScheme;
CString DHWComSchemeProvidedFrom;
double DHWComSchemeCHP2PowerRatio= 0.0;
CString DHWComSchemeSystem;
double DHWComSchemeEff= 0.0;

CString WHtHeatPumpUsesImmer;
CString WHtUsesSummerImmer;
CString WHtFGHRSys;



//---------------------------------------------------------
// GLOBAL VARIABLES
//---------------------------------------------------------
CString isSHWPresent;
CString SHWCollectorType;
CString SHWCollectorOrientation;
CString SHWCollectorTilt;
CString SHWOvershading;
CString isSHWAreaGross;
double  SHWGrossArea = 0.0;
double  SHWZLCollectorEff = 0.0;
double  SHWHLCoeff = 0.0;
CString isSHWSolarStoreCombined;
double  SHWDedicatedSolarStoreVolume = 0.0;
CString SHWSolarCircPump;
CString isRENAdditionalElectGenerated;
double  RENAddiationalElecGenerated = 0.0;
double  REN_TFA = 0.0;
CString isPVPresent;
double  installedPVPeakPower = 0.0;
CString PVCollectorOrientation;
CString PVCollectorTilt;
CString PVOvershading;
CString isWTPresent;
int     WTNumOf = 0;
double  WTDiameter = 0.0;
double  WTHeight = 0.0;

//-------------------------------------------------------
// LIGHTS GLOBAL VARIABLES
//-------------------------------------------------------
double fractionLEL  = 0;
int IntLightsStdFittings = 0;
int IntLightsDedicatedLowEnergy = 0;
int IntLightsNonDedicatedLowEnergy = 0;
int IntLightsTotal = 0;

CString ExtLightsAssess;
CString ExtLightsFittingGT40Lumens;
CString ExtLightsLampsNGT150W;

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

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

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

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

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

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

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

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

CString winOvershading;
CString	winGlazing;

//---------------------------------------------
// RESULTS
//---------------------------------------------
double iStat;
double dwellingVoulme;
double SFP;
double auxillaryElectricity;

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

double Vd_avg;
double DHW_energy;
double distributionLoss;
double winterOpTemp = 85;
double tempFactor;
double storageLoss;
double lossFactor;
double tankVolume;
double volumeFacor;
double heatLossFactor;
double srorageLoss;
double primaryCircuitLoss;
double F_u;
double combiLoss;
double solarDHWInput;

int btnWaterHtFromMainState;

double DomHotWater;

bool display_msg_only_once = true;
bool display_CPSUmsg_only_once = true;
int enterYValue = 0;

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

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

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

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

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

double thermalMass;
double livingRoomFraction;


// Function to add space character between two consecutive commas
// This will be used while reading data from csv file to avoid errors
// IMPORTANT: Note strtok() fn FAILS when no character found between two consecutive string tokens
void strSpecialCopy(char *sourceStr, char *destStr)
{
      int i = 0, j = 0;
      char lastChar = 0, currChar = 0; 

      while (sourceStr[i] != NULL)
      {
            currChar = sourceStr[i++];
            if ( (lastChar == ',')  && (currChar == ',') )
            {
                  destStr[j++] = ' ';
            }

            destStr[j++] = currChar;
            lastChar = currChar;   
      }

       destStr[j] = NULL;
}


BOOL CSAPP1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	
	TCITEM tabItem;
	tabItem.mask = TCIF_TEXT;
	

	//--------------------------------------------
	// Set titles for each tab
	//--------------------------------------------
	tabItem.pszText = _T("Job Details");
	m_c_TabCtrl.InsertItem(0,&tabItem);

	tabItem.pszText = _T("Built Form");
	m_c_TabCtrl.InsertItem(1,&tabItem);

	//tabItem.pszText = _T("Floors");
	//m_c_TabCtrl.InsertItem(2,&tabItem);

	//tabItem.pszText = _T("Walls");
	//m_c_TabCtrl.InsertItem(3,&tabItem);

	//tabItem.pszText = _T("Roofs");
	//m_c_TabCtrl.InsertItem(4,&tabItem);

	//tabItem.pszText = _T("Openings");
	//m_c_TabCtrl.InsertItem(5,&tabItem);

	tabItem.pszText = _T("Windows");
	m_c_TabCtrl.InsertItem(2,&tabItem);

	tabItem.pszText = _T("Areas and U-values");
	m_c_TabCtrl.InsertItem(3,&tabItem);

	tabItem.pszText = _T("Therm Bridging");
	m_c_TabCtrl.InsertItem(4,&tabItem);

	tabItem.pszText = _T("Ventilation");
	m_c_TabCtrl.InsertItem(5,&tabItem);

	tabItem.pszText = _T("Main Heating");
	m_c_TabCtrl.InsertItem(6,&tabItem);

	tabItem.pszText = _T("Main Heating Det");
	m_c_TabCtrl.InsertItem(7,&tabItem);

	tabItem.pszText = _T("Sec Heating");
	m_c_TabCtrl.InsertItem(8,&tabItem);

	tabItem.pszText = _T("Water Heating");
	m_c_TabCtrl.InsertItem(9,&tabItem);

	tabItem.pszText = _T("Renewables");
	m_c_TabCtrl.InsertItem(10,&tabItem);

	tabItem.pszText = _T("Lights");
	m_c_TabCtrl.InsertItem(11,&tabItem);	

	tabItem.pszText = _T("Summer Overheating");
	m_c_TabCtrl.InsertItem(12,&tabItem);

	tabItem.pszText = _T("Results");
	m_c_TabCtrl.InsertItem(13,&tabItem);

	

	//--------------------------------------------
	// Create all dialogs at start up. 
	// Display only the first dialog
	//--------------------------------------------
	m_JobDetails = new CDlg_JobDetails;
	m_JobDetails->Create(IDD_JOBDETAILS,this);
	m_JobDetails->ShowWindow(SW_SHOW);
	
	m_BuiltForm = new CDlg_BuiltForm;
	m_BuiltForm->Create(IDD_BUILTFORM,this);	

	//m_Floors = new CDlg_Floors;
	//m_Floors->Create(IDD_FLOORS,this);	

	//m_Openings = new CDlg_Openings;
	//m_Openings->Create(IDD_OPENINGS,this);

	//m_Roofs = new CDlg_Roofs;
	//m_Roofs->Create(IDD_ROOFS,this);

	//m_Walls = new CDlg_Walls;
	//m_Walls->Create(IDD_WALLS,this);
	m_ThermalBridging = new CDlg_ThermalBridging ;
	m_ThermalBridging ->Create(IDD_THERMALBRIDGING,this);	
    
	m_Ventilation = new CDlg_Ventilation;
	m_Ventilation->Create(IDD_VENTILATION,this);

	m_MainHeating = new CDlg_MainHeating;
	m_MainHeating->Create(IDD_MAINHEATING,this);

	m_MainHeatingDetails = new CDlg_MainHeatingDetails;
	m_MainHeatingDetails->Create(IDD_MAINHEATINGDETAILS,this);

	m_SecHeating = new CDlg_SecHeating;
	m_SecHeating->Create(IDD_SECONDARYHEATING,this);

	m_WaterHeating = new CDlg_WaterHeating;
	m_WaterHeating->Create(IDD_WATERHEATING,this);

	m_Renewables = new CDlg_Renewables ;
	m_Renewables ->Create(IDD_RENEWABLES,this);

	m_LightsAndAppliances = new CDlg_LightsAndAppliances ;
	m_LightsAndAppliances ->Create(IDD_LIGHTSANDAPPLIANCES,this);

	m_SummerOverHeating = new CDlg_SummerOverHeating ;
	m_SummerOverHeating ->Create(IDD_SUMMEROVERHEATING,this);	

	m_Results= new CDlg_Results ;
	m_Results ->Create(IDD_RESULTS,this);	

	m_Windows= new CDlg_Windows ;
	m_Windows ->Create(IDD_WINDOWS,this);

	m_AreaAndUvalues= new CDlg_AreaAndUvalues ;
	m_AreaAndUvalues ->Create(IDD_AREAUVALUES,this);

	
	//--------------------------------------------------------------------
	// Destroy all dialogs except first 
	//--------------------------------------------------------------------

	m_BuiltForm->DestroyWindow();
	delete m_BuiltForm;
	m_BuiltForm=NULL;

	//m_Floors->DestroyWindow();
	//delete m_Floors;
	//m_Floors=NULL;

	//m_Walls->DestroyWindow();
	//delete m_Walls;
	//m_Walls=NULL;

	//m_Roofs->DestroyWindow();
	//delete m_Roofs;
	//m_Roofs=NULL;

	//m_Openings->DestroyWindow();
	//delete m_Openings;
	//m_Openings=NULL;	

	m_Ventilation->DestroyWindow();
	delete m_Ventilation;
	m_Ventilation=NULL;

	m_MainHeating->DestroyWindow();
	delete m_MainHeating;
	m_MainHeating=NULL;

	m_MainHeatingDetails->DestroyWindow();
	delete m_MainHeatingDetails;
	m_MainHeatingDetails=NULL;

	m_SecHeating->DestroyWindow();
	delete m_SecHeating;
	m_SecHeating=NULL;

	m_WaterHeating->DestroyWindow();
	delete m_WaterHeating;
	m_WaterHeating=NULL;

	m_Renewables->DestroyWindow();
	delete m_Renewables;
	m_Renewables=NULL;

	m_LightsAndAppliances->DestroyWindow();
	delete m_LightsAndAppliances;
	m_LightsAndAppliances=NULL;	

	m_ThermalBridging->DestroyWindow();
	delete m_ThermalBridging;
	m_ThermalBridging=NULL;	

	m_SummerOverHeating->DestroyWindow();
	delete m_SummerOverHeating;
	m_SummerOverHeating=NULL;	

	m_Results->DestroyWindow();
	delete m_Results;
	m_Results=NULL;	

	m_Windows->DestroyWindow();
	delete m_Windows;
	m_Windows=NULL;	

	m_AreaAndUvalues->DestroyWindow();
	delete m_AreaAndUvalues;
	m_AreaAndUvalues=NULL;	

	// Read data at start up and populate vectors
	ReadSecHtEffFile();
	ReadsSAPboilers();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSAPP1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSAPP1Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSAPP1Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CSAPP1Dlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{

	int TabIndex = 0;

	//------------------------------------------------------
	// Get the number of the currently selected tab 
	TabIndex = m_c_TabCtrl.GetCurSel();

	DestroyModlessDialogs();

	//------------------------------------------------------------------
	// Show new dialog selected by tab control
	//------------------------------------------------------------------
	if (TabIndex==0)
	{
		m_JobDetails = new CDlg_JobDetails;
		m_JobDetails->Create(IDD_JOBDETAILS, this);
		m_JobDetails->ShowWindow(SW_SHOW);
	}
	else if (TabIndex==1)
	{
		m_BuiltForm = new CDlg_BuiltForm;
		m_BuiltForm->Create(IDD_BUILTFORM,this);
		m_BuiltForm->ShowWindow(SW_SHOW);
	}
	//else if (TabIndex==2)
	//{
	//	m_Floors = new CDlg_Floors;
	//	m_Floors->Create(IDD_FLOORS,this);	
	//	m_Floors->ShowWindow(SW_SHOW);
	//}
	//else if (TabIndex==3)
	//{
	//	m_Walls = new CDlg_Walls;
	//	m_Walls->Create(IDD_WALLS,this);
	//	m_Walls->ShowWindow(SW_SHOW);

	//}
	//else if (TabIndex==4)
	//{
	//	m_Roofs = new CDlg_Roofs;
	//	m_Roofs->Create(IDD_ROOFS,this);
	//	m_Roofs->ShowWindow(SW_SHOW);
	//}
	//else if (TabIndex==5)
	//{			
	//	m_Openings = new CDlg_Openings;
	//	m_Openings->Create(IDD_OPENINGS,this);
	//	m_Openings->ShowWindow(SW_SHOW);			
	//}

	else if (TabIndex==2)
	{
		m_Windows = new CDlg_Windows;
		m_Windows->Create(IDD_WINDOWS,this);
		m_Windows->ShowWindow(SW_SHOW);			
	}

	else if (TabIndex==3)
	{
		m_AreaAndUvalues = new CDlg_AreaAndUvalues;
		m_AreaAndUvalues->Create(IDD_AREAUVALUES,this);
		m_AreaAndUvalues->ShowWindow(SW_SHOW);			
	}

	else if (TabIndex==4)
	{
		m_ThermalBridging = new CDlg_ThermalBridging;
		m_ThermalBridging->Create(IDD_THERMALBRIDGING,this);
		m_ThermalBridging->ShowWindow(SW_SHOW);			
	}

	else if (TabIndex==5)
	{
		m_Ventilation = new CDlg_Ventilation;
		m_Ventilation->Create(IDD_VENTILATION,this);
		m_Ventilation->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==6)
	{
		m_MainHeating = new CDlg_MainHeating;
		m_MainHeating->Create(IDD_MAINHEATING,this);
		m_MainHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==7)
	{
		m_MainHeatingDetails = new CDlg_MainHeatingDetails;
		m_MainHeatingDetails->Create(IDD_MAINHEATINGDETAILS,this);
		m_MainHeatingDetails->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==8)
	{
		m_SecHeating = new CDlg_SecHeating;
		m_SecHeating->Create(IDD_SECONDARYHEATING,this);
		m_SecHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==9)
	{
		m_WaterHeating = new CDlg_WaterHeating;
		m_WaterHeating->Create(IDD_WATERHEATING,this);
		m_WaterHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==10)
	{
		m_Renewables = new CDlg_Renewables;
		m_Renewables->Create(IDD_RENEWABLES,this);
		m_Renewables->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==11)
	{
		m_LightsAndAppliances = new CDlg_LightsAndAppliances;
		m_LightsAndAppliances->Create(IDD_LIGHTSANDAPPLIANCES,this);
		m_LightsAndAppliances->ShowWindow(SW_SHOW);			
	}
	
	else if (TabIndex==12)
	{
		m_SummerOverHeating = new CDlg_SummerOverHeating;
		m_SummerOverHeating->Create(IDD_SUMMEROVERHEATING,this);
		m_SummerOverHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==13)
	{
		m_Results = new CDlg_Results;
		m_Results->Create(IDD_RESULTS,this);
		m_Results->ShowWindow(SW_SHOW);			
	}

	

	*pResult = 0;
}


BOOL CSAPP1Dlg::DestroyModlessDialogs()
{
	//------------------------------------------------------------------
	// Destroy current dialog box before drawing the new one
	//------------------------------------------------------------------
	if (m_JobDetails)
	{
		m_JobDetails->DestroyWindow();
		delete m_JobDetails;
		m_JobDetails=NULL;
	}
	else if(m_BuiltForm)
	{
		m_BuiltForm->DestroyWindow();
		delete m_BuiltForm;
		m_BuiltForm=NULL;
	}
	//else if(m_Floors)
	//{
	//	m_Floors->DestroyWindow();
	//	delete m_Floors;
	//	m_Floors=NULL;
	//}
	//else if(m_Walls)
	//{
	//	m_Walls->DestroyWindow();
	//	delete m_Walls;
	//	m_Walls=NULL;
	//}
	//else if(m_Roofs)
	//{
	//	m_Roofs->DestroyWindow();
	//	delete m_Roofs;
	//	m_Roofs=NULL;
	//}
	//else if(m_Openings)
	//{
	//	m_Openings->DestroyWindow();
	//	delete m_Openings;
	//	m_Openings=NULL;
	//}
	else if(m_ThermalBridging)
	{
		m_ThermalBridging->DestroyWindow();
		delete m_ThermalBridging;
		m_ThermalBridging=NULL;	
	}
	else if(m_Ventilation)
	{
		m_Ventilation->DestroyWindow();
		delete m_Ventilation;
		m_Ventilation=NULL;
	}
	else if(m_MainHeating)
	{
		m_MainHeating->DestroyWindow();
		delete m_MainHeating;
		m_MainHeating=NULL;
	}
	else if(m_MainHeatingDetails)
	{
		m_MainHeatingDetails->DestroyWindow();
		delete m_MainHeatingDetails;
		m_MainHeatingDetails=NULL;
	}
	else if(m_SecHeating)
	{
		m_SecHeating->DestroyWindow();
		delete m_SecHeating;
		m_SecHeating=NULL;
	}
	else if(m_WaterHeating)
	{
		m_WaterHeating->DestroyWindow();
		delete m_WaterHeating;
		m_WaterHeating=NULL;
	}
	else if(m_Renewables)
	{
		m_Renewables->DestroyWindow();
		delete m_Renewables;
		m_Renewables=NULL;
	}
	else if(m_LightsAndAppliances)
	{
		m_LightsAndAppliances->DestroyWindow();
		delete m_LightsAndAppliances;
		m_LightsAndAppliances=NULL;
	}
	
	else if(m_SummerOverHeating)
	{
		m_SummerOverHeating->DestroyWindow();
		delete m_SummerOverHeating;
		m_SummerOverHeating=NULL;	
	}
	else if(m_Results)
	{
		m_Results->DestroyWindow();
		delete m_Results;
		m_Results=NULL;	
	}
	else if(m_Windows)
	{
		m_Windows->DestroyWindow();
		delete m_Windows;
		m_Windows=NULL;	
	}
	else if(m_AreaAndUvalues)
	{
		m_AreaAndUvalues->DestroyWindow();
		delete m_AreaAndUvalues;
		m_AreaAndUvalues=NULL;	
	}
	
	return TRUE;
}


void CSAPP1Dlg::OnFileSave()
{
	//--------------------------------------------------------------------
	// Save dialog to save the project name
	// Warn user not to change the directory
	CFileDialog m_idFile( false, "proj", NULL, OFN_HIDEREADONLY, // false to save

	"Project files (*.csv)|*.csv|", AfxGetMainWnd());
	m_idFile.m_ofn.lpstrInitialDir = "..\\projects"; // default directory os one step up the executable
	
	// If user choses to Save File..
	if (m_idFile.DoModal()==IDOK)
	{
		CString strPathName = m_idFile.GetPathName();
		projectFileName     = m_idFile.GetPathName();// GetFileName();

		// Write a text file to save project
		SaveProjectFile_2();
	}
	else
	{
		return;
	}	
}

void CSAPP1Dlg::SaveProjectFile_2()
{
	FILE *fptr;	
	fptr = fopen( projectFileName,"w");
	// line 1 for headings

	//-------------------------------
	// JOB DETAILS
	//-------------------------------	
	fprintf(fptr,"%s,%s\n",	"Ref Num",JobDetRefNum); 
	fprintf(fptr,"%s,%s\n",	"Assessor Name", assessorName);
	fprintf(fptr,"%s,%s\n",	"Comments", JobDetComments);
	fprintf(fptr,"%s,%s\n",	"Flat Name/Num (Property)", propertyFlatNameorNum);
	fprintf(fptr,"%s,%s\n",	"Letter", propertyLetter);
	fprintf(fptr,"%s,%s\n",	"HouseNum", propertyHouseNum);
	fprintf(fptr,"%s,%s\n",	"Street", propertyStreet);
	fprintf(fptr,"%s,%s\n",	"Locality", propertyLocality);
	fprintf(fptr,"%s,%s\n",	"District", propertyDistrict);
	fprintf(fptr,"%s,%s\n",	"Town", propertyTown);
	fprintf(fptr,"%s,%s\n",	"County", propertyCounty);
	fprintf(fptr,"%s,%s\n",	"PostCode", propertyPostCode);
	fprintf(fptr,"%s,%s\n",	"FlatNameorNum (Client)", clientFlatNameorNum);
	fprintf(fptr,"%s,%s\n",	"House/BlockNum", clientHouseorBlockNum);
	fprintf(fptr,"%s,%s\n",	"Letter", clientLetter);
	fprintf(fptr,"%s,%s\n",	"Street", clientStreet);
	fprintf(fptr,"%s,%s\n",	"Locality", clientLocality);
	fprintf(fptr,"%s,%s\n",	"District", clientDistrict);
	fprintf(fptr,"%s,%s\n",	"Town", clientTown);
	fprintf(fptr,"%s,%s\n",	"County", clientCounty);
	fprintf(fptr,"%s,%s\n",	"PostCode", clientPostCode);

	//-------------------------------
	// BUILT FORM
	//-------------------------------
	fprintf(fptr,"%s,%s\n",	"Dwelling Type",  dwellingType);
	fprintf(fptr,"%s,%s\n",	"Property Type", propertyType);
	fprintf(fptr,"%s,%s\n",	"Built Form", BuiltForm);
	fprintf(fptr,"%s,%s\n",	"FlatType", FlatType);
	fprintf(fptr,"%s,%s\n",	"Year Property Built", yearPropertBuilt);
	//fprintf(fptr,"%s,%s\n",	"Degree Day Location", degreeDayLocation);
	fprintf(fptr,"%s,%d\n",	"Dwelling Sheltered Sides", dwellingShelteredSides);
	fprintf(fptr,"%s,%s\n",	"Dwelling Terrain", dwellingTerrain);
	fprintf(fptr,"%s,%s\n",	"Dwelling Exposure", dwellingExposure);
	fprintf(fptr,"%s,%s\n",	"Storey1", " ");
	fprintf(fptr,"%s,%s\n", "Level", storey1Level);
	fprintf(fptr,"%s,%s\n", "Basement", storey1Basement);
	fprintf(fptr,"%s,%.1f\n", "Area", storey1Area);
	fprintf(fptr,"%s,%.1f\n", "Height",storey1Height);
	fprintf(fptr,"%s,%s\n",	"Storey2", " ");	
	fprintf(fptr,"%s,%s\n", "Level", storey2Level);
	fprintf(fptr,"%s,%s\n", "Basement", storey2Basement);
	fprintf(fptr,"%s,%.1f\n", "Area", storey2Area);
	fprintf(fptr,"%s,%.1f\n", "Height",storey2Height);
	fprintf(fptr,"%s,%s\n",	"Storey3", " ");	
	fprintf(fptr,"%s,%s\n", "Level", storey3Level);
	fprintf(fptr,"%s,%s\n", "Basement", storey3Basement);
	fprintf(fptr,"%s,%.1f\n", "Area", storey3Area);
	fprintf(fptr,"%s,%.1f\n", "Height",storey3Height);
	fprintf(fptr,"%s,%s\n",	"Storey4", " ");	
	fprintf(fptr,"%s,%s\n", "Level", storey4Level);
	fprintf(fptr,"%s,%s\n", "Basement", storey4Basement);
	fprintf(fptr,"%s,%.1f\n", "Area", storey4Area);
	fprintf(fptr,"%s,%.1f\n", "Height",storey4Height);
	fprintf(fptr,"%s,%s\n",	"Storey5", " ");	
	fprintf(fptr,"%s,%s\n", "Level", storey5Level);
	fprintf(fptr,"%s,%s\n", "Basement", storey5Basement);
	fprintf(fptr,"%s,%.1f\n", "Area", storey5Area);
	fprintf(fptr,"%s,%.1f\n", "Height",storey5Height);
	fprintf(fptr,"%s,%s\n",	"Storey6", " ");	
	fprintf(fptr,"%s,%s\n", "Level", storey6Level);
	fprintf(fptr,"%s,%s\n", "Basement", storey6Basement);
	fprintf(fptr,"%s,%.1f\n", "Area", storey6Area);
	fprintf(fptr,"%s,%.1f\n", "Height",storey6Height);
	
	//-------------------------------
	// FLOORS
	//-------------------------------
	//fprintf(fptr,"%s,%s\n",   "Floor1", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor1Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor1Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor1Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor1Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor1Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor1Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor2", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor2Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor2Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor2Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor2Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor2Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor2Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor3", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor3Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor3Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor3Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor3Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor3Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor3Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor4", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor4Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor4Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor4Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor4Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor4Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor4Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor5", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor5Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor5Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor5Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor5Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor5Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor5Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor6", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor6Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor6Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor6Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor6Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor6Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor6Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor7", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor7Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor7Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor7Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor7Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor7Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor7Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor8", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor8Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor8Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor8Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor8Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor8Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor8Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor9", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor9Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor9Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor9Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor9Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor9Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor9Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Floor10", " ");
	//fprintf(fptr,"%s,%s\n",   "Name",   floor10Name);
	//fprintf(fptr,"%s,%s\n",   "Type",   floor10Type);
	//fprintf(fptr,"%s,%s\n",   "Construction", floor10Construction);
	//fprintf(fptr,"%s,%s\n",   "Sealed", isfloor10Sealed);
	//fprintf(fptr,"%s,%.1f\n", "Area",   floor10Area);
	//fprintf(fptr,"%s,%.1f\n", "U-value",floor10Uvalue);

	//-------------------------------
	// WALLS
	//-------------------------------
	//fprintf(fptr,"%s,%s\n",   "Wall1", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall1Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall1Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall1Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall1Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall1Uvalue); 

	//fprintf(fptr,"%s,%s\n",   "Wall2", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall2Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall2Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall2Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall2Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall2Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall3", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall3Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall3Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall3Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall3Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall3Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall4", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall4Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall4Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall4Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall4Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall4Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall5", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall5Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall5Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall5Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall5Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall5Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall6", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall6Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall6Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall6Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall6Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall6Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall7", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall7Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall7Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall7Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall7Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall7Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall8", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall8Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall8Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall8Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall8Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall8Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall9", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall9Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall9Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall9Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall9Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall9Uvalue);

	//fprintf(fptr,"%s,%s\n",   "Wall10", " "); 
	//fprintf(fptr,"%s,%s\n",   "Name",wall10Name); 
	//fprintf(fptr,"%s,%s\n",   "Construction",wall10Construction); 
	//fprintf(fptr,"%s,%s\n",   "Basement",wall10Basement); 
	//fprintf(fptr,"%s,%.1f\n", "Area", wall10Area); 
	//fprintf(fptr,"%s,%.1f\n", "U-value",wall10Uvalue);

	//-------------------------------
	//ROOFS
	//-------------------------------
	//fprintf(fptr,"%s,%s\n",    "Roof1", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof1Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof1Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof1Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof1Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof2", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof2Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof2Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof2Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof2Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof3", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof3Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof3Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof3Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof3Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof4", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof4Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof4Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof4Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof4Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof5", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof5Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof5Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof5Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof5Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof6", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof6Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof6Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof6Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof6Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof7", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof7Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof7Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof7Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof7Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof8", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof8Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof8Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof8Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof8Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof9", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof9Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof9Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof9Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof9Uvalue);

	//fprintf(fptr,"%s,%s\n",    "Roof10", " "); 
	//fprintf(fptr,"%s,%s\n",    "Name", roof10Name);
	//fprintf(fptr,"%s,%s\n",    "Construction", roof10Construction);
	//fprintf(fptr,"%s,%.1f\n",  "Area", roof10Area);
	//fprintf(fptr,"%s,%.1f\n",  "U-value",roof10Uvalue);


	//-------------------------------
	// VENTILATION
	//-------------------------------
	//fprintf(fptr,"%s,%s\n", "Design Air Permeability", designAirPermeability);
	//fprintf(fptr,"%s,%s\n", "Pressure Test Scotland",pressureTestScotland);
	//fprintf(fptr,"%s,%s\n", "Accredited Details Scotland",accreditedDetailsScotland);
	//fprintf(fptr,"%s,%s\n", "Exemption",seekExemptionForLT3Dwellings);
	//fprintf(fptr,"%s,%.1f\n", "Design Air Permeability Rate",designAirPermRate);
	//fprintf(fptr,"%s,%.1f\n", "As Built Permeability Rate",asBuiltAirPermRate);
	//fprintf(fptr,"%s,%s\n", "Air Perm Measured In Dwelling",airPermMeasuredInDwelling);
	//fprintf(fptr,"%s,%s\n", "As Built Ref",asBuiltRef);
	//fprintf(fptr,"%s,%s\n", "As Built Test Date",asBuiltTestDate);
	fprintf(fptr,"%s,%d\n", "Num of Open Fire Places",numsOpenFirePlaces);
	fprintf(fptr,"%s,%d\n", "Num of Open Flues",numsOpenFlues);
	fprintf(fptr,"%s,%d\n", "Num of Flueless Gas Fires",numsFluelessGasFires);
	fprintf(fptr,"%s,%d\n", "Num of Extract Fans",numsExtractFans);
	fprintf(fptr,"%s,%d\n", "Num of Passive Vents",numsPassiveVents);
	//fprintf(fptr,"%s,%.1f\n", "AC Energy Use", ACEnergyUse);
	fprintf(fptr,"%s,%s\n", "Mech Vent Type",mechVentType);
	fprintf(fptr,"%s,%.0f\n","SFP", SFP);
	fprintf(fptr,"%s,%s\n", "Pressure Test YN",pressureTestYN); 
	fprintf(fptr,"%s,%.0f\n", "Measured Q50",measuredQ50 );  
	fprintf(fptr,"%s,%d\n",   "Num Of Storeys",numOfStoreys );  
	fprintf(fptr,"%s,%.2f\n", "Structural Infiltration",structInf);      
	fprintf(fptr,"%s,%.1f\n", "Suspended Floor Infiltration",floorInf );   
	fprintf(fptr,"%s,%s\n",   "Draught Lobby",draughtLobby);
	fprintf(fptr,"%s,%d\n",   "Percentage of Windows Draught Stripped",perWindowDraughtStripped);

	//fprintf(fptr,"%s,%s\n", "Mech Vent Values From",mechVentValuesFrom);
	//fprintf(fptr,"%s,%s\n", "Num of WetRooms",numsWetRooms);
	//fprintf(fptr,"%s,%s\n", "Duct Insulation",ductInsulation);
	

	//------------------------------------------
	// MAIN HEATING
	//------------------------------------------
	fprintf(fptr,"%s,%s\n","Electric Tarrif", electricityTarrif);
	fprintf(fptr,"%s,%s\n","Main Ht Type", mainHtType);
	fprintf(fptr,"%s,%s\n","Main Ht Eff From", mainHtEffFrom);
	fprintf(fptr,"%s,%s\n","Boiler Type", boilerType);
	fprintf(fptr,"%s,%s\n","Main Fuel", mainFuel);
	//fprintf(fptr,"%s,%s\n","Sec Boiler Fuel", isSecBoilerFuelPresent);
	fprintf(fptr,"%s,%s\n","Fan Flue", isFanFluePresent);
	fprintf(fptr,"%s,%s\n","Main Ht System", mainHtSystem);
	fprintf(fptr,"%s,%s\n","Main Ht Controls", mainHtControls);
	fprintf(fptr,"%s,%s\n","Main Ht Emitter", mainHtEmitter);
	fprintf(fptr,"%s,%s\n","Main Ht Interlock", isIterlockPresent);
	fprintf(fptr,"%s,%s\n","Main Ht Compensator", mainHtCompensator);
	fprintf(fptr,"%s,%s\n","Pump In Heated Space", isPumpInHeatedSpace);
	fprintf(fptr,"%s,%s\n","Main Ht Manufacturer Desc", mainHtManufacturerDesc);
	fprintf(fptr,"%s,%s\n","Main Ht Test Method", mainHtTestMethod);
	//fprintf(fptr,"%s,%s\n","Main Ht Bioler Ref", boilerRef);
	//fprintf(fptr,"%s,%s\n","Main Ht Bioler Model", boilerModel);
	fprintf(fptr,"%s,%.2f\n","Main Ht Eff", mainHtEff);

	//------------------------------------------
	// MAIN HETAING DETAILS
	//------------------------------------------
	fprintf(fptr,"%s,%s\n","Oil Pump In Heated Space",   oilPumpInHeatedSpace);
	fprintf(fptr,"%s,%s\n","Oil Boiler Installed",   oilBoilerInstalled);
	fprintf(fptr,"%s,%.1f\n","CPSU Operating Temp", CPSUoperatingTemp);
	fprintf(fptr,"%s,%.1f\n","Heat Emm From Case", heatEmmFromCase);
	fprintf(fptr,"%s,%.1f\n","Heat Transferred To Water", heatTransferredToWater);
	fprintf(fptr,"%s,%s\n","Smoke Controlled Area",   smokeControlledArea);
	fprintf(fptr,"%s,%s\n","Is There CHP",   isThereCHP);
	fprintf(fptr,"%s,%s\n","CHP fuel",   CHPfuel);
	fprintf(fptr,"%s,%.1f\n","Fraction of Ht From CHP", fractOfHtFromCHP);
	fprintf(fptr,"%s,%.1f\n","Elec Eff of CHP", elecEffOfCHP);
	fprintf(fptr,"%s,%.1f\n","Heating Eff of CHP", heatingEffOfCHP);
	fprintf(fptr,"%s,%s\n","Sec Community Boiler Fuel",   secComBoilerFuel);
	fprintf(fptr,"%s,%s\n","Sec Community Boiler System",   secComBoilerSystem);
	fprintf(fptr,"%s,%.1f\n","Sec Community Boiler Eff", secComBoilerEff);
	fprintf(fptr,"%s,%.1f\n","Sec Community Boiler Fract of Ht From Boiler2", secComBoilerFractOfHtFromBoiler2);
	fprintf(fptr,"%s,%s\n","Sec Community Boiler Manufact Desc", secComBoilerManufactDesc);


	//------------------------------------------
	// SECONDARY HEATING
	//------------------------------------------
	fprintf(fptr,"%s,%s\n","Sec Heating", isThereSecHeating);
	fprintf(fptr,"%s,%s\n","Open Flue Chimney", secHtOpenFlueChimney);
	fprintf(fptr,"%s,%s\n","Unconnected Gas Point", secHtUnconnectedGasPoint);
	fprintf(fptr,"%s,%s\n","Eff From", secHtEffFrom);
	fprintf(fptr,"%s,%s\n","Fuel", secHtFuel);
	fprintf(fptr,"%s,%s\n","System", secHtSystem);
	fprintf(fptr,"%s,%s\n","Manufact Desc", secHtManufactDesc);
	fprintf(fptr,"%s,%s\n","Test Method", secHtTestMethod);
	fprintf(fptr,"%s,%.0f\n","Ht Eff", secHtEff);
	fprintf(fptr,"%s,%.2f\n","Sec Ht Fraction",secHtFraction); // atof(str_editSecHtFraction);

	//------------------------------------------
	// WATER HEATING
	//------------------------------------------
	fprintf(fptr,"%s,%s\n","Water Heating type",   WHtype);
	fprintf(fptr,"%s,%s\n","Is Cylinder Within Dwelling",   WHtCylinderWithinDwelling);
	fprintf(fptr,"%s,%s\n","Fuel",   WHtFuel);
	fprintf(fptr,"%s,%s\n","Is Water Separately Timed",   WHtWaterSepTimed);
	fprintf(fptr,"%s,%s\n","Range Cooker Type",   WHtRangeCookerType);
	fprintf(fptr,"%s,%s\n","Cyllinder Manufacturer Loss Factor", WHtCylManufactLossFactor);
	fprintf(fptr,"%s,%.0f\n","Cylinder Declared Factor", WHtCylDeclaredFactor);
	fprintf(fptr,"%s,%.0f\n","Cylinder Volume", WHtCylVolume);
	fprintf(fptr,"%s,%s\n","Cylinder Insulation Type",   WHtCylInsType);
	fprintf(fptr,"%s,%.0f\n","Cylinder Insulation Thickness", WHtCylInsThickness);
	fprintf(fptr,"%s,%s\n","Cylinder Thermostat",   WHtCylThermostat);
	fprintf(fptr,"%s,%s\n","Is Cylinder in Heated Space",   WHtCylInHeatedSpace);
	fprintf(fptr,"%s,%s\n","Cylinder Primary PipeworkI nsulated",   WHtCylPrimaryPipeworkInsulated);
	fprintf(fptr,"%s,%s\n","Cylinder Pumped Primary System",   WHtCylPumpedPrimarySystem);
	fprintf(fptr,"%s,%s\n","Water Heating Eff",WHtEff);
	fprintf(fptr,"%s,%s\n","Therm Storage and CPSU inSingleUnit",   WHtTSnCPSUinSingleUnit);
	fprintf(fptr,"%s,%s\n","TSnCPSUPrimaryPipeworkLT1_5m",   WHtTSnCPSUPrimaryPipeworkLT1_5m);
	fprintf(fptr,"%s,%s\n","Therm Storage and CPSU store In Air Cupbrd",   WHtTSnCPSUstoreInAirCupbrd);
	fprintf(fptr,"%s,%s\n","Combi Keep Hot YN",   WHtCombiKeepHotYN);
	fprintf(fptr,"%s,%s\n","DHW From Community Scheme",   DHWfromCommunityScheme);
	//fprintf(fptr,"%s,%s\n","DHW Only Community Scheme Provided From",   DHWComSchemeProvidedFrom);
	//fprintf(fptr,"%s,%.0f\n","CHP Heat to PowerRatio", DHWComSchemeCHP2PowerRatio);
	//fprintf(fptr,"%s,%s\n","System",   DHWComSchemeSystem);
	//fprintf(fptr,"%s,%.0f\n","Effeciency", DHWComSchemeEff);
	fprintf(fptr,"%s,%s\n","Water Heat Pump Uses Immersion",   WHtHeatPumpUsesImmer);
	fprintf(fptr,"%s,%s\n","Water Heating Uses Summer Immersion",   WHtUsesSummerImmer);
	fprintf(fptr,"%s,%s\n","FGHRS",   WHtFGHRSys);
	
	//------------------------------------------
	// RENEWABLES
	//------------------------------------------
	fprintf(fptr,"%s,%s\n","is SHW Present",   isSHWPresent);
	fprintf(fptr,"%s,%s\n","Collector Type",   SHWCollectorType);
	fprintf(fptr,"%s,%s\n","Collector Orientation",   SHWCollectorOrientation);
	fprintf(fptr,"%s,%s\n","Collector Tilt",   SHWCollectorTilt);
	fprintf(fptr,"%s,%s\n","Overshading",   SHWOvershading);
	fprintf(fptr,"%s,%s\n","Is Area Gross",   isSHWAreaGross);
	fprintf(fptr,"%s,%.1f\n","Gross Area", SHWGrossArea);
	fprintf(fptr,"%s,%.0f\n","ZL Collector Eff", SHWZLCollectorEff);
	fprintf(fptr,"%s,%.0f\n","HL Coefficient", SHWHLCoeff);
	fprintf(fptr,"%s,%s\n","Is Solar StoreCombined",   isSHWSolarStoreCombined);
	fprintf(fptr,"%s,%.0f\n","Dedicated Solar Store Volume", SHWDedicatedSolarStoreVolume);
	fprintf(fptr,"%s,%s\n","Solar Circulating Pump",   SHWSolarCircPump);
	fprintf(fptr,"%s,%s\n","Is Additional Electricity Generated",   isRENAdditionalElectGenerated);
	fprintf(fptr,"%s,%.1f\n","Electricity Generated(kWh/yr)", RENAddiationalElecGenerated);
	fprintf(fptr,"%s,%.1f\n","TFA", REN_TFA);
	fprintf(fptr,"%s,%s\n","Is PV Present",   isPVPresent);
	fprintf(fptr,"%s,%.0f\n","Installed Peak Power", installedPVPeakPower);
	fprintf(fptr,"%s,%s\n","Collector Orientation",   PVCollectorOrientation);
	fprintf(fptr,"%s,%s\n","Collector Tilt",   PVCollectorTilt);
	fprintf(fptr,"%s,%s\n","Overshading",   PVOvershading);
	fprintf(fptr,"%s,%s\n","Is WT Present",   isWTPresent);
	fprintf(fptr,"%s,%d\n","Num Of WTs",   WTNumOf);
	fprintf(fptr,"%s,%.1f\n","Diameter", WTDiameter);
	fprintf(fptr,"%s,%.1f\n","Height", WTHeight);

	//------------------------------------------
	// LIGHTS AND APPLIANCES
	//------------------------------------------
	fprintf(fptr,"%s,%.2f\n","Fraction LEL",   fractionLEL);
	//fprintf(fptr,"%s,%d\n","Internal Lights Std Fittings",   IntLightsStdFittings);
	//fprintf(fptr,"%s,%d\n","Internal Lights Dedicated Low Energy",   IntLightsDedicatedLowEnergy);
	//fprintf(fptr,"%s,%d\n","Internal Lights NonDedicated Low Energy",   IntLightsNonDedicatedLowEnergy);
	//fprintf(fptr,"%s,%d\n","Internal Lights Total",   IntLightsTotal);

	//fprintf(fptr,"%s,%s\n","Assess External Lighting",   ExtLightsAssess);
	//fprintf(fptr,"%s,%s\n","Fitting GT40 Lumens per circuit watt",   ExtLightsFittingGT40Lumens);
	//fprintf(fptr,"%s,%s\n","Lights Lamps NGT150 W off when not needed",   ExtLightsLampsNGT150W);
	

	//------------------------------------------
	// THERMAL BRIDGES
	//------------------------------------------
	//////fprintf(fptr,"%s,%s\n","Metal Box Lintel","na");
	//////fprintf(fptr,"%s,%s\n", "User defined",ThermBMetalBoxLintelUserDef);
	//////fprintf(fptr,"%s,%.2f\n","SiValue",ThermBMetalBoxLintelSiValue);
	//////fprintf(fptr,"%s,%.2f\n","Result",ThermBMetalBoxLintelResult);

	//////fprintf(fptr,"%s,%s\n","Other Lintels","na");
	//////fprintf(fptr,"%s,%s\n", "User defined",ThermBOtherLintelUserDef);
	//////fprintf(fptr,"%s,%.2f\n","SiValue",ThermBOtherLintelsSiValue);
	//////fprintf(fptr,"%s,%.2f\n","Result",ThermBOtherLintelsResult);

	//////fprintf(fptr,"%s,%s\n","Sill","na");
	//////fprintf(fptr,"%s,%s\n", "User defined",ThermBSillUserDef);
	//////fprintf(fptr,"%s,%.2f\n","SiValue",ThermBSillSiValue);
	//////fprintf(fptr,"%s,%.2f\n","Result",ThermBSillResult);

	//////fprintf(fptr,"%s,%s\n","Jamb","na");
	//////fprintf(fptr,"%s,%s\n", "User defined",ThermBJambUserDef);
	//////fprintf(fptr,"%s,%.2f\n","SiValue",ThermBJambSiValue);
	//////fprintf(fptr,"%s,%.2f\n","Result",ThermBJambResult);

	fprintf(fptr,"%s,%.2f\n","Ground Floor perimeter",ThermBGFPerimeter);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBGFPerimeterUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBGFPerimeterSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBGFPerimeterResult);

	fprintf(fptr,"%s,%.2f\n","Floor Within Dwelling Perimeter",ThermBFloorWithingDwellinPerimeter);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBFloorWithinDwellingUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBFloorWithinDwellingSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBFloorWithinDwellingPerimeterResult);

	fprintf(fptr,"%s,%.2f\n","Floor Between Dwelling Perimeter",ThermBFloorBetweenDwellinPerimeter);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBFloorBwDwellingUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBFloorBetweenDwellingSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBFloorBetweenDwellingPerimeterResult);

	fprintf(fptr,"%s,%.2f\n","Balcony Within Dwelling Length",ThermBBalconyWithingDwellingLength);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBBalcWithinDwellingLengthUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBBalconyWithinDwellingSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBBalcWithDwellingLengthResult);

	fprintf(fptr,"%s,%.2f\n","Balcony Between Dwelling Length",ThermBBalconyBetweenDwellingLength);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBBalcBwDwellingLengthUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBBalconyBwDwellingSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBBalconyBwDwellingLengthResult);

	fprintf(fptr,"%s,%.2f\n","Evaes Insulation At Ceiling",ThermBEavesAtCeiling);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBEavesInsAtCeilingUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBEavesInsAtCelingSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBEavesInsCeilingResult);

	fprintf(fptr,"%s,%.2f\n","Evaes Insulation At Rafters",ThermBEavesAtRafter);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBEavesInsAtRafterUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBEavesInsAtRafterSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBEavesInsRafterResult);

	fprintf(fptr,"%s,%.2f\n","Gable Insulation At Ceiling",ThermBGableAtCeiling);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBGableInsAtCeilingUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBGableInsAtCeilingSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBGableInsCeilingResult);

	fprintf(fptr,"%s,%.2f\n","Gable Insulation At Rafters",ThermBGableAtRafter);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBGableInsAtRafetUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBGableInsAtRafterSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBGableInsRafterResult);

	fprintf(fptr,"%s,%.2f\n","Length Normal Corners",ThermBLengthNormalCorners);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBLengthOfNormalCornersUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBLengthOfNormalCornersSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBLengthNormalCornersResult);

	fprintf(fptr,"%s,%.2f\n","Length Inverted Corners",ThermBLengthInvertedCorners);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBLengthOfInvertedCornersUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBLengthOfInvertedCornersSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBLengthInvertedCornersResult);

	fprintf(fptr,"%s,%.2f\n","Party Wall Between Dwelling Length",ThermBPartWallBetweenDwelling);
	fprintf(fptr,"%s,%s\n", "User defined",ThermBPartWallBetweenDwellingUserDef);
	fprintf(fptr,"%s,%.2f\n","SiValue",ThermBPartBwDwellingLengthSiValue);
	fprintf(fptr,"%s,%.2f\n","Result",ThermBPartyWallBwDwellingResult);	

	//------------------------------------------
	// SUMMER OVERHEATING
	//------------------------------------------
	fprintf(fptr,"%s,%s\n",    "Is TMP User Def", isTMPUserDef);
	fprintf(fptr,"%s,%.1f\n",  "TMP value", TMPvalue);
	fprintf(fptr,"%s,%s\n",    "TMP Internal Partition Construction", TMPIntPartConstruction);
	fprintf(fptr,"%s,%s\n",    "TMP Party Wall Construction", TMPPartyWallConstruction);
	fprintf(fptr,"%s,%s\n",    "Is Ventilation User Defined", isVentUserDefined);
	fprintf(fptr,"%s,%.1f\n",  "Air Change Rate", airChangeRate);
	fprintf(fptr,"%s,%s\n",    "Is Cross Ventilation On Most Floors", isCrossVentOnMostFloors);
	fprintf(fptr,"%s,%s\n",    "Wndow Ventilation", windowVentilation);
	fprintf(fptr,"%s,%s\n",    "Are Curtains Closed During Day", areCurtainsClosedDuringDay);
	fprintf(fptr,"%s,%.1f\n",  "Fraction Curtains Closed", fractCurtainsClosed);
	fprintf(fptr,"%s,%s\n",    "Blind Curtain Type", blindCurtainType);
	fprintf(fptr,"%s,%s\n",    "Source User Defined Values", sourceUserDefValues);

	//------------------------------------------
	// OPENINGS
	//------------------------------------------

	//unsigned int i = 0;
	//CString temp;
	//unsigned int temp2 = 0;
	//temp2 = openingListData_New.size();
	//

	//if(addOpening>0)
	//{
	//	for(i=0; i<openingListData_New.size();i++)
	//	{
	//		
	//		temp = openingListData_New[i].openingName;

	//		fprintf(fptr,"%s%,%s\n",  "Opening Details", openingListData_New[i].openingName);
	//		//fprintf(fptr,"%s%,%s\n",  "Source",               openingListData_New[i].openingFromSource); 20feb
	//		//fprintf(fptr,"%s%,%s\n",  "Description",          openingListData_New[i].openingDescription); 20feb
	//		fprintf(fptr,"%s%,%s\n",  "Glz Type",             openingListData_New[i].openingGlzType);
	//		fprintf(fptr,"%s%,%s\n",  "LowE Coating",         openingListData_New[i].openingLowECoating);
	//		fprintf(fptr,"%s%,%s\n",  "User Def Emissivity",  openingListData_New[i].openingUsedDefEmissivity);
	//		fprintf(fptr,"%s%,%.2f\n","Emissivity",            openingListData_New[i].openingEmissivty);

	//		fprintf(fptr,"%s%,%s\n", "Argon Filled",    openingListData_New[i].openingArgonFilled);
	//		fprintf(fptr,"%s%,%s\n", "Gap",             openingListData_New[i].openingGap);
	//		fprintf(fptr,"%s%,%.2f\n", "Pitch",         openingListData_New[i].openingPitch); 
	//		fprintf(fptr,"%s%,%s\n", "Orientation",     openingListData_New[i].openingOrientation);
	//		fprintf(fptr,"%s%,%s\n", "Overshading",     openingListData_New[i].openingOvershading);

	//		fprintf(fptr,"%s%,%.2f\n", "Width",           openingListData_New[i].openingWidth);
	//		fprintf(fptr,"%s%,%.2f\n", "Height",          openingListData_New[i].openingHeight);
	//		fprintf(fptr,"%s%,%s\n", "Location Name",     openingListData_New[i].openingLocationName);
	//		fprintf(fptr,"%s%,%.2f\n", "Overhang Depth",  openingListData_New[i].openingOverhangDepth);
	//		fprintf(fptr,"%s%,%.2f\n", "Overhang Width",  openingListData_New[i].openingOverhangWidth);

	//		fprintf(fptr,"%s%,%s\n", "Ref",             openingListData_New[i].openingRef);
	//		fprintf(fptr,"%s%,%s\n", "Linkage Master",  openingListData_New[i].openingLinkageMaster);
	//		fprintf(fptr,"%s%,%s\n", "Linked To",       openingListData_New[i].openingLinkedTo);

	//		fprintf(fptr,"%s%,%s\n", "Frame",            openingListData_New[i].openingFrame);
	//		fprintf(fptr,"%s%,%s\n", "Thermal Break",    openingListData_New[i].openingThermalBreak);
	//		fprintf(fptr,"%s%,%s\n", "Draught Proofing", openingListData_New[i].openingDraughtProofing);
	//		fprintf(fptr,"%s%,%s\n", "Metal Lintel",     openingListData_New[i].openingMetalLintel);

	//		fprintf(fptr,"%s%,%s\n", "Transmittance Selected",  openingListData_New[i].openingTransmittanceSelected);
	//		fprintf(fptr,"%s%,%.2f\n", "Transmittance Factor",  openingListData_New[i].openingTransmittanceFactor);

	//		fprintf(fptr,"%s%,%s\n", "Frame Selected",   openingListData_New[i].openingFrameSelected);
	//		fprintf(fptr,"%s%,%.2f\n", "Frame Factor",   openingListData_New[i].openingFrameFactor);

	//		fprintf(fptr,"%s%,%s\n", "U-value Selected", openingListData_New[i].openingUvalueSelected);
	//		fprintf(fptr,"%s%,%.2f\n", "U-value",        openingListData_New[i].openingUvalue);
	//		fprintf(fptr,"%s,%s\n",  "End opening", "End opening");
	//	}


	//	for(i=0; i<openingsData_New.size();i++)
	//	{
	//		int temp_int = 0;
	//		temp = openingsData_New[i].openingName;
	//		fprintf(fptr,"%s%,%s\n", "Opening Name",   openingsData_New[i].openingName);

	//		temp = openingsData_New[i].parentSurface;
	//		fprintf(fptr,"%s%,%s\n", "Parent Surface",   openingsData_New[i].parentSurface);

	//		temp_int = openingsData_New[i].multipier;
	//		fprintf(fptr,"%s%,%d\n", "Multiplier",     openingsData_New[i].multipier);
	//	}
	//}

	fclose(fptr);
}


void CSAPP1Dlg::OnFileOpen()
{
	//--------------------------------------------------------------------
	// Open dialog to read the project name
	CFileDialog m_idFile( true, "proj", NULL, OFN_HIDEREADONLY, // false to open

	"Project files (*.csv)|*.csv|", AfxGetMainWnd());
	m_idFile.m_ofn.lpstrInitialDir = "..\\projects"; // default directory os one step up the executable
	
	// If user choses to Open File..
	if (m_idFile.DoModal()==IDOK)
	{
		CString strPathName = m_idFile.GetPathName();
		projectFileName     = m_idFile.GetPathName();// GetFileName();

		// Open saved project
		OpenProjectFile();
	}
	else
	{
		return;
	}	
}

void CSAPP1Dlg::OpenProjectFile()
{
	//--------------------------------------------
	// Clear vectors before writing data
	//--------------------------------------------
	stringsWithValues.clear();
	openingsData_New.clear();
	openingListData_New.clear();		

	FILE *fptr;
	char tempStr[1000];
	char *pError;
	char *pch;
	LineEntryInfo tempCBoxEntry;
	openingListData tempCBoxEntry2;
	openingsData tempCBoxEntry3;
	bool isOk = TRUE;
	int linesRead = 0;
	int openingDetailsIndex = 0;
	int openingNamesIndex = 0;
	int lineNum = 0;

	int testTemp = 0;
	CString tempString1;
	CString tempString2;
	CString tempString3;
	CString tempString4;
	char tempBuffer[1000];
	bool populateListDataVector = false;
	bool populateDataVector = false;

	CString tempt;
	unsigned int i_2 = 0;

	//--------------------------------------------------------------------------	
	// Open the file
	fptr = fopen(projectFileName,"r");
	if (fptr == NULL)
	{
		return;
	}

	// Keep on reading (and proessing) each line from the CSV file
	// until reached end of file OR some error occured	
	while (TRUE)
	{
		// Read a line from a CSV file
		pError = fgets(tempStr,1000,fptr);
		linesRead ++;

		// if reached end of file
		if(pError == NULL)
		{	
			break;
		}
	
		//--------------------------------------------------------------------
		// 1.	Read the "entry label" for the combo box
		pch = strtok (tempStr, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempCBoxEntry.entryLabel,pch);

		//--------------------------------------------------------------------
		// 2.	Read the "entry string" for this entry
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		
		strcpy(tempCBoxEntry.entryString,pch );
		// If have read end-of-line character, replace it with null
		if (tempCBoxEntry.entryString[strlen(pch)-1] == 0x0A)
		{
			tempCBoxEntry.entryString[strlen(pch)-1] = 0;
		}

		//--------------------------------------------------------------------
		// Enter this information in the vector
		stringsWithValues.push_back(tempCBoxEntry);

		if(linesRead>SUM_OVHT_USER_DEF_VALUES_SOURCE) 
		{
			//---------------------------------------------------------
			if (strcmp(tempCBoxEntry.entryLabel,"Opening Details")==0)
			{
				//populateListDataVector = true;
				//----------------------------------------------
				// 1. Opening Name
				strcpy(tempCBoxEntry2.openingName,pch );
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingName[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingName[strlen(pch)-1] = 0;
				}
			}
			// 20feb
			//////---------------------------------------------------------
			////if(strcmp(tempCBoxEntry.entryLabel,"Source")==0)
			////{
			////	//----------------------------------------------
			////	// 2. Source
			////	strcpy(tempCBoxEntry2.openingFromSource,pch );
			////	// If have read end-of-line character, replace it with null
			////	if (tempCBoxEntry2.openingFromSource[strlen(pch)-1] == 0x0A)
			////	{
			////		tempCBoxEntry2.openingFromSource[strlen(pch)-1] = 0;
			////	}				
			////}
			//////---------------------------------------------------------
			////if(strcmp(tempCBoxEntry.entryLabel,"Description")==0)
			////{
			////	//----------------------------------------------
			////	// 3. Description
			////	strcpy(tempCBoxEntry2.openingDescription,pch );
			////	// If have read end-of-line character, replace it with null
			////	if (tempCBoxEntry2.openingDescription[strlen(pch)-1] == 0x0A)
			////	{
			////		tempCBoxEntry2.openingDescription[strlen(pch)-1] = 0;
			////	}				
			////}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Glz Type")==0)
			{
				//----------------------------------------------
				// 4. Glz Type
				strcpy(tempCBoxEntry2.openingGlzType,pch );
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingGlzType[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingGlzType[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"LowE Coating")==0)
			{
				//----------------------------------------------
				// 5. LowE Coating
				strcpy(tempCBoxEntry2.openingLowECoating,pch );
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingLowECoating[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingLowECoating[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"User Def Emissivity")==0)
			{
				//----------------------------------------------
				// 6. User Def Emissivity
				strcpy(tempCBoxEntry2.openingUsedDefEmissivity,pch );
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingUsedDefEmissivity[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingUsedDefEmissivity[strlen(pch)-1] = 0;
				}							
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Emissivity")==0)
			{
				//----------------------------------------------
				// 7. Emissivity
				strcpy(tempBuffer,pch );

				// If have read end-of-line character, replace it with null
				if (tempBuffer[strlen(pch)-1] == 0x0A)
				{
					tempBuffer[strlen(pch)-1] = 0;
				}	
				tempCBoxEntry2.openingEmissivty = atof(tempBuffer);	
										
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Argon Filled")==0)
			{
				//----------------------------------------------
				// 8. Argon Filled
				strcpy(tempCBoxEntry2.openingArgonFilled, pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingArgonFilled[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingArgonFilled[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Gap")==0)
			{
				//----------------------------------------------
				// 9. Gap
				strcpy(tempCBoxEntry2.openingGap,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingGap[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingGap[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Pitch")==0)
			{
				//----------------------------------------------
				// 10. Pitch
				tempCBoxEntry2.openingPitch = atof(pch);								
			}
			CString tempString;
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Orientation")==0)
			{
				//----------------------------------------------
				// 11. Orientation
				strcpy(tempCBoxEntry2.openingOrientation,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingOrientation[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingOrientation[strlen(pch)-1] = 0;
				}
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Overshading")==0)
			{
				//----------------------------------------------
				// 12. Overshading
				strcpy(tempCBoxEntry2.openingOvershading, pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingOvershading[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingOvershading[strlen(pch)-1] = 0;
				}				
			}

			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Width")==0)
			{
				//----------------------------------------------
				// 13. Width
				tempCBoxEntry2.openingWidth = atof(pch);
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Height")==0)
			{
				//----------------------------------------------
				// 14. Height
				tempCBoxEntry2.openingHeight = atof(pch);
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Location Name")==0)
			{
				//----------------------------------------------
				// 15. Location Name
				strcpy(tempCBoxEntry2.openingLocationName ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingLocationName[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingLocationName[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Overhang Depth")==0)
			{
				//----------------------------------------------
				// 16. Overhang Depth
				tempCBoxEntry2.openingOverhangDepth = atof(pch);
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Overhang Width")==0)
			{
				//----------------------------------------------
				// 17. Overhang Width
				tempCBoxEntry2.openingOverhangWidth = atof(pch);
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Ref")==0)
			{
				//----------------------------------------------
				// 18. Ref
				strcpy(tempCBoxEntry2.openingRef ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingRef[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingRef[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Linkage Master")==0)
			{
				//----------------------------------------------
				// 19. Linkage Master
				strcpy(tempCBoxEntry2.openingLinkageMaster ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingLinkageMaster[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingLinkageMaster[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Linked To")==0)
			{
				//----------------------------------------------
				// 20. Linked To
				strcpy(tempCBoxEntry2.openingLinkedTo ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingLinkedTo[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingLinkedTo[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Frame")==0)
			{
				//----------------------------------------------
				// 21. Frame
				strcpy(tempCBoxEntry2.openingFrame ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingFrame[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingFrame[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Thermal Break")==0)
			{
				//----------------------------------------------
				// 22. Thermal Break
				strcpy(tempCBoxEntry2.openingThermalBreak ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingThermalBreak[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingThermalBreak[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Draught Proofing")==0)
			{
				//----------------------------------------------
				// 23. Draught Proofing
				strcpy(tempCBoxEntry2.openingDraughtProofing ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingDraughtProofing[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingDraughtProofing[strlen(pch)-1] = 0;
				}				
			}

			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Metal Lintel")==0)
			{
				//----------------------------------------------
				// 24. Metal Lintel
				strcpy(tempCBoxEntry2.openingMetalLintel ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingMetalLintel[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingMetalLintel[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Transmittance Selected")==0)
			{
				//----------------------------------------------
				// 25. Transmittance Selected
				strcpy(tempCBoxEntry2.openingTransmittanceSelected ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingTransmittanceSelected[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingTransmittanceSelected[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Transmittance Factor")==0)
			{
				//----------------------------------------------
				// 26. Transmittance Factor
				tempCBoxEntry2.openingTransmittanceFactor = atof(pch);
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Frame Selected")==0)
			{
				//----------------------------------------------
				// 27. Frame Selected
				strcpy(tempCBoxEntry2.openingFrameSelected ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingFrameSelected[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingFrameSelected[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Frame Factor")==0)
			{
				//----------------------------------------------
				// 28. Frame Factor
				tempCBoxEntry2.openingFrameFactor = atof(pch);
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"U-value Selected")==0)
			{
				//----------------------------------------------
				// 29. U-value Selected
				strcpy(tempCBoxEntry2.openingUvalueSelected ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry2.openingUvalueSelected[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry2.openingUvalueSelected[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"U-value")==0)
			{
				//----------------------------------------------
				// 30. U-value
				tempCBoxEntry2.openingUvalue = atof(pch);
				populateListDataVector = true;
			}	    

			
			
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"End opening")==0)
			{
				//----------------------------------------------
				// 1. Opening Name
				strcpy(tempCBoxEntry3.openingName ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry3.openingName[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry3.openingName[strlen(pch)-1] = 0;
				}				
			}

			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Opening Name")==0)
			{
				//----------------------------------------------
				// 1. Opening Name
				strcpy(tempCBoxEntry3.openingName ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry3.openingName[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry3.openingName[strlen(pch)-1] = 0;
				}				
			}

			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Parent Surface")==0)
			{
				//----------------------------------------------
				// 2. Parent Surface
				strcpy(tempCBoxEntry3.parentSurface ,pch);
				// If have read end-of-line character, replace it with null
				if (tempCBoxEntry3.parentSurface[strlen(pch)-1] == 0x0A)
				{
					tempCBoxEntry3.parentSurface[strlen(pch)-1] = 0;
				}				
			}
			//---------------------------------------------------------
			if(strcmp(tempCBoxEntry.entryLabel,"Multiplier")==0)
			{
				//----------------------------------------------
				// 3. Multiplier
				tempCBoxEntry3.multipier  = atoi(pch);
				populateDataVector = true;
			}
				
			// @SAB all this commented as openings are removed now from the dialog
			//---------------------------------------------------------
			// Populate vector with data
			//---------------------------------------------------------
			////if(populateListDataVector == true)
			////{
				populateListDataVector = false;
				////--------------------------------------------------
				//// Enter this information in the appropriate vector
			////	openingListData_New.push_back(tempCBoxEntry2);								
			////}

			////---------------------------------------------------------
			//// Populate vector with data
			////---------------------------------------------------------
			//if(populateDataVector == true)
			//{
			//	populateDataVector = false;
			//	//--------------------------------------------------
			//	// Enter this information in the appropriate vector
			//	openingsData_New.push_back(tempCBoxEntry3);	
			//}
		}			
	}

	//--------------------------------------------------  
	// Close the CSV file
	fclose(fptr);

	unsigned int i = 0;
	//------------------------------------------------------
	// JOB DETAILS
	//------------------------------------------------------
	JobDetRefNum = stringsWithValues[REF_NUM].entryString;
	assessorName = stringsWithValues[ASSESOR_NAME].entryString;
	JobDetComments = stringsWithValues[COMMENTS].entryString;
	propertyFlatNameorNum = stringsWithValues[PROPERTY_FLAT_NAME_NUM].entryString;
	propertyLetter  = stringsWithValues[PROPERTY_LETTER].entryString;
	propertyHouseNum= stringsWithValues[PROPERTY_HOUSE_NUM].entryString;
	propertyStreet  = stringsWithValues[PROPERTY_STREET].entryString;
	propertyLocality= stringsWithValues[PROPERTY_LOCALITY].entryString;
	propertyDistrict= stringsWithValues[PROPERTY_DISTRICT].entryString;
	propertyTown    = stringsWithValues[PROPERTY_TOWN].entryString;
	propertyCounty  = stringsWithValues[PROPERTY_COUNTY].entryString;
	propertyPostCode= stringsWithValues[PROPERTY_POSTCODE].entryString;
	clientFlatNameorNum = stringsWithValues[CLIENT_FLAT_NAME_NUM].entryString;
	clientHouseorBlockNum = stringsWithValues[CLIENT_LETTER].entryString;
	clientLetter = stringsWithValues[CLIENT_HOUSE_NUM].entryString;
	clientStreet = stringsWithValues[CLIENT_STREET].entryString;
	clientLocality = stringsWithValues[CLIENT_LOCALITY].entryString;
	clientDistrict = stringsWithValues[CLIENT_DISTRICT].entryString;
	clientTown     = stringsWithValues[CLIENT_TOWN].entryString;
	clientCounty   = stringsWithValues[CLIENT_COUNTY].entryString;
	clientPostCode = stringsWithValues[CLIENT_POSTCODE].entryString;

	//------------------------------------------------------
	// BUILT FORM
	//------------------------------------------------------
	dwellingType = stringsWithValues[DWELLING_TYPE].entryString;
	propertyType = stringsWithValues[PROPERTY_TYPE].entryString;
	BuiltForm = stringsWithValues[BUILT_FORM].entryString;
	FlatType = stringsWithValues[FLAT_TYPE].entryString;
	yearPropertBuilt = stringsWithValues[YEAR_PROPERTY_BUILT].entryString;
	//degreeDayLocation = stringsWithValues[DD_LOCATION].entryString;
	dwellingShelteredSides = atoi(stringsWithValues[DWEL_SHELTERED_SIDES].entryString);
	dwellingTerrain = stringsWithValues[DWEL_TERRAIN].entryString;
	dwellingExposure = stringsWithValues[DWEL_EXPOSURE].entryString;

	storey1      =  "storey1" ;//stringsWithValues[STOREY1].entryString;
	storey1Level = stringsWithValues[STOREY1_LEVEL].entryString;
	storey1Basement = stringsWithValues[STOREY1_BASEMENT].entryString;
	storey1Area     = atof(stringsWithValues[STOREY1_AREA].entryString);
	storey1Height   = atof(stringsWithValues[STOREY1_HEIGHT].entryString);

	storey2      = "storey2" ;//stringsWithValues[STOREY2].entryString;
	storey2Level = stringsWithValues[STOREY2_LEVEL].entryString;
	storey2Basement = stringsWithValues[STOREY2_BASEMENT].entryString;
	storey2Area     = atof(stringsWithValues[STOREY2_AREA].entryString);
	storey2Height   = atof(stringsWithValues[STOREY2_HEIGHT].entryString);

	storey3      = "storey3" ;//stringsWithValues[STOREY3].entryString;
	storey3Level = stringsWithValues[STOREY3_LEVEL].entryString;
	storey3Basement = stringsWithValues[STOREY3_BASEMENT].entryString;
	storey3Area     = atof(stringsWithValues[STOREY3_AREA].entryString);
	storey3Height   = atof(stringsWithValues[STOREY3_HEIGHT].entryString);

	storey4      = "storey4" ;//stringsWithValues[STOREY4].entryString;
	storey4Level = stringsWithValues[STOREY4_LEVEL].entryString;
	storey4Basement = stringsWithValues[STOREY4_BASEMENT].entryString;
	storey4Area     = atof(stringsWithValues[STOREY4_AREA].entryString);
	storey4Height   = atof(stringsWithValues[STOREY4_HEIGHT].entryString);

	storey5      = "storey5" ;//stringsWithValues[STOREY5].entryString;
	storey5Level = stringsWithValues[STOREY5_LEVEL].entryString;
	storey5Basement = stringsWithValues[STOREY5_BASEMENT].entryString;
	storey5Area     = atof(stringsWithValues[STOREY5_AREA].entryString);
	storey5Height   = atof(stringsWithValues[STOREY5_HEIGHT].entryString);

	storey6         = "storey6" ;//stringsWithValues[STOREY6].entryString;
	storey6Level    = stringsWithValues[STOREY6_LEVEL].entryString;
	storey6Basement = stringsWithValues[STOREY6_BASEMENT].entryString;
	storey6Area     = atof(stringsWithValues[STOREY6_AREA].entryString);
	storey6Height   = atof(stringsWithValues[STOREY6_HEIGHT].entryString);

	//----------------------------------------------------------------------
	// FLOORS
	//----------------------------------------------------------------------
	//floor1Selected     = stringsWithValues[FLOOR1].entryString;
	//floor1Name         = stringsWithValues[FLOOR1_NAME].entryString;
	//floor1Type         = stringsWithValues[FLOOR1_TYPE].entryString;
	//floor1Construction = stringsWithValues[FLOOR1_CONSTRUCTION].entryString;
	//isfloor1Sealed     = stringsWithValues[FLOOR1_SEALED].entryString;
	//floor1Area         = atof(stringsWithValues[FLOOR1_AREA].entryString);
	//floor1Uvalue       = atof(stringsWithValues[FLOOR1_UVALUE].entryString);

	//floor2Selected     = stringsWithValues[FLOOR2].entryString;
	//floor2Name         = stringsWithValues[FLOOR2_NAME].entryString;
	//floor2Type         = stringsWithValues[FLOOR2_TYPE].entryString;
	//floor2Construction = stringsWithValues[FLOOR2_CONSTRUCTION].entryString;
	//isfloor2Sealed     = stringsWithValues[FLOOR2_SEALED].entryString;
	//floor2Area         = atof(stringsWithValues[FLOOR2_AREA].entryString);
	//floor2Uvalue       = atof(stringsWithValues[FLOOR2_UVALUE].entryString);

	//floor3Selected     = stringsWithValues[FLOOR3].entryString;
	//floor3Name         = stringsWithValues[FLOOR3_NAME].entryString;
	//floor3Type         = stringsWithValues[FLOOR3_TYPE].entryString;
	//floor3Construction = stringsWithValues[FLOOR3_CONSTRUCTION].entryString;
	//isfloor3Sealed     = stringsWithValues[FLOOR3_SEALED].entryString;
	//floor3Area         = atof(stringsWithValues[FLOOR3_AREA].entryString);
	//floor3Uvalue       = atof(stringsWithValues[FLOOR3_UVALUE].entryString);

	//floor4Selected     = stringsWithValues[FLOOR4].entryString;
	//floor4Name         = stringsWithValues[FLOOR4_NAME].entryString;
	//floor4Type         = stringsWithValues[FLOOR4_TYPE].entryString;
	//floor4Construction = stringsWithValues[FLOOR4_CONSTRUCTION].entryString;
	//isfloor4Sealed     = stringsWithValues[FLOOR4_SEALED].entryString;
	//floor4Area         = atof(stringsWithValues[FLOOR4_AREA].entryString);
	//floor4Uvalue       = atof(stringsWithValues[FLOOR4_UVALUE].entryString);

	//floor5Selected     = stringsWithValues[FLOOR5].entryString;
	//floor5Name         = stringsWithValues[FLOOR5_NAME].entryString;
	//floor5Type         = stringsWithValues[FLOOR5_TYPE].entryString;
	//floor5Construction = stringsWithValues[FLOOR5_CONSTRUCTION].entryString;
	//isfloor5Sealed     = stringsWithValues[FLOOR5_SEALED].entryString;
	//floor5Area         = atof(stringsWithValues[FLOOR5_AREA].entryString);
	//floor5Uvalue       = atof(stringsWithValues[FLOOR5_UVALUE].entryString);

	//floor6Selected     = stringsWithValues[FLOOR6].entryString;
	//floor6Name         = stringsWithValues[FLOOR6_NAME].entryString;
	//floor6Type         = stringsWithValues[FLOOR6_TYPE].entryString;
	//floor6Construction = stringsWithValues[FLOOR6_CONSTRUCTION].entryString;
	//isfloor6Sealed     = stringsWithValues[FLOOR6_SEALED].entryString;
	//floor6Area         = atof(stringsWithValues[FLOOR6_AREA].entryString);
	//floor6Uvalue       = atof(stringsWithValues[FLOOR6_UVALUE].entryString);

	//floor7Selected     = stringsWithValues[FLOOR7].entryString;
	//floor7Name         = stringsWithValues[FLOOR7_NAME].entryString;
	//floor7Type         = stringsWithValues[FLOOR7_TYPE].entryString;
	//floor7Construction = stringsWithValues[FLOOR7_CONSTRUCTION].entryString;
	//isfloor7Sealed     = stringsWithValues[FLOOR7_SEALED].entryString;
	//floor7Area         = atof(stringsWithValues[FLOOR7_AREA].entryString);
	//floor7Uvalue       = atof(stringsWithValues[FLOOR7_UVALUE].entryString);

	//floor8Selected     = stringsWithValues[FLOOR8].entryString;
	//floor8Name         = stringsWithValues[FLOOR8_NAME].entryString;
	//floor8Type         = stringsWithValues[FLOOR8_TYPE].entryString;
	//floor8Construction = stringsWithValues[FLOOR8_CONSTRUCTION].entryString;
	//isfloor8Sealed     = stringsWithValues[FLOOR8_SEALED].entryString;
	//floor8Area         = atof(stringsWithValues[FLOOR8_AREA].entryString);
	//floor8Uvalue       = atof(stringsWithValues[FLOOR8_UVALUE].entryString);

	//floor9Selected     = stringsWithValues[FLOOR9].entryString;
	//floor9Name         = stringsWithValues[FLOOR9_NAME].entryString;
	//floor9Type         = stringsWithValues[FLOOR9_TYPE].entryString;
	//floor9Construction = stringsWithValues[FLOOR9_CONSTRUCTION].entryString;
	//isfloor9Sealed     = stringsWithValues[FLOOR9_SEALED].entryString;
	//floor9Area         = atof(stringsWithValues[FLOOR9_AREA].entryString);
	//floor9Uvalue       = atof(stringsWithValues[FLOOR9_UVALUE].entryString);

	//floor10Selected     = stringsWithValues[FLOOR10].entryString;
	//floor10Name         = stringsWithValues[FLOOR10_NAME].entryString;
	//floor10Type         = stringsWithValues[FLOOR10_TYPE].entryString;
	//floor10Construction = stringsWithValues[FLOOR10_CONSTRUCTION].entryString;
	//isfloor10Sealed     = stringsWithValues[FLOOR10_SEALED].entryString;
	//floor10Area         = atof(stringsWithValues[FLOOR10_AREA].entryString);
	//floor10Uvalue       = atof(stringsWithValues[FLOOR10_UVALUE].entryString);

	//------------------------------------------------------
	// WALLS
	//------------------------------------------------------
	//wall1Selected      = stringsWithValues[WALL1].entryString;
	//wall1Name          = stringsWithValues[WALL1_NAME].entryString;
	//wall1Construction  = stringsWithValues[WALL1_CONSTRUCTION].entryString; 
	//wall1Basement      = stringsWithValues[WALL1_BASEMENT].entryString;
	//wall1Area          = atof(stringsWithValues[WALL1_AREA].entryString ); 
	//wall1Uvalue        = atof(stringsWithValues[WALL1_UVALUE].entryString );

	//wall2Selected      = stringsWithValues[WALL2].entryString;
	//wall2Name          = stringsWithValues[WALL2_NAME].entryString;
	//wall2Construction  = stringsWithValues[WALL2_CONSTRUCTION].entryString; 
	//wall2Basement      = stringsWithValues[WALL2_BASEMENT].entryString;
	//wall2Area          = atof(stringsWithValues[WALL2_AREA].entryString ); 
	//wall2Uvalue        = atof(stringsWithValues[WALL2_UVALUE].entryString ); 

	//wall3Selected      = stringsWithValues[WALL3].entryString;
	//wall3Name          = stringsWithValues[WALL3_NAME].entryString;
	//wall3Construction  = stringsWithValues[WALL3_CONSTRUCTION].entryString; 
	//wall3Basement      = stringsWithValues[WALL3_BASEMENT].entryString;
	//wall3Area          = atof(stringsWithValues[WALL3_AREA].entryString ); 
	//wall3Uvalue        = atof(stringsWithValues[WALL3_UVALUE].entryString ); 

	//wall4Selected      = stringsWithValues[WALL4].entryString;
	//wall4Name          = stringsWithValues[WALL4_NAME].entryString;
	//wall4Construction  = stringsWithValues[WALL4_CONSTRUCTION].entryString; 
	//wall4Basement      = stringsWithValues[WALL4_BASEMENT].entryString;
	//wall4Area          = atof(stringsWithValues[WALL4_AREA].entryString ); 
	//wall4Uvalue        = atof(stringsWithValues[WALL4_UVALUE].entryString ); 

	//wall5Selected      = stringsWithValues[WALL5].entryString;
	//wall5Name          = stringsWithValues[WALL5_NAME].entryString;
	//wall5Construction  = stringsWithValues[WALL5_CONSTRUCTION].entryString; 
	//wall5Basement      = stringsWithValues[WALL5_BASEMENT].entryString;
	//wall5Area          = atof(stringsWithValues[WALL5_AREA].entryString ); 
	//wall5Uvalue        = atof(stringsWithValues[WALL5_UVALUE].entryString ); 

	//wall6Selected      = stringsWithValues[WALL6].entryString;
	//wall6Name          = stringsWithValues[WALL6_NAME].entryString;
	//wall6Construction  = stringsWithValues[WALL6_CONSTRUCTION].entryString; 
	//wall6Basement      = stringsWithValues[WALL6_BASEMENT].entryString;
	//wall6Area          = atof(stringsWithValues[WALL6_AREA].entryString ); 
	//wall6Uvalue        = atof(stringsWithValues[WALL6_UVALUE].entryString ); 

	//wall7Selected      = stringsWithValues[WALL7].entryString;
	//wall7Name          = stringsWithValues[WALL7_NAME].entryString;
	//wall7Construction  = stringsWithValues[WALL7_CONSTRUCTION].entryString; 
	//wall7Basement      = stringsWithValues[WALL7_BASEMENT].entryString;
	//wall7Area          = atof(stringsWithValues[WALL7_AREA].entryString ); 
	//wall7Uvalue        = atof(stringsWithValues[WALL7_UVALUE].entryString ); 

	//wall8Selected      = stringsWithValues[WALL8].entryString;
	//wall8Name          = stringsWithValues[WALL8_NAME].entryString;
	//wall8Construction  = stringsWithValues[WALL8_CONSTRUCTION].entryString; 
	//wall8Basement      = stringsWithValues[WALL8_BASEMENT].entryString;
	//wall8Area          = atof(stringsWithValues[WALL8_AREA].entryString ); 
	//wall8Uvalue        = atof(stringsWithValues[WALL8_UVALUE].entryString ); 

	//wall9Selected      = stringsWithValues[WALL9].entryString;
	//wall9Name          = stringsWithValues[WALL9_NAME].entryString;
	//wall9Construction  = stringsWithValues[WALL9_CONSTRUCTION].entryString; 
	//wall9Basement      = stringsWithValues[WALL9_BASEMENT].entryString;
	//wall9Area          = atof(stringsWithValues[WALL9_AREA].entryString ); 
	//wall9Uvalue        = atof(stringsWithValues[WALL9_UVALUE].entryString ); 

	//wall10Selected      = stringsWithValues[WALL10].entryString;
	//wall10Name          = stringsWithValues[WALL10_NAME].entryString;
	//wall10Construction  = stringsWithValues[WALL10_CONSTRUCTION].entryString; 
	//wall10Basement      = stringsWithValues[WALL10_BASEMENT].entryString;
	//wall10Area          = atof(stringsWithValues[WALL10_AREA].entryString ); 
	//wall10Uvalue        = atof(stringsWithValues[WALL10_UVALUE].entryString ); 

	//------------------------------------------------------
	// ROOFS
	//------------------------------------------------------
	//isRoof1Selected   = stringsWithValues[ROOF1].entryString;
	//roof1Name         = stringsWithValues[ROOF1_NAME].entryString;
	//roof1Construction = stringsWithValues[ROOF1_CONSTRUCTION].entryString;
	//roof1Area         = atof(stringsWithValues[ROOF1_AREA].entryString);
	//roof1Uvalue       = atof(stringsWithValues[ROOF1_UVALUE].entryString);

	//isRoof2Selected   = stringsWithValues[ROOF2].entryString;
	//roof2Name         = stringsWithValues[ROOF2_NAME].entryString;
	//roof2Construction = stringsWithValues[ROOF2_CONSTRUCTION].entryString;
	//roof2Area         = atof(stringsWithValues[ROOF2_AREA].entryString);
	//roof2Uvalue       = atof(stringsWithValues[ROOF2_UVALUE].entryString);

	//isRoof3Selected   = stringsWithValues[ROOF3].entryString;
	//roof3Name         = stringsWithValues[ROOF3_NAME].entryString;
	//roof3Construction = stringsWithValues[ROOF3_CONSTRUCTION].entryString;
	//roof3Area         = atof(stringsWithValues[ROOF3_AREA].entryString);
	//roof3Uvalue       = atof(stringsWithValues[ROOF3_UVALUE].entryString);

	//isRoof4Selected   = stringsWithValues[ROOF4].entryString;
	//roof4Name         = stringsWithValues[ROOF4_NAME].entryString;
	//roof4Construction = stringsWithValues[ROOF4_CONSTRUCTION].entryString;
	//roof4Area         = atof(stringsWithValues[ROOF4_AREA].entryString);
	//roof4Uvalue       = atof(stringsWithValues[ROOF4_UVALUE].entryString);

	//isRoof5Selected   = stringsWithValues[ROOF5].entryString;
	//roof5Name         = stringsWithValues[ROOF5_NAME].entryString;
	//roof5Construction = stringsWithValues[ROOF5_CONSTRUCTION].entryString;
	//roof5Area         = atof(stringsWithValues[ROOF5_AREA].entryString);
	//roof5Uvalue       = atof(stringsWithValues[ROOF5_UVALUE].entryString);

	//isRoof6Selected   = stringsWithValues[ROOF6].entryString;
	//roof6Name         = stringsWithValues[ROOF6_NAME].entryString;
	//roof6Construction = stringsWithValues[ROOF6_CONSTRUCTION].entryString;
	//roof6Area         = atof(stringsWithValues[ROOF6_AREA].entryString);
	//roof6Uvalue       = atof(stringsWithValues[ROOF6_UVALUE].entryString);

	//isRoof7Selected   = stringsWithValues[ROOF7].entryString;
	//roof7Name         = stringsWithValues[ROOF7_NAME].entryString;
	//roof7Construction = stringsWithValues[ROOF7_CONSTRUCTION].entryString;
	//roof7Area         = atof(stringsWithValues[ROOF7_AREA].entryString);
	//roof7Uvalue       = atof(stringsWithValues[ROOF7_UVALUE].entryString);

	//isRoof8Selected   = stringsWithValues[ROOF8].entryString;
	//roof8Name         = stringsWithValues[ROOF8_NAME].entryString;
	//roof8Construction = stringsWithValues[ROOF8_CONSTRUCTION].entryString;
	//roof8Area         = atof(stringsWithValues[ROOF8_AREA].entryString);
	//roof8Uvalue       = atof(stringsWithValues[ROOF8_UVALUE].entryString);

	//isRoof9Selected   = stringsWithValues[ROOF9].entryString;
	//roof9Name         = stringsWithValues[ROOF9_NAME].entryString;
	//roof9Construction = stringsWithValues[ROOF9_CONSTRUCTION].entryString;
	//roof9Area         = atof(stringsWithValues[ROOF9_AREA].entryString);
	//roof9Uvalue       = atof(stringsWithValues[ROOF9_UVALUE].entryString);

	//isRoof10Selected   = stringsWithValues[ROOF10].entryString;
	//roof10Name         = stringsWithValues[ROOF10_NAME].entryString;
	//roof10Construction = stringsWithValues[ROOF10_CONSTRUCTION].entryString;
	//roof10Area         = atof(stringsWithValues[ROOF10_AREA].entryString);
	//roof10Uvalue       = atof(stringsWithValues[ROOF10_UVALUE].entryString);

	// OPENINGS
	// TO BE DONE LATER

	//------------------------------------------------------
	// VENTILATION
	//------------------------------------------------------
	//designAirPermeability  = stringsWithValues[DES_AIR_PERM].entryString;
	//pressureTestScotland   = stringsWithValues[PRESS_TEST_SCOT].entryString;
	//accreditedDetailsScotland    = stringsWithValues[ACC_DET_SCOT].entryString;
	//seekExemptionForLT3Dwellings = stringsWithValues[SEEK_EXEMPTION].entryString;
	//designAirPermRate  = atof(stringsWithValues[DES_AIR_PERM_RATE].entryString);
	//asBuiltAirPermRate = atof(stringsWithValues[AS_BUILT_AIR_PERM_RATE].entryString);
	//airPermMeasuredInDwelling = stringsWithValues[AIR_PERM_MEAS_DWEL].entryString;
	//asBuiltRef      = stringsWithValues[AS_BUILT_REF].entryString;
	//asBuiltTestDate = stringsWithValues[AS_BUILT_TEST_DATE].entryString;
	//draughtLobby    = stringsWithValues[DRAUGHT_LOBBY].entryString;
	//mechVentValuesFrom = stringsWithValues[MECH_VENT_VALUES_FROM].entryString;
	//numsWetRooms   = stringsWithValues[NUM_WET_ROOMS].entryString;
	//ductInsulation = stringsWithValues[DUCT_INS].entryString;
	numsOpenFirePlaces   = atoi( stringsWithValues[NUM_OPEN_FIRES].entryString);
	numsOpenFlues        = atoi( stringsWithValues[NUM_OPEN_FLUES].entryString);
	numsFluelessGasFires = atoi( stringsWithValues[NUM_FLUELESS_GAS_FIRES].entryString);
	numsExtractFans      = atoi( stringsWithValues[NUM_EXTRCT_FANS].entryString );
	numsPassiveVents     = atoi( stringsWithValues[NUM_PASSIVE_VENTS].entryString );
	//ACEnergyUse          = atof( stringsWithValues[AC_ENERGY_USE].entryString);		

	mechVentType    = stringsWithValues[MECH_VENT_TYPE].entryString;
	mechVentEff		= atof(stringsWithValues[MECH_VENT_EFF].entryString);
	SFP				= atof(stringsWithValues[MECH_VENT_SFP].entryString);
	pressureTestYN = stringsWithValues[PRESSURE_TEST_YN].entryString;
	measuredQ50    = atof(stringsWithValues[MEASURED_Q50].entryString);
	numOfStoreys   = atoi(stringsWithValues[NUM_OF_STOREYS].entryString);
	structInf      = atof(stringsWithValues[STRUCT_INF].entryString);
	floorInf       = atof(stringsWithValues[FLOOR_INF].entryString);
	draughtLobby    = stringsWithValues[DRAUGHT_LOBBY].entryString;
	perWindowDraughtStripped = atoi(stringsWithValues[PER_WINDOW_DRAUGHT_STRIPPED].entryString);

	//------------------------------------------------------
	// MAIN HEATING
	//------------------------------------------------------
	electricityTarrif = stringsWithValues[ELECTRIC_TARRIF].entryString;
	mainHtType        = stringsWithValues[MAIN_HT_TYPE].entryString;
	mainHtEffFrom     = stringsWithValues[MAIN_HT_EFF_FROM].entryString;
	boilerType        = stringsWithValues[BOILER_TYPE].entryString;
	mainFuel          = stringsWithValues[MAIN_FUEL].entryString;
	//isSecBoilerFuelPresent = stringsWithValues[IS_SEC_BOILER_FUEL].entryString;
	isFanFluePresent  = stringsWithValues[IS_FAN_FLUE].entryString;
	mainHtSystem      = stringsWithValues[MAIN_HT_SYS].entryString;
	mainHtControls    = stringsWithValues[MAIN_HT_CONTROLS].entryString;
	mainHtEmitter     = stringsWithValues[MAIN_HT_EMITTER].entryString;
	isIterlockPresent = stringsWithValues[MAIN_HT_INTERLOCK].entryString;
	mainHtCompensator = stringsWithValues[MAIN_HT_COMPENSATOR].entryString;
	isPumpInHeatedSpace    = stringsWithValues[IS_PUMP_IN_HTD_SPACE].entryString;
	mainHtManufacturerDesc = stringsWithValues[MAIN_HT_MANUFACT_DESC].entryString;
	mainHtTestMethod       = stringsWithValues[MAIN_HT_TESE_METHOD].entryString;
	//boilerRef              = stringsWithValues[MAIN_HT_BOILER_REF].entryString;
	//boilerModel			   = stringsWithValues[MAIN_HT_BOILER_MODEL].entryString;
	mainHtEff              = atof(stringsWithValues[MAIN_HT_EFF].entryString);

	//------------------------------------------------------
	// MAIN HETAING DETAILS
	//------------------------------------------------------
	oilPumpInHeatedSpace = stringsWithValues[OIL_PUMP_IN_HEATED_SPACE].entryString;
	oilBoilerInstalled   = stringsWithValues[OIL_BOILER_INSTALLED].entryString;
	CPSUoperatingTemp    = atof(stringsWithValues[CPSU_OP_TEMP].entryString );
	heatEmmFromCase      = atof(stringsWithValues[HEAT_EMM_FROM_CASE].entryString );
	heatTransferredToWater = atof( stringsWithValues[HEAT_TRANSFER_TO_WATER].entryString);
	smokeControlledArea  = stringsWithValues[SMOKE_CONTROLLED_AREA].entryString;
	isThereCHP           = stringsWithValues[CHP_PRESENT].entryString;
	CHPfuel              = stringsWithValues[CHP_FUEL].entryString;
	fractOfHtFromCHP     = atof( stringsWithValues[FRACT_OF_HT_FROM_CHP].entryString);
	elecEffOfCHP         = atof(stringsWithValues[ELEC_EFF_CHP].entryString );
	heatingEffOfCHP      = atof( stringsWithValues[HT_EFF_CHP].entryString);
	secComBoilerFuel     = stringsWithValues[SEC_COM_BOILER_FUEL].entryString;
	secComBoilerSystem   = stringsWithValues[SEC_COM_BOILER_SYSTEM].entryString;
	secComBoilerEff      = atof(stringsWithValues[SEC_COM_BOILER_EFF].entryString );
	secComBoilerFractOfHtFromBoiler2 = atof( stringsWithValues[SEC_COM_BOILER_FRACT_HEAT_FRM_BOILER2].entryString);
	secComBoilerManufactDesc         = stringsWithValues[SEC_COM_BOILER_MANUFACT_DESC].entryString;

	//------------------------------------------------------
	// SECONDARY HEATING
	//------------------------------------------------------
	isThereSecHeating    = stringsWithValues[SEC_HT_PRESENT].entryString;
	secHtOpenFlueChimney = stringsWithValues[SEC_HT_OPEN_FLUE_CHIMNEY].entryString;
	secHtUnconnectedGasPoint = stringsWithValues[SEC_HT_UNCONNECTED_FAS_POINT].entryString;
	secHtEffFrom         = stringsWithValues[SEC_HT_EFF_FROM].entryString;
	secHtFuel            = stringsWithValues[SEC_HT_FUEL].entryString;
	secHtSystem          = stringsWithValues[SEC_HT_SYSTEM].entryString;
	secHtManufactDesc    = stringsWithValues[SEC_HT_MANUFACT_DESC].entryString;
	secHtTestMethod      = stringsWithValues[SEC_HT_TEST_METHOD].entryString;
	secHtEff             = atof(stringsWithValues[SEC_HT_EFF].entryString );
	secHtFraction        = atof(stringsWithValues[SEC_HT_FRA].entryString );

	//------------------------------------------------------
	// WATER HEATING
	//------------------------------------------------------
	WHtype                    = stringsWithValues[WHT_TYPE].entryString;
	WHtCylinderWithinDwelling = stringsWithValues[WHT_CYL_WITHIN_DWELLING].entryString;
	WHtFuel                   = stringsWithValues[WHT_FUEL].entryString;
	WHtWaterSepTimed          = stringsWithValues[WHT_WATER_SEP_TIMED].entryString;
	WHtRangeCookerType        = stringsWithValues[WHT_RANGE_COOKER_TYPE].entryString;
	WHtCylManufactLossFactor  = stringsWithValues[WHT_MANUFACT_LOSS_FACTOR].entryString;
	WHtCylDeclaredFactor      = atof(stringsWithValues[WHT_CYL_DECLARED_FACTOR].entryString);
	WHtCylVolume              = atof(stringsWithValues[WHT_CYL_VOLUME].entryString);
	WHtCylInsType             = stringsWithValues[WHT_CYL_INS_TYPE].entryString;
	WHtCylInsThickness        = atof(stringsWithValues[WHT_CYL_INS_THICKNESS].entryString);
	WHtCylThermostat          = stringsWithValues[WHT_CYL_THERMOSTAT].entryString;
	WHtCylInHeatedSpace       = stringsWithValues[WHT_CYL_IN_HEATED_SPACE].entryString;
	WHtCylPrimaryPipeworkInsulated  = stringsWithValues[WHT_CYL_PIPEWORK_INS].entryString;
	WHtCylPumpedPrimarySystem       = stringsWithValues[WHT_CYL_PUMP_SYS].entryString;
	WHtEff                          = atof(stringsWithValues[WHT_EFF].entryString);
	WHtTSnCPSUinSingleUnit          = stringsWithValues[WHT_TSN_CPSU_IN_SINGLE_UNIT].entryString;
	WHtTSnCPSUPrimaryPipeworkLT1_5m = stringsWithValues[WHT_TSN_CPSU_PIPEWORK_INFO].entryString;
	WHtTSnCPSUstoreInAirCupbrd      = stringsWithValues[WHT_TSN_CPSU_AIR_CUPBD].entryString;
	WHtCombiKeepHotYN               = stringsWithValues[WHT_COMBI_KEPT_HOT_YN].entryString;
	DHWfromCommunityScheme                          = stringsWithValues[DHW_FROM_COM_SCHEME].entryString;
//	DHWComSchemeProvidedFrom        = stringsWithValues[DHW_SCHEME_PROVIDED_FROM].entryString;
//	DHWComSchemeCHP2PowerRatio      = atof(stringsWithValues[DHW_SCHEME_CHP2POWER_RATIO].entryString);
//	DHWComSchemeSystem              = stringsWithValues[DHW_SCHEME_SYS].entryString;
//	DHWComSchemeEff                 = atof(stringsWithValues[DHW_SCHEME_EFF].entryString);
	WHtHeatPumpUsesImmer            = stringsWithValues[WHT_PUMP_USES_IMMER].entryString;
	WHtUsesSummerImmer              = stringsWithValues[WHT_USES_SUMMER_IMMER].entryString;
	WHtFGHRSys                      = stringsWithValues[WHT_FGHRS].entryString;
	
	//------------------------------------------------------
	//	RENEWABLES
	//------------------------------------------------------
	isSHWPresent     = stringsWithValues[SHW_PRESENT].entryString;
	SHWCollectorType = stringsWithValues[SHW_COLLECTOR_TYPE].entryString;
	SHWCollectorOrientation = stringsWithValues[SHW_COL_ORIENTATION].entryString;
	SHWCollectorTilt = stringsWithValues[SHW_COL_TILT].entryString;
	SHWOvershading   = stringsWithValues[SHW_OVERSHADING].entryString;
	isSHWAreaGross   = stringsWithValues[SHW_IS_GROSS_AREA].entryString;
	SHWGrossArea     = atof( stringsWithValues[SHW_GROSS_AREA].entryString);
	SHWZLCollectorEff  = atof( stringsWithValues[SHW_ZL_COL_EFF].entryString);
	SHWHLCoeff         = atof(stringsWithValues[SHW_HL_COEFF].entryString );
	isSHWSolarStoreCombined       = stringsWithValues[SHW_COMBINED_SOLAR_STORE].entryString;
	SHWDedicatedSolarStoreVolume  = atof(stringsWithValues[SHW_SOLAR_STORE_VOLUME].entryString );
	SHWSolarCircPump              = stringsWithValues[SHW_CIRC_PUMP].entryString;
	isRENAdditionalElectGenerated = stringsWithValues[IS_ELEC_GENERATED].entryString;
	RENAddiationalElecGenerated   = atof( stringsWithValues[ELEC_GENERATED].entryString);
	REN_TFA                = atof(stringsWithValues[RENEWABLES_TFA].entryString );
	isPVPresent            = stringsWithValues[PV_PRESENT].entryString;
	installedPVPeakPower   = atof( stringsWithValues[PV_PEAK_POWER].entryString);
	PVCollectorOrientation = stringsWithValues[PV_ORIENTATION].entryString;
	PVCollectorTilt        = stringsWithValues[PV_TILT].entryString;
	PVOvershading          = stringsWithValues[PV_OVERSHADING].entryString;
	isWTPresent             = stringsWithValues[WT_PRESENT].entryString;
	WTNumOf                = atoi(stringsWithValues[WT_NUM_OF].entryString );
	WTDiameter             = atof(stringsWithValues[WT_DIAMETER].entryString );
	WTHeight               = atof(stringsWithValues[WT_HEIGHT].entryString );

	//------------------------------------------------------
	//	LIGHTS
	//------------------------------------------------------
	fractionLEL = atof(stringsWithValues[FRACTION_LEL].entryString);
	//IntLightsStdFittings           = atoi(stringsWithValues[INT_LIGHTS_STD_FITTINGS].entryString);
	//IntLightsDedicatedLowEnergy    = atoi(stringsWithValues[INT_LIGHTS_DED_LOWE].entryString);
	//IntLightsNonDedicatedLowEnergy = atoi(stringsWithValues[INT_LIGHTS_NONDED_LOWE].entryString);
	//IntLightsTotal                 = atoi(stringsWithValues[INT_LIGHTS_TOTAL].entryString);
	//ExtLightsAssess            = stringsWithValues[EXT_LIGHTS_ASSESS].entryString;
	//ExtLightsFittingGT40Lumens = stringsWithValues[EXT_LIGHTS_FITITNGS].entryString;
	//ExtLightsLampsNGT150W      = stringsWithValues[EXT_LIGHTS_LAMPS].entryString;

	//------------------------------------------------------
	// THERMAL BRIDGES
	//------------------------------------------------------
	//////ThermBMetalBoxLintelUserDef = stringsWithValues[MB_LINTEL_USER_DEF].entryString;
	//////ThermBMetalBoxLintelSiValue = atof(stringsWithValues[MB_LINTEL_SI_VALUE].entryString );
	//////ThermBMetalBoxLintelResult  = atof(stringsWithValues[MB_LINTEL_RESULT].entryString );

	//////ThermBOtherLintelUserDef  = stringsWithValues[OTHER_LINTEL_USER_DEF].entryString;
	//////ThermBOtherLintelsSiValue = atof(stringsWithValues[OTHER_LINTEL_SI_VALUE].entryString );
	//////ThermBOtherLintelsResult  = atof(stringsWithValues[OTHER_LINTEL_RESULT].entryString );

	//////ThermBSillUserDef = stringsWithValues[SILL_USER_DEF].entryString;
	//////ThermBSillSiValue = atof(stringsWithValues[SILL_SI_VALUE].entryString );
	//////ThermBSillResult  = atof(stringsWithValues[SILL_RESULT].entryString );

	//////ThermBJambUserDef = stringsWithValues[JAMB_USER_DEF].entryString;
	//////ThermBJambSiValue = atof(stringsWithValues[JAMB_SI_VALUE].entryString );
	//////ThermBJambResult  = atof( stringsWithValues[JAMB_RESULT].entryString);

	ThermBGFPerimeter        = atof(stringsWithValues[GF_PERIM].entryString );
	ThermBGFPerimeterUserDef = stringsWithValues[GF_USER_DEF].entryString;
	ThermBGFPerimeterSiValue = atof(stringsWithValues[GF_SI_VALUE].entryString );
	ThermBGFPerimeterResult  = atof(stringsWithValues[GF_RESULT].entryString );

	ThermBFloorWithingDwellinPerimeter       = atof(stringsWithValues[FLOOR_WN_DWELLING_PERIM].entryString );
	ThermBFloorWithinDwellingUserDef         = stringsWithValues[FLOOR_WN_DWELLING_USER_DEF].entryString;
	ThermBFloorWithinDwellingSiValue         = atof(stringsWithValues[FLOOR_WN_DWELLING_SI_VALUE].entryString );
	ThermBFloorWithinDwellingPerimeterResult = atof(stringsWithValues[FLOOR_WN_DWELLING_RESULT].entryString );

	ThermBFloorBetweenDwellinPerimeter= atof(stringsWithValues[FLOOR_BW_DWELLING_PERIM].entryString );
	ThermBFloorBwDwellingUserDef      = stringsWithValues[FLOOR_BW_DWELLING_USER_DEF].entryString;
	ThermBFloorBetweenDwellingSiValue = atof(stringsWithValues[FLOOR_BW_DWELLING_SI_VALUE].entryString );
	ThermBFloorBetweenDwellingPerimeterResult = atof(stringsWithValues[FLOOR_BW_DWELLING_RESULT].entryString );

	ThermBBalconyWithingDwellingLength    = atof(stringsWithValues[BALC_WN_DWELLING_PERIM].entryString );
	ThermBBalcWithinDwellingLengthUserDef = stringsWithValues[BALC_WN_DWELLING_USER_DEF].entryString;
	ThermBBalconyWithinDwellingSiValue    = atof(stringsWithValues[BALC_WN_DWELLING_SI_VALUE].entryString );
	ThermBBalcWithDwellingLengthResult    = atof(stringsWithValues[BALC_WN_DWELLING_RESULT].entryString );

	ThermBBalconyBetweenDwellingLength  = atof(stringsWithValues[BALC_BW_DWELLING_PERIM].entryString );
	ThermBBalcBwDwellingLengthUserDef   = stringsWithValues[BALC_BW_DWELLING_USER_DEF].entryString;
	ThermBBalconyBwDwellingSiValue      = atof(stringsWithValues[BALC_BW_DWELLING_SI_VALUE].entryString );
	ThermBBalconyBwDwellingLengthResult = atof(stringsWithValues[BALC_BW_DWELLING_RESULT].entryString );

	ThermBEavesAtCeiling           = atof(stringsWithValues[EAVES_AT_CEILING_PERIM].entryString );
	ThermBEavesInsAtCeilingUserDef = stringsWithValues[EAVES_AT_CEILING_USER_DEF].entryString;
	ThermBEavesInsAtCelingSiValue  = atof(stringsWithValues[EAVES_AT_CEILING_SI_VALUE].entryString );
	ThermBEavesInsCeilingResult    = atof(stringsWithValues[EAVES_AT_CEILING_RESULT].entryString );

	ThermBEavesAtRafter           = atof(stringsWithValues[EAVES_AT_RAFTER_PERIM].entryString );
	ThermBEavesInsAtRafterUserDef = stringsWithValues[EAVES_AT_RAFTER_USER_DEF].entryString;
	ThermBEavesInsAtRafterSiValue = atof(stringsWithValues[EAVES_AT_RAFTER_SI_VALUE].entryString );
	ThermBEavesInsRafterResult    = atof(stringsWithValues[EAVES_AT_RAFTER_RESULT].entryString);

	ThermBGableAtCeiling           = atof(stringsWithValues[GABLE_AT_CEILING_PERIM].entryString );
	ThermBGableInsAtCeilingUserDef = stringsWithValues[GABLE_AT_CEILING_USER_DEF].entryString;
	ThermBGableInsAtCeilingSiValue = atof(stringsWithValues[GABLE_AT_CEILING_SI_VALUE].entryString );
	ThermBGableInsCeilingResult    = atof(stringsWithValues[GABLE_AT_CEILING_RESULT].entryString);

	ThermBGableAtRafter           = atof(stringsWithValues[GABLE_AT_RAFTER_PERIM].entryString );
	ThermBGableInsAtRafetUserDef  = stringsWithValues[GABLE_AT_RAFTER_USER_DEF].entryString;
	ThermBGableInsAtRafterSiValue = atof(stringsWithValues[GABLE_AT_RAFTER_SI_VALUE].entryString );
	ThermBGableInsRafterResult    = atof(stringsWithValues[GABLE_AT_RAFTER_RESULT].entryString );

	ThermBLengthNormalCorners          = atof(stringsWithValues[LENGTH_NCORNERS_PERIM].entryString );
	ThermBLengthOfNormalCornersUserDef = stringsWithValues[LENGTH_NCORNERS_USER_DEF].entryString;
	ThermBLengthOfNormalCornersSiValue = atof(stringsWithValues[LENGTH_NCORNERS_SI_VALUE].entryString );
	ThermBLengthNormalCornersResult    = atof(stringsWithValues[LENGTH_NCORNERS_RESULT].entryString );

	ThermBLengthInvertedCorners          = atof(stringsWithValues[LENGTH_ICORNERS_PERIM].entryString );
	ThermBLengthOfInvertedCornersUserDef = stringsWithValues[LENGTH_ICORNERS_USER_DEF].entryString;
	ThermBLengthOfInvertedCornersSiValue = atof(stringsWithValues[LENGTH_ICORNERS_SI_VALUE].entryString );
	ThermBLengthInvertedCornersResult    = atof(stringsWithValues[LENGTH_ICORNERS_RESULT].entryString );

	ThermBPartWallBetweenDwelling        = atof(stringsWithValues[PARTY_WALL_PERIM].entryString );
	ThermBPartWallBetweenDwellingUserDef = stringsWithValues[PARTY_WALL_USER_DEF].entryString;
	ThermBPartBwDwellingLengthSiValue    = atof(stringsWithValues[PARTY_WALL_SI_VALUE].entryString );
	ThermBPartyWallBwDwellingResult      = atof(stringsWithValues[PARTY_WALL_RESULT].entryString);

	//------------------------------------------------------
	// SUMMER OVERHEATING
	//------------------------------------------------------
	isTMPUserDef               = stringsWithValues[TMP_USER_DEF].entryString;
	TMPvalue                   = atof(stringsWithValues[TMP_VALUE].entryString );
	TMPIntPartConstruction     = stringsWithValues[TMP_INT_PART_CONSTRUCTION].entryString;
	TMPPartyWallConstruction   = stringsWithValues[TMP_PARTY_WALL_CONSTRUCTION].entryString;
	isVentUserDefined          = stringsWithValues[VENT_USER_DEF].entryString;
	airChangeRate              = atof(stringsWithValues[AIR_CHANGE_RATE].entryString );
	isCrossVentOnMostFloors    = stringsWithValues[CROSS_VENT_ON_FLOORS].entryString;
	windowVentilation          = stringsWithValues[WINDOW_VENT].entryString;
	areCurtainsClosedDuringDay = stringsWithValues[CURTAINS_CLOSED_DURING_DAY].entryString;
	fractCurtainsClosed        = atof(stringsWithValues[FRACT_CURTAINS_CLOSED].entryString );
	blindCurtainType           = stringsWithValues[BLIND_OR_CURTAIN_TYPE].entryString;
	sourceUserDefValues        = stringsWithValues[SUM_OVHT_USER_DEF_VALUES_SOURCE].entryString;


	//i = openingListData_New.size(); // ver 4.01
	//for (i = 0; i<openingListData_New.size(); i++)
	//{
	//	tempt = openingListData_New[i].openingName;
	//	//////tempt = openingListData_New[i].openingFromSource; 20feb
	//	//////tempt = openingListData_New[i].openingDescription; //20feb
	//	tempt = openingListData_New[i].openingGlzType;
	//	tempt = openingListData_New[i].openingLowECoating;
	//	tempt = openingListData_New[i].openingUsedDefEmissivity;
	//	//////			tempt.Format("%.f"%,openingListData_New[i].openingEmissivty);	//20feb
	//}

	int TabIndex = 0;
	//------------------------------------------------------------------
	// Get the current number of tab selected	
	TabIndex =  m_c_TabCtrl.GetCurSel();

	//------------------------------------------------------------------
	// Destroy windows
	//------------------------------------------------------------------
	if (!DestroyModlessDialogs()) 
	{
		return;
	}

	//------------------------------------------------------------------
	// Show new dialog selected by tab control
	//------------------------------------------------------------------
	if (TabIndex==0)
	{
		m_JobDetails = new CDlg_JobDetails;
		m_JobDetails->Create(IDD_JOBDETAILS,this);
		m_JobDetails->ShowWindow(SW_SHOW);		
	}
	else if (TabIndex==1)
	{
		m_BuiltForm = new CDlg_BuiltForm;
		m_BuiltForm->Create(IDD_BUILTFORM,this);
		m_BuiltForm->ShowWindow(SW_SHOW);	
	}
	//else if (TabIndex==2)
	//{
	//	m_Floors = new CDlg_Floors;
	//	m_Floors->Create(IDD_FLOORS,this);	
	//	m_Floors->ShowWindow(SW_SHOW);	
	//}
	//else if (TabIndex==3)
	//{
	//	m_Walls = new CDlg_Walls ;
	//	m_Walls->Create(IDD_WALLS ,this);
	//	m_Walls->ShowWindow(SW_SHOW);	
	//}
	//else if (TabIndex==4)
	//{
	//	m_Roofs = new CDlg_Roofs;
	//	m_Roofs->Create(IDD_ROOFS,this);
	//	m_Roofs->ShowWindow(SW_SHOW);	
	//}
	//else if (TabIndex==5)
	//{
	//	m_Openings = new CDlg_Openings;
	//	m_Openings->Create(IDD_OPENINGS,this);
	//	m_Openings->ShowWindow(SW_SHOW);	
	//}

	else if (TabIndex==2)
	{
		m_Windows = new CDlg_Windows;
		m_Windows->Create(IDD_WINDOWS,this);
		m_Windows->ShowWindow(SW_SHOW);			
	}

	else if (TabIndex==3)
	{
		m_AreaAndUvalues = new CDlg_AreaAndUvalues;
		m_AreaAndUvalues->Create(IDD_AREAUVALUES,this);
		m_AreaAndUvalues->ShowWindow(SW_SHOW);			
	}

	else if (TabIndex==4)
	{
		m_Ventilation = new CDlg_Ventilation;
		m_Ventilation->Create(IDD_VENTILATION,this);
		m_Ventilation->ShowWindow(SW_SHOW);
	}
	else if (TabIndex==5)
	{
		m_MainHeating = new CDlg_MainHeating;
		m_MainHeating->Create(IDD_MAINHEATING,this);
		m_MainHeating->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==6)
	{
		m_MainHeatingDetails = new CDlg_MainHeatingDetails;
		m_MainHeatingDetails->Create(IDD_MAINHEATINGDETAILS,this);
		m_MainHeatingDetails->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==7)
	{
		m_SecHeating = new CDlg_SecHeating;
		m_SecHeating->Create(IDD_SECONDARYHEATING,this);
		m_SecHeating->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==8)
	{
		m_WaterHeating = new CDlg_WaterHeating;
		m_WaterHeating->Create(IDD_WATERHEATING,this);
		m_WaterHeating->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==9)
	{
		m_Renewables = new CDlg_Renewables ;
		m_Renewables ->Create(IDD_RENEWABLES,this);
		m_Renewables->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==10)
	{
		m_LightsAndAppliances = new CDlg_LightsAndAppliances ;
		m_LightsAndAppliances ->Create(IDD_LIGHTSANDAPPLIANCES,this);
		m_LightsAndAppliances->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==11)
	{
		m_ThermalBridging = new CDlg_ThermalBridging ;
		m_ThermalBridging ->Create(IDD_THERMALBRIDGING,this);	
		m_ThermalBridging->ShowWindow(SW_SHOW);	
	}
	else if (TabIndex==12)
	{
		m_SummerOverHeating = new CDlg_SummerOverHeating ;
		m_SummerOverHeating ->Create(IDD_SUMMEROVERHEATING,this);
		m_SummerOverHeating->ShowWindow(SW_SHOW);	
	}	
	else if (TabIndex==13)
	{
		m_Results = new CDlg_Results;
		m_Results->Create(IDD_RESULTS,this);
		m_Results->ShowWindow(SW_SHOW);			
	}	
}

void CSAPP1Dlg::OnFileNew()
{
	int TabIndex = 0;
	file_new_selected = true;

	//------------------------------------------------------
	// Get the number of the currently selected tab 
	TabIndex = m_c_TabCtrl.GetCurSel();

	DestroyModlessDialogs();

	//------------------------------------------------------------------
	// Create new instances of all dialogs
	//------------------------------------------------------------------	
	if (TabIndex==0)
	{
		m_JobDetails = new CDlg_JobDetails;
	    m_JobDetails->Create(IDD_JOBDETAILS, this);
		m_JobDetails->ShowWindow(SW_SHOW);
	}
	else if (TabIndex==1)
	{	
		m_BuiltForm = new CDlg_BuiltForm;
		m_BuiltForm->Create(IDD_BUILTFORM,this);
		m_BuiltForm->ShowWindow(SW_SHOW);
	}
	//else if (TabIndex==2)
	//{		
	//	m_Floors = new CDlg_Floors;
	//	m_Floors->Create(IDD_FLOORS,this);
	//	m_Floors->ShowWindow(SW_SHOW);
	//}
	//else if (TabIndex==3)
	//{		
	//	m_Walls = new CDlg_Walls;
	//	m_Walls->Create(IDD_WALLS,this);
	//	m_Walls->ShowWindow(SW_SHOW);
	//}
	//else if (TabIndex==4)
	//{	
	//	m_Roofs = new CDlg_Roofs;
	//	m_Roofs->Create(IDD_ROOFS,this);
	//	m_Roofs->ShowWindow(SW_SHOW);
	//}
	//else if (TabIndex==5)
	//{	
	//	m_Openings = new CDlg_Openings;
	//	m_Openings->Create(IDD_OPENINGS,this);
	//	m_Openings->ShowWindow(SW_SHOW);			
	//}
	else if (TabIndex==2)
	{
		m_Windows = new CDlg_Windows;
		m_Windows->Create(IDD_WINDOWS,this);
		m_Windows->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==3)
	{
		m_AreaAndUvalues = new CDlg_AreaAndUvalues;
		m_AreaAndUvalues->Create(IDD_AREAUVALUES,this);
		m_AreaAndUvalues->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==4)
	{		
		m_Ventilation = new CDlg_Ventilation;
		m_Ventilation->Create(IDD_VENTILATION,this);
		m_Ventilation->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==5)
	{	
		m_MainHeating = new CDlg_MainHeating;
		m_MainHeating->Create(IDD_MAINHEATING,this);
		m_MainHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==6)
	{		
		m_MainHeatingDetails = new CDlg_MainHeatingDetails;
		m_MainHeatingDetails->Create(IDD_MAINHEATINGDETAILS,this);
		m_MainHeatingDetails->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==7)
	{
		m_SecHeating = new CDlg_SecHeating;
		m_SecHeating->Create(IDD_SECONDARYHEATING,this);
		m_SecHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==8)
	{		
		m_WaterHeating = new CDlg_WaterHeating;
		m_WaterHeating->Create(IDD_WATERHEATING,this);
		m_WaterHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==9)
	{		
		m_Renewables = new CDlg_Renewables;
		m_Renewables->Create(IDD_RENEWABLES,this);
		m_Renewables->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==10)
	{		
		m_LightsAndAppliances = new CDlg_LightsAndAppliances;
		m_LightsAndAppliances->Create(IDD_LIGHTSANDAPPLIANCES,this);
		m_LightsAndAppliances->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==11)
	{	
		m_ThermalBridging = new CDlg_ThermalBridging;
		m_ThermalBridging->Create(IDD_THERMALBRIDGING,this);
		m_ThermalBridging->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==12)
	{		
		m_SummerOverHeating = new CDlg_SummerOverHeating;
		m_SummerOverHeating->Create(IDD_SUMMEROVERHEATING,this);
		m_SummerOverHeating->ShowWindow(SW_SHOW);			
	}
	else if (TabIndex==13)
	{
		m_Results = new CDlg_Results;
		m_Results->Create(IDD_RESULTS,this);
		m_Results->ShowWindow(SW_SHOW);			
	}
	

	//-----------------------
	// JOB DETAILS
	//-----------------------
	JobDetRefNum.Empty();
	assessorName.Empty();
	JobDetComments.Empty();

	propertyFlatNameorNum.Empty();
	propertyLetter.Empty();
	propertyHouseNum.Empty();
	propertyStreet.Empty();
	propertyLocality.Empty();
	propertyDistrict.Empty();
	propertyTown.Empty();
	propertyCounty.Empty();
	propertyPostCode.Empty();

	clientFlatNameorNum.Empty();
	clientLetter.Empty();
	clientHouseorBlockNum.Empty();
	clientStreet.Empty();
	clientLocality.Empty();
	clientDistrict.Empty();
	clientTown.Empty();
	clientCounty.Empty();
	clientPostCode.Empty();


	//-----------------------
	// BUILT FORM DLG
	//-----------------------
	//-----------------------------------------------
	// TYPE OF DWELLING
	//-----------------------------------------------
	dwellingType.Empty();

	//-----------------------------------------------
	// PROPERTY TYPE
	//-----------------------------------------------
	propertyType.Empty();

	//-----------------------------------------------
	// BUILT FORM
	//-----------------------------------------------
	BuiltForm.Empty();

	//-----------------------------------------------
	// FLAT TYPE
	//-----------------------------------------------
	FlatType.Empty();

	//-----------------------------------------------
	// YEAR BUILT
	//-----------------------------------------------
	yearPropertBuilt.Empty();

	//-----------------------------------------------
	// DEGREE DAY LOCATION
	//-----------------------------------------------
	degreeDayLocation.Empty();

	//-----------------------------------------------
	// SHELTERED SIDES
	//-----------------------------------------------		
	dwellingShelteredSides = 0;

	//-----------------------------------------------
	// TERRAIN
	//-----------------------------------------------
	dwellingTerrain.Empty();

	//-----------------------------------------------
	// EXPOSURE
	//-----------------------------------------------
	dwellingExposure.Empty();

	//-----------------------------------------------
	// NUMBER OF STOREYS SELECTED
	//-----------------------------------------------
	storey1 = "no";
	storey2 = "no";
	storey3 = "no";
	storey4 = "no";
	storey5 = "no";
	storey6 = "no";

	//-----------------------------------------------
	// LEVEL OF STOREYS 
	//-----------------------------------------------		
	storey1Level.Empty();
	storey2Level.Empty();
	storey3Level.Empty();
	storey4Level.Empty();
	storey5Level.Empty();
	storey6Level.Empty();

	//-----------------------------------------------
	// BASEMENT FOR STOREYS SELECTED
	//-----------------------------------------------	
	storey1Basement = "no";
	storey2Basement = "no";
	storey3Basement = "no";
	storey4Basement = "no";
	storey5Basement = "no";
	storey6Basement = "no";

	//-----------------------------------------------
	// AREA OF STOREYS 
	//-----------------------------------------------		
	storey1Area = 0;
	storey2Area = 0;
	storey3Area = 0;
	storey4Area = 0;
	storey5Area = 0;
	storey6Area = 0;

	//-----------------------------------------------
	// HEIGHT OF STOREYS 
	//-----------------------------------------------		
	storey1Height = 0;
	storey2Height = 0;
	storey3Height = 0;
	storey4Height = 0;
	storey5Height = 0;
	storey6Height = 0;

	//-------------------------
	// FLOORS DLG
	//-------------------------

	//-------------------------
	// FLOOR CHECK BOX
	//-------------------------
	floor1Selected = "no";
	floor2Selected = "no";
	floor3Selected = "no";
	floor4Selected = "no";
	floor5Selected = "no";
	floor6Selected = "no";
	floor7Selected = "no";
	floor8Selected = "no";
	floor9Selected = "no";
	floor10Selected = "no";

	//-------------------------
	// FLOOR NAME
	//-------------------------
	floor1Name.Empty();
	floor2Name.Empty();
	floor3Name.Empty();
	floor4Name.Empty();
	floor5Name.Empty();
	floor6Name.Empty();
	floor7Name.Empty();
	floor8Name.Empty();
	floor9Name.Empty();
	floor10Name.Empty();

	//-------------------------
	// FLOOR TYPE
	//-------------------------
	floor1Type.Empty();
	floor2Type.Empty();
	floor3Type.Empty();
	floor4Type.Empty();
	floor5Type.Empty();
	floor6Type.Empty();
	floor7Type.Empty();
	floor8Type.Empty();
	floor9Type.Empty();
	floor10Type.Empty();

	//-------------------------
	// FLOOR CONSTRUCTION
	//-------------------------
	floor1Construction.Empty();
	floor2Construction.Empty();
	floor3Construction.Empty();
	floor4Construction.Empty();
	floor5Construction.Empty();
	floor6Construction.Empty();
	floor7Construction.Empty();
	floor8Construction.Empty();
	floor9Construction.Empty();
	floor10Construction.Empty();

	//-------------------------
	// IS FLOOR SEALED
	//-------------------------
	isfloor1Sealed = "no";
	isfloor2Sealed = "no";
	isfloor3Sealed = "no";
	isfloor4Sealed = "no";
	isfloor5Sealed = "no";
	isfloor6Sealed = "no";
	isfloor7Sealed = "no";
	isfloor8Sealed = "no";
	isfloor9Sealed = "no";
	isfloor10Sealed = "no";
	//-------------------------
	// FLOORS AREA
	//-------------------------
	floor1Area = 0;
	floor2Area = 0;
	floor3Area = 0;
	floor4Area = 0;
	floor5Area = 0;
	floor6Area = 0;
	floor7Area = 0;
	floor8Area = 0;
	floor9Area = 0;
	floor10Area = 0;

	floor1Uvalue = 0;
	floor2Uvalue = 0;
	floor3Uvalue = 0;
	floor4Uvalue = 0;
	floor5Uvalue = 0;
	floor6Uvalue = 0;
	floor7Uvalue = 0;
	floor8Uvalue = 0;
	floor9Uvalue = 0;
	floor10Uvalue = 0;

	//-------------------------
	// WALL DLG
	//-------------------------

	//------------------------------------------
	//	WALL CHECK BUTTON
	//------------------------------------------
	wall1Selected = "no";
	wall2Selected = "no";
	wall3Selected = "no";
	wall4Selected = "no";
	wall5Selected = "no";
	wall6Selected = "no";
	wall7Selected = "no";
	wall8Selected = "no";
	wall9Selected = "no";
	wall10Selected = "no";

	//------------------------------------------
	//	WALL NAME
	//------------------------------------------
	wall1Name.Empty();
	wall2Name.Empty();
	wall3Name.Empty();
	wall4Name.Empty();
	wall5Name.Empty();
	wall6Name.Empty();
	wall7Name.Empty();
	wall8Name.Empty();
	wall9Name.Empty();
	wall10Name.Empty();

	//------------------------------------------
	//	WALL CONSTRUCTION
	//------------------------------------------
	wall1Construction.Empty();
	wall2Construction.Empty();
	wall3Construction.Empty();
	wall4Construction.Empty();
	wall5Construction.Empty();
	wall6Construction.Empty();
	wall7Construction.Empty();
	wall8Construction.Empty();
	wall9Construction.Empty();
	wall10Construction.Empty();

	//------------------------------------------
	//	WALL BASEMENT
	//------------------------------------------
	wall1Basement.Empty();
	wall2Basement.Empty();
	wall3Basement.Empty();
	wall4Basement.Empty();
	wall5Basement.Empty();
	wall6Basement.Empty();
	wall7Basement.Empty();
	wall8Basement.Empty();
	wall9Basement.Empty();
	wall10Basement.Empty();

	//------------------------------------------
	//	WALL AREA
	//------------------------------------------
	wall1Area = 0;
	wall2Area = 0;
	wall3Area = 0;
	wall4Area = 0;
	wall5Area = 0;
	wall6Area = 0;
	wall7Area = 0;
	wall8Area = 0;
	wall9Area = 0;
	wall10Area = 0;

	//------------------------------------------
	//	WALL U-VALUE
	//------------------------------------------
	wall1Uvalue = 0;
	wall2Uvalue = 0;
	wall3Uvalue = 0;
	wall4Uvalue = 0;
	wall5Uvalue = 0;
	wall6Uvalue = 0;
	wall7Uvalue = 0;
	wall8Uvalue = 0;
	wall9Uvalue = 0;
	wall10Uvalue = 0;

	//--------------------
	//	ROOF DLG
	//--------------------

	//------------------------------------------
	//	ROOF CHECK BUTTON
	//------------------------------------------
	isRoof1Selected = "no";
	isRoof2Selected = "no";
	isRoof3Selected = "no";
	isRoof4Selected = "no";
	isRoof5Selected = "no";
	isRoof6Selected = "no";
	isRoof7Selected = "no";
	isRoof8Selected = "no";
	isRoof9Selected = "no";
	isRoof10Selected = "no";

	//------------------------------------------
	//	ROOF NAME
	//------------------------------------------
	roof1Name.Empty();
	roof2Name.Empty();
	roof3Name.Empty();
	roof4Name.Empty();
	roof5Name.Empty();
	roof6Name.Empty();
	roof7Name.Empty();
	roof8Name.Empty();
	roof9Name.Empty();
	roof10Name.Empty();

	//------------------------------------------
	//	ROOF CONSTRUCTION
	//------------------------------------------
	roof1Construction.Empty();
	roof2Construction.Empty();
	roof3Construction.Empty();
	roof4Construction.Empty();
	roof5Construction.Empty();
	roof6Construction.Empty();
	roof7Construction.Empty();
	roof8Construction.Empty();
	roof9Construction.Empty();
	roof10Construction.Empty();

	//------------------------------------------
	//	ROOF AREA
	//------------------------------------------
	roof1Area = 0;
	roof2Area = 0;
	roof3Area = 0;
	roof4Area = 0;
	roof5Area = 0;
	roof6Area = 0;
	roof7Area = 0;
	roof8Area = 0;
	roof9Area = 0;
	roof10Area= 0;

	//------------------------------------------
	//	ROOF U-VALUE
	//------------------------------------------
	roof1Uvalue = 0;
	roof2Uvalue = 0;
	roof3Uvalue = 0;
	roof4Uvalue = 0;
	roof5Uvalue = 0;
	roof6Uvalue = 0;
	roof7Uvalue = 0;
	roof8Uvalue = 0;
	roof9Uvalue = 0;
	roof10Uvalue= 0;

	//-----------------------
	// VENTILATION DLG
	//-----------------------
	designAirPermeability.Empty();
	pressureTestScotland.Empty();
	accreditedDetailsScotland.Empty();
	seekExemptionForLT3Dwellings.Empty();

	designAirPermRate  = 0;
	asBuiltAirPermRate = 0;

	airPermMeasuredInDwelling.Empty();
	asBuiltRef.Empty();
	asBuiltTestDate.Empty();
	draughtLobby.Empty();
	mechVentType.Empty();
	mechVentEff = 0;
	SFP = 0;
	//mechVentValuesFrom.Empty();
	//numsWetRooms.Empty();
	//ductInsulation.Empty();	

	numsOpenFirePlaces   = 0;
	numsOpenFlues        = 0;
	numsFluelessGasFires = 0;

	numsExtractFans  = 0;
	numsPassiveVents = 0;

	pressureTestYN.Empty();
	measuredQ50= 0;
	numOfStoreys= 0;
	structInf= 0;
	floorInf= 0;
	draughtLobby.Empty();
	perWindowDraughtStripped= 0;

	isACPresent.Empty();
	ACEnergyUse = 0;

	//-----------------------
	// MAIN HT DLG
	//-----------------------
	electricityTarrif.Empty();
	mainHtType.Empty();
	mainHtEffFrom.Empty();
	boilerType.Empty();
	mainFuel.Empty();

	isSecBoilerFuelPresent.Empty();
	isFanFluePresent.Empty();
	mainHtSystem.Empty();
	mainHtControls.Empty();
	mainHtEmitter.Empty();
	isIterlockPresent.Empty();
	mainHtCompensator.Empty();

	isPumpInHeatedSpace.Empty();

	mainHtManufacturerDesc.Empty();
	mainHtTestMethod .Empty();
	mainHtEff              = 0;

	//-----------------------
	// MAIN HT DETAILS DLG
	//-----------------------
	oilPumpInHeatedSpace.Empty();
	oilBoilerInstalled.Empty();

	CPSUoperatingTemp = 0;
	heatEmmFromCase   = 0;
	heatTransferredToWater = 0;

	smokeControlledArea.Empty();
	isThereCHP.Empty();
	CHPfuel.Empty();

	fractOfHtFromCHP = 0;
	elecEffOfCHP     = 0;
	heatingEffOfCHP  = 0;

	secComBoilerFuel.Empty();
	secComBoilerSystem.Empty();

	secComBoilerEff = 0;
	secComBoilerFractOfHtFromBoiler2 = 0;
	secComBoilerManufactDesc.Empty();

	//-----------------------
	// SEC HT DLG
	//-----------------------
	isThereSecHeating.Empty();
	secHtOpenFlueChimney.Empty();
	secHtUnconnectedGasPoint.Empty();

	secHtEffFrom.Empty();
	secHtFuel.Empty();
	secHtSystem.Empty();

	secHtManufactDesc.Empty();
	secHtTestMethod.Empty();
	secHtEff          = 0;
	secHtFraction = 0;

	//-----------------------
	// WATER HT DLG
	//-----------------------
	WHtype.Empty();
	WHtCylinderWithinDwelling.Empty();
	WHtFuel.Empty();
	WHtWaterSepTimed.Empty();
	WHtRangeCookerType.Empty();

	WHtCylManufactLossFactor.Empty();
	WHtCylDeclaredFactor     = 0;
	WHtCylVolume             = 0;

	WHtCylInsType.Empty();
	WHtCylInsThickness  =  0;
	WHtCylThermostat.Empty();
	WHtCylInHeatedSpace.Empty();
	WHtCylPrimaryPipeworkInsulated.Empty();
	WHtCylPumpedPrimarySystem.Empty();
	WHtEff = 0;

	WHtTSnCPSUinSingleUnit.Empty();
	WHtTSnCPSUPrimaryPipeworkLT1_5m.Empty();
	WHtTSnCPSUstoreInAirCupbrd.Empty();

	WHtCombiKeepHotYN.Empty();
	//WHtCombiKeepHotUsesElec.Empty();
	//WHtCombiPowerRating     = 0;

	DHWfromCommunityScheme.Empty();
	//DHWComSchemeProvidedFrom.Empty();
	//DHWComSchemeCHP2PowerRatio = 0;
	//DHWComSchemeSystem.Empty();
	//DHWComSchemeEff            = 0;

	WHtHeatPumpUsesImmer.Empty();
	WHtUsesSummerImmer.Empty();
	WHtFGHRSys.Empty();

	//-----------------------
	// RENEWABLES DLG
	//-----------------------
	isSHWPresent.Empty();
	SHWCollectorType.Empty();
	SHWCollectorOrientation.Empty();
	SHWCollectorTilt.Empty();
	SHWOvershading.Empty();
	isSHWAreaGross.Empty();

	SHWGrossArea      = 0;
	SHWZLCollectorEff = 0;
	SHWHLCoeff        = 0;

	isSHWSolarStoreCombined.Empty();
	SHWDedicatedSolarStoreVolume = 0;

	SHWSolarCircPump.Empty();
	isRENAdditionalElectGenerated.Empty();

	RENAddiationalElecGenerated = 0;
	REN_TFA = 0;

	isPVPresent.Empty();
	installedPVPeakPower = 0;

	PVCollectorOrientation.Empty();
	PVCollectorTilt.Empty();
	PVOvershading.Empty();
	isWTPresent.Empty();

	WTNumOf    = 0;
	WTDiameter = 0;
	WTHeight   = 0;

	//-----------------------
	// LIGHTS DLG
	//-----------------------
	fractionLEL = 0;
	//IntLightsStdFittings           = 0;
	//IntLightsDedicatedLowEnergy    = 0;
	//IntLightsNonDedicatedLowEnergy = 0;

	//ExtLightsAssess .Empty();
	//ExtLightsFittingGT40Lumens.Empty();
	//ExtLightsLampsNGT150W.Empty();

	//IntLightsTotal = 0;

	//-----------------------
	// THERMAL BRIDGING DLG
	//-----------------------
	ThermBGFPerimeter = 0;
	ThermBFloorWithingDwellinPerimeter = 0;
	ThermBFloorBetweenDwellinPerimeter = 0;
	ThermBBalconyWithingDwellingLength = 0;
	ThermBBalconyBetweenDwellingLength = 0;
	ThermBEavesAtCeiling = 0;
	ThermBEavesAtRafter  = 0;
	ThermBGableAtCeiling = 0;
	ThermBGableAtRafter  = 0;
	ThermBLengthNormalCorners     = 0;
	ThermBLengthInvertedCorners   = 0;
	ThermBPartWallBetweenDwelling = 0;

	ThermBMetalBoxLintelUserDef.Empty();
	ThermBOtherLintelUserDef.Empty();
	ThermBSillUserDef.Empty();
	ThermBJambUserDef.Empty();
	ThermBGFPerimeterUserDef.Empty();
	ThermBFloorWithinDwellingUserDef.Empty();
	ThermBFloorBwDwellingUserDef.Empty();
	ThermBBalcWithinDwellingLengthUserDef.Empty();
	ThermBBalcBwDwellingLengthUserDef.Empty();
	ThermBEavesInsAtCeilingUserDef.Empty();
	ThermBEavesInsAtRafterUserDef.Empty();
	ThermBGableInsAtCeilingUserDef.Empty();
	ThermBGableInsAtRafetUserDef.Empty();
	ThermBLengthOfNormalCornersUserDef.Empty();
	ThermBLengthOfInvertedCornersUserDef.Empty();
	ThermBPartWallBetweenDwellingUserDef.Empty();

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

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

	//-----------------------
	// SUMMER OVER HT DLG
	//-----------------------
	isTMPUserDef.Empty();
	TMPvalue     = 0;
	TMPIntPartConstruction.Empty();
	TMPPartyWallConstruction.Empty();
	isVentUserDefined.Empty();
	airChangeRate     = 0;
	isCrossVentOnMostFloors.Empty();
	windowVentilation.Empty();
	areCurtainsClosedDuringDay.Empty();
	fractCurtainsClosed = 0;
	blindCurtainType.Empty();
	sourceUserDefValues.Empty();

	stringsWithValues.clear();
	openingsData_New.clear();
	openingListData_New.clear();


	//----------------------------
	//WINDOWS
	//----------------------------
	winNArea  = 0;
	winNEArea = 0;
	winEArea  = 0;
	winSEArea = 0;
	winSArea  = 0;
	winSWArea = 0;
	winWArea  = 0;
	winNWArea = 0;
	rooflightsArea = 0;

	winNSolTrans = 0;
	winNESolTrans = 0;
	winESolTrans = 0;
	winSESolTrans = 0;
	winSSolTrans = 0;
	winSWSolTrans = 0;
	winWSolTrans = 0;
	winNWSolTrans = 0;
	rooflightsSolTrans = 0;

	winNFrameFactor = 0;
	winNEFrameFactor = 0;
	winEFrameFactor = 0;
	winSEFrameFactor = 0;
	winSFrameFactor = 0;
	winSWFrameFactor = 0;
	winWFrameFactor = 0;
	winNWFrameFactor = 0;
	rooflightsFrameFactor = 0;

	totalGlzArea = 0;

	winOvershading.Empty();
	winGlazing.Empty();

	//----------------------------
	//RESULTS
	//----------------------------
		
	iStat = 0;
	dwellingVoulme = 0;
	SFP   = 0;
	auxillaryElectricity   = 0;
	
	numOfOccupants= 0;
	TFA= 0;
	EB= 0;
	C1= 0;
	ZL= 0;
	gL= 0;
	GL_total= 0;
	C2= 0;
	lightElectricity = 0;

	Vd_avg= 0;
	DHW_energy= 0;
	distributionLoss= 0;
	tempFactor= 0;
	storageLoss= 0;
	lossFactor= 0;
	tankVolume= 0;
	volumeFacor= 0;
	heatLossFactor= 0;
	srorageLoss;
	primaryCircuitLoss= 0;
	F_u= 0;
	combiLoss= 0;
	solarDHWInput= 0;
	DomHotWater = 0;
	btnWaterHtFromMainState = 0;

	file_new_selected = false;
}

void CSAPP1Dlg::ReadsSAPboilers()
{
	//--------------------------------------------
	// Clear vectors before writing data
	//--------------------------------------------
	SAPboilers_db.clear();	

	//char *tempString;

	FILE *fptr;
	char tempStr[1000];
	char tempStr2[1010];
	char tempString[1000];

	char *pError;
	char *pch;
	SAPboilers tempCBoxEntry;
	bool isOk = TRUE;
	int linesRead = 0;
	int temp = 0;
	int length = 0;
	int num = 0;

	//--------------------------------------------------------------------------	
	// Open the file
	fptr = fopen(PATH_TO_SAP_BOILER_DB_FILE,"r");
	if (fptr == NULL)
	{
		return;
	}

	// Keep on reading (and proessing) each line from the CSV file
	// until reached end of file OR some error occured	
	while (TRUE)
	{
		// Read a line from a CSV file
		pError = fgets(tempStr,1000,fptr);
		linesRead ++;

		// if reached end of file
		if(pError == NULL)
		{	
			break;
		}

		strSpecialCopy(tempStr,tempStr2);

		//Now run strtoke on str. Notice as second argument to strtok() ONLY comma characters are being passed

		printf ("Splitting string \"%s\" into tokens:\n",tempStr2);

		//--------------------------------------------------------------------
		// 1.	Read the "entry label" for the combo box
		pch = strtok (tempStr2, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempCBoxEntry.boilerRef,pch);

		//--------------------------------------------------------------------
		// 2.	Skip 2nd coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}	
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 3.	Read the "entry string" for this entry
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempCBoxEntry.boilerModel,pch);

		//--------------------------------------------------------------------
		// 4.	Skip 4th coloumn

		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 5.	Skip 5th coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 6.	Skip 6th coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 7.	Skip 7th coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 8.	Skip 8th coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 9.	Skip 9th coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempString,pch);

		//--------------------------------------------------------------------
		// 10.	Read the "entry string" for this entry
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		tempCBoxEntry.effeciency = atof(pch);

		SAPboilers_db.push_back(tempCBoxEntry);			
	}
}

void CSAPP1Dlg::ReadSecHtEffFile()
{
	//--------------------------------------------
	// Clear vectors before writing data
	//--------------------------------------------
	secHtSysData_New.clear();		

	FILE *fptr;
	char tempStr[1000];
	char *pError;
	char *pch;
	secHtSysData tempCBoxEntry;
	bool isOk = TRUE;
	int linesRead = 0;

	//--------------------------------------------------------------------------	
	// Open the file
	fptr = fopen(PATH_TO_SEC_HT_EFF_FILE,"r");
	if (fptr == NULL)
	{
		return;
	}

	// Keep on reading (and proessing) each line from the CSV file
	// until reached end of file OR some error occured	
	while (TRUE)
	{
		// Read a line from a CSV file
		pError = fgets(tempStr,1000,fptr);
		linesRead ++;

		// if reached end of file
		if(pError == NULL)
		{	
			break;
		}

		//--------------------------------------------------------------------
		// 1.	Read 1st coloumn for boiler ref
		pch = strtok (tempStr, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempCBoxEntry.fuelType,pch);		

		//--------------------------------------------------------------------
		// 2.	Read 3rd coloumn
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		strcpy(tempCBoxEntry.systemType,pch);		

		//--------------------------------------------------------------------
		// 3.	Read the 10th coloumn, efficiency
		pch = strtok (NULL, ",");

		// If some error has occured
		if (pch == NULL)
		{
			isOk = FALSE;
			break;
		}
		tempCBoxEntry.effeciency = atoi(pch);

		secHtSysData_New.push_back(tempCBoxEntry);
	}
}

BOOL CSAPP1Dlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)
	{
		if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
			pMsg->wParam=NULL ;
	} 

	return CDialog::PreTranslateMessage(pMsg);
}