Commit a7fc33da authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Add --osamplesize allowing the app to convert to an arbitrary target type.

parent 73ed74bb
......@@ -98,6 +98,7 @@ public:
std::array<std::int64_t,4> fakesize;
std::array<std::int64_t,3> chunksize;
std::array<std::int64_t,3> obricksize;
OpenZGY::SampleDataType osamplesize;
std::vector<OpenZGY::DecimationType> algorithm;
int lod; // Still unused. Maybe not useful.
int threads;
......@@ -118,6 +119,7 @@ public:
, fakesize(std::array<std::int64_t,4>{0,0,0,0})
, chunksize(std::array<std::int64_t,3>{128,128,0})
, obricksize(std::array<std::int64_t,3>{64,64,64})
, osamplesize(OpenZGY::SampleDataType::unknown)
, algorithm()
, lod()
, threads(1)
......@@ -158,6 +160,7 @@ public:
"-s, --size I,J,K,S: Size, if no input file. E.g. 16x16x16x2.",
"-b, --bricksize I,J,K: Chunk size when copying. E.g. 64x64x64 samples.",
"-B, --obricksize I,J,K Brick size in output. E.g. 64x64x64 samples.",
"-O, --osamplesize type Output float int16, or int8"
"-g, --algorithm 1,2,N: LOD algorithms as 3 int: lod1,lod2,lodN.",
//"-l, --lod N: *Level of detail, 0 = full resolution.",
"-t, --threads N: Number of threads to use for reading.",
......@@ -201,6 +204,21 @@ public:
<< obricksize[1] << "x"
<< obricksize[2] << " ";
switch (osamplesize) {
default:
case OpenZGY::SampleDataType::unknown:
break;
case OpenZGY::SampleDataType::int8:
os << "--osamplesize int8 ";
break;
case OpenZGY::SampleDataType::int16:
os << "--osamplesize int16 ";
break;
case OpenZGY::SampleDataType::float32:
os << "--osamplesize float32 ";
break;
}
if (!algorithm.empty()) {
for (size_t ii=0; ii<algorithm.size(); ++ii)
if (ii == 0)
......@@ -312,7 +330,7 @@ public:
static const char* short_options()
{
return "hvqGuraDNFp:i:o:s:l:b:B:g:t:n:Q:";
return "hvqGuraDNFp:i:o:s:l:b:B:O:g:t:n:Q:";
}
static const struct option *long_options()
......@@ -334,6 +352,7 @@ public:
{"size", required_argument, 0, 's' },
{"bricksize", required_argument, 0, 'b' },
{"obricksize", required_argument, 0, 'B' },
{"osamplesize",required_argument, 0, 'O' },
{"algorithm", required_argument, 0, 'g' },
{"threads", required_argument, 0, 't' },
{"brickcount", required_argument, 0, 'n' },
......@@ -410,6 +429,22 @@ public:
}
break;
case 'O':
if (0==strcmp(optarg, "float32") || 0==strcmp(optarg, "float"))
osamplesize = OpenZGY::SampleDataType::float32;
else if (0==strcmp(optarg, "int16"))
osamplesize = OpenZGY::SampleDataType::int16;
else if (0==strcmp(optarg, "int8"))
osamplesize = OpenZGY::SampleDataType::int8;
else
throw std::runtime_error("command line: sample type must be float32, int16, or int8");
// --osamplesize implies --float, so in fact the --float option is
// now almost redundant. If you want "don't change value type but
// do read/write as float" then --float means you don't need to
// state the existing data type.
native = false;
break;
case 'g': algorithm = getDecimationTypes(optarg); break;
case 'l': throw std::runtime_error("--lod not supported"); //lod = geti(optarg); break;
case 't': threads = geti(optarg); break;
......@@ -421,6 +456,11 @@ public:
help(myname);
exit(1);
}
if (sqnr > 0 &&
osamplesize != OpenZGY::SampleDataType::float32 &&
osamplesize != OpenZGY::SampleDataType::unknown) {
throw std::runtime_error("command line: Don't use --osamplesize with compressed output files");
}
}
#ifdef HAVE_GETOPT
......@@ -642,7 +682,7 @@ suggestRange(float value, OpenZGY::SampleDataType dt, float *lo, float *hi)
}
void
copy(const Options& opt, SummaryPrintingTimer& rtimer, SummaryPrintingTimer& wtimer, SummaryPrintingTimer& rwtimer, SummaryPrintingTimer& ftimer)
copy(const Options& opt, SummaryPrintingTimer& rtimer, SummaryPrintingTimer& wtimer, SummaryPrintingTimer& rwtimer, SummaryPrintingTimer& ftimer, SummaryPrintingTimer& stimer)
{
using namespace OpenZGY;
ProgressWithDots p1, p2;
......@@ -654,10 +694,12 @@ copy(const Options& opt, SummaryPrintingTimer& rtimer, SummaryPrintingTimer& wti
IZgyReader::open(opt.input, &context):
Test::ZgyReaderMock::mock(opt.fakesize);
args.metafrom(r).filename(opt.output);
if (opt.osamplesize != OpenZGY::SampleDataType::unknown)
args.datatype(opt.osamplesize);
if (opt.sqnr > 0)
args.zfp_compressor(static_cast<float>(opt.sqnr))
.zfp_lodcompressor(static_cast<float>(opt.sqnr))
.datatype(SampleDataType::float32);
.datatype(OpenZGY::SampleDataType::float32);
if (opt.obricksize[0]>0 && opt.obricksize[1]>0 && opt.obricksize[2]>0)
args.bricksize(opt.obricksize[0], opt.obricksize[1], opt.obricksize[2]);
args.iocontext(&context);
......@@ -829,19 +871,61 @@ copy(const Options& opt, SummaryPrintingTimer& rtimer, SummaryPrintingTimer& wti
// now instead of having them printed automatically in main(). If the code
// threw an exception we won't get here. But in that case the normal
// mechanism of printing from the timer's destructor is invoked.
// PS, don't use this code as a quick introduction to how simple my
// Timer class is. You might get the wrong impression.
rtimer.print();
wtimer.print();
rwtimer.print();
rwt.done(); // Pretend it went out of scope.
rwtimer.print(); // Ditto for the printing timer that owns it.
// In case Timer logging is enabled in OpenZGY then get the
// read-related timers to output now. close the Some timers are
// printed on close() and some when the writer goes out of scope but
// that is just an implementation detail. To keep them together I
// will destruct the writer immediately afyter closing it.
r->close();
r.reset();
SimpleTimer ft(ftimer);
if (opt.nolod) {
SimpleTimer ft(ftimer, !opt.output.empty());
w->close_incomplete();
}
else {
// Don't report timing for finalizing a mocked output file.
// Yes it does actually have a (tiny) cost but the user won't
// expect to see finalize reported at all when discarding the output.
SimpleTimer ft(ftimer, !opt.output.empty());
w->finalize(opt.algorithm, std::ref(p2));
w->close();
// If Timer logging is also enabled inside OpenZGY there will now
// be multiple lines of output when the output file is finalized
// and closed. Unless we are writing to the mocked dummy output
// file. All these times are related to writing. Even the
// File::read() timer which now reports reads done while making
// LOD bricks. Some timers are printed on close() and some when
// the writer goes out of scope but that is just an implementation
// detail. To keep them together I will destruct the writer
// immediately afyter closing it.
w.reset();
}
#ifndef _WIN32
// This is only for performance measurements and I am only enabling
// it for Linux as I don't know the Windows equivalent. It only
// makes sense when something was written to a local disk. If there
// are any dirty buffers after a read+discard or after a write to
// cloud then they don't belong to us. NOTE: Technically this ought
// to have been a fsync(fd) to only flush our own data. But that
// means exposing fsync from FileADT and that isn't worth the
// trouble. A machine running benchmarks shouldn't have other
// activity anyway.
if (!opt.output.empty() && opt.output.substr(0,5) != "sd://") {
SimpleTimer stim(stimer);
sync();
}
#endif
ftimer.print();
stimer.print();
}
#ifndef _WIN32
......@@ -910,20 +994,14 @@ int main(int argc, char **argv)
try {
Options options(argc, argv);
signals(options);
SummaryPrintingTimer stimer("sync");
SummaryPrintingTimer ftimer("finalize");
SummaryPrintingTimer rwtimer("read+write");
SummaryPrintingTimer wtimer("write");
SummaryPrintingTimer rtimer("read");
PrintingTimer t1("TOTAL");
copy(options, rtimer, wtimer, rwtimer, ftimer);
#ifndef _WIN32 // only for performance measurements on Linux.
{
SimpleTimer stim(stimer);
sync();
}
stimer.print();
#endif
SummaryPrintingTimer stimer("Tool:sync");
SummaryPrintingTimer ftimer("Tool:finalize");
SummaryPrintingTimer rwtimer("Tool:read+write");
SummaryPrintingTimer wtimer("Tool:write");
SummaryPrintingTimer rtimer("Tool:read");
SummaryPrintingTimer ttimer("Tool:TOTAL");
SimpleTimer t1(ttimer);
copy(options, rtimer, wtimer, rwtimer, ftimer, stimer);
}
catch (const std::exception& ex) {
std::string myname(argc >= 1 ? argv[0] : "zgycopyc");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment