I use ipython for my testing purpose, here are some code I try on ipython:
I have pylab installed for my vector/matrix and math calculations;
first import pylab:
>>> import pylab
then load some file, my file is (geomtable.txt) formatted like this (it is a seismic coordinate/geometry table):
1 206 659 709842.0 9311099.0 10.99 -136.215
2 207 658 709842.0 9311099.0 10.99 -165.6061
3 207 658 709829.0 9311071.0 10.99 -134.7688
4 208 657 709829.0 9311071.0 10.99 -165.412
5 208 657 709819.0 9311044.0 11.1 -136.6259
6 209 656 709819.0 9311044.0 11.1 -166.709
7 209 656 709809.0 9311015.0 11.16 -136.0713
8 205 660 709752.0 9310875.0 11.13 136.2151
9 205 660 709747.0 9310844.0 11.1 -135.1495
10 205 660 709728.0 9310819.0 11.48 136.2746
use this command:
>>> rcvpos = pylab.loadtxt("geomtable.txt")
your table will be loaded, next step is sorting the table according to specified column in the table, in my case I will sort the table according to column 3 & 4 (that is UTM coordinate)
use this command to sort:
>>> sorted(rcvpos, key=lambda item:item[3])
in my case I will get minimum and maximum value of column 3 and 4 respectively, use these code below:
>>> minx = sorted(rcvpos, key=lambda item:item[3])[0][3]
>>> miny = sorted(rcvpos, key=lambda item:item[4])[0][4]
>>> maxx = sorted(rcvpos, key=lambda item:item[3])[1334][3]
>>> maxy = sorted(rcvpos, key=lambda item:item[4])[1334][4]
hope this helpful.
Ini catatan biar tetep ingat...
Semoga bukan "trend sesaat"(tm)
Wednesday 6 July 2011
Wednesday 22 June 2011
Tornado Web Server
Recently I am playing with tornado.
here's some code snippet:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, from Tornado World !")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == '__main__':
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
here's some code snippet:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, from Tornado World !")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == '__main__':
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
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_;
Labels:
cpp,
howto,
software dev
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:
Then we need to add our external library into ODWork environment.
The steps are:
If there's any question please feel free to ask.
and thanks to Mas Toto for helping me with this.
Some extra note:
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:
- Copy (or link) *.so file into $(ODWork)/bin/lux32/G/so
- Copy (or link) *.a and * so into $(ODWork)/lib/lux32/G
- Copy *.h files of our external library into $(ODWork)/include/Alglib
- Copy *.cpp/*.cc files of our external library into $(ODWork)/src/Alglib
- Edit make.od.ModDeps file in $(ODWork)/Pmake, adding LAlglib := -lAlglib3 and IAlglib := Alglib
- 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.
Thursday 10 February 2011
Linux C++ error (double free or corruption error)
if your program suddenly crashed during runtime and give you this kind of error:
use this command before executing your program:
*** glibc detected *** double free or corruption (fasttop): 0x08097c40 ***
use this command before executing your program:
export MALLOC_CHECK_=0
start_program &
Tuesday 1 February 2011
Wednesday 26 January 2011
Making Our Own AttributeProvider in OpenDtect
As the default AttributeEngine's Provider class cannot altered as we wish. We need to do some re-routing of it if our plugin wanted to access some protected or read-only members from the original Provider.
Here's the diagram showing what I alter to allow my plugin to do things that the default Provider won't allow it to do:
Something like that...
Here's the diagram showing what I alter to allow my plugin to do things that the default Provider won't allow it to do:
Something like that...
Subscribe to:
Posts (Atom)