DATRW++ library: seismic data I/O with multiple formats
sucomanager.h
Go to the documentation of this file.
1 /*! \file sucomanager.h
2  * \brief manage coordinate scaling (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 06/12/2010
8  *
9  * manage coordinate scaling (prototypes)
10  *
11  * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
12  *
13  * ----
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27  * ----
28  *
29  *
30  * REVISIONS and CHANGES
31  * - 06/12/2010 V1.0 Thomas Forbriger
32  * - 22/01/2012 V1.1
33  * - handle control parameters
34  * - Coordinates and ScalCoo are prepared to receive
35  * control parameters
36  * - add conversion functions
37  *
38  * ============================================================================
39  */
40 
41 // include guard
42 #ifndef DATRW_SUCOMANAGER_H_VERSION
43 
44 #define DATRW_SUCOMANAGER_H_VERSION \
45  "DATRW_SUCOMANAGER_H V1.1"
46 
47 #include<datrwxx/suheaderstruct.h>
48 #include<datrwxx/suformat.h>
49 
50 namespace datrw {
51 
52  namespace su {
53 
54  /*======================================================================*/
55  // conversion functions
56 
57  /*! \brief convert a decimal power to a SeismicUn*x scale value
58  * \ingroup group_su
59  *
60  * \param p exponent for the power of ten
61  * \return corresponding SeismicUn*x scale value like scalco or scalel
62  */
63  short powertoscale(const int& p);
64 
65  /*----------------------------------------------------------------------*/
66 
67  /*! \brief convert a SeismicUn*x scale value to a decimal power
68  * \ingroup group_su
69  *
70  * \param s SeismicUn*x scale value like scalco or scalel
71  * \param strict if true: abort if scale does not match original
72  * definition
73  * \return corresponding exponent for the power of ten
74  */
75  int scaletopower(short s, const bool& strict=true);
76 
77  /*----------------------------------------------------------------------*/
78 
79  /*! \brief fix a SeismicUn*x scale value
80  * \ingroup group_su
81  *
82  * some code out there produces SU data with scale values understood
83  * as exponents of ten; SEGY defines the scale value to be taken as
84  * numerator or denominator of the scaling factor with values -10000,
85  * -1000, -100, -10, 1, 10, 100, 1000, 10000 only; here we allow for
86  * the non-standard setting indicated by the absolute value of scale
87  * being larger than 1 and smaller than 10
88  *
89  * \param s scale value to be fixed (input and output parameter)
90  * \param strict if true: abort if scale does not match original definition
91  */
92  void fixscalevalue(short& s, const bool& strict=true);
93 
94  /*----------------------------------------------------------------------*/
95 
96  /*! \brief convert scale value to a factor to be applied
97  * \ingroup group_su
98  *
99  * \param s SeismicUn*x scale value like scalco or scalel
100  * \param strict if true: abort if scale does not match original
101  * definition
102  * \return factor to be multiplied with actual coordinate value
103  */
104  double scalefactor(short s, const bool& strict=true);
105 
106  /*======================================================================*/
107 
108  /*! \brief scaled coordinate.
109  * \ingroup group_su
110  *
111  * This struct holds one coordinate together with a scale value.
112  * It provides functions to support appropriate scaling and to explore
113  * dynamic range.
114  *
115  * This class is used insed datrw::su::Coordinates to scale coordinates
116  * coherently, since SU provides only scaling factors for all horizontal
117  * coordinates on one hand and all vertical cooridnates on the other hand
118  * together.
119  * The functions inside this class are primarily required upon writing SU
120  * data.
121  *
122  * \sa Coordinates
123  */
124  struct ScalCoo {
125  //! constructor
127  const bool& debug=false)
128  : scale(ctrl.scalco), coo(0), Mcontrol(ctrl), Mdebug(debug)
129  {
131  }
132 
133  /*! \brief lower limit of values
134  *
135  * Coordinate values smaller than this will be regarded as zero.
136  * They cannot be represented, since the scaling limits the exponential
137  * factor to the range 1.e-4 to 1.e+4. It is unsafe to handle these
138  * values with the standard scaling algorithm, since this requires to
139  * take the logarithm of the coordinate value, which will approach
140  * infinity for coordinates approaching zero.
141  */
142  static double effectivezero;
143 
144  /*! \brief maximum number of significant digits to be used
145  *
146  * Floating point number representation and conversion easily leads to
147  * cases where 0.01 becomes 0.00999999977648 which is not intended.
148  * In such cases we will round to the nearest value.
149  */
150  static int maxnsigdigits;
151 
152  //! set from header fields
153  void set(const short& s, const int& c);
154  //! set from coordinate value in meters
155  void set(const double& v);
156  //! return decimal power of scaling factor
157  int power() const;
158  //! scale to given scaling factor as defined by decimal power
159  void scaletopower(const int& p);
160  //! smallest possible power larger or equal desired
161  int smallestpower(const short& desiredscale
163  //! return coordinate value
164  double value() const;
165  //! adjust scale to optimal representation of significant digits
166  void adjustscale();
167 
168  //! scale like scalco
169  short scale;
170  //! coordinate
171  int coo;
172  //! control parameters
174  //! debug mode
175  bool Mdebug;
176  }; // struct ScalCoo
177 
178  /*----------------------------------------------------------------------*/
179 
180  /*! \brief full set of coordinates.
181  * \ingroup group_su
182  *
183  * This struct holds a full set of coordinates for a SEG-Y trace header.
184  * It provides functions to read the values from a given trace header and
185  * to set values in a trace header. Further it provides a function to
186  * chose equal scaling values for horizontal coordinates on one hand and
187  * vertical coordinates on the other hand.
188  * This class combines six members of type datrw::su::ScalCoo in order to
189  * scale coordinates coherently.
190  * It is used in the set functions of datrw::su::SUheader not as a member
191  * data but as a conversion and scaling tool.
192  *
193  * \sa ScalCoo, SUheader.set()
194  */
195  struct Coordinates {
196  //! constructor
198  const bool& debug=false)
199  : sx(ctrl, debug), sy(ctrl, debug), gx(ctrl, debug), gy(ctrl, debug),
200  sdepth(ctrl, debug), gelev(ctrl, debug),
201  Mcontrol(ctrl), Mdebug(debug)
202  { }
203  //! read values from SU header
204  void getvaluesfrom(const TraceHeaderStruct& h);
205  //! set values in SU header
207  //! equalize scaling
208  void equalizescaling();
209 
210  //! source x coordinate
212  //! source y coordinate
214  //! receiver x coordinate
216  //! receiver y coordinate
218  //! source z coordinate
220  //! source y coordinate
222  //! control parameters
224  //! debug mode
225  bool Mdebug;
226  }; // struct Coordinates
227 
228  } // namespace su
229 
230 } // namespace datrw
231 
232 #endif // DATRW_SUCOMANAGER_H_VERSION (includeguard)
233 
234 /* ----- END OF sucomanager.h ----- */
datrw::su::options::SpatialSampling Mcontrol
control parameters
Definition: sucomanager.h:223
int scaletopower(short s, const bool &strict)
convert a SeismicUn*x scale value to a decimal power
Definition: sucomanager.cc:485
void adjustscale()
adjust scale to optimal representation of significant digits
Definition: sucomanager.cc:276
full set of coordinates.This struct holds a full set of coordinates for a SEG-Y trace header...
Definition: sucomanager.h:195
ScalCoo gy
receiver y coordinate
Definition: sucomanager.h:217
const char *const scalco
set desired scalco value
Definition: suformat.cc:64
scaled coordinate.This struct holds one coordinate together with a scale value. It provides functions...
Definition: sucomanager.h:124
bool Mdebug
debug mode
Definition: sucomanager.h:225
SEG-Y and SU trace header as taken from segy.h coming with SeismicUnixsegy - trace identification hea...
bool bestrict
if true: strictly use header definition by SeismicUnix source
Definition: suformat.h:133
ScalCoo sx
source x coordinate
Definition: sucomanager.h:211
int coo
coordinate
Definition: sucomanager.h:171
short scale
scale like scalco
Definition: sucomanager.h:169
options to control the way spatial sampling header variables are handeled.
Definition: suformat.h:122
const char *const strict
strictly interpret header as defined in SeismicUnix source
Definition: suformat.cc:65
ScalCoo gx
receiver x coordinate
Definition: sucomanager.h:215
Root namespace of library.
Definition: aalibdatrwxx.cc:16
const short scalco
default scalco value
Definition: suformat.cc:74
ScalCoo gelev
source y coordinate
Definition: sucomanager.h:221
static double effectivezero
lower limit of values
Definition: sucomanager.h:142
ScalCoo sdepth
source z coordinate
Definition: sucomanager.h:219
datrw::su::options::SpatialSampling Mcontrol
control parameters
Definition: sucomanager.h:173
int smallestpower(const short &desiredscale=datrw::su::subformat::def::scalco) const
smallest possible power larger or equal desired
Definition: sucomanager.cc:298
void equalizescaling()
equalize scaling
Definition: sucomanager.cc:411
short powertoscale(const int &p)
convert a decimal power to a SeismicUn*x scale value
Definition: sucomanager.cc:474
void scaletopower(const int &p)
scale to given scaling factor as defined by decimal power
Definition: sucomanager.cc:238
bool Mdebug
debug mode
Definition: sucomanager.h:175
ScalCoo sy
source y coordinate
Definition: sucomanager.h:213
double value() const
return coordinate value
Definition: sucomanager.cc:349
int power() const
return decimal power of scaling factor
Definition: sucomanager.cc:230
ScalCoo(const datrw::su::options::SpatialSampling &ctrl, const bool &debug=false)
constructor
Definition: sucomanager.h:126
static int maxnsigdigits
maximum number of significant digits to be used
Definition: sucomanager.h:150
void fixscalevalue(short &s, const bool &strict)
fix a SeismicUn*x scale value
Definition: sucomanager.cc:498
Coordinates(const datrw::su::options::SpatialSampling &ctrl, const bool &debug=false)
constructor
Definition: sucomanager.h:197
void setvaluesin(TraceHeaderStruct &h)
set values in SU header
Definition: sucomanager.cc:384
void getvaluesfrom(const TraceHeaderStruct &h)
read values from SU header
Definition: sucomanager.cc:360
double scalefactor(short s, const bool &strict)
convert scale value to a factor to be applied
Definition: sucomanager.cc:546