wid2isample.cc 1.77 KB
Newer Older
1
2
3
4
5
/*! \file wid2isample.cc
 * \brief calculate sample index for given time (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: wid2isample.cc,v 1.3 2004-09-17 15:35:00 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
18
19
20
 * 
 * ============================================================================
 */
#define TF_WID2ISAMPLE_CC_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
21
  "TF_WID2ISAMPLE_CC   V1.1   "
22
#define TF_WID2ISAMPLE_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
23
  "$Id: wid2isample.cc,v 1.3 2004-09-17 15:35:00 tforb Exp $"
24
25
26
27
28
29
30
31
32

#include <sffxx.h>

namespace sff {

  //! return index offset of sample at idate
  long int wid2isample(const WID2& wid2, 
                       const libtime::TAbsoluteTime& idate)
  {
33
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
34
35
36
37
38
39
40
41
    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)
  {
42
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
43
44
45
46
47
48
49
50
    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)
  {
51
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
thomas.forbriger's avatar
thomas.forbriger committed
52
    libtime::TRelativeTime retval=(idate-wid2.date)%dt;
53
54
55
56
57
58
    return(retval);
  }

} // namespace sff

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