Commit 8d8c0554 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new function

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 2230
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent c49e292f
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.17 2006-03-29 07:32:12 tforb Exp $
# $Id: Makefile,v 1.18 2007-03-02 11:13:33 tforb Exp $
#
# Copyright (c) 2003 by Thomas Forbriger (BFO Schiltach)
#
......@@ -69,7 +69,7 @@ clean: ;
# ------------
LIBSRC=sffxx.cc wid2compare.cc wid2inrange.cc wid2isample.cc \
wid2lastsample.cc sffostream.cc srcesynref.cc
wid2lastsample.cc sffostream.cc srcesynref.cc offset.cc
INCSRC=sffxx.h sffostream.h
-include $(patsubst %.cc,%.d,$(LIBSRC))
......
/*! \file offset.cc
* \brief offset calculation (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: offset.cc,v 1.1 2007-03-02 11:13:33 tforb Exp $
* \author Thomas Forbriger
* \date 02/03/2007
*
* offset calculation (implementation)
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* ----
* 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
* ----
*
* REVISIONS and CHANGES
* - 02/03/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_OFFSET_CC_VERSION \
"TF_OFFSET_CC V1.0 "
#define TF_OFFSET_CC_CVSID \
"$Id: offset.cc,v 1.1 2007-03-02 11:13:33 tforb Exp $"
#include <cmath>
#include <sffxx.h>
#include <tfxx/error.h>
namespace sff {
//! return offset in meters
double offset(const SRCE& srce, const INFO& info;
const double& radius=6371.)
{
double retval;
TFXX_assert((srce.cs == info.cs),
"ERROR (offset): inconsistent coordinate systems!");
if (srce.cs == CS_spherical)
{
const double convfac=0.017453293;
double rtet=(90.-info.cx)*convfac;
double stet=(90.-srce.cx)*convfac;
double rphi=info.cy*convfac;
double sphi=srce.cy*convfac;
double cosepi=cos(stet)*cos(rtet)+sin(stet)*sin(rtet)*cos(sphi-rphi);
retval=acos(cosepi)*radius*1.e3;
}
else if (srce.cs == CS_cartesian)
{
double dx=srce.cx-info.cx;
double dy=srce.cy-info.cy;
retval=sqrt(dx*dx+dy*dy);
}
else
{
TFXX_abort("ERROR (offset): unknown coordinate system!");
}
return(retval);
} // double offset(const SRCE& srce, const INFO& info;
// const double& radius=6371.)
/*----------------------------------------------------------------------*/
//! return offset in degrees
double offsetdeg(const SRCE& srce, const INFO& info,
const double& radius=6371.);
{
double retval=offsetm(srce, info, radius)*1.e-3*360./(2.*PI*radius);
return(retval);
} // double offsetdeg(const SRCE& srce, const INFO& info,
// const double& radius=6371.);
} // namespace sff
/*----------------------------------------------------------------------*/
/*
* Fortran function
*
character*1 cs,rs
real c1,c2,c3,r1,r2,r3
cE
real distance
real rtet, stet, rphi, sphi
real convfac, earthradius, cosepi
parameter(convfac=0.017453293, earthradius=6371.)
c
if (cs.ne.rs) stop 'ERROR (sffu_offset): different reference frames'
if (cs.eq.'C') then
distance=sqrt((c1-r1)**2+(c2-r2)**2+(c3-r3)**2)
elseif (cs.eq.'S') then
c print *,'source ',c1,c2,c3
c print *,'receiver ',r1,r2,r3
rtet=(90.-r1)*convfac
stet=(90.-c1)*convfac
rphi=r2*convfac
sphi=c2*convfac
c print *,'source ',stet,sphi
c print *,'receiver ',rtet,rphi
cosepi=cos(stet)*cos(rtet)+sin(stet)*sin(rtet)*cos(sphi-rphi)
distance=acos(cosepi)*earthradius*1.e3
c print *,'distance ',distance
else
stop
&'ERROR (sffu_offset): reference frame is neither cartesian nor spherical'
endif
sffu_offset=distance
return
end
cS
*/
/* ----- END OF offset.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.31 2006-07-24 13:52:37 tforb Exp $
* $Id: sffxx.h,v 1.32 2007-03-02 11:13:34 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -38,6 +38,7 @@
* - 23/12/2004 V1.3 added full block append to FREE
* - 27/03/2006 V1.4 introduced sff::STAT::decode_libversion
* - 27/06/2006 V1.5 added INFO comparison
* - 02/03/2007 V1.6 added offset calculation
*
* ============================================================================
*/
......@@ -46,9 +47,9 @@
#ifndef TF_SFFXX_H_VERSION
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.5"
"TF_SFFXX_H V1.6"
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.31 2006-07-24 13:52:37 tforb Exp $"
"$Id: sffxx.h,v 1.32 2007-03-02 11:13:34 tforb Exp $"
#include<string>
#include<cmath>
......@@ -533,6 +534,13 @@ namespace sff {
//! return synthetic time reference from nothing
sff::SRCE srce_reference();
//! return offset in meters
double offset(const SRCE& srce, const INFO& info;
const double& radius=6371.);
//! return offset in degrees
double offsetdeg(const SRCE& srce, const INFO& info,
const double& radius=6371.);
} // namespace sff
#endif // TF_SFFXX_H_VERSION (includeguard)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment