OpendTect  6.6
segyhdr.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Bril
8  Date: 10-5-1995
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "seismod.h"
15 #include "segythdef.h"
16 #include "coord.h"
17 #include "samplingdata.h"
18 #include "datachar.h"
19 #include "coordsystem.h"
20 class SeisTrcInfo;
21 class od_ostream;
22 
23 
24 namespace SEGY
25 {
26 class Hdrdef;
27 
28 #define SegyTxtHeaderLength 3200
29 #define SegyBinHeaderLength 400
30 #define SegyTrcHeaderLength 240
31 
40 {
41 public:
42 
43  TxtHeader() : revision_(1) { clearText(); }
44  TxtHeader(int rev);
45  void clear() { clearText(); setLineStarts(); }
46 
47  void setUserInfo(const char*);
49  void setPosInfo(const TrcHeaderDef&);
50  void setStartPos(float);
51 
52  void getText(BufferString&) const;
53  void setText(const char*);
54 
55  bool isAscii() const;
56  void setAscii();
57  void setEbcdic();
58 
59  unsigned char txt_[SegyTxtHeaderLength];
60 
61  static bool& info2D();
62 
63  void setLineStarts();
64  void dump(od_ostream&) const;
65 
66 protected:
67 
68  int revision_;
69 
70  void putAt(int,int,int,const char*);
71  void getFrom(int,int,int,char*) const;
72 
73  void clearText();
74 };
75 
76 
80 {
81 public:
82 
84  void setInput(const void*,bool needswap=false);
85  void setForWrite();
86 
87  int bytesPerSample() const
88  { return formatBytes( format() ); }
89  static int formatBytes( int frmt )
90  { return frmt == 3 ? 2 : (frmt == 8 ? 1 : 4); }
91  static bool isValidFormat( int f )
92  { return f==1 || f==2 || f==3 || f==5 || f==8; }
93  static DataCharacteristics getDataChar(int frmt,bool dataswapped);
94 
95  int valueAt(int bytenr);
96  void setValueAt(int bytenr,int);
97  inline int entryVal( int idx ) const
98  { return hdrDef()[idx]->getValue(buf_,needswap_); }
99  inline void setEntryVal( int idx, int val )
100  { return hdrDef()[idx]->putValue(buf_,val); }
101 
102  short format() const { return (short) entryVal(EntryFmt()); }
103  int nrSamples() const { return entryVal(EntryNs()); }
104  int rawSampleRate() const { return entryVal(EntryDt()); }
105  float sampleRate(bool isdpth) const;
106  bool isInFeet() const { return entryVal(EntryMFeet()) == 2; }
107  int revision() const;
108  bool isRev0() const { return revision() < 1; }
110 
111  void setIsSwapped( bool yn ) { needswap_ = yn; }
112  bool isSwapped() const { return needswap_; }
114  void unSwap();
115 
116  void setFormat( short i ) { setEntryVal(EntryFmt(),i); }
117  void setNrSamples( int i ) { setEntryVal(EntryNs(),i); }
118  void setSampleRate(float,bool isdpth);
119  void setInFeet( bool yn ) { setEntryVal(EntryMFeet(),yn?2:1); }
120 
121  void dump(od_ostream&) const;
122 
123  static const HdrDef& hdrDef();
124  unsigned char* buf() { return buf_; }
125  const unsigned char* buf() const { return buf_; }
126 
127 protected:
128 
129  unsigned char buf_[SegyBinHeaderLength];
130  bool forwrite_;
131  bool needswap_;
132 
133 public:
134 
135  // 'well-known' headers, not often abused
136  static int EntryJobID() { return 0; }
137  static int EntryLino() { return 1; }
138  static int EntryDt() { return 5; }
139  static int EntryNs() { return 7; }
140  static int EntryFmt() { return 9; }
141  static int EntryTsort() { return 11; }
142  static int EntryMFeet() { return 24; }
143  static int EntryRevCode() { return 147; }
144 
145 };
146 
147 
149 {
150 public:
151 
152  TrcHeader(unsigned char*,const TrcHeaderDef&,bool rev0,
153  bool manbuf=false);
154  TrcHeader( const TrcHeader& oth )
155  : buf_(0), mybuf_(false), hdef_(oth.hdef_)
156  { *this = oth; }
157  void initRead();
159  TrcHeader& operator =(const TrcHeader&);
160 
161  static const HdrDef& hdrDef();
162 
163  unsigned short nrSamples() const;
164  void putSampling(SamplingData<float>,unsigned short);
165 
166  void use(const SeisTrcInfo&);
167  void fill(SeisTrcInfo&,float) const;
168  void setNeedSwap( bool yn=true ) { needswap_ = yn; }
169 
170  float postScale(int numbfmt) const;
171  Coord getCoord(bool rcv,float extcoordsc) const;
172 
173  unsigned char* buf_;
175  bool isrev0_;
176 
177  bool isusable; // trid < 2 ; mostly ignored but not always
178  bool nonrectcoords; // counit == 1, 2 or 3
179 
180  void dump(od_ostream&) const;
181 
182 protected:
183 
184  bool mybuf_;
185  bool needswap_;
186  int previnl_;
187  int seqnr_;
189 
190  double getCoordScale(float extcoordsc) const;
191 
192  void putRev1Flds(const SeisTrcInfo&) const;
193  void getRev1Flds(SeisTrcInfo&) const;
194 
195 public:
196 
197  // 'well-known' headers
198  static int EntryTracl() { return 0; }
199  static int EntryTracr() { return 1; }
200  static int EntryFldr() { return 2; }
201  static int EntryOldSP() { return 4; }
202  static int EntryCdp() { return 5; }
203  static int EntryTrid() { return 7; }
204  static int EntryDUse() { return 10; }
205  static int EntryOffset() { return 11; }
206  static int EntryScalel() { return 19; }
207  static int EntryScalco() { return 20; }
208  static int EntrySx() { return 21; }
209  static int EntrySy() { return 22; }
210  static int EntryGx() { return 23; }
211  static int EntryGy() { return 24; }
212  static int EntryCoUnit() { return 25; }
213  static int EntryLagA() { return 33; }
214  static int EntryLagB() { return 34; }
215  static int EntryDelRt() { return 35; }
216  static int EntryNs() { return 38; }
217  static int EntryDt() { return 39; }
218  static int EntryTrwf() { return 65; }
219  static int EntryXcdp() { return 71; }
220  static int EntryYcdp() { return 72; }
221  static int EntryInline() { return 73; }
222  static int EntryCrossline() { return 74; }
223  static int EntrySP() { return 75; }
224  static int EntrySPscale() { return 76; }
225 
226  inline int entryVal( int idx ) const
227  { return hdrDef()[idx]->getValue(buf_,needswap_); }
228  inline void setEntryVal( int idx, int val ) const
229  { return hdrDef()[idx]->putValue(buf_,val); }
230 
231 };
232 
233 } // namespace
234 
235 
SEGY::HdrDef
Definition: segyhdrdef.h:85
SEGY::TxtHeader::isAscii
bool isAscii() const
SEGY::TxtHeader::setEbcdic
void setEbcdic()
SEGY::TrcHeader::previnl_
int previnl_
Definition: segyhdr.h:186
SEGY::TrcHeader::EntryInline
static int EntryInline()
Definition: segyhdr.h:221
SEGY::TrcHeader::EntryYcdp
static int EntryYcdp()
Definition: segyhdr.h:220
SEGY::BinHeader::setFormat
void setFormat(short i)
Definition: segyhdr.h:116
SEGY::BinHeader::valueAt
int valueAt(int bytenr)
SEGY::TrcHeader::fill
void fill(SeisTrcInfo &, float) const
SEGY::TrcHeader::getCoordScale
double getCoordScale(float extcoordsc) const
SEGY::BinHeader::EntryNs
static int EntryNs()
Definition: segyhdr.h:139
SEGY::BinHeader::setInput
void setInput(const void *, bool needswap=false)
SEGY::TrcHeader::hdef_
const TrcHeaderDef & hdef_
Definition: segyhdr.h:174
SeisTrcInfo
Information for a seismic trace, AKA trace header info.
Definition: seisinfo.h:27
SEGY::TrcHeader::EntrySPscale
static int EntrySPscale()
Definition: segyhdr.h:224
datachar.h
SEGY::TrcHeader::hdrDef
static const HdrDef & hdrDef()
coordsystem.h
SEGY::TxtHeader::revision_
int revision_
Definition: segyhdr.h:68
SEGY::BinHeader::setSampleRate
void setSampleRate(float, bool isdpth)
SEGY::TxtHeader::clear
void clear()
Definition: segyhdr.h:45
SEGY::BinHeader::nrSamples
int nrSamples() const
Definition: segyhdr.h:103
SEGY::TrcHeader::EntryTrid
static int EntryTrid()
Definition: segyhdr.h:203
SEGY::BinHeader::EntryFmt
static int EntryFmt()
Definition: segyhdr.h:140
SEGY::BinHeader::setValueAt
void setValueAt(int bytenr, int)
Seis
Summary for a Seismic object.
Definition: segydirectdef.h:22
SEGY::BinHeader::EntryRevCode
static int EntryRevCode()
Definition: segyhdr.h:143
SEGY::BinHeader::BinHeader
BinHeader()
SEGY::TrcHeader::use
void use(const SeisTrcInfo &)
SEGY::TxtHeader::dump
void dump(od_ostream &) const
SEGY::TrcHeader::EntryFldr
static int EntryFldr()
Definition: segyhdr.h:200
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
od_istream
OD class for stream read common access to the std::cin.
Definition: od_istream.h:24
SEGY::BinHeader::formatBytes
static int formatBytes(int frmt)
Definition: segyhdr.h:89
samplingdata.h
SEGY::BinHeader::format
short format() const
Definition: segyhdr.h:102
SEGY::TxtHeader::getText
void getText(BufferString &) const
SEGY::TrcHeader::~TrcHeader
~TrcHeader()
SEGY::TxtHeader
3200 byte SEG-Y text header.
Definition: segyhdr.h:40
SEGY::BinHeader::bytesPerSample
int bytesPerSample() const
Definition: segyhdr.h:87
SEGY::TrcHeader::buf_
unsigned char * buf_
Definition: segyhdr.h:173
SEGY::TxtHeader::putAt
void putAt(int, int, int, const char *)
SEGY::TrcHeader::getRev1Flds
void getRev1Flds(SeisTrcInfo &) const
SEGY::TrcHeader::TrcHeader
TrcHeader(const TrcHeader &oth)
Definition: segyhdr.h:154
SEGY::BinHeader::entryVal
int entryVal(int idx) const
Definition: segyhdr.h:97
SEGY::TxtHeader::info2D
static bool & info2D()
SEGY::BinHeader::setNrSamples
void setNrSamples(int i)
Definition: segyhdr.h:117
SEGY::TrcHeader::putRev1Flds
void putRev1Flds(const SeisTrcInfo &) const
SEGY::TrcHeader::putSampling
void putSampling(SamplingData< float >, unsigned short)
SEGY::TrcHeader::EntryLagA
static int EntryLagA()
Definition: segyhdr.h:213
SEGY::TrcHeader::EntryDelRt
static int EntryDelRt()
Definition: segyhdr.h:215
SEGY::TrcHeader::EntryTracl
static int EntryTracl()
Definition: segyhdr.h:198
SEGY::TrcHeader::EntryDUse
static int EntryDUse()
Definition: segyhdr.h:204
SEGY::TxtHeader::setLineStarts
void setLineStarts()
segythdef.h
SEGY::TrcHeader::EntryXcdp
static int EntryXcdp()
Definition: segyhdr.h:219
SEGY::BinHeader::EntryDt
static int EntryDt()
Definition: segyhdr.h:138
SEGY::BinHeader::getDataChar
static DataCharacteristics getDataChar(int frmt, bool dataswapped)
SEGY::TrcHeader::setEntryVal
void setEntryVal(int idx, int val) const
Definition: segyhdr.h:228
SEGY::BinHeader::sampleRate
float sampleRate(bool isdpth) const
Coord
A cartesian coordinate in 2D space.
Definition: coord.h:25
SEGY::BinHeader::guessIsSwapped
void guessIsSwapped()
SEGY::TrcHeader::setNeedSwap
void setNeedSwap(bool yn=true)
Definition: segyhdr.h:168
SEGY::TrcHeader::isrev0_
bool isrev0_
Definition: segyhdr.h:175
SEGY::BinHeader::skipRev1Stanzas
int skipRev1Stanzas(od_istream &)
returns number skipped
SEGY::BinHeader::setIsSwapped
void setIsSwapped(bool yn)
Definition: segyhdr.h:111
SEGY::TrcHeader::TrcHeader
TrcHeader(unsigned char *, const TrcHeaderDef &, bool rev0, bool manbuf=false)
SEGY::TrcHeaderDef
stores HdrEntry info of the needed fields from the trace header.
Definition: segythdef.h:30
SEGY::TrcHeader::dump
void dump(od_ostream &) const
SEGY::TxtHeader::setPosInfo
void setPosInfo(const TrcHeaderDef &)
SEGY::BinHeader::revision
int revision() const
SEGY::TrcHeader
Definition: segyhdr.h:149
SEGY::TrcHeader::EntryTrwf
static int EntryTrwf()
Definition: segyhdr.h:218
SEGY::TrcHeader::EntrySP
static int EntrySP()
Definition: segyhdr.h:223
SEGY::TxtHeader::setUserInfo
void setUserInfo(const char *)
SEGY::BinHeader::hdrDef
static const HdrDef & hdrDef()
SamplingData< float >
SEGY::BinHeader::isValidFormat
static bool isValidFormat(int f)
Definition: segyhdr.h:91
SEGY::TrcHeader::EntrySx
static int EntrySx()
Definition: segyhdr.h:208
SEGY::BinHeader::setForWrite
void setForWrite()
SEGY::TxtHeader::setSurveySetupInfo
void setSurveySetupInfo(const Coords::CoordSystem *)
Coords::CoordSystem
Definition: coordsystem.h:31
SegyTxtHeaderLength
#define SegyTxtHeaderLength
Definition: segyhdr.h:28
SEGY::BinHeader::forwrite_
bool forwrite_
Definition: segyhdr.h:130
SEGY::TrcHeader::isusable
bool isusable
Definition: segyhdr.h:177
SEGY::BinHeader
400 byte SEG-Y binary header
Definition: segyhdr.h:80
SEGY::TxtHeader::clearText
void clearText()
SEGY::TrcHeader::entryVal
int entryVal(int idx) const
Definition: segyhdr.h:226
SEGY::BinHeader::EntryMFeet
static int EntryMFeet()
Definition: segyhdr.h:142
SEGY::TrcHeader::EntryGy
static int EntryGy()
Definition: segyhdr.h:211
SEGY::TrcHeader::mybuf_
bool mybuf_
Definition: segyhdr.h:184
SegyBinHeaderLength
#define SegyBinHeaderLength
Definition: segyhdr.h:29
SEGY::TxtHeader::setText
void setText(const char *)
SEGY::TrcHeader::EntryOldSP
static int EntryOldSP()
Definition: segyhdr.h:201
SEGY::TrcHeader::EntryNs
static int EntryNs()
Definition: segyhdr.h:216
SEGY::TrcHeader::initRead
void initRead()
must call once before first usage
SEGY::TxtHeader::TxtHeader
TxtHeader()
Definition: segyhdr.h:43
SEGY::TxtHeader::setAscii
void setAscii()
SEGY::TrcHeader::seqnr_
int seqnr_
Definition: segyhdr.h:187
SEGY::BinHeader::isRev0
bool isRev0() const
Definition: segyhdr.h:108
SEGY::TrcHeader::EntryOffset
static int EntryOffset()
Definition: segyhdr.h:205
SEGY::BinHeader::needswap_
bool needswap_
Definition: segyhdr.h:131
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
SEGY::TrcHeader::EntryCoUnit
static int EntryCoUnit()
Definition: segyhdr.h:212
SEGY::TxtHeader::TxtHeader
TxtHeader(int rev)
rev only relevant when writing
SEGY::BinHeader::isInFeet
bool isInFeet() const
Definition: segyhdr.h:106
SEGY::BinHeader::buf
const unsigned char * buf() const
Definition: segyhdr.h:125
SEGY::TrcHeader::EntryLagB
static int EntryLagB()
Definition: segyhdr.h:214
SEGY::TrcHeader::nonrectcoords
bool nonrectcoords
Definition: segyhdr.h:178
SEGY::TrcHeader::EntryGx
static int EntryGx()
Definition: segyhdr.h:210
SEGY::BinHeader::EntryLino
static int EntryLino()
Definition: segyhdr.h:137
SEGY::TxtHeader::setStartPos
void setStartPos(float)
SEGY::BinHeader::unSwap
void unSwap()
SEGY
Keys that should be used with od_process_segyio.cc.
Definition: segybatchio.h:22
SEGY::TrcHeader::getCoord
Coord getCoord(bool rcv, float extcoordsc) const
SEGY::BinHeader::buf
unsigned char * buf()
Definition: segyhdr.h:124
SEGY::TrcHeader::EntryCdp
static int EntryCdp()
Definition: segyhdr.h:202
SEGY::TrcHeader::EntryCrossline
static int EntryCrossline()
Definition: segyhdr.h:222
SEGY::TrcHeader::EntryDt
static int EntryDt()
Definition: segyhdr.h:217
SEGY::TrcHeader::lineseqnr_
int lineseqnr_
Definition: segyhdr.h:188
SEGY::TrcHeader::EntrySy
static int EntrySy()
Definition: segyhdr.h:209
SEGY::TxtHeader::getFrom
void getFrom(int, int, int, char *) const
SEGY::TrcHeader::needswap_
bool needswap_
Definition: segyhdr.h:185
SEGY::TrcHeader::EntryScalel
static int EntryScalel()
Definition: segyhdr.h:206
SEGY::BinHeader::dump
void dump(od_ostream &) const
SEGY::BinHeader::EntryTsort
static int EntryTsort()
Definition: segyhdr.h:141
SEGY::TrcHeader::nrSamples
unsigned short nrSamples() const
SEGY::TrcHeader::EntryTracr
static int EntryTracr()
Definition: segyhdr.h:199
SEGY::TrcHeader::postScale
float postScale(int numbfmt) const
SEGY::BinHeader::EntryJobID
static int EntryJobID()
Definition: segyhdr.h:136
SEGY::BinHeader::isSwapped
bool isSwapped() const
Definition: segyhdr.h:112
SEGY::BinHeader::setEntryVal
void setEntryVal(int idx, int val)
Definition: segyhdr.h:99
SEGY::BinHeader::setInFeet
void setInFeet(bool yn)
Definition: segyhdr.h:119
SEGY::TrcHeader::EntryScalco
static int EntryScalco()
Definition: segyhdr.h:207
SEGY::BinHeader::rawSampleRate
int rawSampleRate() const
Definition: segyhdr.h:104
od_ostream
OD class for stream write common access to the user log file, or std::cout in other than od_main.
Definition: od_ostream.h:26
DataCharacteristics
byte-level data characteristics of stored data.
Definition: datachar.h:37
coord.h

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021