Commit a57b8ba3 authored by Andrea Orlat's avatar Andrea Orlat
Browse files

changed the skyFrequency function in order to address the lowe side bands

parent 2f089a47
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
/* Marco Bartolini (bartolini@ira.inaf.it)  18/06/2014	   added function ACS::Time getACSTime() */
/* Andrea Orlati(aorlati@ira.inaf.it)  12/08/2015	  Function to check if a file exists or not */
/* Andrea Orlati(aorlati@ira.inaf.it)  19/11/2015	  Function timeToStrExtended was added */
/* Andrea Orlati(aorlati@ira.inaf.it)  12/01/2016	  reviewed the function skyFrequency in order to address also lower side band during down conversion */

#include <time.h>
#include <sys/time.h>
@@ -305,6 +306,12 @@ public:
	/**
	 * This function computes the intersection between two bands. Its use, for example, could be to compute the resulting band from the intersection between
	 * an IF coming from a receiver and a filter applied before a backend.
	 * The band are defined by giving the start frequency and the bandwidth. If the start frequency is negative the method consider the corresponding band
	 * to be inverted. In that case the results of the method is affected accordingly.
	 * If we consider an RF band 1600-1800 MHz: a down conversion with an LO=1500 will produce a band f=100, bw=200
	 * a down conversion with an LO=1900 will produce a band f=-300, bw=200. The same convention could be then adopted for backends Nyquist zones.
	 * The rsulting band is extpressed in the form startFrequency(f) and bandwidth (bw). Up converting to RF band is always done by the following
	 * formulas: f1=f+LO, f2=Lo+f+bw;
	 * @param bf backend start frequency.
	 * @param bbw backend bandwidth
	 * @param rf receiver start frequency
@@ -707,6 +714,37 @@ public:
	  */
	 static double getMaximumValue(const ACS::doubleSeq& array,long& pos);

private:


	 /**
	  * Used to convert from two different notation used to identify a band limits. The source notation is start frequency (f) and
	  * bandwidth (w). In that case a negative f denotes a lower side band. The destination notation is first frequency (f1), last frequency (f2) and
	  * band side (upper).
	  * @param f start frequency
	  * @param w bandwidth
	  * @param f1 first frequency (output)
	  * @param f1 last frequency (output)
	  * param upper side band (output). True means upper side band, false lower side band.
	  * @return true if the parameters are coherent and the conversion could be done
	  */
	 static bool bandLimits(const double&f,const double& w,double& f1,double& f2,bool& upper);

	 /**
	  * This function merges two bands. The resulting sub-band is provided in the form: start frequency (f) and bandwidth (w).
  	  * @param rf1 first frequency of first band
	  * @param rf2 last frequency of first band
	  * @param rside side band of the first one. True is upper side band.
  	  * @param bf1 first frequency of second band
	  * @param bf2 last frequency of second band
	  * @param bside side band of the second one. True is upper side band.
	  * @param f start frequency (output)
	  * @param w bandwidth (output)
	  * @return true if the parameters are coherent and the merging produces a not empty sub-band.
	  */
	 static bool mergeBands(const double& rf1,const double& rf2,const bool& rside,const double& bf1,
			 const double& bf2,const bool& bside,double&f,double& w);

};
	
}
+28 −2
Original line number Diff line number Diff line
@@ -331,7 +331,33 @@ public: // Operations
	 * @return the converted long double
	*/		
	long double ToLongDouble() const;
	// operators

	/**
	 * Check if the string contains a valid long value before converting it.
	 * @return true if the string caould be converted to an integer
	 */
	bool CheckIsValidLong() const;
	/**
	 * Check if the string contains a valid long long value before converting it.
	 * @return true if the string caould be converted to an integer
	 */
	bool CheckIsValidLongLong() const;
	/**
	 * Check if the string contains a valid float value before converting it.
	 * @return true if the string caould be converted to an integer
	 */
	bool CheckIsValidFloat() const;
	/**
	 * Check if the string contains a valid double value before converting it.
	 * @return true if the string caould be converted to an integer
	 */
	bool CheckIsValidDouble() const;
	/**
	 * Check if the string contains a valid long double value before converting it.
	 * @return true if the string caould be converted to an integer
	 */
	bool CheckIsValidLongDouble() const;

	char operator [] (int index) const;
	// cast
	operator const char *() const;
+68 −2
Original line number Diff line number Diff line
@@ -359,7 +359,13 @@ double CIRATools::getHWAzimuth(const double& current,const double& dest,const do

bool CIRATools::skyFrequency(const double& bf,const double& bbw,const double& rf,const double& rbw,double& f,double& bw)
{
	double bs=bf+bbw;
	bool bside,rside;
	double rf1,rf2,bf1,bf2;
	if (!bandLimits(bf,bbw,bf1,bf2,bside)) return false;
	if (!bandLimits(rf,rbw,rf1,rf2,rside)) return false;
	if (!mergeBands(rf1,rf2,rside,bf1,bf2,bside,f,bw)) return false;
	return true;
	/*double bs=bf+bbw;
	double rs=rf+rbw;
	f=MAX(bf,rf);
	double s=MIN(bs,rs);
@@ -371,7 +377,7 @@ bool CIRATools::skyFrequency(const double& bf,const double& bbw,const double& rf
	}
	else {
		return true;
	}
	}*/
}

bool CIRATools::getNextToken(const IRA::CString& str,int &start,char delimiter,IRA::CString &ret)
@@ -1172,3 +1178,63 @@ double CIRATools::getMaximumValue(const ACS::doubleSeq& array,long& pos)
		return 0.0;
	}
}

// *******************************//
// private:

bool CIRATools::bandLimits(const double&f,const double& w,double& f1,double& f2,bool& upper)
{
	if (w<0) {
		return false;
	}
	if (f>=0) {
		f1=f;
		f2=f+w;
		upper=true;
	}
	else {
		if (w>-f) {
			return false;
		}
		f1=-f-w;
		f2=-f;
		upper=false;
	}
	return true;
}

bool CIRATools::mergeBands(const double& rf1,const double& rf2,const bool& rside,const double& bf1,
		 const double& bf2,const bool& bside,double&f,double& w)
{
	double startF,stopF,bw;

	if ((rf1>rf2) || (bf1>bf2)) {
		return false;
	}
	startF=MAX(rf1,bf1);
	stopF=MIN(rf2,bf2);
	bw=stopF-startF;
	if (bw<=0) {
		f=rf1;
		w=0;
		return false;
	}
	if (rside && bside) { //UU
		f=startF;
		w=stopF-startF;
	}
	else if (rside && !bside) {  //UL
		f=stopF;
		w=startF-stopF;
	}
	else if (!rside && bside) {  //LU
		f=-startF;
		w=startF-stopF;
	}
	else if (!rside && !bside) { //LL
		f=-stopF;
		w=stopF-startF;
	}
	return true;
}
+80 −1
Original line number Diff line number Diff line
@@ -493,7 +493,6 @@ long long CString::ToLongLong() const
	return atoll(m_cpString);
}


float CString::ToFloat() const
{
	if (IsEmpty()) return 0.0;
@@ -512,6 +511,86 @@ long double CString::ToLongDouble() const
	return (long double)atof(m_cpString);
}

bool CString::CheckIsValidLong() const
{
    char *endptr;
    long val;
	if (IsEmpty()) return false;
    errno=0;
    val = strtol(m_cpString,&endptr,10);
    if ((errno==ERANGE && (val==LONG_MAX || val==LONG_MIN)) || (errno != 0 && val == 0)) {
    	return false;
    }
    if (endptr==m_cpString) {
    	return false;
    }
    return true;
}

bool CString::CheckIsValidLongLong() const
{
    char *endptr;
    long long val;
	if (IsEmpty()) return false;
    errno=0;
    val = strtoll(m_cpString,&endptr,10);
    if ((errno==ERANGE && (val==LLONG_MAX || val==LLONG_MIN)) || (errno != 0 && val == 0)) {
    	return false;
    }
    if (endptr==m_cpString) {
    	return false;
    }
    return true;
}

bool CString::CheckIsValidFloat() const
{
    char *endptr;
    float val;
	if (IsEmpty()) return false;
    errno=0;
    val = strtof(m_cpString,&endptr);
    if (errno==ERANGE) {
    	return false;
    }
    if (endptr==m_cpString) {
    	return false;
    }
    return true;
}

bool CString::CheckIsValidDouble() const
{
    char *endptr;
    double val;
	if (IsEmpty()) return false;
    errno=0;
    val = strtod(m_cpString,&endptr);
    if (errno==ERANGE) {
    	return false;
    }
    if (endptr==m_cpString) {
    	return false;
    }
    return true;
}

bool CString::CheckIsValidLongDouble() const
{
    char *endptr;
    long double val;
	if (IsEmpty()) return false;
    errno=0;
    val = strtold(m_cpString,&endptr);
    if (errno==ERANGE) {
    	return false;
    }
    if (endptr==m_cpString) {
    	return false;
    }
    return true;
}

//************** OPERATORS DEFINITIONS *****************

char CString::operator [] (int index) const
+185 −0
Original line number Diff line number Diff line
@@ -64,6 +64,191 @@ public:
		}
	}

	::testing::AssertionResult skyFrequency_noIntersection() {
		double f,bw;
		double rf=100;
		double rbw=500;
		double bf=600;
		double bbw=300;
		::testing::Test::RecordProperty("description","check if the resulting sky frequency is actually empty");
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			return ::testing::AssertionFailure() << "resulting band should be empty but bandwidth is " << bw;
		}
		rf=100;
		rbw=500;
		bf=-800;
		bbw=100;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			return ::testing::AssertionFailure() << "resulting band should be empty but bandwidth is " << bw;
		}
		else {
			return ::testing::AssertionSuccess();
		}
	}

	::testing::AssertionResult skyFrequency_intersection() {
		double f,bw;
		double rf=100;
		double rbw=200;
		double bf=200;
		double bbw=200;
		::testing::Test::RecordProperty("description","check (various data set) if the resulting sky frequency is not empty and band limits are correct");

		// R=100,200(100:300)U B=200,200(200:400)U => 200,100(200:300)
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=200) {
				return ::testing::AssertionFailure() << "1) straight receiver, straight backend, start frequency should be 200 but is " << f << " instead";
			}
			else if (bw!=100) {
				return ::testing::AssertionFailure() << "1) straight receiver, straight backend, start bandwidth should be 100 but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "1) straight receiver, straight backend, resulting band should not be empty" ;
		}
		// R=100,200(100:300)U B=150,50(150:200)U => 150,50(150:200)
		rf=100;
		rbw=200;
		bf=150;
		bbw=50;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=bf) {
				return ::testing::AssertionFailure() << "2) straight receiver, straight backend, backend included, start frequency should be "
						<< bf << " but is " << f << " instead";
			}
			else if (bw!=bbw) {
				return ::testing::AssertionFailure() << "2) straight receiver, straight backend, backend included, start bandwidth should be "
						<< bbw << " but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "2) straight receiver, straight backend, backend included, resulting band should not be empty" ;
		}
		// R=100,200(100:300)U B=50,500(50:550)U => 100,200(100:300)
		rf=100;
		rbw=200;
		bf=50;
		bbw=500;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=rf) {
				return ::testing::AssertionFailure() << "3) straight receiver, straight backend, receiver included, start frequency should be "
						<< rf << " but is " << f << " instead";
			}
			else if (bw!=rbw) {
				return ::testing::AssertionFailure() << "3) straight receiver, straight backend, receiver included, start bandwidth should be "
						<< rbw << " but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "3) straight receiver, straight backend, receiver included, resulting band should not be empty" ;
		}
		// R=-300,200(100:300)L B=200,100(200:300)U => -200,-100
		rf=-300;
		rbw=200;
		bf=200;
		bbw=100;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=-200) {
				return ::testing::AssertionFailure() << "4) inverted receiver, straight backend, start frequency should be -200 but is " << f << " instead";
			}
			else if (bw!=-100) {
				return ::testing::AssertionFailure() << "4) inverted receiver, straight backend, start bandwidth should be -100 but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "4) inverted receiver, straight backend, resulting band should not be empty" ;
		}
		// R=-300,200(100:300)L B=100,100(100:300)U => -100,-100
		rf=-300;
		rbw=200;
		bf=100;
		bbw=100;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=-100) {
				return ::testing::AssertionFailure() << "5) inverted receiver, straight backend, start frequency should be -200 but is " << f << " instead";
			}
			else if (bw!=-100) {
				return ::testing::AssertionFailure() << "5) inverted receiver, straight backend, start bandwidth should be -100 but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "5) inverted receiver, straight backend, resulting band should not be empty" ;
		}
		// R=-300,200(300:100)L B=150,50(150:200)U => -150,-50
		rf=-300;
		rbw=200;
		bf=150;
		bbw=50;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=-bf) {
				return ::testing::AssertionFailure() << "6) inverted receiver, straight backend, backend included, start frequency should be "
						<< -bf << " but is " << f << " instead";
			}
			else if (bw!=-bbw) {
				return ::testing::AssertionFailure() << "6) inverted receiver, straight backend, backend included, start bandwidth should be "
						<< -bbw << " but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "6) inverted receiver, straight backend, backend included, resulting band should not be empty" ;
		}
		// R=-300,200(300:100)L B=50,500(50:550)U => -100,-200
		rf=-300;
		rbw=200;
		bf=50;
		bbw=500;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=-100) {
				return ::testing::AssertionFailure() << "7) inverted receiver, straight backend, receiver included, start frequency should be -100"
						<< " but is " << f << " instead";
			}
			else if (bw!=-200) {
				return ::testing::AssertionFailure() << "7) inverted receiver, straight backend, receiver included, start bandwidth should be -200"
						<< " but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "7) inverted receiver, straight backend, receiver included, resulting band should not be empty" ;
		}
		// R=100,200(100:300)U B=-150,100(50:150)L => 150,-50
		rf=100;
		rbw=200;
		bf=-150;
		bbw=100;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=150) {
				return ::testing::AssertionFailure() << "8) straight receiver, inverted backend, start frequency should be 150"
						<< " but is " << f << " instead";
			}
			else if (bw!=-50) {
				return ::testing::AssertionFailure() << "8) straight receiver, inverted backend, start bandwidth should be -50"
						<< " but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "8) straight receiver, inverted backend, resulting band should not be empty" ;
		}
		// R=-300,200(100:300)L B=-200,100(100:200)L => -200,100
		rf=-300;
		rbw=200;
		bf=-200;
		bbw=100;
		if (IRA::CIRATools::skyFrequency(bf,bbw,rf,rbw,f,bw)) {
			if (f!=-200) {
				return ::testing::AssertionFailure() << "9) inverted receiver, inverted backend, start frequency should be -200"
						<< " but is " << f << " instead";
			}
			else if (bw!=100) {
				return ::testing::AssertionFailure() << "9) inverted receiver, inverted backend, start bandwidth should be 100"
						<< " but is " << bw << " instead";
			}
		}
		else {
			return ::testing::AssertionFailure() << "9) inverted receiver, inverted backend, resulting band should not be empty" ;
		}
		return ::testing::AssertionSuccess();
	}


protected:
	static IRA::CString simpleDirPath;
Loading