wid2isample.cc 1.71 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.2 2004-02-10 21:15:24 tforb Exp $
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * \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 \
22
  "$Id: wid2isample.cc,v 1.2 2004-02-10 21:15:24 tforb Exp $"
23
24
25
26
27
28
29
30
31

#include <sffxx.h>

namespace sff {

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

} // namespace sff

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