wid2isample.cc 2.47 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$
7
8
9
10
 * \author Thomas Forbriger
 * \date 06/02/2004
 * 
 * calculate sample index for given time (implementation)
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
27
28
29
30
31
 * 
 * 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
32
 *  - 17/09/2004   V1.1   used wrong operator for rest
33
 *  - 28/07/2005   V1.2   returned signed sample index
34
35
36
37
 * 
 * ============================================================================
 */
#define TF_WID2ISAMPLE_CC_VERSION \
38
  "TF_WID2ISAMPLE_CC   V1.2"
39
#define TF_WID2ISAMPLE_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
40
  "$Id$"
41
42
43
44
45
46
47
48
49

#include <sffxx.h>

namespace sff {

  //! return index offset of sample at idate
  long int wid2isample(const WID2& wid2, 
                       const libtime::TAbsoluteTime& idate)
  {
50
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
51
    long int retval=(idate-wid2.date)/dt;
52
    if (idate<wid2.date) retval *= -1;
53
54
55
56
57
58
59
    return(retval);
  }

  //! return time of sample with index offset i
  libtime::TAbsoluteTime wid2isample(const WID2& wid2, 
                                     const long int& i)
  {
60
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
61
62
63
64
65
66
67
68
    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)
  {
69
    libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
thomas.forbriger's avatar
thomas.forbriger committed
70
    libtime::TRelativeTime retval=(idate-wid2.date)%dt;
71
72
73
74
75
76
    return(retval);
  }

} // namespace sff

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