Batch programs in OpendTect

Before reading this page, you may consider reading the overview doc first.




What we call a 'batch program' is usually called 'console program' on Windows. All our batch programs accept a single parameter file as argument, and optionally '-bg' if it has to run in the background (it will be ignored on Windows though).

Rather than specifying a 'main', you have to specify:

bool BatchProgram::go(std::ostream&);

The std::ostream& parameter is the log file you can write to. It can be specified in the par file:

Log file: window

other possibilities are 'stdout' or a file name.

That reveals what the par file is: a standard OpendTect Ascii data file with an asistream/ascostream header (see Basic/ascstream.h) and as contents a single IOPar written with IOPar::putTo(ascostream&) (see Basic/iopar.h). This file is read by the BatchProgram constructor into an IOPar instance which is available as 'pars()', like in:

const bool usewavelet = pars().isTrue( "Use Wavelet" );

That would become false if the par file contains a line like:

Use Wavelet: No

Rather than returning an int, like main(), you return a bool. You can of course always use ExitProgram(int) from genc.h to return another value than 0 or 1 from main().

Example code is in od_example_batchprog.cc, the program's example par file is od_example_batchprog.par. In CMakeLists.txt you need to add a line like:

SET(OD_MODULE_BATCHPROGS your_program_file_name_without_cc_extension  )

Output from the example program: