[Developers] Using Unix pipes in OpendTect

Raman Singh raman.singh at dgb-group.com
Tue May 20 13:55:51 CEST 2008


Hi all,

While working on the Madagascar link for OpendTect I recently had an
interesting experience with Unix pipes. Many of you must be familiar
with these pipes, but let me illustrate its use vis-a-vis OpendTect. It
may not be very interesting for Windows programmers though.

This is particularly useful for those programs where the output of one
process becomes the input for another.

A  --> ProcessX -->  B
B  --> ProcessY -->  C
C  --> ProcessZ -->  D.

In this case, A and D are the input and output datasets respectively.
But B and C are just intermediaries and probably not interesting. Quite
often, we don't want to write B or C to the disc especially if they
occupy a huge chunk of memory. Using pipes we can channelize the output 
of Process X to the input of Process Y and save the trouble of storing 
the intermediaries. So, the flow becomes:

A      --> ProcessX -->  stdout
stdin  --> ProcessY -->  stdout
stdin  --> ProcessY -->  D.

and the command line reads something like:

$ ProcessX < A | ProcessY | PreocessZ > C

In OpendTect code, we can make a string like:

BufferString comm = "@ProcessX < A par1=val1... | ProcessY... |
ProcessZ... > D";

and execute it using

StreamProvider( comm ).executeCommand();

Alternatively, in ProcessX code, we can write

BufferString comm = "@ProcessY... | ProcessZ... > D";
StreamData sd = StreamProvider( comm ).makeOStream();

and write all the output to *sd.ostrm.

For example, you can have a look at the odmadexec program code under 
Madagascar plugin.

your comments and suggestions are always welcome.

Cheers,
Raman


-- 
Raman K Singh
dGB India
304, Gateway Plaza
Hiranandani Gardens, Powai
Mumbai  400 076
India

Ph.  +91 22 25704984
Mob: +91 98190 82417

http://www.dgb-group.com/
http://www.opendtect.org






More information about the Developers mailing list