DATRW++ library: seismic data I/O with multiple formats
tsoftsffcontainer.cc
Go to the documentation of this file.
1 /*! \file tsoftsffcontainer.cc
2  * \brief a container to hold SFF data for one file (implementation)
3  * \ingroup group_tsoft
4  *
5  * ----------------------------------------------------------------------------
6  *
7  * \author Thomas Forbriger
8  * \date 11/11/2009
9  *
10  * a container to hold SFF data for one file (implementation)
11  *
12  * Copyright (c) 2009 by Thomas Forbriger (BFO Schiltach)
13  *
14  * ----
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28  * ----
29  *
30  * REVISIONS and CHANGES
31  * - 11/11/2009 V1.0 Thomas Forbriger
32  *
33  * ============================================================================
34  */
35 #define DATRW_TSOFTSFFCONTAINER_CC_VERSION \
36  "DATRW_TSOFTSFFCONTAINER_CC V1.0 "
37 
38 #include <datrwxx/tsoftsffcontainer.h>
39 #include <datrwxx/tsoftreader.h>
40 #include <datrwxx/channeltranslation.h>
41 #include <aff/iterator.h>
42 
43 namespace datrw {
44 
45  namespace tsoft {
46 
47  //! read complete file
48  File readfile(std::istream& is, const ReaderConfig& rc)
49  {
50  TSOFTfile infile(is, rc);
51  File outfile;
52  outfile.Mfree.append(infile.free());
53  const Datacontainer& dc=infile.dc();
54 
55  // count traces
56  int ntraces=0;
57  for (int ich=0; ich<infile.nchannels(); ++ich)
58  {
59  const Channeldata& cd=dc[ich];
60  /*
61  std::cout << "ich " << ich <<
62  " has " << cd.nsequences() << " sequences" << std::endl;
63  */
64  ntraces += cd.ntraces();
65  }
66  // std::cout << "found " << ntraces << " traces" << std::endl;
67 
68  // reserve space for n traces
69  outfile.Mtraces=Ttraceseries(ntraces);
70 
71  // cycle trough all input traces
72  aff::Iterator<Ttraceseries> I(outfile.Mtraces);
73  for (int ich=0; ich<infile.nchannels(); ++ich)
74  {
75  const Channeldata& cd=dc[ich];
76  const Channelinfo& ci=cd.chinfo();
77  sff::FREE channelfree;
78  channelfree.append(channelinfofree(ci));
79  for (int itr=0; itr<cd.ntraces(); ++itr)
80  {
81  I->Mfree=channelfree;
82  const Datatrace& ds=cd.trace(itr);
83 
84  // extract samples
85  I->Mseries=ds.series();
86 
87  // extract header
88  I->Mwid2.date=ds.date();
89  I->Mwid2.dt=libtime::time2double(ds.interval());
90  I->Mwid2.nsamples=I->Mseries.size();
91 
92  TSOFTchannelid tci;
93  tci.location=ci.thelocation();
94  tci.instrument=ci.theinstrument();
95  tci.datatype=ci.thedatatype();
96  /*
97  std::cout << "translate: "
98  << tci.location << ":"
99  << tci.instrument << ":"
100  << tci.datatype << ":" << std::endl;
101  */
102  SFFchannelid sci=translate(tci);
103 
104  I->Mwid2.station=sci.station;
105  I->Mwid2.channel=sci.channel;
106  I->Mwid2.instype=sci.instrument;
107  I->Mwid2.auxid=sci.auxid;
108 
109  ++I;
110  }
111  }
112 
113  return(outfile);
114  } // File readfile(const std::istream& is)
115 
116  } // namespace tsoft
117 
118 } // namespace datrw
119 
120 /* ----- END OF tsoftsffcontainer.cc ----- */
config parameters for data extractionThese parameters control the way gaps in the input data are hand...
Definition: tsoftconfig.h:57
contains channel info.
Definition: tsoftdata.h:173
Tdseries Mseries
samples
Definition: tsoftdata.h:258
int ntraces() const
number of data traces
Definition: tsoftdata.h:352
trace of contiguous data.
Definition: tsoftdata.h:242
const std::string & thedatatype() const
return datatype
Definition: tsoftdata.h:190
::sff::FREE Mfree
free comment lines
void series(const Tdseries &s)
set series
Definition: tsoftdata.h:249
data container.
Definition: tsoftdata.h:385
const Datatrace & trace(const unsigned int &i) const
return data trace
Definition: tsoftdata.h:332
contents of a complete TSOFT file
File readfile(std::istream &is, const ReaderConfig &rc)
read complete file
const std::string & theinstrument() const
return instrument
Definition: tsoftdata.h:188
read a complete file
Definition: tsoftreader.h:86
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void chinfo(const Channelinfo &ci)
set channel info
Definition: tsoftdata.h:346
SFFchannelid translate(const TSOFTchannelid &ci)
return SFF channel ID for given TSOFT channel ID
Tlos channelinfofree(const Channelinfo &ci)
prepare free comment block from channel info
Definition: tsoftdata.cc:403
hold TSOFT channel description
const std::string & thelocation() const
return location
Definition: tsoftdata.h:186
int nchannels() const
return number of channels
Definition: tsoftreader.h:106
date for one channel.
Definition: tsoftdata.h:320
void date(const libtime::TAbsoluteTime d)
set time of first sample
Definition: tsoftdata.h:245
aff::Series< datrw::tsoft::Trace > Ttraceseries
collection of traces
const Tlos & free() const
return free lines
Definition: tsoftreader.h:112
Ttraceseries Mtraces
all traces in file
void interval(const libtime::TRelativeTime i)
set sampling interval
Definition: tsoftdata.h:247
const Datacontainer & dc() const
return number of channels
Definition: tsoftreader.h:108
hold SFF channel description