Commit 707cdd93 authored by Giuseppe Carboni's avatar Giuseppe Carboni
Browse files

Fix #641, added some functions to `IRATools` in order to handle UNIX epochs (#648)

parent 2f6589a6
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@
#define ABS(X,Y) (X>=Y)?X-Y:Y-X
#define ABS(X,Y) (X>=Y)?X-Y:Y-X


#define LIGHTSPEED_MS 299792458.0
#define LIGHTSPEED_MS 299792458.0
#define ACSTIME2UNIXEPOCHOFFSET 122192928000000000


/** 
/** 
 * Creates an exception
 * Creates an exception
+18 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
/* Andrea Orlati(aorlati@ira.inaf.it)  12/08/2015	  Function to check if a file exists or not */
/* 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)  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 */
/* Andrea Orlati(aorlati@ira.inaf.it)  12/01/2016	  reviewed the function skyFrequency in order to address also lower side band during down conversion */
/* Giuseppe Carboni (giuseppe.carboni@inaf.it) 07/12/2021 added the getUNIXEpoch, ACSTime2UNIXEpoch and UNIXEpoch2ACSTime functions */


#include <time.h>
#include <time.h>
#include <sys/time.h>
#include <sys/time.h>
@@ -136,6 +137,23 @@ public:
	 * @return the ACS::Time variable containing the current time
	 * @return the ACS::Time variable containing the current time
	*/
	*/
	static ACS::Time getACSTime();
	static ACS::Time getACSTime();
	/**
	 * Call this function to get the current UNIX epoch
	 * @return a double containing the current UNIX epoch
	*/
	static double getUNIXEpoch();
	/**
	 * Call this function in order to get the UNIX Epoch of the given ACS::Time
	 * @param acs_time the given ACS::Time
	 * @return a double containing the UNIX epoch of the given ACS::Time
	*/
	static double ACSTime2UNIXEpoch(ACS::Time acs_time);
	/**
	 * Call this function in order to get the ACS::Time of the given UNIX Epoch
	 * @param unix_epoch the given UNIX Epoch (double)
	 * @return a ACS::Time object of the given UNIX Epoch
	*/
	static ACS::Time UNIXEpoch2ACSTime(double unix_epoch);
	/** 
	/** 
	 * This function performs the copy of an epoch
	 * This function performs the copy of an epoch
	 * @param dst destination epoch
	 * @param dst destination epoch
+18 −3
Original line number Original line Diff line number Diff line
@@ -56,6 +56,21 @@ ACS::Time CIRATools::getACSTime()
	return now.value().value;
	return now.value().value;
}
}


double CIRATools::getUNIXEpoch()
{
	return CIRATools::ACSTime2UNIXEpoch(CIRATools::getACSTime());
}

double CIRATools::ACSTime2UNIXEpoch(ACS::Time acs_time)
{
	return double(acs_time - ACSTIME2UNIXEPOCHOFFSET) / 10000000;
}

ACS::Time CIRATools::UNIXEpoch2ACSTime(double unix_epoch)
{
	return ACS::Time(long(unix_epoch * 10000000) + ACSTIME2UNIXEPOCHOFFSET);
}

void CIRATools::timeCopy(TIMEVALUE& dst,const TIMEVALUE& src)
void CIRATools::timeCopy(TIMEVALUE& dst,const TIMEVALUE& src)
{
{
	// EpochHelper.value() should have to have the 'const' qualifiers....that would result in a warning
	// EpochHelper.value() should have to have the 'const' qualifiers....that would result in a warning