The daily ramblings …

C++ : Static

Posted in C++ General by akamal on January 26, 2007

Static data types can be accessed without the instantiation of the class in C++. Applicable for static functions too. A typical use of static members is for recording data common to all objects. E.g: We can use static data to record the number of objects created.

To access static member, we uses ::(scope resolution) operator. An example is shown below:

01#include <iostream>
02using namespace std;
04class Circle
07	// Initially declare radius as type double and static
08	static double radius;
10	Circle() {} // constructor
11	static void setRadius(double var)
12	{
13		radius = var;
14	}
15	static double getRadius()
16	{
17		return radius;
18	}
19	static double getArea()
20	{
21		return radius * radius;
22	}
25double Circle::radius = 30;
27int main()
29	Circle circ;
30	cout << "Circle 1 radius is : " << Circle::getRadius() << "n";
31	// object circ can also access static method getArea
32	cout << "Circle 1 area is : " << circ.getArea() << "n";
33	Circle::setRadius(50);
34	cout << "Circle 1 radius is now : " << Circle::getRadius() << "n";
35	cout << "Circle 1 area is : " << Circle::getArea() << "n";
36	system("PAUSE");
37	return 0;

From the example above, we don’t need to instantiate the class to access static method “method1”. So, that’s the plain use of static.

Remember the rules of thumb below:

1 – Static members can be called even when no instantiation of class is made. Normal members of class (non-static) can only be called when an object is instantiated out of the class.

2 – Static member / funcntion cannot have access to ‘pointer of the’ class. Meaning that pointer to a class will have its own members, and the static member won’t have access to that.

3 – Static member function cannot be declared virtual, while non-static member can.

4 – Static data members must be defined out side of class definition, because they don’t belong to any specific instance of the class.

01class X
04	static int i;
06// definition outside class declaration
07int X::i = 0;

5 – Static member functions get defined in the class and so should static member variables.


Geophysics : An Introduction to Velocity

Posted in Geophysics by akamal on January 18, 2007

[ Introduction]

Velocity by definition refers to the rate at which an object changes its position. It is of a vector quantity, and as such, is direction aware. To illustrate this, imagine a person moving rapidly, one step forward and another backward, always returning to the original position. While this might result in a change of activity, it would result in a zero velocity, as the person always return to the original position (no distance to comapare with).

In geophysics, velocity is an extremely important trait that enables us to predict the sort of content the earth’s ground covers. As it is related to how fast waves travel between layers of the earth, it also tells us of how compact they are in between.

It’s formula is:

velocity = total distance / total time , or put simply,
v = d/t

As in the usual case of physics, there are 2 types of fundamental velocity to deal with. Let’s have a quick look into all 2.

[ Average Velocity ]
Much like the name suggests, it actually calculates the average speed between the distance traveled and time taken. For example, when traveling to Petaling which is 50km in distance, and taking 1 hour, my velocity would be

v = 50 km / 1 hour = 50 km/h

It’s comparison will be your starting distance and time against your last.

[ Instantaneous Velocity ]
Shows the velocity at one given point. As the name indicated, it’s a velocity at one instance of time. In average velocity, we consider the speed between point A and B, so they’re like intervals between them.

[ Example ]

Consider the example below (don’t bother to ask where I got the diagram, I freakingly did it myself) :

Velocity Diagram 001

Consider a car going from point A to B. As the diagram indicated, the car arrives at point B in 50 mintues time. To calculate the average speed, we use the following information.

total distance = sum of distance; td = 25 + 20 + 30 + 10 = 85 km
total time = end time – starting time; tt = 50 – 0 = 50 minutes

The average velocity is:

td / tt = 85
50 = 1.7 km per minute

In geophysics, the standard is meter/second, so I’d take the answer as 24 meter/second.

Now, to understand the concept of instantaneous velocity, I’d have to write some lengthy explanation here. Remember that instantaneous refers to a reading at one particular point or time.

Suppose the velocity of the car is varying, because for example, you’re in a traffic jam. You look at the speedometer and it’s varying a lot, all the way from zero to 60 mph. What is the instantaneous velocity? It is, more or less, what you read on the speedometer. I’m assuming you’ve got a good speedometer that isn’t too sluggish and can change its reading quite quickly. Your speedometer is measuring the the average velocity but one measured over quite a short time, to ensure that you’re getting an up to date reading of your velocity.

So if you measure the displacement of the car d over t, you can use that to determine the average velocity of the car. What we want is to take the limit as difference of t goes to zero. More formally, the instantaneous velocity v is defined as

v = d / t; where t -> is nearing to 0

What the heck do I mean by that? I know you’d be confused. Just consider this, instant velocity still uses the same equation as of average. v = d/t, but instead of taking the total difference between the 2 variables, we try to limit the range of the difference, example, to get velocity at 40km, we use these information:

time difference = 160 seconds – 159.5 seconds
distance difference = 40km – 39.75km

The comparison looks so small right? That’s what you call instantaneous velocity, because we’re comparing the velocity at time 160 seconds, as compared to the previous velocity at 159.5 seconds. Usually, with average, you’re just comparing from time at some xx seconds and 0 (initial time). So what is the limit you say? Yeah, there is a limit to what extent you should define the difference on. You can’t just write difference of time as 60 seconds – 59.999999 seconds, that’s absurd.

To explain on the concept of limits, I’ll explain it in another article.

C++ : Methods of Object Instantiations with Classes

Posted in C++ General by akamal on January 16, 2007

When it comes to programming, the best method to learn is by digging up codes from existing source codes, but question remains, how do you learn by looking at thousands of lines of codes? Well firstly, you have to get your basics right.

To recap, Classes and OOP are the main feature provided by C++. With classes, you’d be able to expand your built codes for other future needs, or simply to tackle similar problems by re usability. The purpose of this article is not to look at classes (well not now), but rather a quick peek on the styles of code-writing when instantiating / using classes. Remember that the concept of class is strongly linked to pointers, especially in C++. So you might want to get a brush-up on it first. Look it up here.

Fundamentally, there are 2 styles when writing class instantiations.

  1. The first style assigns a variable with the instantiation of the object itself (as seen in type A).
  2. The second, goes for a more versatile approach by using a variable to store the address of the created object (type B).

type B:

1// We assign a variable named window in line 9. 
2// Its type is not int, char or whatever, but instead it is an 
3// object of class QWidget.
4// To access its properties, we use "." to access its method,
5// as seen in line 10 ---
6int main(int argc, char * argv[])
8	QApplication app(argc,argv);
9	QWidget window;
11	return app.exec();

type B:

1// here, we initially declare a pointer named window 
2// which is of type object. Variable window be allocated in the 
3// memory with no value. Next, we assign the window variable to the 
4// address of the QWidget object just created (new QWidget creates an object).
5// To access its properties, we use "->", known as throwing at, 
6// to access method show() as seen in line 6.
7int main (int argc, char * argv[])
9QApplication app(argc,argv);
10QWidget *window;
11window = new QWidget;
13return app.exec();

Between the 2, there’s aren’t many differences generally, and certainly no pros/cons that I know of. But just to get some people accustomed to the style of writing, one should be aware that class instantiation can be done in 2 ways, as explained above.

C++ : The Concept of Pointer

Posted in C++ General by akamal on January 16, 2007

I was doing my normal programming routine today, when halted for request on ad hoc pointer tutorial by some of my team members. The 1 hour & 30 minutes tutorial spoke for itself, seeing how hard it is for newcomers to grasp the concept.

Throughout the session, questions bombarded ranging from “why the need to pass between functions” to “how important as to store address of a var”? and so on.

So I’ve come up with this small article on this, just a reminder to those who’s so regularly confused with the concept, I know I do.

When programming for software requiring large design, there’ll be hundreds, literally thousands of codes meddling in functions here and there. Especially on a critical / memory heavy s/w, unnecessary usage of memory is certainly a thing to avoid.

The use of pointer allows programmer to keep on using the same variable, WITH the same memory location, passing it to any external functions so as long it requires.

A safe practise of programing always involves pointers, especially in C++. Since we do not have the luxury of automatic memory management, as Java does, those who codes in C++ must always keep in mind on variable allocation and de-allocation (aka deletion).


& is a reference operator. Also means “address of variable to point to”
* means “is a dereference operator. Also means value pointed by the variable”


To understand what the 2 above means, please have a look at the codes below. No point dwelling on lengthy explanations, right? I’d better kick it off with codes review! Let’s begin..

Ok, in line 1 you have a variable var1 of type, say, int. var1 is then assigned the value of 25. Next, you declare

int var1 = 25;
int *var2;
var2 = &var1;
cout << var2;
cout << *var2;

1 int var1 = 25;

var1 = 25; // var1 hold the value 25 in some memory address, say address 1000
2 var2 = &var1; // var2 stores the address of var1, so when typing …
3 cout << var2; // you would get the address of var1, which is 1000
4 var3 = *var2; // now var3 will take the value pointed by var2
5 // var2 has address 1000, and value pointed by address 1000 is 25

The funny thing is a lot of people may understand this concept through books and tutorials, but
when it comes to “real” programming, they’d be perplexed with the way values and address are passed all

I say, that the only way to fully grasps this concept, is to practice regularly with pointers, yeah.

QT : Signals and Slots Mechanism

Posted in QT by akamal on January 16, 2007

One great feature installed inside Qt is the signal and slot mechanism. It’s specially developed for event driven software approach, where no single use case dictates the flow of the software. This feature indeed is central to the whole of Qt concept, which probably made it different to other frameworks.

Signals and slots primarily allows communications between objects. Just like in any other GUI programming, when we change / execute a widget, we often want another widget to be notified. Beneath the concept, we want the objects to ba able to communicate with one another.

When a user clicks the close pushbutton, we’d probably want the mainWindow to close, by calling a close()

Now, for most frameworks, (wxwidget, fltk, win32) the only way to achieve this is to use callbacks, basically a pointer to functions. Based from my experience, callbacks inherits 2 fundamental flaws, firstly they are not type safe, meaning that we can never be certain whether the processing function
will call the callback with correct arguments.

Secondly, a callback is strongly linked to the calling function since the processing function must know which callback to call. In large software development, things can go complex when there’s too many callbacks to call.


An example syntax of signals and slots in Qt is shown below:
QObject::connect(&button_1,SIGNAL(clicked()), &application(quit()));

Like the name says, button_1 is given a signal flag, in the form of a click. When the signal is executed, the application will recevie instruction to respond to the signal, by quitting.

QT : GUI Toolkit Review

Posted in QT by akamal on January 16, 2007

I’ve had my hands on most C++ GUI toolkit available in the market so far, from OSS oriented products like wxWidgets, FLTK, fox toolkit to the commercial ones such as QT, and not forgetting those savvy yet difficult-to-implement GUI libraries, win32 and mfc.

Well, It doesn’t take a rocket scientist to realize, being resource short on mapower, concludes me to
axe both win32 and mfc, due to the amount of commitment need to be thrown at.

So, of all toolkits available, 2 are on my mind. Qt and wxWidgets. I have been an avid fan of wxWidgets all
these while, having at least 50% of previous UI work built using it, but I have to say of recent, the features and hype with Qt programming struck me.

One central feature of QT is in the dealing of object communication, signal and slot mechanism. It’s so
flexible and limitless, where usually with callback routines, you can only call a function (callback)
from a processing function, but with signals+slots, chains of events can be constructed with a single

Plus, just like wxWidgets, there are so many utility classes provided by Qt, and since I am involved heavily in 3D graphics development for scientific interpretations, qt’s support for 3D through openGL plus its wrapper framework to Coin3D library, certainly gave a plus point.

The best thing in Qt is of course it’s cross-platform assurance, since qt doesn’t take on native widgets
when drawing GUI, instead it is built on its own. So, if I am ever required to deploy an app on linux, no / minimum coding is only required.

I’m currently in process of transfering the already developed seismic viewer program, originally built on top of wxWidgets, and though the portings are taking my time, I do think it’s worthwhile to migrate now, then to continue with the current library. One thing leaving me out of terms with wxWidgets was always of its limited 3D graphics extendability. Even though it supports openGL, the lack of external integrated graphic toolkit, left me fazed, not expecting myself to code everything including plotting libraries and all.

PETRONAS Chronicles says : Hello World

Posted in Software Update by akamal on January 12, 2007

Hi, since this is the first post on software updates, I think a run-down of the software is needed to keep this blog going!

Developing a Time Depth Conversion software requires me to write not only the workflow involved in those methods, but I somehow have to come up with a COMPLETE SOLUTION.

Don’t be fazed by the word, a brave look into English for Idiots gave me this clear definition, haha:

Incorporate a complete workbench, automated workflow, not forgetting data loading / operation / database management, systems core of the software, graphical representations of the data and such. You get the picture.

Honestly speaking, 2006 hasn’t been the most pleasant ride for me, especially on software development. Not ranting or anything, but I took almost a year to familiarize myself with the terms and standardization of this “geophysical” thing.

FYI, the software is currently developed using MATLAB. Yeah, it’s a cumbersome language, easy to use, but limited in expandability. Kinda restraining for the future of a software growth. But IF I’m required to justify on the language used, I’d give only 2 reasons:

  1. There’s only 2 geo-programmers to dvlp a software as complete as one with 20 pro-programmers!
  2. The geophysical world is COMPLEX!

There are plans for me to migrate to C++. I’m fast at coding, a speedo typer, and a fast learner. The only thing I need to do now is to complete the software, albeit limited functionality, and when everything’s checked alright, the methods, workflow, I’d then make that move to C++.

Until then, may the journey begin! As Yankumi (ref: Gokusen) used to say,

Fight ooo! Ohh!!!

And yeah, what’s up with PETRONAS Chronicles? It’s the software name…

Preface : BOT Research Project Intro

Posted in Software Update by akamal on January 12, 2007

I’d like to take this opportunity to write an important introduction of what I currently do, my job that is.

I am one of the team member of this rebel group (kidding) under geoscience department at PETRONAS Research, actively researching on subsurface technology.
Here are the details on the project :

Project Title: Enhancing Velocity Determination Techniques and Quantifying Tolerance in Depth Uncertainties for subSurface Geological evaluation

Project Budgeted: RM15.6 Million MYR

Duration: 3 years

Project Brief: To determine and develop a robust technique for optimum velocity/depth models and to quantify tolerance in final models and images for complex geological areas. Conversion of seismic time images to depth domain as an earth model is crucial to reflect the real reflection location. Velocity is critical to recreate actual subsurface structural images and true reservoir location.

That’s what at least is required. I’m assigned on the software development part, to automate the quantification of tolerance in depth uncertainties. Simply known as just Time to Depth Conversion software.

Hello world!

Posted in Ramblings by akamal on January 12, 2007

Hi, it’s refreshing to see my first post here in this blog, solely created to record my software development undertakings and lessons / knowledge learned in geophysics.

I’m not being egoistic, or just having a shout out of how great life is with my current career. No, infact, it’s a diffcult career to be, in geophysics that is. There’s constant learning everywhere, technologies and theories emerging month by month, voiding the knowledge you acquired just recently, plus you’d have to understand geology, which sometimes amuses me of the amount of things you need to know, just like medicine.

And also, just because I came here with a paper on computer science, I’m expected to know on clusters, parallel processing and top-down low-high level programming.

So, I decided that I need to record what I know, and what more interesting way than to blog?

The other main reason for a blog? I am currently assigned to one of the task only seniours would dare to dream, a programming project leader, requiring me to battle my wits producing a state of the art geophysical software. Ain’t that something?

Yes, it is, and it’s making my life like hell. I’m going to go heads on with big guns like Schlumberger, Landmark, CGG and Veritas. So, here I am, writing as if I have nothing else to do. And yeah, pray for my luck. I’m gonna need it.