SFF++ library: reading and writing SFF from C++
offset.cc
Go to the documentation of this file.
1 
36 #define TF_OFFSET_CC_VERSION \
37  "TF_OFFSET_CC V1.2"
38 
39 #include <cmath>
40 #include <sffxx.h>
41 
42 namespace sff {
43 
45  double offset(const SRCE& srce, const INFO& info,
46  const double& radius)
47  {
48  double retval;
49  SFF_assert((srce.cs == info.cs),
50  "ERROR (offset): inconsistent coordinate systems!");
51  if (srce.cs == CS_spherical)
52  {
53  const double convfac=0.017453293;
54  double rtet=(90.-info.cx)*convfac;
55  double stet=(90.-srce.cx)*convfac;
56  double rphi=info.cy*convfac;
57  double sphi=srce.cy*convfac;
58  double cosepi=cos(stet)*cos(rtet)+sin(stet)*sin(rtet)*cos(sphi-rphi);
59  retval=acos(cosepi)*radius*1.e3;
60  }
61  else if (srce.cs == CS_cartesian)
62  {
63  double dx=srce.cx-info.cx;
64  double dy=srce.cy-info.cy;
65  retval=sqrt(dx*dx+dy*dy);
66  }
67  else
68  {
69  SFF_abort("ERROR (offset): unknown coordinate system!");
70  }
71  return(retval);
72  } // double offset(const SRCE& srce, const INFO& info;
73  // const double& radius=6371.)
74 
75  /*----------------------------------------------------------------------*/
76 
78  double sourcedistance(const SRCE& srce, const INFO& info)
79  {
80  double retval;
81  SFF_assert((srce.cs == info.cs),
82  "ERROR (sourcedistance): inconsistent coordinate systems!");
83  SFF_assert((srce.cs == CS_cartesian),
84  "ERROR (sourcedistance): "
85  "only provided in Cartesian coordinates!");
86  if (srce.cs == CS_cartesian)
87  {
88  double dx=srce.cx-info.cx;
89  double dy=srce.cy-info.cy;
90  double dz=srce.cz-info.cz;
91  retval=sqrt(dx*dx+dy*dy+dz*dz);
92  }
93  else
94  {
95  SFF_abort("ERROR (sourcedistance): unknown coordinate system!");
96  }
97  return(retval);
98  } // double sourcedistance(const SRCE& srce, const INFO& info)
99 
100  /*----------------------------------------------------------------------*/
101 
103  double offsetdeg(const SRCE& srce, const INFO& info,
104  const double& radius)
105  {
106  double retval=offset(srce, info, radius)*1.e-3*360./(2.*M_PI*radius);
107  return(retval);
108  } // double offsetdeg(const SRCE& srce, const INFO& info,
109  // const double& radius=6371.)
110 
111 } // namespace sff
112 
113 /*----------------------------------------------------------------------*/
114 
115 /*
116  * Fortran function
117  *
118  character*1 cs,rs
119  real c1,c2,c3,r1,r2,r3
120 cE
121  real distance
122  real rtet, stet, rphi, sphi
123  real convfac, earthradius, cosepi
124  parameter(convfac=0.017453293, earthradius=6371.)
125 c
126  if (cs.ne.rs) stop 'ERROR (sffu_offset): different reference frames'
127  if (cs.eq.'C') then
128  distance=sqrt((c1-r1)**2+(c2-r2)**2+(c3-r3)**2)
129  elseif (cs.eq.'S') then
130 c print *,'source ',c1,c2,c3
131 c print *,'receiver ',r1,r2,r3
132  rtet=(90.-r1)*convfac
133  stet=(90.-c1)*convfac
134  rphi=r2*convfac
135  sphi=c2*convfac
136 c print *,'source ',stet,sphi
137 c print *,'receiver ',rtet,rphi
138  cosepi=cos(stet)*cos(rtet)+sin(stet)*sin(rtet)*cos(sphi-rphi)
139  distance=acos(cosepi)*earthradius*1.e3
140 c print *,'distance ',distance
141  else
142  stop
143  &'ERROR (sffu_offset): reference frame is neither cartesian nor spherical'
144  endif
145  sffu_offset=distance
146  return
147  end
148 cS
149 */
150 
151 /* ----- END OF offset.cc ----- */
all SFF modules
Definition: offset.cc:42
double cz
Definition: sffxx.h:176
double cy
Definition: sffxx.h:202
double cx
Definition: sffxx.h:202
double offsetdeg(const SRCE &srce, const INFO &info, const double &radius)
return offset in degrees
Definition: offset.cc:103
#define SFF_assert(C, M)
check condition
Definition: sffxx.h:82
double cz
Definition: sffxx.h:202
Ecoosys cs
Definition: sffxx.h:175
#define SFF_abort(M)
abort by throwing an exception
Definition: sffxx.h:91
double offset(const SRCE &srce, const INFO &info, const double &radius)
return offset in meters
Definition: offset.cc:45
double cx
Definition: sffxx.h:176
double cy
Definition: sffxx.h:176
double sourcedistance(const SRCE &srce, const INFO &info)
return spatial distance between source and receiver in meters
Definition: offset.cc:78
Ecoosys cs
Definition: sffxx.h:201
SFF library (prototypes)