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

◆ select() [2/2]

bool datrw::sequentialtracereader::select ( const std::string &  filename,
const int &  itrace,
const std::string &  format 
)

Definition at line 67 of file tracereader.cc.

References DATRW_assert, Mdebug, Mfilename, Mindex, Mopen, MPias, and MPis.

70  {
71  if (Mdebug)
72  {
73  std::cerr << "DEBUG: sequentialtracereader: "
74  << "entered select with parameters:" << std::endl
75  << " filename: " << filename << std::endl
76  << " itrace: " << itrace << std::endl
77  << " format: " << format << std::endl;
78  if (Mopen)
79  {
80  std::cerr << " current filename: " << Mfilename << std::endl
81  << " current trace: " << Mindex << std::endl;
82  }
83  }
84  bool doopen=false;
85  // check: must a new file be opened?
86  if (!Mopen)
87  {
88  doopen=true;
89  if (Mdebug)
90  {
91  std::cerr << "DEBUG: sequentialtracereader: "
92  << "open file, because no file is open" << std::endl;
93  }
94  }
95  else
96  {
97  if (filename != Mfilename)
98  {
99  doopen=true;
100  if (Mdebug)
101  {
102  std::cerr << "DEBUG: sequentialtracereader: "
103  << "open file, because file name differs" << std::endl;
104  }
105  }
106  else if (itrace < Mindex)
107  {
108  doopen=true;
109  if (Mdebug)
110  {
111  std::cerr << "DEBUG: sequentialtracereader: "
112  << "open file, because trace index (" << itrace << ") "
113  << "is less than current index (" << Mindex << ")" << std::endl;
114  }
115  }
116  }
117  // if yes: open new file
118  if (doopen)
119  {
120  if (this->Mopen)
121  {
122  if (Mdebug)
123  {
124  std::cerr << "DEBUG: sequentialtracereader: "
125  << "close previous file" << std::endl;
126  }
127  delete MPis;
128  delete MPias;
129  }
130  Mindex=1;
131  Mfilename=filename;
132  MPis=new std::ifstream(Mfilename.c_str(),
133  datrw::ianystream::openmode(format));
134  MPias=new datrw::ianystream(*MPis, format, Mdebug);
135  Mopen=true;
136  if (Mdebug)
137  {
138  std::cerr << "DEBUG: sequentialtracereader: "
139  << "file " << Mfilename << " is opened" << std::endl;
140  }
141  }
142  // skip to selected trace
143  int nskip=itrace-Mindex;
144  DATRW_assert(nskip>=0, "sequentialtracereader::select: "
145  "cannot skip backwards!");
146  if (Mdebug)
147  {
148  std::cerr << "DEBUG: sequentialtracereader: "
149  << nskip << " skips: " << std::endl;
150  }
151  for (int iskip=0; iskip<nskip; ++iskip)
152  {
153  DATRW_assert(MPias->good(), "sequentialtracereader::select: "
154  "input is not good!");
155  MPias->skipseries();
156  ++Mindex;
157  }
158  return(MPias->good());
159  } // sequentialtracereader::select
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
Class to read any type of data file.
Definition: readany.h:82
datrw::ianystream * MPias
Definition: tracereader.h:117