DATRW++ library: seismic data I/O with multiple formats

◆ readfile()

File datrw::tsoft::readfile ( std::istream &  is,
const ReaderConfig rc 
)

read complete file

function to read a complete TSOFT file

Definition at line 48 of file tsoftsffcontainer.cc.

References datrw::tsoft::SFFchannelid::auxid, datrw::tsoft::SFFchannelid::channel, channelinfofree(), datrw::tsoft::Channeldata::chinfo(), datrw::tsoft::TSOFTchannelid::datatype, datrw::tsoft::Datatrace::date(), datrw::tsoft::TSOFTfile::dc(), datrw::tsoft::TSOFTfile::free(), datrw::tsoft::TSOFTchannelid::instrument, datrw::tsoft::SFFchannelid::instrument, datrw::tsoft::Datatrace::interval(), datrw::tsoft::TSOFTchannelid::location, datrw::tsoft::File::Mfree, datrw::tsoft::Datatrace::Mseries, datrw::tsoft::File::Mtraces, datrw::tsoft::TSOFTfile::nchannels(), datrw::tsoft::Channeldata::ntraces(), datrw::tsoft::Datatrace::series(), datrw::tsoft::SFFchannelid::station, datrw::tsoft::Channelinfo::thedatatype(), datrw::tsoft::Channelinfo::theinstrument(), datrw::tsoft::Channelinfo::thelocation(), datrw::tsoft::Channeldata::trace(), and translate().

Referenced by datrw::itsoftstream::read().

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)
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
aff::Series< datrw::tsoft::Trace > Ttraceseries
collection of traces
Here is the call graph for this function:
Here is the caller graph for this function: