diff --git a/MAC/APL/StsMisc/src/CalculateHeathRegulation.cpp b/MAC/APL/StsMisc/src/CalculateHeathRegulation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8373d5edfc198613525669ca503c02bb35688baa
--- /dev/null
+++ b/MAC/APL/StsMisc/src/CalculateHeathRegulation.cpp
@@ -0,0 +1,390 @@
+#include "CalculateHeathRegulation.h"
+
+
+//namespace LOFAR 
+//{
+
+CalculateHeathRegulation::CalculateHeathRegulation()//int32 samplePerMinutes, int32 numberOfDays)
+//	: samplePerMinute(samplePerMinutes), numberOfDays(numberOfDays)
+{
+	this->itsSetpoint = 0.0;
+	this->itsUpdateValue = 0.0;
+	this->itsMinTamb = 50;
+	this->itsMaxTamb = -50;
+	this->itsTimeDifference = 0;
+	this->itsDayMomentTamb = 0.0083333;		//difference average day|nicht temperature (10 degrees) / 1200 hours
+	this->itsMinAverage = 0.0;					
+	this->itsMaxAverage = 0.0;
+
+}
+
+void CalculateHeathRegulation::setup(int32 samplePerMinutes, int32 numberOfDays)
+{
+	this->itsSamplePerMinute = samplePerMinutes;
+	this->itsNumberOfDays = numberOfDays;
+}
+
+CalculateHeathRegulation::~CalculateHeathRegulation()
+{
+}
+
+
+//
+// update setpoint every poll, when updateValue != 0
+//
+void CalculateHeathRegulation::calculateSetpoint()
+{
+	if(itsSetpoint >= 37 && itsUpdateValue >= 0)
+	{
+		itsSetpoint = 37;
+		itsUpdateValue = 0;
+	} 
+	else if(itsSetpoint <= 5 && itsUpdateValue <= 0)
+	{
+		itsSetpoint = 5;
+		itsUpdateValue = 0;
+	} 
+	else 
+	{
+		itsSetpoint += itsUpdateValue; 
+	}		
+	
+	itsMaxTemp = itsSetpoint + 0.025;
+	itsMinTemp = itsSetpoint - 0.025;
+
+}
+
+//
+//	This function calculate the startsetpoint, when this program make a cold start
+//	 RT[6] wordt uiteindelijk RT[0]
+void CalculateHeathRegulation::startSetup(int32 systemMonth, int32 systemTime)
+{
+	int16 tAmb = RT[0] * 100;
+	//
+	// average month temperatures about the last 100 years coming form KNMI
+	//
+	double monthTempAverage[3][12] = 
+	{
+	{  4.4,  5.0, 8.6, 12.2, 17.0, 19.4, 21.4, 21.9, 18.2, 13.5, 8.4, 5.5},	//average month maxium temperature
+	{  2.0,  2.1, 4.9,  7.5, 11.9, 14.4, 16.5, 16.5, 13.5,  9.6, 5.5, 3.2}, //average month day/night temperature
+	{ -0.8, -0.8, 1.2,  2.7,  6.5,  9.1, 11.3, 11.1,  8.8,  5.6, 2.5, 0.5}  //average month minium temperature
+	};
+	
+	//
+	// fills the day by start with the average temperatures
+	//
+	for (int16 l = 0; l < (itsNumberOfDays); l++) 
+	{
+
+		itsMaxPoint[l] = monthTempAverage[0][systemMonth];
+		itsMinPoint[l] = monthTempAverage[2][systemMonth];	
+	}
+		
+	//
+	//When the connection is not good, don't upgrade the last 
+	//value with temperatures of that moment 
+	//By a 11008 value you know that there is no connection with the ADAM
+	//
+	if(tAmb != 11008)
+	{
+		//
+		// On the last day we set an actual temperature	that we have measure
+		//
+		for (int16 g = 2; g < (itsNumberOfDays); g++) 
+		{
+			// Calculate the time between 7:00 and 19:00 hours
+			if(systemTime > 700 && systemTime <= 1900) 		
+			{				
+				//
+				// set itsTimeDifference, that gives an idea of the day heating 
+				//
+				itsTimeDifference = 1900 - 400 - systemTime;			
+				if(itsTimeDifference < 200)
+				{
+					itsTimeDifference = 0;
+				}
+				
+				//
+				// The average difference between day and night is about 10 degree Celsius
+				// With itsTimeDiffefence make we an estimate of maximum and minimum 
+				// temperature of that day
+				//
+				itsMinPoint[g] = RT[6 /*0*/] - (10 - (itsDayMomentTamb * itsTimeDifference));	// Schat de verwachtte laagste temperatuur van die dag
+				itsMaxPoint[g] = RT[6 /*0*/] + (itsDayMomentTamb * itsTimeDifference);			// Schat de verwachtte hoogste temperatuur van die dag
+			} else 
+			{	
+				// Calculate the espected temperatures in the night
+				//	gives the expected temperatures before midnight
+				if(systemTime > 1900)
+				{											 
+					itsTimeDifference = (2400 + 700) - systemTime - 400;
+				} else {
+					itsTimeDifference = 700 - systemTime;
+				}
+				
+				if(itsTimeDifference < 200)
+				{
+					itsTimeDifference = 0;
+				}			
+
+				itsMaxPoint[g] = RT[6 /*0*/] + (10 - (itsDayMomentTamb * itsTimeDifference));
+				itsMinPoint[g] = RT[6 /*0*/] - (itsDayMomentTamb * itsTimeDifference);
+			}
+		} 
+	}
+
+	//
+	// telt de waarden van 3 dagen bij elkaar
+	//
+	for (int16 h = 0; h < itsNumberOfDays; h++) {
+		itsMaxAverage += itsMaxPoint[h];
+		itsMinAverage += itsMinPoint[h];
+	} 
+
+	//
+	// Calculate the average temperature 
+	//
+	itsMaxAverage = (itsMaxAverage / itsNumberOfDays);
+	itsMinAverage = (itsMinAverage / itsNumberOfDays);
+	itsAverage = (itsMinAverage + itsMaxAverage) / 2;
+
+
+	//
+	// Calculate Setpoint by the start of this program
+	//
+	itsSetpoint = itsAverage + 11 + 5 + 1.5;  //average + verschil MaxTamb en Gemiddelde tamb + minimale verschil + marge RT1
+
+	//
+	// Control the setpoint. If setpoint higher than 37 degree Celsius, setpoint will be set on 37
+	// When the setpoint is lower than 5 degree, setpoint will be set on 5. 
+	// This is for safe the hardware in the Cabinets. 
+	//
+	if(itsSetpoint >= 37)
+	{
+		itsSetpoint = 37;
+	} 
+	if(itsSetpoint <= 5)
+	{
+		itsSetpoint = 5;
+	}
+
+	//
+	// Set Setpoint hysterese of this regulation
+	//
+	itsMaxTemp = itsSetpoint + 0.025;
+	itsMinTemp = itsSetpoint - 0.025;
+
+}
+
+
+//
+// calculate temperatures of the sensors
+//
+void CalculateHeathRegulation::calculateTemp(int16 &T, int16 selectSensor) 
+{	
+	RT[selectSensor] = 0.0;
+	
+	// rtValue must be int32 to get values higher than 50 degree Celsius 
+	int32 rtValue = htons(T);
+	double temp = (rtValue / 327.5) - 50;
+	
+	RT[selectSensor] = temp;
+	
+}
+
+
+//
+// Send temperatures back out this class
+//
+double CalculateHeathRegulation::getTemperatures(int16 selectSensor)
+{
+	return RT[selectSensor];
+}
+
+//
+// The fans of each rack will be controlled 
+// RTH0 are the fans of rack 0. The fans are on, when RTH0 = 1
+// RTH1 are the fans of rack 1. The fans are on, when RTH1 = 2
+// RTH2 are the fans of rack 2. The fans are on, when RTH2 = 4
+// RTH3 are the fans of rack 3. The fans are on, when RTH2 = 8
+//
+int32 CalculateHeathRegulation::getStateFans(int16 selectFan)
+{			
+	int16 stateFan;	
+	
+	// RTH0 == 3 in the test fase
+	if(RTH[selectFan] == 3 || RTH[selectFan] == 2 || RTH[selectFan] == 4 || RTH[selectFan] == 8)
+	{
+		stateFan = 1;
+	} 
+	else
+	{
+		stateFan = 0;
+	}
+
+	return stateFan;
+}
+
+//
+//Get the setpoint of this moment
+//
+double CalculateHeathRegulation::getSetpoint()
+{
+	return itsSetpoint;
+}
+
+
+//
+// kan er later uit, wordt gebruikt om te testen of setpoint na 12 uur wel klopt.
+//
+double CalculateHeathRegulation::getAverage()
+{
+	double controlSetpoint;
+
+	controlSetpoint = itsAverage + 11 + 5 + 1.5;
+	
+	
+	return controlSetpoint;
+}
+
+//kan eruit, gebruikt voor testen
+double CalculateHeathRegulation::getMaxAverage()
+{
+	return itsMaxAverage;
+}
+
+//kan eruit, gebruikt voor testen
+double CalculateHeathRegulation::getMinAverage()
+{
+	return itsMinAverage;
+}
+
+//
+// Regulate the temperatures of the Cabinets
+//
+int32 CalculateHeathRegulation::heathControl(int16 selectSensor, int16 selectFan)
+{	
+	if (RT[selectSensor] > itsMaxTemp)// maxTemp)			//Sensor 3, 6, 9 en 12 wordt op geregeld
+	{
+		//als alles goed is aangesloten. fan1 = 1, fan2 = 2, fan3 = 3 en fan4 = 4
+		switch(selectFan)
+		{
+			case 0: RTH[0] = 3;  //must be 1 when you control all the 4 compartiments
+					break;
+			case 1:	RTH[1] = 2;
+					break;
+			case 2: RTH[2] = 4;
+					break;
+			case 3: RTH[3] = 8;
+					break;
+		}
+	}
+	if (RT[selectSensor] < itsMinTemp)// > RT3)
+	{
+		RTH[selectFan] = 0;
+	}
+
+	return RTH[selectFan]; 
+}
+
+
+
+
+//
+// Update of the average temperatures and updateValue
+//
+void CalculateHeathRegulation::averageUpdate(int32 systemTime) 
+{
+	int32 tAmb = RT[6] * 100;			// wordt S[0]
+
+	//
+	// if there is no connection, there is no update for the maxTamb of a day and minTamb of a day 
+	// else  maxTamb is searching for the maximum temperature of a day and minTamb for the minimum
+	// temperature of the day
+	//
+	// RT[6] must be RT[0] the outdoor sensor, if every is right enclosed to every adam 
+	//
+	if(tAmb != 11008)  
+	{
+		if(RT[6] > itsMaxTamb) {				
+			itsMaxTamb = RT[6];
+		} else {
+			itsMaxTamb = itsMaxTamb;
+		}
+
+		if(RT[6] < itsMinTamb) {
+			itsMinTamb = RT[6];
+		} else {
+			itsMinTamb = itsMinTamb;
+		}
+	}
+
+	//
+	// update max values and calculate a new setpoint value
+	//
+	if((systemTime) >= 210000 && (systemTime ) <= 210059)
+	{
+		itsUpdateValue = 0;
+		
+		itsMaxPoint[0] = itsMaxPoint[1];
+		itsMaxPoint[1] = itsMaxPoint[2];
+		itsMaxPoint[2] = itsMaxTamb;
+		
+		// change only the temperature if there is a connection. in other way use
+		// the old temperatures to get a realistic average temperature
+		if(tAmb != 11009){
+			itsMaxTamb = -50;
+		}
+
+		itsMaxAverage = 0;
+		for(int16 j = 0; j < itsNumberOfDays; j++) {
+			itsMaxAverage = itsMaxAverage + itsMaxPoint[j];
+		}
+		itsMaxAverage = (itsMaxAverage / itsNumberOfDays);
+	
+		itsOldAverage = itsAverage;
+		itsAverage = 0;
+		itsAverage = (itsMinAverage + itsMaxAverage) / 2;
+
+		itsUpdateValue = itsAverage - itsOldAverage;
+		itsUpdateValue = (itsUpdateValue / 12) / (60 * itsSamplePerMinute);
+
+	}
+
+	//
+	// Update minium values and calculate a new setpoint
+	//
+	if((systemTime) >= 90000 && (systemTime) <= 90059)
+	{
+		itsUpdateValue = 0;
+
+		itsMinPoint[0] = itsMinPoint[1];
+		itsMinPoint[1] = itsMinPoint[2];
+		itsMinPoint[2] = itsMinTamb;
+		
+		// change only the temperature if there is a connection. in other way use
+		// the old temperatures to get a realistic average temperature
+		if(tAmb != 11009){
+			itsMinTamb = 50;			
+		}
+		
+		itsMinAverage = 0;
+		for(int16 k = 0; k < itsNumberOfDays; k++) {
+			itsMinAverage = itsMinAverage + itsMinPoint[k];
+		}
+		itsMinAverage = (itsMinAverage / itsNumberOfDays);
+
+		// Calculate the new average 
+		itsOldAverage = itsAverage;
+		itsAverage = 0;
+		itsAverage = (itsMinAverage + itsMaxAverage) / 2;
+
+		// Calculate the update value by each polling of the temperatures
+		itsUpdateValue = itsAverage - itsOldAverage;
+		itsUpdateValue = (itsUpdateValue / 12) / (60 * itsSamplePerMinute);  // update value setpoint every minute, but maximum 12 hours update
+	
+	}
+
+}
+
+//} //close Lofar namespace
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/CalculateHeathRegulation.h b/MAC/APL/StsMisc/src/CalculateHeathRegulation.h
new file mode 100644
index 0000000000000000000000000000000000000000..47a67da1ff4a0563cbca28dea6620e6388663dee
--- /dev/null
+++ b/MAC/APL/StsMisc/src/CalculateHeathRegulation.h
@@ -0,0 +1,122 @@
+#ifndef CALCULATEHEATHREGULATION_H
+#define CALCULATEHEATHREGULATION_H
+
+#include "import/LofarTypes.h"
+#include "import/lofar_string.h"
+#include "socket.h"
+
+
+
+//namespace LOFAR 
+//{
+class CalculateHeathRegulation 
+{
+	
+	public:
+
+		//
+		// constructor
+		//
+		 CalculateHeathRegulation();
+		 
+		 //
+		 //Set values get from HeathRegulationControl
+		 //
+		 void setup(int32 samplePerMinutes, int32 numberOfDays);
+
+
+		//
+		// destructor
+		//
+		~CalculateHeathRegulation();
+
+		//
+		// calculate the setpoint for the regulation
+		//
+		void calculateSetpoint();
+
+		//
+		//  start setpoint when the program start.
+		//
+		void startSetup(int32 systemMonth, int32 systemTime);
+		
+		//
+		//	get setpoint in other class
+		//
+		double getSetpoint();
+
+		//
+		// Shows which fans are on or off
+		//
+		int32 getStateFans(int16 selectFan);
+
+		//
+		//	calculate the temperatures from the sensors
+		//
+		void calculateTemp(int16 &T, int16 selectSensor);
+
+		//
+		// Controls the fans of the air to air exchanger
+		//
+		int32 heathControl(int16 selectSensor, int16 selectFan);
+		
+		//
+		// update the setpoint slowy in 12 hours, every sample
+		//
+		void averageUpdate(int32 systemTime);
+
+		//
+		// get temperatures in other classes
+		//
+		double getTemperatures(int16 selectSensor);
+
+		//
+		// methodes die na het testen eruit kunnen
+		//
+		double getAverage();
+		double getMinAverage();
+		double getMaxAverage();
+
+	
+
+	private:
+		//
+		// the datamembers
+		//
+		int32 itsSamplePerMinute;				// number of sample in a minute
+		int32 itsNumberOfDays;					// This value set the number of day's for the average 
+
+		double itsMaxPoint[3];					// the highest temperature of a number of each day's
+		double itsMinPoint[3];					// the lowest temperature of a number of each day's
+
+		int32 RTH[4];
+
+		double itsTimeDifference;
+		double itsDayMomentTamb;				// 12/1200   (dag|nacht verschil / een periode van 12 uur) 
+
+		double itsSetpoint;						// setpoint where the regulation controls the temperature in the Cabinets 
+		double itsMaxTemp;						// Maxium value of hysterese 
+		double itsMinTemp;						// Minium value of hysterese
+
+		double itsMinAverage;					// Average of the lowest temperature from each day of the last 3 days.
+		double itsMaxAverage;					// Average of the highest temperature from each day of the last 3 days.
+		double itsAverage;						// Average of minAverage en maxAverage
+		double itsOldAverage;					// The old value of average before average get his new value
+		
+		double itsSetPointStering;				// Value that change the setpoint slow to his new value in 12 hours
+
+		double itsMaxTamb;						// maxium Temperature that is measurement with outside temperature sensor (start with temperature that is impossible in the Netherlands)
+		double itsMinTamb;						// minium Temperature that is measurement with outside temperature sensor (start with temperature that is impossible as the lowest temperature in the Netherlands)
+
+		double itsUpdateValue;					// Value that update the setpoint every sample
+
+		
+
+
+		// temperature sensors
+		double RT[14];
+
+};
+//} close namespace LOFAR
+
+#endif
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/DigitalInputControl.cpp b/MAC/APL/StsMisc/src/DigitalInputControl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a3c65927ca6024e8510c4867e3811113488a50ea
--- /dev/null
+++ b/MAC/APL/StsMisc/src/DigitalInputControl.cpp
@@ -0,0 +1,57 @@
+/*
+//this class can you use for controle input from the ADAM 6050
+//on this moment this class control only the doorClosers. 
+//the value that you can get from ADAM 6050 is between 0 and 4096
+//if you use all the 12 Digital inputs
+*/
+
+#include  "DigitalInputControl.h"
+
+
+//namespace LOFAR 
+//{
+DigitalInputControl::DigitalInputControl()
+{
+	// there are 12 input ports on an ADAM 6050
+	setBit = 11;
+}
+
+DigitalInputControl::~DigitalInputControl()
+{
+}
+
+//
+//This function set the right bits true from the input value
+//MaximumValue have the default value of 2048
+//
+int32 DigitalInputControl::setInput(int32 digitalInput, int32 maximumValue)
+{
+	inputBit[setBit] = digitalInput/maximumValue;
+
+	if(maximumValue <= 1)
+	{
+		setBit = 11;
+		return 0;
+	}	
+	else if(digitalInput < maximumValue)
+	{
+		setBit= setBit - 1;
+		return setInput(digitalInput, (maximumValue/2));
+	}	
+	else 
+	{
+		setBit= setBit - 1;
+		return setInput((digitalInput%maximumValue), (maximumValue/2));
+	}
+}
+
+
+//
+//returns the value of the selected bit
+//
+int16 DigitalInputControl::getInput(int16 selectBit)
+{
+	return inputBit[selectBit];
+}
+
+//} // close namespace lofar
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/DigitalInputControl.h b/MAC/APL/StsMisc/src/DigitalInputControl.h
new file mode 100644
index 0000000000000000000000000000000000000000..143c634995a4379436cc23f66e4baacc5cb0c028
--- /dev/null
+++ b/MAC/APL/StsMisc/src/DigitalInputControl.h
@@ -0,0 +1,48 @@
+/*
+//this class can you use for controle input from the ADAM 6050
+//on this moment this class control only the doorClosers. 
+//the value that you can get from ADAM 6050 is between 0 and 4096
+//if you use all the 12 Digital inputs
+*/
+
+
+
+#ifndef DIGITALINPUTCONTROL_H
+#define DIGITALINPUTCONTROL_H
+
+#include "import/LofarTypes.h"
+#include "import/lofar_string.h"
+
+
+
+//namespace LOFAR 
+//{
+class DigitalInputControl
+{
+	
+	public:
+		DigitalInputControl();
+		~DigitalInputControl();
+		
+		//
+		// This function split the value coming from the Adam 6050 up in
+		// a bit patron of 12 bits. The bits returns 1 or 0.
+		//		
+		int32 setInput(int32 digitalInput, int32 maximumValue = 2048);
+
+		//
+		//read the value of the selected bit
+		//
+		int16 getInput(int16 selectBit);
+
+
+
+	private:
+
+		int16 inputBit[12];
+		int16 setBit;
+
+};
+//} close namespace lofar
+
+#endif
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/HeathRegulation.cpp b/MAC/APL/StsMisc/src/HeathRegulation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a1e4d5730702e4c481aaf0b34ceba7c3e09018c2
--- /dev/null
+++ b/MAC/APL/StsMisc/src/HeathRegulation.cpp
@@ -0,0 +1,54 @@
+#include <string>
+#include <iostream>
+#include "import/LofarTypes.h"
+#include "import/lofar_string.h"
+#include "HeathRegulationControl.h"
+
+
+// { //namespace LOFAR
+
+
+int32 main()
+{
+	const int32 sampleMinute = 60000 / 10000;
+	const int32 numberOfDays = 3;
+
+
+	// Initialize class HeathRegulationControl 
+	HeathRegulationControl control(sampleMinute, numberOfDays);				
+
+	// read adress and port for ADAMS
+	control.readInputFile();
+	
+	// make connection to the ADAMS
+	control.makeConnection();
+	
+	// Initialize start values
+	control.startUpMode();										
+	
+	control.closeConnection();
+	//  wait 30 seconds
+	Sleep(30000);
+	
+
+
+	// loop for regulation of the temperatures in the cabinets
+	while(1) 
+	{
+
+		// control the temperatures of the Cabinets
+		control.controlsTemperatures();
+		
+		//  wait 10 seconds (an minute  is = 60000)
+		Sleep (10000);
+	}
+
+		
+	control.~HeathRegulationControl();
+
+	return 0;
+}
+
+
+//} // Namespace Lofar
+
diff --git a/MAC/APL/StsMisc/src/HeathRegulationControl.cpp b/MAC/APL/StsMisc/src/HeathRegulationControl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..77be96e6da9fc605c403900e1e438ba921b5d50f
--- /dev/null
+++ b/MAC/APL/StsMisc/src/HeathRegulationControl.cpp
@@ -0,0 +1,557 @@
+#include "HeathRegulationControl.h"
+
+
+//namespace LOFAR 
+//{
+
+//
+// HeathRegulation()
+//
+HeathRegulationControl::HeathRegulationControl(int32 samplePerMinute, int32 numberOfDays)
+	:itsSamplePerMinute(samplePerMinute), itsNumberOfDays(numberOfDays)
+{
+	calculate.setup(samplePerMinute, numberOfDays);
+	itsConnectionFlag = false;
+	itsNumberOfLogs = 0;
+
+}
+
+
+//
+// ~HeathRegulation()
+//
+HeathRegulationControl::~HeathRegulationControl() 
+{
+	calculate.~CalculateHeathRegulation();
+	time.~SystemTime();
+	inputadam.~DigitalInputControl();
+	
+	// close Sockets 
+	closeConnection();
+}
+
+//
+//	Get the connection to the Adams
+//
+void HeathRegulationControl::makeConnection()
+{	
+	Socket readConnect0("readContact 0", itsAddress1, itsPort1, itsProtocol1); //"10.151.218.1", 502, 1);
+//		Socket readConnection1("readContact 1", itsAddress2, itsPort2, itsProtocol2);
+	Socket writeConnect("writeContact ", itsAddress3, itsPort3, itsProtocol3); //"10.151.218.2", 502, 1); //
+
+	itsReadConnection0 = readConnect0.connection();
+	itsReadConnection1 = readConnect0.connection();  //	= readConnection1.connection();
+	itsWriteConnection = writeConnect.connection();;	
+
+	itsConnectionFlag = true;
+}
+
+
+//
+// close connections with the adams
+//
+void HeathRegulationControl::closeConnection()
+{	
+	closesocket(itsReadConnection0);
+	closesocket(itsReadConnection1);
+	closesocket(itsWriteConnection);
+	itsReadConnection0.~Socket();
+	itsReadConnection1.~Socket();
+	itsWriteConnection.~Socket();
+
+	itsConnectionFlag = false;
+}
+
+
+//
+// Write to the Adan for reading data from the Adam 6015 and 6050
+//
+void HeathRegulationControl::writeToAdam(int16 adam, int16 function) 
+{
+	SendToAdam demand;
+
+	demand.TransactionIdentifier = htons(0);
+	demand.ProtocolIdentifier = htons(0);
+	demand.Length = htons(8);					//moeten 4 bits zijn
+	demand.UnitIdentifier = 01;
+	
+	//
+	//for reading the 6015 itsFunction must be 3 and  
+	//for reading the 6050 itsFunction must be 1
+	//
+	demand.Function = function;				
+	demand.ReferenceNumber = 0;
+	demand.WordCount = htons(18);
+
+	int32 result = send(adam, (char*)&demand, sizeof(demand), 0);
+}
+
+
+//
+// Read input data from the Adam 6015 and 6050
+// use the GetFromAdan struct to get the right bits for the information that you want to receiv
+//
+void HeathRegulationControl::readAdam(int16 adam, int16 connectie) 
+{
+	GetFromAdam receiv;
+	
+	int16 selectAdam = 0;
+		
+	receiv.TransactionIdentifier;	
+	receiv.ProtocolIdentifier;
+	receiv.Length;
+	receiv.UnitIdentifier;
+	receiv.Function;
+	receiv.ByteCount;
+	receiv.T[0];				// get the information from the sensor on port 0
+	receiv.T[1];				// get the information from the sensor on port 1
+	receiv.T[2];				// get the information from the sensor on port 2
+	receiv.T[3];				// get the information from the sensor on port 3
+	receiv.T[4];				// get the information from the sensor on port 4
+	receiv.T[5];				// get the information from the sensor on port 5
+	receiv.T[6];				// get the information from the sensor on port 6
+	receiv.Data;
+
+	int32 itsUitpt = recv(adam, (char*)&receiv, sizeof(receiv), 0);
+
+	// choose the sensors by the right connected Adam
+	// 0 = Adam0 of type 6015; 1 = Adam1 of type 6015; 3 = Adam type 6050
+	//
+	switch(connectie)
+	{
+		case 0: selectAdam = 0;		// Connection0 is Adam 0 sensors 0 t/m 6
+			break;		
+		case 1: selectAdam = 7;		// Connection1 is Adam 1 sensors 7 t/m 13
+			break;
+		case 2:	// check for connection problem with the ADAM 6050. By -13108 there is no connection
+				// and create a logFile
+				//
+				if(receiv.T[0] == -13108)
+				{
+					logFile("No connection with ADAM 6050");
+				} else
+				{
+					inputadam.setInput(receiv.T[0]);  //set the right bits true 
+				}
+			break;
+	}
+
+	// Data of the sensors Calculate to values that you can easy read and understand in CalculateHeathRegulation class
+	if(connectie == 0 || connectie == 1)
+	{		
+		// check first of the connection is good
+		// when there are problems, make a logFile
+		//
+		if(receiv.T[0] == -13108)
+		{
+			logFile("No connection with ADAM 6015 number ", connectie);
+		}
+
+		for(int16 sensor=0; sensor<7; sensor++)
+		{
+			// set values of the sensors 
+			calculate.calculateTemp(receiv.T[sensor], (sensor + selectAdam));
+		}
+	}
+}
+
+
+//
+// write to Adam 6050, for setting the fans "on" or "off"
+//
+void HeathRegulationControl::writeToAdam6050()	// (14 bytes) Declare Modbus_TCP struct type
+{	
+	Modbus_TCP command;
+
+	command.TransactionIdentifier = htons(0);
+	command.ProtocolIdentifier = htons(0);
+	command.Length = htons(8);							//Must be 4 bits
+	command.UnitIdentifier = 01;
+	command.FunctionForceMultipleCoils = 15;			//set the Adam in writing mode
+	command.ReferenceNumber = htons(16);				//Set this value to write to the right bit
+	command.BitCount = htons(6);
+	command.ByteCount = 01;
+
+	//write to the Adam 6050 which fan you set on and which one is out
+	command.Data = itsRTH; //	//controls the fans (hexadecimal value)
+
+	//
+	// Send you value to the ADAM 6050 with send and recv to make the ADAM 6050
+	// ready for reading input signals. If you don't read after you send,
+	// the input signal send a wrong value from the digital inputs
+	//
+	int32 writeResult = send(itsWriteConnection, (char*)&command, sizeof(command), 0);
+	writeResult = recv(itsWriteConnection, (char*)&command, sizeof(command), 0);
+}  
+
+
+//
+//	startup info for the system
+//  with this fucntion you set recommend values to start the heathregulation
+//
+int32 HeathRegulationControl::startUpMode()
+{
+	time.updateDateTime();
+	// AL the 4 fans are on when you send 15 to ADAM 6050
+	itsRTH = 15;
+
+	// set the fans on by starting the system
+	writeToAdam6050();
+
+	//
+	//write to Adam 6050 for control the doors
+	//the second parameter must be 1 for reading the ADAM 6050
+	//
+	writeToAdam(itsWriteConnection, 1);	
+	readAdam(itsWriteConnection, 2);
+	
+	//
+	//If the door is open, set this in the error logfile
+	//
+	if(inputadam.getInput(0) == 1)
+	{
+		logFile("Cabinet door is open");
+	}
+
+	//
+	//write to Adam1 of 6015 for control the outdoor temperature
+	//the second parameter mus be 3 for reading the ADAM 6015
+	//
+	writeToAdam(itsReadConnection0, 3);
+	readAdam(itsReadConnection0, 0);
+	writeToAdam(itsReadConnection1, 3);
+	readAdam(itsReadConnection1, 1);
+	
+	//
+	//With startSetup you set the start temperature values of the system
+	//
+	//parameter time.getMonth() you get this month
+	//
+	//with time.getTime(1) get you hours and minutes as one value, by example 2359. 
+	//this stands for 23 hours and 59 seconds
+	//
+	calculate.startSetup(time.getMonth(), time.getTime(1));
+	
+	//
+	//Control the setpoint of this moment and is to high of low 
+	//
+	if(calculate.getSetpoint() == 37)
+	{
+		logFile("Maximum setpoint is set, keep an eye on the temperatures");
+	}
+	if(calculate.getSetpoint() == 5)
+	{
+		logFile("Minimum setpoint is set, keep an eye on the themperatures");
+	}
+	
+	//
+	//Get time for screen values and the logFile of the temperatures
+	//
+	time.getTimeDate();
+	
+	//
+	//print the information on screen with screen and make a file with LogTemperatures
+	//
+	logPrint("screen");
+	logPrint("LogTemperatures");
+
+	return (HEATHREUGLATION_OK);
+}
+
+//
+// This function you use to control the temperatures, set the fan's on or off,
+// control the door and write logFiles of temperatures and when the are ploblems 
+//
+void HeathRegulationControl::controlsTemperatures()
+{
+	time.updateDateTime();
+	itsNumberOfLogs = 0;
+	itsRTH = 0;
+	
+	//
+	//If the connectionFlag is not set, make a new Connection
+	//
+	if(itsConnectionFlag == false)
+	{
+		makeConnection();
+		logFile("Made a new connection to the ADAMS");
+	}
+
+	//
+	// read the temperature sensors of the 2 ADAMS 6015
+	// ON THIS MOMENT THERE IS ONE ADAM 6015 INSTALLED
+	//
+	writeToAdam(itsReadConnection0, 3);
+	writeToAdam(itsReadConnection1, 3);
+	readAdam(itsReadConnection0, 0);
+	readAdam(itsReadConnection1, 1);
+
+	//
+	//Control the temperatures and set the fans on or of
+	//
+	for(int subrack = 1; subrack < 5; subrack++)
+	{
+		itsRTH += calculate.heathControl((subrack*3), (subrack-1));
+	}
+	writeToAdam6050();
+
+	//
+	// write the new setpoint, if updateValue != 0
+	//
+	calculate.calculateSetpoint();
+	if(calculate.getSetpoint() == 37)
+	{
+		logFile("Maximum setpoint is set, keep an eye on the temperatures");
+	}
+	if(calculate.getSetpoint() == 5)
+	{
+		logFile("Minimum setpoint is set, keep an eye on the temperatures");
+	}
+
+	logPrint("screen");
+
+	//
+	// each minute update values and control system
+	//
+	if(time.getTime(5) > 49 && time.getTime(5) <= 59)		
+	{
+		logPrint("LogTemperatures");
+		
+		schrijfFile(); // moet er nog uit
+
+		//
+		//write to Adam 6050 for control the doors
+		//the second parameter must be 1 for reading the ADAM 6050
+		//
+		writeToAdam(itsWriteConnection, 1);	
+		readAdam(itsWriteConnection, 2);
+		
+		calculate.averageUpdate(time.getTime(0));
+
+		// if door is open, write to logfile
+		if(inputadam.getInput(0) == 1)
+		{
+			logFile("Cabinet door is open");
+		} 
+
+		closeConnection();
+		logFile("Close the connection to the ADAMS");
+	} 
+}
+
+
+//
+//print() information on screen or in a logfile
+//
+void HeathRegulationControl::logPrint(string function) {		
+	// LET OP: Nummering moet van 0..6 lopen niet van 1..7
+	
+	double tempory = 0.0;
+	int16 number = -1;
+	FILE *fp;
+	
+	if(function == "LogTemperatures")
+	{
+		fp = fopen("temperaturen.txt", "a");
+	} else {
+		fp = stderr;
+	}
+	
+		
+	for(int16 j=0; j<14; j++)
+	{
+		tempory = calculate.getTemperatures(j);				// get the values of the sensors out program
+		int16 tAmb = tempory * 100;
+		switch(j)
+		{
+			case 0: fprintf(fp, "%s", time.getTimeDate());
+					fprintf(fp, "Outdoor Temperature=%5.2f \n", calculate.getTemperatures(0));//itsTempory);
+					fprintf(fp, "Setpoint=%5.2f \n", calculate.getSetpoint());
+				break;
+			case 1: case 4: case 7: case 10:
+					fprintf(fp, "Subrack %i: Front:RT%2i=%5.2f  ", number+=1, j, tempory);
+					// By temperatures higher than 60 degree, there is a problem
+					// By tAmb with a value of 11008 there is no connection
+					if(tempory >= 45 && tAmb != 11008 && function == "LogTemperatures")
+					{
+						logFile( "High temperature, control the fan of the FRONT DOOR of Rack ", number);
+					}
+				break;
+			case 2:	case 5: case 8: case 11:
+					fprintf(fp, " Rear:RT%2i=%5.2f  ", j, tempory);
+					// By temperatures higher than 60 degree, there is a problem
+					// By tAmb with a value of 11008 there is no connection
+					if(tempory >= 60 && tAmb != 11008 && function == "LogTemperatures")
+					{
+						logFile( "High temperature, control the fan of the BACK DOOR of Rack ", number);
+					}
+				break;
+			case 3: case 6: case 9: case 12:
+					fprintf(fp, " Control:RT%2i=%5.2f  Fans=%s \n", j, tempory, (calculate.getStateFans((j/3)-1)==1) ? "on" : "off");
+				break;
+		}
+	}
+	fprintf(fp, "\n" );
+
+	if(function == "LogTemperatures")
+	{
+		fclose(fp);
+	}
+}
+
+
+
+void HeathRegulationControl::logFile(char *problem, int16 number) 
+{
+	//wegschrijven naar file//
+
+	FILE	*lf;
+
+	lf = fopen("logfile.txt", "a");
+
+	if (itsNumberOfLogs == 0)
+	{
+		fprintf(lf, "\n %s", time.getTimeDate());
+	}
+	
+	
+	if (number >= 0)
+	{
+		fprintf(lf, "	%s%i \n",		problem, number);
+		itsNumberOfLogs = itsNumberOfLogs + 1;
+	} 
+	else
+	{
+		fprintf(lf, "	%s \n", problem);
+		itsNumberOfLogs = itsNumberOfLogs + 1;
+	}
+
+	fclose(lf);
+}
+
+
+//
+// Get ports and addresses from a file
+//
+int32 HeathRegulationControl::readInputFile()
+{
+	int counter = 0;
+
+	std::vector<string> v;
+	
+	string filenaam = "inputfile\\startValues.txt" ;
+	std::ifstream invoer(filenaam.c_str() );
+	string itsX;
+	
+	if(invoer.fail())
+	{
+		logFile("Problems with reading from the input file");
+		return (NO_INPUT);
+	}
+
+	while(invoer.good())
+	{
+		
+		invoer >> itsX;
+		v.push_back(itsX);
+			
+		counter++;
+	}
+
+	// controleren van adressen benamingen
+
+	for(int32 pos = 0; pos < counter; ++pos)
+	{
+		if(v[pos] == "addressAdam1:") 
+		{
+			itsAddress1 = v[pos+1];
+			itsPort1 = atoi(v[pos+3].c_str());
+			itsProtocol1 = atoi(v[pos+5].c_str());
+		} 
+		if(v[pos] == "addressAdam2:")
+		{
+			itsAddress2 = v[pos+1];
+			itsPort2 = atoi(v[pos+3].c_str());
+			itsProtocol2 = atoi(v[pos+5].c_str());
+		}
+		if(v[pos] == "addressAdam3:")
+		{
+			itsAddress3 = v[pos+1];
+			itsPort3 = atoi(v[pos+3].c_str());
+			itsProtocol3 = atoi(v[pos+5].c_str());
+		}
+	}
+
+	invoer.clear();
+	invoer.close();
+	
+	return (HEATHREUGLATION_OK);
+}
+
+string HeathRegulationControl::errstr () const
+{
+	static char const *socketErrStr[] = {
+		"OK",
+		"Cabinet door is open",
+		"Can't create read connection (%d: %s)",
+		"Can't create write connection",
+		"Can't read to ADAM (%d: %s)",
+		"Can't write to ADAM",
+		"Temperature are to high on the backside (%d: %s)",
+		"Temperature are to high on the frontside (%d: %s)",
+		"Wrong address from inputfile (%d: %s)",
+		"No more clients (%d: %s)",
+		"Wrong port from inputfile (%d: %s)",
+		"Wrong connection type (%d: %s)",
+		"No input file with connections values"
+	};  
+
+	if (itsErrno > 0) {
+    	return ("");
+	}
+
+ 	return 0;  //sprintf("%d %d %s ", err, errInt, errChar);
+		
+		//formatString(socketErrStr[-itsErrno], itsSysErrno, strerror(itsSysErrno)));
+}
+
+
+//
+//schrijfFile() for test fase. This file can you use in excel to make a grafic ot the data
+//
+void HeathRegulationControl::schrijfFile() {
+	//wegschrijven naar file//
+
+	FILE	*hp;
+
+	hp = fopen("temperaturener.txt", "a");
+
+	char dateStr [9];
+	char timeStr [9];
+	_strdate( dateStr);
+	_strtime( timeStr);
+	fprintf(hp, "%s - ", dateStr);
+	fprintf(hp, "%s ", timeStr);
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(0));
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(1));
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(2));
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(3));
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(4));
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(5));
+	fprintf(hp, "%3.2f ", calculate.getTemperatures(6));
+	fprintf(hp, "%3.2f ", calculate.getSetpoint());
+	fprintf(hp, "%3.2f ", calculate.getAverage());
+	fprintf(hp, "Outdoor Temperature=%5.2f ", calculate.getTemperatures(6));
+	fprintf(hp, "(Buiten_regeling_%s)", (calculate.getStateFans((4/3)-1)==1) ? "aan" : "uit");
+	fprintf(hp, "%3.2f ", calculate.getMaxAverage());
+	fprintf(hp, "%3.2f \n", calculate.getMinAverage());
+
+	fclose(hp);
+}
+
+
+
+
+//} //close Lofar namespace
+
+
diff --git a/MAC/APL/StsMisc/src/HeathRegulationControl.h b/MAC/APL/StsMisc/src/HeathRegulationControl.h
new file mode 100644
index 0000000000000000000000000000000000000000..a5ff186adcdcafe427e49b49d1b098efce6e5e51
--- /dev/null
+++ b/MAC/APL/StsMisc/src/HeathRegulationControl.h
@@ -0,0 +1,231 @@
+#ifndef HEATHREGULATION_CONTROL_H
+#define HEATHREGULATION_CONTROL_H
+
+#include <fstream>
+#include "Socket.h"
+#include "SystemTime.h"
+#include "DigitalInputControl.h"
+#include "import/TypeNames.h"
+#include "import/lofar_string.h"
+#include "import/lofar_iostream.h"
+#include "import/lofar_vector.h"
+#include "import/LofarLogger.h"
+#include "import/StringUtil.h"
+#include "import/Exception.h"
+#include "CalculateHeathRegulation.h"
+
+
+#pragma pack(1)
+
+
+		
+//namespace LOFAR {
+
+class HeathRegulationControl
+{
+	public:
+
+		//
+		//	struct SendToAdam	
+		//
+		//  Write to ADAM to make a connection with one of the ADAMS
+		//
+		struct SendToAdam {
+			short TransactionIdentifier;			// = 2 bytes
+			short ProtocolIdentifier;				// = 2 bytes
+			short Length;							// = 2 bytes
+			BYTE  UnitIdentifier;					// = 1 byte
+
+		//  -modbus									= 6 bytes (telt unit identifier mee anders 5)
+			BYTE Function;							//:15 = 1 bytes
+			short ReferenceNumber;					// = 2 bytes
+			short WordCount;						// = 2 bytes
+
+		} ;
+
+
+		//
+		//	struct GetFromAdam
+		// read data from the ADAMS input ports
+		//	
+		struct GetFromAdam {
+			short TransactionIdentifier;			// = 2 bytes
+			short ProtocolIdentifier;				// = 2 bytes
+			short Length;							// = 2 bytes
+			byte  UnitIdentifier;					// = 1 byte
+
+			//  -modbus								= 6 bytes (telt unit identifier mee anders 5)
+			byte Function;							//:15 = 1 bytes 
+			byte ByteCount;							// = 1 bytes
+			short T[7];								// = 7 x 2 bytes
+
+			WORD Data[22];							// = rest data 22 bytes over
+
+		} ;
+
+
+		//
+		//	struct Modbus_TCP
+		//
+		// Write data to the ADAM 6050 output ports
+		//
+		struct Modbus_TCP {							// (14 bytes) Declare Modbus_TCP struct type
+					
+			short TransactionIdentifier;			// = 2 bytes
+			short ProtocolIdentifier;				// = 2 bytes
+			short Length;							// = 2 bytes
+			byte  UnitIdentifier;					// = 1 byte
+
+		//  -modbus									= 8 bytes (telt unit identifier mee anders 7)
+			byte FunctionForceMultipleCoils;		//:15 = 1 bytes 
+			short ReferenceNumber;					// = 2 bytes
+			short BitCount;							// = 2 bytes
+			byte ByteCount;							// = 1 byte
+			byte Data;								// = 1 byte (hier bepaal je wat aan en uit gaat)
+
+		} ;
+
+
+		
+		HeathRegulationControl(int32 samplePerMinute, int32 numberOfDays);	
+		~HeathRegulationControl();
+
+
+		//
+		// initialize connections
+		//
+		void makeConnection();
+
+		// close connections
+		//
+		void closeConnection();
+
+		//
+		// initialise system for Regulation
+		//
+		int32 startUpMode();//int32 readConnection0);
+
+		//
+		// print sensor information on screen
+		//
+		void logPrint(string function);
+
+		//
+		// save information in a file
+		//
+		void logFile(char *problem, int16 number = -1);
+
+		//
+		// read address, ports and type out a input .txt file
+		//
+		int32 readInputFile();
+
+		//
+		// sensor data that is coming from the Adam 6015 and 6050
+		//
+		void readAdam(int16 adam, int16 connectie);
+
+		//
+		// connect to Adam 6015 for readin the ADAM out
+		//
+		void writeToAdam(int16 adam, int16 function);
+
+
+		//
+		// write en connect to Adam 6050
+		//
+		void writeToAdam6050();
+			
+
+		//
+		// control the temperatures of the cabinets
+		//
+		void controlsTemperatures(); 
+
+		//
+		// Dit gedeelte werkt nogniet
+		//
+		string errstr() const;
+
+			inline int32 errcode() const;
+			inline int32 errnoSys() const;
+
+			//Error codes
+			typedef enum {
+                HEATHREUGLATION_OK		=  0,     ///< Ok
+				DOOR_OPEN				= -1,     ///< Cabinet door is open
+                CONNECTION_READ			= -2,     ///< Can't create read connection
+                CONNECTION_WRITE		= -3,     ///< Can't create write connection             
+                READ_ERROR				= -4,     ///< Can't read from ADAM
+                WRITE_ERROR				= -5,     ///< Can't write to ADAM
+                TEMP_PROBLEM_BACK		= -6,     ///< Temperature are to high on the backside (fans's ??)
+                TEMP_PROBLEM_FRONT		= -7,     ///< Temperature are to high on the frontside (fans's ??) 
+                ADDRESS_ERROR			= -8,     ///< Wrong address from inputfile
+                PORT_ERROR				= -9,     ///< Wrong port from inputfile
+                TYPE_ERROR				= -10,    ///< Wrong connection type (must be TCP)
+				NO_INPUT				= -11	  ///< No input file with connections values
+			} ErrorCodes;
+
+		//
+		// wordt alleen voor testfase gebruikt om makelijk grafieken te makenin excel, kan er later uit
+		//
+		void schrijfFile();
+		//
+
+	protected:
+		inline int32 setErrno(int32 ErrorNr);
+
+	private:
+		//
+		// Datamembers
+		//
+		int32 itsSamplePerMinute;
+		int32 itsNumberOfDays;
+		
+		CalculateHeathRegulation calculate;
+		SystemTime time;
+		DigitalInputControl inputadam;
+		
+
+		int32 itsReadConnection0;				//read data from ADAM 6015
+		int32 itsReadConnection1;				//read data from ADAM 6015
+		int32 itsWriteConnection;				//write data to ADAM 6050
+		
+		int32 itsRTH;							//Ventilator that regulates the outdoor convection
+
+
+		string itsAddress1, itsAddress2, itsAddress3;
+		int32 itsPort1, itsPort2, itsPort3;
+		int32 itsProtocol1, itsProtocol2, itsProtocol3;
+
+
+		bool itsConnectionFlag;
+
+		int16 itsNumberOfLogs;
+
+		//own error number
+		int32 itsErrno;
+		int32 itsSysErrno;
+
+};
+
+inline int32 HeathRegulationControl::errcode() const
+{
+	return (itsErrno);
+}
+
+inline int32 HeathRegulationControl::errnoSys() const
+{
+	return (itsSysErrno);
+}
+
+inline int32 HeathRegulationControl::setErrno(int32 errorNr)
+{
+	itsSysErrno = errno;				// save system errno
+	return (itsErrno = errorNr);		// save and return given error
+}
+
+//} // namespace LOFAR
+
+
+#endif
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/Socket.cpp b/MAC/APL/StsMisc/src/Socket.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4973821e07c99f845ebc3e5726d100956ba69ca9
--- /dev/null
+++ b/MAC/APL/StsMisc/src/Socket.cpp
@@ -0,0 +1,73 @@
+// Voor deze class wordt zometeen lofar socket gebruikt.
+// De aanroep van sommige onderdelen moet dan wat worden aangepast.
+
+
+
+#include "Socket.h"
+
+
+
+Socket::Socket(const std::string& socketname, const std::string& hostname, int service, int protocol)
+ :itsSocketname(socketname),itsSocketID(-1),	itsIsServer(false),	itsIsConnected(false),	itsHost(hostname),
+	itsPort(service),	itsAllowIntr(false),	itsIsInitialized(false),	itsIsBlocking(false)
+{		
+	
+}
+
+Socket::~Socket(){}
+
+int Socket::connection()
+{	
+	WORD wVersionRequested = MAKEWORD(1,1);
+	WSADATA wsaData;
+	int nRet;
+
+	nRet = WSAStartup(wVersionRequested, &wsaData);
+	if (wsaData.wVersion != wVersionRequested)
+	{	
+		fprintf(stderr,"\n Wrong version\n");
+		return(-1);
+	}
+	return(open_connection());
+
+}
+
+
+int Socket::open_connection() 
+{
+	SOCKET mySocket =  socket(AF_INET, SOCK_STREAM, 0);
+	struct sockaddr_in  itsTCPAddr;
+	memset (&itsTCPAddr, 0, sizeof(itsTCPAddr));
+	itsTCPAddr.sin_family = AF_INET;
+
+	unsigned int IPbytes;
+
+	// try if hostname is hard ip address
+	if ((IPbytes = inet_addr(itsHost.c_str())) == INADDR_NONE) {
+		
+		// No, try to resolve the name
+		struct hostent*       hostEnt;        // server host entry
+		if (!(hostEnt = gethostbyname(itsHost.c_str()))) {
+                           
+			return (-2);
+		}
+
+		// Check type
+		if (hostEnt->h_addrtype != AF_INET) {
+			return (-3);
+		}
+     
+		memcpy (&IPbytes, hostEnt->h_addr, sizeof (IPbytes));
+	}
+	memcpy ((char*) &itsTCPAddr.sin_addr.s_addr, (char*) &IPbytes, sizeof(IPbytes));
+
+	itsTCPAddr.sin_port = htons(itsPort);
+	
+	int result = connect(mySocket, (struct sockaddr *)&itsTCPAddr, sizeof(struct sockaddr_in));
+	return (mySocket);
+}
+
+//void   Close(){
+//}
+
+
diff --git a/MAC/APL/StsMisc/src/SystemTime.cpp b/MAC/APL/StsMisc/src/SystemTime.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..da8a9b312b6cae5fe9c06ba4b8e4b1430f70e731
--- /dev/null
+++ b/MAC/APL/StsMisc/src/SystemTime.cpp
@@ -0,0 +1,97 @@
+#include "SystemTime.h"
+
+//namespace LOFAR 
+//{
+
+SystemTime::SystemTime()
+{ 
+}
+
+SystemTime::~SystemTime()
+{
+
+}
+
+//
+// Get systemdate and time  
+//
+void SystemTime::updateDateTime()
+{
+	time_t rawtime;
+	struct tm * timeinfo;
+
+	time ( &rawtime );
+	timeinfo = localtime ( &rawtime );
+
+
+	// update the date values from the system 
+	itsYear = timeinfo->tm_year;
+	itsMonth = timeinfo->tm_mon;
+	itsDay = timeinfo->tm_mday;
+
+	//update the time value from the system
+	itsHours = timeinfo->tm_hour;
+	itsMin = timeinfo->tm_min;
+	itsSec = timeinfo->tm_sec;
+}
+
+int16 SystemTime::getYear()
+{	
+	return itsYear;
+}
+
+int16 SystemTime::getMonth()
+{
+	return itsMonth;
+}
+
+int16 SystemTime::getDay()
+{
+	return itsDay;
+}
+
+//
+// Get time of the system, with the follow choises 
+//
+// 0 = get times as follow 154059. This stands for 15 hours, 40 minutes and 59 seconds
+// 1 = get hours and minutes as follow 1349. This stands for 13 hours and 49 minutes
+// 2 = get minutes and seconds as follow 1503. This stands for 15 minutes and 3 seconds 
+// 3 = get only the hours
+// 4 = get only the minutes
+// 5 = get only the seconds
+//
+int32 SystemTime::getTime(int16 timePart)
+{
+	int32 time;
+
+	switch(timePart)
+	{
+		case 0: time = (10000 * itsHours) + (100 * itsMin) + itsSec; 
+			break;
+		case 1: time = (100 * itsHours) + itsMin;  
+			break;
+		case 2: time = (100 * itsMin) + itsSec;		
+			break;
+		case 3: time = itsHours;						
+			break;
+		case 4: time = itsMin;							
+			break;
+		case 5: time = itsSec;							
+	}
+	
+	return time;
+}
+
+//
+// get time and date from system for the logfiles
+//
+char* SystemTime::getTimeDate()
+{
+	time_t rawtime;
+	time ( &rawtime );
+	
+	return (ctime (&rawtime));  //(ctime (&rawtime));;
+}
+
+
+//} // close lofar namespace
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/SystemTime.h b/MAC/APL/StsMisc/src/SystemTime.h
new file mode 100644
index 0000000000000000000000000000000000000000..c48ff5c9558c78f1357d8a46d221a2561342ec39
--- /dev/null
+++ b/MAC/APL/StsMisc/src/SystemTime.h
@@ -0,0 +1,66 @@
+#ifndef SYSTEMTIME_H
+#define SYSTEMTIME_H
+
+#include <time.h>
+#include "import/LofarTypes.h"
+#include "import/lofar_string.h"
+#include <ctime>
+
+
+
+//namespace LOFAR 
+//{
+class SystemTime
+{
+	
+	public:
+		SystemTime();
+		~SystemTime();
+		
+		//
+		// set the time for system for all output files
+		//
+		char* getTimeDate();
+
+		//
+		//Get the time and date of the system
+		//
+		void updateDateTime();
+
+		//
+		// select year 
+		//
+		int16 getYear();
+		
+		//
+		// select month 
+		//
+		int16 getMonth();
+		
+		//
+		// select day
+		//
+		int16 getDay();
+		
+		//
+		// select time
+		//
+		int32 getTime(int16 timePart);
+
+
+
+	private:
+		int16 itsYear;
+		int16 itsMonth;
+		int16 itsDay;
+		int16 itsHours;
+		int16 itsMin;
+		int16 itsSec;
+
+		
+
+
+};
+//} // close namespace lofar
+
+#endif
\ No newline at end of file
diff --git a/MAC/APL/StsMisc/src/socket.h b/MAC/APL/StsMisc/src/socket.h
new file mode 100644
index 0000000000000000000000000000000000000000..0bd9774751bb3731fa4f01ce47831fd09fcc829e
--- /dev/null
+++ b/MAC/APL/StsMisc/src/socket.h
@@ -0,0 +1,113 @@
+/*   Socket.h
+
+Deze class wordt vervangen door de lofar socket class
+
+*/
+
+#ifndef SOCKET_H
+#define SOCKET_H
+
+#include <WinSock2.h>
+//#include "TypeNames.h"
+
+#include <string>
+
+enum TypeSocket {BlockingSocket, NonBlockingSocket};
+
+class Socket {
+public:
+
+//	Socket();
+  virtual ~Socket();
+  Socket(const Socket&);
+  Socket& operator=(Socket&);
+
+  std::string ReceiveLine();
+  std::string ReceiveBytes();
+  
+
+  
+
+  // The parameter of SendLine is not a const reference
+  // because SendLine modifes the std::string passed.
+  void   SendLine (std::string);
+
+  // The parameter of SendBytes is a const reference
+  // because SendBytes does not modify the std::string passed 
+  // (in contrast to SendLine).
+  void   SendBytes(const std::string&);
+
+//protected:
+	  friend class SocketServer;
+	  friend class SocketSelect;
+
+//  Socket(SOCKET s);
+	Socket(const std::string& socketname, const std::string& hostname, int service, int protocol);
+	int initClient (const std::string& hostname, const int	service, int protocol);
+	int connection();
+	int open_connection();
+	void Close();
+
+  SOCKET s_;
+
+  int* refCounter_;
+
+
+private:
+  static void Start();
+  static void End();
+  static int  nofSockets_;
+
+          // Name of socket given by user
+		 std::string                   itsSocketname;
+        // Own error number
+        int                           itsErrno;
+        // System error number
+        int                          itsSysErrno;
+        // File descriptor of the socket
+        int                           itsSocketID;
+        // Socket type
+        int                          itsType;
+        // Server or Client Socket
+        bool                         itsIsServer;
+        // Connected or not
+        bool                         itsIsConnected;
+        // Name of host at other side
+		std::string                     itsHost;
+        // Portnr of server
+		int								itsPort;
+        // Interrupt read/write block call
+        bool                            itsAllowIntr;
+        // Socket is initialized
+        bool                            itsIsInitialized;
+        // Blocking mode or not
+        bool                            itsIsBlocking;
+};
+
+class SocketClient : public Socket {
+public:
+  SocketClient(const std::string& host, int port);
+};
+
+
+class SocketServer : public Socket {
+public:
+  SocketServer(int port, int connections, TypeSocket type=BlockingSocket);
+
+  Socket* Accept();
+};
+
+// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/wsapiref_2tiq.asp
+class SocketSelect {
+  public:
+    SocketSelect(Socket const * const s1, Socket const * const s2=NULL, TypeSocket type=BlockingSocket);
+
+    bool Readable(Socket const * const s);
+
+  private:
+    fd_set fds_;
+}; 
+
+
+
+#endif