Friday 25 March 2011

Dynamic n-dimension array

This post is a note when I'm working with a 3-d array. Here's the code:

//================= declare the array
float*** datacol_ = new float**[100];
int nrc = 100;
int siz = 100;

//================= populate with value
for(int i = 0; i < 100; i++){
datacol_[i] = new float*[nrc];
for( int icomp = 0; icomp < nrc; icomp++ ){
datacol_[i][icomp] = new float[siz];
for( int idx = 0; idx < siz; idx++){
datacol_[i][icomp][idx] = trcin_.get(idx, icomp);
}
}
}

//================= delete the array
for(int i = 0; i < totnr_; i++){
for(int j = 0; j < trcin_.nrComponents(); j++){
delete [] datacol_[i][j];
}
delete [] datacol_[i];
}
delete [] datacol_;

Thursday 24 March 2011

Adding External Library as OpenDtect Module

If we wanted to use external library(ies) for opendtect, we need to compile or get the compiled *.so and *.a files.

In my case, I use alglib, which should be compiled by user. Here's the makefile:

# Alglib sample makefile
# Tested on ubuntu 10.4 LTS
# Used for OpenDtect 4.0.1 ( http://opendtect.org )

CC=gcc
AR=ar
SRC=*.cpp
FLAGS=-Wall
OUT=/home/user/lib/libAlglib3
all:
$(CC) -c -fPIC $(SRC) $(FLAGS)
$(AR) -rcs $(OUT).a *.o
$(CC) -shared -Wl,-soname,$(OUT).so.1 -o $(OUT).so *.o $(FLAGS)
rm *.o
clean:
rm *.o


Then we need to add our external library into ODWork environment.
The steps are:

  1. Copy (or link) *.so file into $(ODWork)/bin/lux32/G/so

  2. Copy (or link) *.a and * so into $(ODWork)/lib/lux32/G

  3. Copy *.h files of our external library into $(ODWork)/include/Alglib

  4. Copy *.cpp/*.cc files of our external library into $(ODWork)/src/Alglib

  5. Edit make.od.ModDeps file in $(ODWork)/Pmake, adding LAlglib := -lAlglib3 and IAlglib := Alglib

  6. Edit our plugin makefile, add Alglib to our MODDEPS variable



If there's any question please feel free to ask.

and thanks to Mas Toto for helping me with this.

Some extra note:

  • Don't forget to use "ldd" to help you determine which lib needed by your plugin.