OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
example.h
Go to the documentation of this file.
1 // Copyright 2017-2020, Schlumberger
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <openzgy/api.h>
16 #include <iostream>
17 #include <stdexcept>
18 #include <stdlib.h>
19 
28 void copy(const std::string& srcname, const std::string& dstname)
29 {
30  using namespace OpenZGY;
31  ProgressWithDots p1, p2;
32  std::shared_ptr<IZgyReader> r = IZgyReader::open(srcname);
33  std::shared_ptr<IZgyWriter> w = IZgyWriter::open(ZgyWriterArgs().metafrom(r).filename(dstname));
34  const std::array<std::int64_t,3> size = r->size();
35  const std::array<std::int64_t,3> brick = r->bricksize();
36  const std::array<std::int64_t,3> bs{brick[0], brick[1], size[2]};
37  const std::int64_t total = ((size[0] + bs[0] - 1) / bs[0]) *
38  ((size[1] + bs[1] - 1) / bs[1]);
39  std::int64_t done{0};
40  std::unique_ptr<float> buf(new float[bs[0]*bs[1]*bs[2]]);
41  std::array<std::int64_t,3> pos;
42  for (pos[0] = 0; pos[0] < size[0]; pos[0] += bs[0]) {
43  for (pos[1] = 0; pos[1] < size[1]; pos[1] += bs[1]) {
44  for (pos[2] = 0; pos[2] < size[2]; pos[2] += bs[2]) {
45  r->read(pos, bs, buf.get(), 0);
46  w->write(pos, bs, buf.get());
47  p1(++done, total);
48  }
49  }
50  }
51  w->finalize(std::vector<DecimationType>(), p2);
52  w->close();
53 }
54 
55 int main(int argc, const char **argv)
56 {
57  if (argc != 3) {
58  std::cerr << "Usage: " << argv[0] << " infile outfile" << std::endl;
59  exit(1);
60  }
61  try {
62  copy(argv[1], argv[2]);
63  }
64  catch (const std::exception& ex) {
65  std::cerr << argv[0] << ": " << ex.what() << std::endl;
66  exit(1);
67  }
68 }
OpenZGY::ZgyWriterArgs
Argument package for creating a ZGY file.
Definition: api.h:388
OpenZGY::IZgyWriter::write
virtual void write(const size3i_t &start, const size3i_t &size, const float *data) const =0
Write an arbitrary region.
OpenZGY::ProgressWithDots
Simple progress bar.
Definition: api.h:814
OpenZGY::IZgyWriter::finalize
virtual void finalize(const std::vector< DecimationType > &decimation=std::vector< DecimationType >(), const std::function< bool(std::int64_t, std::int64_t)> &progress=nullptr, bool force=false)=0
Generate low resolution data, statistics, and histogram.
OpenZGY
The entire public API is in this namespace.
Definition: api.cpp:68
OpenZGY::IZgyMeta::bricksize
virtual size3i_t bricksize() const =0
Size of one brick. Almost always (64,64,64), change at your own peril.
OpenZGY::IZgyWriter::close
virtual void close()=0
Flush the file to disk and close it.
OpenZGY::IZgyReader::read
virtual void read(const size3i_t &start, const size3i_t &size, float *data, int lod=0) const =0
Read an arbitrary region.
OpenZGY::IZgyMeta::size
virtual size3i_t size() const =0
Size in inline, crossline, vertical directions.
OpenZGY::IZgyReader::open
static std::shared_ptr< IZgyReader > open(const std::string &filename, const IOContext *iocontext=nullptr)
Open a ZGY file for reading.
Definition: api.cpp:1183
OpenZGY::IZgyWriter::open
static std::shared_ptr< IZgyWriter > open(const ZgyWriterArgs &args)
Create a ZGY file and open it for writing.
Definition: api.cpp:1189