Commit 628aa742 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

resturctured libtime binary source code

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.
introduced new tsxx functions
introduced new libsffxx functions


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1473
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 7b56cf13
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.7 2004-01-28 15:56:08 tforb Exp $
# $Id: Makefile,v 1.8 2004-02-07 17:38:12 tforb Exp $
#
# Copyright (c) 2003 by Thomas Forbriger (BFO Schiltach)
#
......@@ -48,7 +48,8 @@ clean: ;
# library part
# ------------
LIBSRC=sffxx.cc wid2compare.cc
LIBSRC=sffxx.cc wid2compare.cc wid2inrange.cc wid2isample.cc \
wid2lastsample.cc
INCSRC=sffxx.h
-include $(patsubst %.cc,%.d,$(LIBSRC))
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.12 2004-02-02 09:50:23 tforb Exp $
* $Id: sffxx.h,v 1.13 2004-02-07 17:38:12 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -29,7 +29,7 @@
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.2 "
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.12 2004-02-02 09:50:23 tforb Exp $"
"$Id: sffxx.h,v 1.13 2004-02-07 17:38:12 tforb Exp $"
#include<string>
#include<cmath>
......@@ -425,6 +425,19 @@ namespace sff {
double Mdatetolerance; //!< relative to mean sampling interval
}; // class WID2compare
/*======================================================================*/
// functions
// ---------
libtime::TAbsoluteTime wid2lastsample(const WID2& wid2);
libtime::TAbsoluteTime wid2nextdate(const WID2& wid2);
long int wid2isample(const WID2& wid2,
const libtime::TAbsoluteTime& idate);
libtime::TAbsoluteTime wid2isample(const WID2& wid2,
const long int& i);
libtime::TRelativeTime wid2isamplerest(const WID2& wid2,
const libtime::TAbsoluteTime& idate);
} // namespace sff
#endif // TF_SFFXX_H_VERSION (includeguard)
......
/*! \file wid2inrange.cc
* \brief check if time is in range (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: wid2inrange.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
* check if time is in range (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 06/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_WID2INRANGE_CC_VERSION \
"TF_WID2INRANGE_CC V1.0 "
#define TF_WID2INRANGE_CC_CVSID \
"$Id: wid2inrange.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $"
#include <sffxx.h>
namespace sff {
} // namespace sff
/* ----- END OF wid2inrange.cc ----- */
/*! \file wid2isample.cc
* \brief calculate sample index for given time (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: wid2isample.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
* calculate sample index for given time (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 06/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_WID2ISAMPLE_CC_VERSION \
"TF_WID2ISAMPLE_CC V1.0 "
#define TF_WID2ISAMPLE_CC_CVSID \
"$Id: wid2isample.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $"
#include <sffxx.h>
namespace sff {
//! return index offset of sample at idate
long int wid2isample(const WID2& wid2,
const libtime::TAbsoluteTime& idate)
{
libtime::TRelativeTime dt=double2time(wid2.dt);
long int retval=(idate-wid2.date)/dt;
return(retval);
}
//! return time of sample with index offset i
libtime::TAbsoluteTime wid2isample(const WID2& wid2,
const long int& i)
{
libtime::TRelativeTime dt=double2time(wid2.dt);
libtime::TAbsoluteTime retval=wid2.date+i*dt;
return(retval);
}
//! return residual between idate and sample next to it
libtime::TRelativeTime wid2isamplerest(const WID2& wid2,
const libtime::TAbsoluteTime& idate)
{
libtime::TRelativeTime dt=double2time(wid2.dt);
libtime::TRelativeTime retval=(idate-wid2.date)/dt;
return(retval);
}
} // namespace sff
/* ----- END OF wid2isample.cc ----- */
/*! \file wid2lastsample.cc
* \brief return time of last sample (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: wid2lastsample.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
* return time of last sample (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 06/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_WID2LASTSAMPLE_CC_VERSION \
"TF_WID2LASTSAMPLE_CC V1.0 "
#define TF_WID2LASTSAMPLE_CC_CVSID \
"$Id: wid2lastsample.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $"
#include <sffxx.h>
namespace sff {
//! return date of last sample
libtime::TAbsoluteTime wid2lastsample(const WID2& wid2)
{
libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
libtime::TAbsoluteTime retval=wid2.date+(dt*wid2.nsamples);
return(retval);
}
//! return date of sample after last sample
libtime::TAbsoluteTime wid2nextdate(const WID2& wid2)
{
libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
libtime::TAbsoluteTime retval=wid2.date+(dt*(wid2.nsamples+1));
return(retval);
}
} // namespace sff
/* ----- END OF wid2lastsample.cc ----- */
/* this is <base_constr.cc>
* ----------------------------------------------------------------------------
*
* $Id: base_constr.cc,v 1.11 2004-02-02 09:37:13 tforb Exp $
* $Id: base_constr.cc,v 1.12 2004-02-07 17:38:15 tforb Exp $
*
* 09/08/2000 by Thomas Forbriger (IfG Stuttgart)
*
......@@ -43,45 +43,6 @@ void TBaseClassTime::string_read(const std::string &timestring)
char_read(charstring);
}
TAbsoluteTime now()
{
std::time_t nowtime=std::time(NULL);
std::tm *nowtm=std::localtime(&nowtime);
int year=nowtm->tm_year+1900;
int month=nowtm->tm_mon+1;
int day=nowtm->tm_mday;
int hour=nowtm->tm_hour;
int minute=nowtm->tm_min;
int second=nowtm->tm_sec;
TAbsoluteTime thetime(year, month, day, hour, minute, second);
return(thetime);
} // now()
TRelativeTime double2time(const double& seconds)
{
time_kernel::time_Ts thetime_Ts(TRelativeTime(0));
double remain=seconds;
typedef long int li;
thetime_Ts.second=li(seconds);
remain-=double(thetime_Ts.second);
remain*=1.e3;
thetime_Ts.milsec=li(remain);
remain-=double(thetime_Ts.milsec);
remain*=1.e3;
thetime_Ts.micsec=li(remain);
return(TRelativeTime(thetime_Ts));
} // TRelativeTime double2time(const double& seconds)
double time2double(const TRelativeTime& rtime)
{
double retval(0.);
retval=rtime.float_second();
retval += 60.*rtime.minute();
retval += 3600.*rtime.hour();
retval += 24.*3600.*rtime.days();
return(retval);
} // double time2float(const TRelativeTime&)
}; // namespace libtime
/* ----- END OF base_constr.cc ----- */
/*! \file convert.cc
* \brief convert time representation (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: convert.cc,v 1.1 2004-02-07 17:38:15 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
* convert time representation (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 06/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_CONVERT_CC_VERSION \
"TF_CONVERT_CC V1.0 "
#define TF_CONVERT_CC_CVSID \
"$Id: convert.cc,v 1.1 2004-02-07 17:38:15 tforb Exp $"
#include <libtime++.h>
namespace libtime {
TRelativeTime double2time(const double& seconds)
{
time_kernel::time_Ts thetime_Ts(TRelativeTime(0));
double remain=seconds;
typedef long int li;
thetime_Ts.second=li(seconds);
remain-=double(thetime_Ts.second);
remain*=1.e3;
thetime_Ts.milsec=li(remain);
remain-=double(thetime_Ts.milsec);
remain*=1.e3;
thetime_Ts.micsec=li(remain);
return(TRelativeTime(thetime_Ts));
} // TRelativeTime double2time(const double& seconds)
double time2double(const TRelativeTime& rtime)
{
double retval(0.);
retval=rtime.float_second();
retval += 60.*rtime.minute();
retval += 3600.*rtime.hour();
retval += 24.*3600.*rtime.days();
return(retval);
} // double time2float(const TRelativeTime&)
} // namespace libtime
/* ----- END OF convert.cc ----- */
/*! \file cxxtime_util_fatal.cc
* \brief fatal error handling (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: cxxtime_util_fatal.cc,v 1.1 2004-02-07 17:38:15 tforb Exp $
* \author Thomas Forbriger
* \date 07/02/2004
*
* fatal error handling (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 07/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_CXXTIME_UTIL_FATAL_CC_VERSION \
"TF_CXXTIME_UTIL_FATAL_CC V1.0 "
#define TF_CXXTIME_UTIL_FATAL_CC_CVSID \
"$Id: cxxtime_util_fatal.cc,v 1.1 2004-02-07 17:38:15 tforb Exp $"
#include <libtime++.h>
#include <string>
extern "C" {
/*
* Fortran calling convention:
*/
int time_util_fatal__(char *caller, char *text,
time_kernel::ftnlen caller_len,
time_kernel::ftnlen text_len)
{
std::string callerstring, textstring;
int i;
for (i=0; i<caller_len; i++) { callerstring += *(caller++); }
for (i=0; i<text_len; i++) { textstring += *(text++); }
std::string message="ERROR ("+callerstring+"): "+textstring;
throw(libtime::Exception(message.c_str()));
return(0);
} /* time_util_fatal__ */
} // extern "C"
/* ----- END OF cxxtime_util_fatal.cc ----- */
/*! \file cxxtime_util_warning.cc
* \brief issue warning (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: cxxtime_util_warning.cc,v 1.1 2004-02-07 17:38:16 tforb Exp $
* \author Thomas Forbriger
* \date 07/02/2004
*
* issue warning (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 07/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_CXXTIME_UTIL_WARNING_CC_VERSION \
"TF_CXXTIME_UTIL_WARNING_CC V1.0 "
#define TF_CXXTIME_UTIL_WARNING_CC_CVSID \
"$Id: cxxtime_util_warning.cc,v 1.1 2004-02-07 17:38:16 tforb Exp $"
#include <libtime++.h>
#include <string>
#include <iostream>
namespace libtime {
bool Warning::suppress_normal=false;
bool Warning::suppress_year=false;
bool Warning::suppress_any=false;
} // namespace libtime
extern "C" {
/*
* Fortran calling convention:
*/
int time_util_warning__(char *caller, char *text,
time_kernel::ftnlen caller_len,
time_kernel::ftnlen text_len)
{
std::string callerstring, textstring;
int i;
if (!(libtime::Warning::suppress_normal|| libtime::Warning::suppress_any))
{
for (i=0; i<caller_len; i++) { callerstring += *(caller++); }
for (i=0; i<text_len; i++) { textstring += *(text++); }
std::string message="ERROR ("+callerstring+"): "+textstring;
std::cerr << message << std::endl;
}
return(0);
} /* time_util_warning__ */
int time_util_warning_n__(char *caller, char *text,
time_kernel::integer *n,
time_kernel::ftnlen caller_len,
time_kernel::ftnlen text_len)
{
std::string callerstring, textstring;
int i;
if (!(libtime::Warning::suppress_year|| libtime::Warning::suppress_any))
{
for (i=0; i<caller_len; i++) { callerstring += *(caller++); }
for (i=0; i<text_len; i++) { textstring += *(text++); }
std::string message="ERROR ("+callerstring+"): "+textstring;
i=(int)*n;
std::cerr << message << " " << i << std::endl;
}
return(0);
} /* time_util_warning_n__ */
} // extern "C"
/* ----- END OF cxxtime_util_warning.cc ----- */
/*! \file error.cc
* \brief exception class (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: error.cc,v 1.1 2004-02-07 17:38:16 tforb Exp $
* \author Thomas Forbriger
* \date 07/02/2004
*
* exception class (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 07/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_ERROR_CC_VERSION \
"TF_ERROR_CC V1.0 "
#define TF_ERROR_CC_CVSID \
"$Id: error.cc,v 1.1 2004-02-07 17:38:16 tforb Exp $"
#include <iostream>
#include <libtime++.h>
using std::cerr;
using std::endl;
namespace libtime {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
//! construct from nothing
Exception::Exception():
Mmessage(0), Mfile(0), Mline(0), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(0), Mline(0), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(0), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
}
//! report
void Exception::report() const
{
base_report();
}
//! report
void Exception::base_report() const
{
cerr << "Exception report:" << endl;
if (Mmessage==0)
{
cerr << " No message" << endl;
}
else
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=0)
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=0)
{
cerr << " by condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
}
}
} // namespace libtime
/* ----- END OF error.cc ----- */
/*! \file now.cc
* \brief return system time (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: now.cc,v 1.1 2004-02-07 17:38:17 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
* return system time (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 06/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_NOW_CC_VERSION \
"TF_NOW_CC V1.0 "
#define TF_NOW_CC_CVSID \
"$Id: now.cc,v 1.1 2004-02-07 17:38:17 tforb Exp $"
#include <libtime++.h>
namespace libtime {
TAbsoluteTime now()
{
std::time_t nowtime=std::time(NULL);
std::tm *nowtm=std::localtime(&nowtime);
int year=nowtm->tm_year+1900;
int month=nowtm->tm_mon+1;
int day=nowtm->tm_mday;
int hour=nowtm->tm_hour;
int minute=nowtm->tm_min;
int second=nowtm->tm_sec;
TAbsoluteTime thetime(year, month, day, hour, minute, second);
return(thetime);
} // now()
} // namespace libtime
/* ----- END OF now.cc ----- */
/*! \file ranges.cc
* \brief time range class (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: ranges.cc,v 1.1 2004-02-07 17:38:17 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
* time range class (implementation)
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 06/02/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_RANGES_CC_VERSION \
"TF_RANGES_CC V1.0 "
#define TF_RANGES_CC_CVSID \
"$Id: ranges.cc,v 1.1 2004-02-07 17:38:17 tforb Exp $"
#include <libtime++.h>
#include<iostream>
namespace libtime {
TRange::TRange(const TAbsoluteTime& begin,
const TAbsoluteTime& end):