AGtivity Nuggets
Some little tid bits of useful information that we came across worked out during the development of this project. Most of them about handling timestamps between UNIX, GNUplot and Excel.
UNIX Time
Converting between UNIX time and something readable using the UNIX date command:
date --date=@123456789 date --date="4 Jan 1982" +"%s"
Excel Time
This is a floating point number were the integer part gives the date and the decimal part the time. It uses a different epoch than UNIX time. To convert from UNIX time to Excel time:
Te = Tu/86400.0 + 25569
GNUplot Time
GNUplot has a different epoch from UNIX also. Though it will read UNIX timestamps if the time format is specified as:
set xdata time set timefmt x "%s"
However if you want to specify specific points on a graph with time axes to position annotation say you will need to use GNUplot time:
Tg = Tu -946684800
String Hashing
When comparing a set of strings it is far more efficient to convert the strings to an integer and then just compare these. We using the following hashing function found on Stackoverflow.com (C):
unsigned int hash_string(char *str) {
unsigned int hash = 0;
int c;
while (str && (c = *str++)) {
/* hash = hash * 33 ^ c */
hash = ((hash << 5) + hash) ^ c;
}
return hash;
}
You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.