wid2isample.cc 1.86 KB
Newer Older
1
2
3
4
5
/*! \file wid2isample.cc
 * \brief calculate sample index for given time (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
6
 * $Id: wid2isample.cc,v 1.4 2005-07-28 13:48:26 tforb Exp $
7
8
9
10
11
12
13
14
15
 * \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
thomas.forbriger's avatar
thomas.forbriger committed
16
 *  - 17/09/2004   V1.1   used wrong operator for rest
17
 *  - 28/07/2005   V1.2   returned signed sample index
18
19
20
21
 * 
 * ============================================================================
 */
#define TF_WID2ISAMPLE_CC_VERSION \
22
  "TF_WID2ISAMPLE_CC   V1.2"
23
#define TF_WID2ISAMPLE_CC_CVSID \
24
  "$Id: wid2isample.cc,v 1.4 2005-07-28 13:48:26 tforb Exp $"
25
26
27
28
29
30
31
32
33

#include <sffxx.h>

namespace sff {

  //! return index offset of sample at idate
  long int wid2isample(const WID2& wid2, 
                       const libtime::TAbsoluteTime& idate)
  {
34
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
35
    long int retval=(idate-wid2.date)/dt;
36
    if (idate<wid2.date) retval *= -1;
37
38
39
40
41
42
43
    return(retval);
  }

  //! return time of sample with index offset i
  libtime::TAbsoluteTime wid2isample(const WID2& wid2, 
                                     const long int& i)
  {
44
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
45
46
47
48
49
50
51
52
    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)
  {
53
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
thomas.forbriger's avatar
thomas.forbriger committed
54
    libtime::TRelativeTime retval=(idate-wid2.date)%dt;
55
56
57
58
59
60
    return(retval);
  }

} // namespace sff

/* ----- END OF wid2isample.cc ----- */