OpenZGY/C++ Public API (ALPHA)
Access seismic data stored in ZGY format.
// Copyright 2017-2020, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <openzgy/api.h>
#include <iostream>
#include <stdexcept>
#include <stdlib.h>
void copy(const std::string& srcname, const std::string& dstname)
{
using namespace OpenZGY;
std::shared_ptr<IZgyReader> r = IZgyReader::open(srcname);
std::shared_ptr<IZgyWriter> w = IZgyWriter::open(ZgyWriterArgs().metafrom(r).filename(dstname));
const std::array<std::int64_t,3> size = r->size();
const std::array<std::int64_t,3> brick = r->bricksize();
const std::array<std::int64_t,3> bs{brick[0], brick[1], size[2]};
const std::int64_t total = ((size[0] + bs[0] - 1) / bs[0]) *
((size[1] + bs[1] - 1) / bs[1]);
std::int64_t done{0};
std::unique_ptr<float> buf(new float[bs[0]*bs[1]*bs[2]]);
std::array<std::int64_t,3> pos;
for (pos[0] = 0; pos[0] < size[0]; pos[0] += bs[0]) {
for (pos[1] = 0; pos[1] < size[1]; pos[1] += bs[1]) {
for (pos[2] = 0; pos[2] < size[2]; pos[2] += bs[2]) {
r->read(pos, bs, buf.get(), 0);
w->write(pos, bs, buf.get());
p1(++done, total);
}
}
}
w->finalize(std::vector<DecimationType>(), p2);
w->close();
}
int main(int argc, const char **argv)
{
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " infile outfile" << std::endl;
exit(1);
}
try {
copy(argv[1], argv[2]);
}
catch (const std::exception& ex) {
std::cerr << argv[0] << ": " << ex.what() << std::endl;
exit(1);
}
}
OpenZGY::IZgyWriter::close
virtual void close()=0
Flush the file to disk and close it.
OpenZGY::IZgyMeta::bricksize
virtual size3i_t bricksize() const =0
Size of one brick. Almost always (64,64,64), change at your own peril.
OpenZGY::ProgressWithDots
Simple progress bar.
Definition: api.h:814
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::write
virtual void write(const size3i_t &start, const size3i_t &size, const float *data) const =0
Write an arbitrary region.
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::IZgyWriter::open
static std::shared_ptr< IZgyWriter > open(const ZgyWriterArgs &args)
Create a ZGY file and open it for writing.
Definition: api.cpp:1189
OpenZGY
The entire public API is in this namespace.
Definition: api.h:38
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::ZgyWriterArgs
Argument package for creating a ZGY file.
Definition: api.h:388