## Tuesday, December 16, 2008

### Any Video Converter and CamStudio

(Dec 16, 2008)

I tried to convert AVI video files created by CamStudio to the WMV format. After searching the Internet for good candidates, I decided to use 'Any Video Converter' to do the job. It works well if the number of frames per second in an AVI file is 30.

CamStudio, however, may increase the number of frames per second if your machine is fast. To make the change, go to 'Options->Video Options' and uncheck 'Auto Adjust'.

Any Video Converter is available at http://www.any-video-converter.com
I use a free version (see the bottom of its webpage)

CamStudio is released under GPL. Its website is at http://camstudio.org/

## Saturday, December 13, 2008

### Issue in C++ File Stream

(Dec 13, 2008)

I encountered a strange file writing/reading issue in C++. I don't understand why closing a file and re-open it does not do its job well. After consulting with Prob (my friend), we can fix this issue by 'clear()' after 'close()'.

## Saturday, November 15, 2008

### The Cost of Running a PC

(Nov 15, 2008)

Knowing the cost of running a PC is important since it will help approximate the budget of an organization well. AnandTech gives a good example on cost estimation.

http://anandtech.com/casecoolingpsus/showdoc.aspx?i=3458&p=2

## Sunday, November 09, 2008

### ว่ากันด้วยปัญหาของการประกันราคาสินค้า

(Nov 9, 2008)

การประกันราคาสินค้าเป็นเรื่องที่ซับซ้อน เพราะถ้าหากเราประกันไว้ที่ประเทศไทยโดยรัฐจ่ายเงินชดเชยให้ ก็อาจจะมีสินค้าจากประเทศเพื่อนบ้านทะลักเข้ามาเพื่อจะขายเอากำไรจากส่วนต่าง สูบเงินจากนโยบายประกันราคาของรัฐบาลไป ดังที่จะเห็นได้จากตัวอย่างการประกันราคาปาล์มข้างล่างนี้

จาก ประชาชาติธุรกิจ วันที่ 10 พฤศจิกายน พ.ศ. 2551 ปีที่ 32 ฉบับที่ 4052

"ไชยา"ทุ่ม3,300ล้านประกันปาล์ม ตลาดปั่นป่วน-รง.ชะลอซื้อขายหวังรอราคาใหม่

วง การปาล์มน้ำมันปั่นป่วน หลัง "ไชยา" ประกาศแทรกแซงตลาดปาล์มน้ำมันด้วยการประกันราคาผลปาล์มสดสูงถึง ก.ก.ละ 3.50 บาท น้ำมันปาล์มดิบที่ ก.ก.ละ 22.50 บาท ส่งผลตลาดหยุดชะงักรอ "ส่วนต่าง" ราคาทำกำไรทันที เพราะเหตุไม่มีการตรวจสต๊อกน้ำมันปาล์ม คาดมีน้ำมันปาล์มล้นเกินอยู่ไม่ต่ำกว่า 300,000 ตัน ซื้อเสร็จแล้วไม่รู้จะระบายไปที่ไหน ขณะที่ราคาน้ำมันปาล์มมาเลเซียตก ก.ก.ละ 16-17 บาท รอการทะลักเข้าประเทศตามแนวชายแดน

(อ่านเพิ่มเติมได้ที่ http://www.matichon.co.th/prachachat/prachachat_detail.php?s_tag=02inv06101151&day=2008-11-10§ionid=0203)

(Nov 9, 2008)

## Friday, October 31, 2008

### How to ask professors to serve on Ph.D. committee

I have to take the comprehensive exam in the near future and need to form a Ph.D. committee. With the help from Rahul, I came up with a succinct email for this.

===========================================================

The format is

I am a Ph.D. student working with Dr. [my advisor]. My work focuses on [very compact description of your thesis]. I was going through your research interests and found out about your expertise in [related expertise of professor to ask]. I would very much appreciate if you would agree to serve on my Ph.D. committee and guide me in my research. Would it be possible for you to serve on my PhD committee?

I look forward to your positive response.

Sincerely,
[my name]

===========================================================

## Monday, October 27, 2008

(Oct 27, 2008)

I closed WinEdt's error dialog at one time and could not find a way to open it again. After spending quite some times, I finally found the way. In WinEdt 5.5, go to Options->Settings. Then, we will see the 'Errors' tab. There are three things we need to check
1. C++ style errors
2. Extended TeX Messages
3. TeX Source Tracking.
Finally, there is another option we have to UNcheck, 'Quick Mode'. When the 'Quick Mode' option is unchecked, error search dialog will work normally.

# Eclipse CDT + MinGW + FreeGLUT

[Note: if this document seems out-of-date to you, you might want to see the updated and related documents in the bottom.]

(May 24, 2008)
Today, I tried to use Eclipse CDT + MinGW + FreeGLUT to study OpenGL to build my skill for current research and future career development.  This note is created to show how I could get everything done and perhaps, it can be useful for other people.

I started with installing MinGW version 3.4.5 on Windows XP service pack 2.  During installation, we need to install only g++ to get C/C++ compiler.  We should not include the MinGW make tool if we want to make things easier when we work with source base derived from the Unix world.  In such a case, we should use MSYS (Minimal SYStem), instead [1].  However, if you want to use Eclipse CDT's make system, you have no need to worry about this.  It is interesting to note that MinGW already contains GL header files right from its package.  This makes thing very simple for those who want to quickly set things up.

Next, I installed Eclipse CDT.  It is worth noting that we can have multiple Eclipse copies in a single machine.  We can even have each copy of Eclipse associated with one task (project or solution).  If we do not have any specific reason to share this Eclipse CDT copy with other tasks, we can just download a new copy to get only Eclipse CDT.  This can reduce complexity and confusion in the tool as well.  The figure below shows Eclipse features I used.  You can see that it is very lean because it contains only relevant features for C/C++ development.

Figure 1: Eclipse CDT features

Now, we are close to the last step: getting FreeGLUT up and running with Eclipse CDT and MinGW.  I suggest you obtain a compiled DLL from 'Temp Variable's Blog' [2].  The compiled package also comes with necessary header files, so we don't need to go else where, including the official FreeGLUT web site.  If you need to build Free Glut from scratch or need another version, please see the 'update' note at the bottom of this page.  Next, we are ready to create an Eclipse project with a very simple OpenGL program.  This is just for testing the software configuration.  To avoid confusion, I break the process down to steps:

1. Create an Eclipse project with MinGW compiler

Figure 2: When we choose to create a C or C++ project, we need to choose a compiler / toolchain we want to use.

2. Once the project is created, we probably see the default list of included files related to MinGW in the Eclipse project view.  Check if its main include folder has GL header files.  If not, we probably did something wrong.

Figure 3: Default MinGW include paths, including GL header files

3. We have to place FreeGLUT header files in an appropriate place.  We may choose to put them in the GL folder shown above, in an Eclipse project folder, or in a shared folder (so that you can have only one FreeGLUT header copy in your system).  If we choose the last choice (I chose this one too), we have to add an include directory containing FreeGLUT header files.  To do this, right click on the project item in Eclipse and select Properties.  Then, add an include directory as shown in Figure 4.

Figure 4: 'Adding include directories' can be done in C/C++ Build -> Settings -> GCC C++ Compiler -> Directories

4. Now, we need to refer to the OpenGL layer in Windows, opengl32.  This OpenGL layer will connect to a video driver in a machine.  We don't need to worry if we change a video card.  Things will be the same as long as the new video card driver supports OpenGL commands we employ.  This OpenGL layer is, in fact, a library used by a linker.  Hence, we need to set up the GCC C++ linker.  It can be done from almost the same spot shown in Figure 4.  Just scroll down from the 'GCC C++ Compiler' option to 'MinGW C++ Linker'.  Then, add two libraries: opengl32 and freeglut.  Of course, if your OpenGL project is more complicated, you probably need to add more libraries. We don't need to specify any library search path for opengl32 since they are in a system folder.  For freeglut, however, we need to specify library search path for it if it is not in a system folder.  Note that Eclipse CDT will not search for any library in its project folder.  We need to explicitly specify it for any non-system library search path.

By the way, it is interesting to note that, even if we are working on Windows 64-bit version, we still use opengl32, NOT opengl64.  This may sound odd, but it makes things easier since programs from a 32-bit world can be run seamlessly on Windows 64-bit version without any recompilation.  And for programmers, they don't need to change OpenGL configuration much; Windows will handle it by connecting to an appropriate video driver.

5. Create the main file with a very simple usage of OpenGL.  Once again, I suggest you use the same example as in 'Temp Variable's Blog'.  The file seems to be in a book by E. Angel, Interactive Computer Graphics, A Top-Down Approach with OpenGL, Third Edition, Addison-Wesley Longman, 2003 [3].  The direct link to the file is http://www.box.net/shared/u2o7k31ogc

6. Build a project (press Ctrl + B or click the hammer button).

7. Try running your application.  You may find that there is nothing happens.  Your program just terminated.  When you try to debug it, you will see only an error message that "there is an error occurred", but no other clue.  This problem arises from a missing DLL.  It is important to know that the executable file we get will not try to search for libraries specified in the Eclipse settings.  Thus, we need to put the DLL in the executable folder  (or in a system one if you prefer).  Make sure that you have DLL copies in both Debug and Release folders.  Anyway, if you encounter 'silent errors' like this in Eclipse CDT, I recommend you run an executable file from the Windows command prompt; Windows may give you more information than Eclipse CDT.

Note: if you are new to Eclipse CDT, you may wonder how to run a program in a Debug or Release mode as you wish.  From the beginning, it will run solely in a Debug mode, even when you set the active configuration to Release.  To change the default running mode, you have to do it in the 'Run Dialog'.  It can be found from the menu bar on the top of Eclipse as shown in Figure 6.  When you go there, you may find two configurations you can choose, but still have no idea which one is Release (I had this problem before).  You can differentiate it by its location.  From the main tab, you can see a project name and 'C/C++ Application'.  The latter will tell you about an application location as shown in Figure 7.  Notice the release folder name before an executable file name.

Figure 6: 'Run Dialog' can be accessed from the menu bar.  Note: click on the arrow beside the green Run button, not the Run button itself.
Figure 7: Main tap in the 'Run Dialog' can show us the location of an executable.  We can use the location to figure out what mode it is in

### References:

1. Eclipse CDT: Before You Begin, http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm
2. Temp Variable's Blog: Installing freeglut on Visual Studio 2008, http://tempvariable.blogspot.com/2008/02/installing-freeglut-on-visual-studio.html
3. E. Angel, Interactive Computer Graphics, A Top-Down Approach with OpenGL, Third Edition, Addison-Wesley Longman, 2003. (a portion of source code in the book is obtained from http://www.box.net/shared/u2o7k31ogc)

Pinyo Taeprasartsit
(May 2008, May 2010, Oct 2011)

=======

Update: [May 2010] I now have a few other documents that closely related to this one.  They discuss how to compile FreeGlut for both 32 and 64-bit applications and using more recent versions of MinGW, including the 64-bit version.  Check them out if you are interested:
1. Eclipse CDT with MinGW x64.  If you want to use MinGW 64-bit with Eclipse, this is a document for you.
2. Build FreeGlut 2.6.0 with MinGW in both 32 and 64 bit.  Pre-compiled binary packages are also available.  This package is newer than the one discussed in this document and come with both static and dynamic library.  Very handy if you need one.
3. Eclipse CDT + MinGW + FreeGlut (2).  This adds information about 64-bit version of MinGW and FreeGlut.  It shows you how to use both static and dynamic library versions of FreeGlut.  Also, if you need to easily download MinGW 4.5.0 32-bit without bothering with wget and bash as mentioned in MinGW web site.  The package provided in this document will help you with that.  This should be helpful until MinGW comes with a more polished installer.

## Sunday, May 18, 2008

### Enable mouse scrolling in Ubuntu 8.04 on VMWare 6.0.3

(May 18, 2008)

Last night, I installed Ubuntu 8.04 on VMWare 6.0.3 and mouse scroll did not work, even after VMWare tools were installed. My friend, P' Moo+, told me to update Ubuntu, install VMWare and do some X config. I am, however, too lazy to revert my VM to previous snapshot, so I searched Internet for a solution.

I found a topic "How To Enable Mouse Wheel Scrolling in Ubuntu 8.04 on VMware" on http://www.windowsvistaplace.com/how-to-enable-mouse-wheel-scrolling-in-ubuntu-804-on-vmware/othersoftware
This solution does help (my host machine is Windows XP, the author's is Mac OS X). In short, I have to replace

Section "InputDevice"
Identifier "Configured Mouse"
Driver "vmmouse"
[.. blah blah blah ..]
EndSection

with

Section "InputDevice"
Identifier "Configured Mouse"
Driver "vmmouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ImPS/2"
Option "Buttons" "5"
Option "ZAxisMapping" "4 5"
EndSection

Many thanks to 'computerboom' (the author of the article I found).

## Friday, April 04, 2008

### OOXML as an ISO standard. What a joke.

(April 4, 2008)

Recently, OOXML was approved as an ISO standard. At first, I thought it's okay, even though it might increase cost for software development to support two standards at the same time. However, once I found this article: http://www.robweir.com/blog/2008/03/disharmony-of-ooxml.html, I think it is really embarrassing to have OOXML as an ISO standard for document. This implies that even Microsoft itself cannot enforce reasonable standards among its own products and it did impose difficulty in software development to itself and the outside world.

I really wonder what the committee was thinking during ballot casting.

## Saturday, March 22, 2008

### Math Object Wrap Space in OpenOffice.org's Writer

(Mar 22, 2008)

By default, math object wrap space in OO.o's Writer is pretty annoying. If a math object is at the end of a sentence and follows by a foot stop, the foot stop will be put too far from the math object. Earlier, I needed to put it inside the problematic math object. Although the printing output was fine, it changed semantics of the math object.

OO.o, however, has a solution for this. In case we want to change a specific wrap space for a specific math object, we can right click on the math object, go to 'Option', then 'Wrap', and set 'Spacing' to zero as shown in figures below.

In case we want to set zero space as a default setting, we can use 'Styles and Formatting'. Formula setting can be accessed from 'Frame Styles' as shown below.

Reference:
http://documentation.openoffice.org/faqs/formula/016.html

## Wednesday, March 19, 2008

### Importance of WINVER definition in Visual Studio 2008

(Mar 19, 2008)

Recently, MIPL starts to port stuff to VS 2008. It turns out that code compiled on Vista worked 100% correct only on Vista, but on Windows XP, it showed some glitches.

This is because the default WINVER in VS 2008 is 0x0600 (Vista). Thus, when we build our code, it will perform some Vista specific links, and an executable file may not work correctly on XP.

To solve this problem, just go to StdAfx.h and put the definition of WINVER to XP:

#define WINVER 0x0501

With this definition, built executable files should work on both XP and Vista.

## Tuesday, March 18, 2008

### เรื่องงงๆ ใน OpenOffice

(Mar 18, 2008)

พยายามใช้ Style and Formatting ใน OpenOffice แล้วปรากฎว่าเวลาเปลี่ยนไสตล์แล้วรูปแบบตัวอักษรมันไม่ได้เปลี่ยนไปด้วยเลย ทั้งที่แต่ก่อนมันก็เปลี่ยนให้เราเอง พยายามยังไงมันก็ยังไม่ยอมเปลี่ยนให้แบบอัตโนมัติเหมือนเคย

แต่ยังไงเราก็พบว่าถ้าเราไฮไลต์มันแล้วคลิกขวา จากนั้นก็เลือก Default formatting มันก็จะจัดรูปแบบให้เราตามที่เรากำหนดไว้ ถ้าไม่อยากใช้เมาส์ จะกด Ctrl+Shft+Space ก็ได้

### Alias can be a tricky problem in C++'s STL vector

(Mar 14, 2008)

Alias can be a tricky problem in C++'s STL vector.

Sometimes, I don't want to write an awkward code such as willFail.m_vecProblematic[0] all the time, so I create an alias (prob1 in this example). This alias will work fine until we push or pop elements in a vector to a certain number and the vector is needed to reallocate.

Problematic* prob1 = &( willFail.m_vecProblematic[0] );
prob1->m_vec2.push_back( 55 );
prob1->m_vec1.push_back( 11111 );

// Push an element to a vector may cause a vector to reallocate.
willFail.m_vecProblematic.push_back( Problematic );

// prob1 may not point to a correct storage, but this value assignment

// may not cause a program to crash instantly.
prob1->i = 24;

// prob1 may not point to a correct storage, and such object

// operation usually cause a program to crash
prob1->m_vec2.push_back( 66 );

Note: simple value assignment to an invalid place may not cause a program to crash so easily, but calling a method from an invalid object pointer will cause a program to crash very easily since the method table of an object is already messed up. If we want to find where a program goes wrong, we may try to call a method of a suspecious object pointer.

## Tuesday, February 26, 2008

### Apache + SSL + SVN

(Feb 26, 2008)

(previous posts:
1. Apache+OpenSSL
2. SVN + Apache
)

From my two previous posts above, I discussed about SVN + Apache and Apache + OpenSSL separately. Now, it's time to put things together.

There are two possibilities for doing this. First, we may allow users to use SVN in both secure and insecure manners. Second, we may force users to only use SVN in a secure manner.

If we want to allow both, we put SVN configuration outside secured virtual host. If we want to enforce secured SVN, just move the SVN configuration inside secured virtual host configuration.

Note: the SVN configuration I mentioned is
<Location /super_angel> DAV svn SVNPath E:/svn_repos/super_angel AuthType Basic AuthName "Subversion Super-Angel repository" AuthUserFile c:/etc/svn-auth-file Require valid-user AuthzSVNAccessFile c:/etc/svn-acl</location>

### OpenSSL กับ Apache

(Feb 26, 2008)

สำหรับการติดตั้ง Apache 2.0 บน Windows ที่เราต้องการทำ self-signed certificate เราควรจะเริ่มจากการดาวน์โหลดแพคเกจ OpenSSL สำหรับนักพัฒนามาจาก http://www.slproweb.com/products/Win32OpenSSL.html

(ที่ต้องใช้แบบนักพัฒนาก็เพราะว่าเราต้องการที่จะ sign certificate เอง ถ้าดาวน์โหลดแบบ light เราจะ sign ไม่ได้
Note: if we do not use a developer package from http://www.slproweb.com/products/Win32OpenSSL.html, we might encounter a problem when we want to sign a certificate since it will look for a file bss_file.c in ./crypto/bio ... which is not available in a light package.
)

หลังจากนั้นเราก็สร้าง key กับ sign certificate ด้วยตัวเองด้วยคำสั่ง
openssl genrsa -out server.key 1024
openssl req -new -sha1 -x509 -key ca-key.pem -out server.crt -days 365

(เลขที่อยู่ด้านหลังสุดบอกจำนวนวันก่อนที่ certificate จะหมดอายุ)

เมื่อเราคัดลอกไฟล์ server.key กัล server.crt ไปไว้ในที่ๆ เหมาะสมแล้ว ก็ถึงคราวที่เราจะต้องไปแก้ไฟล์ httpd.conf ของ Apache

ขั้นแรกก็ต้อง uncomment บรรทัด LoadModule ssl_module modules/mod_ssl.so
จากนั้นไปที่ด้านท้ายของไฟล์ เราก็จะเห็น

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#

SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

ให้เรา uncomment บรรทัด
Include conf/extra/httpd-ssl.conf ออกตามระเบียบ แล้วก็เข้าไปแก้ไฟล์ httpd-ssl.conf ซึ่งจุดสำคัญมีดังนี้
1. บรรทัด SSLMutex ควรแก้จากตำแหน่งไฟล์เป็น default
2. ตำแหน่ง certificate file (ดูบรรทัดที่มี SSLCertificateFile)
3. ตำแหน่ง key file (ดูบรรทัดที่มี SSLCertificateKeyFile)
4. DocumentRoot
5. ServerName

## Tuesday, February 19, 2008

### Set SVN server with Apache on Windows

(Feb 19, 2008)

We can download subversion zip package and just expand it some where. Then, copy mod_dav_svn.so to Apache's module directory. To prevent confusion, I copied it to modules/svn directory. Next, add this line to httpd.conf

Finally, uncomment this line in the config file to allow dav. Note that this line must come before dav_svn_module line

But wait, this just makes Apache load itself with SVN capability. We need to config SVN server and create repository too. Also note that we should not assign the document root to the root of repository to avoid name conflicts. If name conflicts occur, we will normally get Error 301.

The best practice of configure SVN server is at http://svn.spears.at/. I claimed it the best practice since it elegantly separate SVN configuration from other of Apache by using an Include command :
Include c:/etc/subversion.conf

In subversion.conf, we may enter some thing like this:
<Location /super_angel>  DAV svn  SVNPath E:/svn_repos/super_angel  AuthType Basic  AuthName "Subversion Super-Angel repository"  AuthUserFile c:/etc/svn-auth-file  Require valid-user  AuthzSVNAccessFile c:/etc/svn-acl</Location>

This will create a virtual address at localhost:8080/super_angel. This virtual address will be mapped to E:/svn_repos/super_angel, which is an actual repository for a project. Thus, we need to create a repository there using a command:
svnadmin create --fs-type bdb E:/svn_repos/super_angelNext, we need to create an authentication password file.  If the file is to be a brand new one, the command will have a c flag:htpasswd -cm C:\etc\svn-auth-file johnFor additional users, a command will behtpasswd -m C:\etc\svn-auth-file JaneFinally, we need to assign usage rights and groups for users in svn-acl file.  The content of the file will look like this.## specify groups here#[groups]team1 = moo, pinyotae## team1 group has a read/write access to project1 repository# all subdirectories# all others have read access only#[super_angel:/]@team1 = rw* = rThis will ready our Apache.  We just need to restart it and access our repository at the virtual address we specify earlier.Note: svn-acl is actually flexible.  Please refer to http://svn.spears.at/ for more details.

## Monday, February 18, 2008

### Special Olympics Oath

(Feb 18, 2008)

This special Olympics oath sounds very meaningful for me. I'm impressed.

"Let me win. But if I cannot win, let me be brave in the attempt."

## Wednesday, February 13, 2008

### Good and Free Utility Software

(Feb 12, 2008)

(references
Free Commander: http://www.freecommander.com/
FileAnt: http://www.fileant.com/
Capivara: http://capivara.sourceforge.net/

There are some software I expect to use often in the near future. First, I need a better file manager able to view Thai file names. Second, I need a software to synchronize my local folder with an FTP server.

For the file manger, there are two good candidates that catch my attention. The first one is 'FileAnt' and the second is 'Free Commander'. I have used FileAnt for a while and I like it. It has a unique feature--double click to go up one level. In details, if we double click on an empty space of a folder, we will go out of the current folder. This is very handy and make navigation fast. FileAnt, however, cannot view Thai file names.

So, I looked for another candidate and end up with Free Commander (http://www.freecommander.com/). Its user interface looks good and can view Thai file names. It has a shortcut to a favorite folder. If we set up favorite folders, ctrl-shift+1 (or 2, 3, 4, ..) will take us to a favorite folder. In fact, the shortcut can be set to a pair of folders. Namely, if we enter a shortcut, it will change an active panel to a folder and an inactive one to another folder we set. This should be very convenient when we need to transfer files between two specific folders often to back up data, for example.

For file synchronization, I chose Capivara (http://capivara.sourceforge.net/) since it has all features I need. These features are SFTP support and file change detection (the second is a must for file synchronizer). Its user interface is very intuitive too. With Capivara, we can have files at three places: home, office, and central server. We can choose to work at an office and just synchronize to the server when we are done. Then, we can retrieve updated files at home from the server to continue our work and synchronize again when we finish. This scenario will make every thing handy and safe (unless we force overwriting a newer files carelessly).

## Monday, February 04, 2008

### Tex2Im Tool

(Feb 4, 2008)

Today, Roger's Online Equation (http://rogercortesi.com/eqn/) almost put me in trouble when my friend used it and could not make it work on his equation with norm:

d_{S} = 2d_{D} + \left|\left|\left[\Delta x,\Delta y,\Delta z\right]^{T}\right|\right|

I don't know why it did not work in Roger's Online Equation Server. Perhaps, it does not have some important packages. Thus, I tried using tex2im locally.

Since I already had LaTex tool on my Cygwin already, I could just copy tex2im directly to Cygwin's bin directory. Next, create a test.tex file with the equation above. Then, generate the output file with resolution 600 x 600, white text, black background, with transparency, without antialias. The above task can be done with the following command:

tex2im -r "600x600" -t "white" -b "black" -z test.tex

Note if we use the -z option, the anti-alias option will be disabled by default, but if we don't use the -z option, the anti-alias option will be enabled by default.

## Saturday, February 02, 2008

### AMD Stream Processing

(Feb 2, 2008)

AMD recently announced its first stream processing board. Although it tried to promote and talked only about its flagship, AMD Firestream 9170 with 320 stream cores, from documents related to CAL requirements, we need only ATI Radeon HD2400 or better. This is good, but I'm sure that not many documents are around, and there must be some unseen issues waiting for me if I jump into stream processing stuff.

I think I should wait a year or two so that the platform will be matured.

Reference: http://ati.amd.com/technology/streamcomputing/

### VirtaulBox

(Feb 2, 2008)

พอดีผ่านไปเจอ น่าสนใจดีเหมือนกัน น่าจะมาลองใช้ดูในอนาคต คงจะช่วยทำให้เรามี clean system ไว้ทดสอบการติดตั้งโปรแกรมเหมือนกัน วิธีติดตั้งก็ดูได้จากหมอนี่ http://linux.sothorn.org/node/258

พวกระบบแบบนี้น่าสนใจตรงที่ว่า ถ้าหากเรามี clean system มันก็จะทำให้เราช่วยทำ "Core Load" ได้ คือว่าถ้าเก็บ snapshot ของระบบเปล่าๆ พร้อมซอฟต์แวร์ที่จำเป็นสำหรับองค์กรเราแล้ว เราก็เติมซอฟต์แวร์เพิ่ม แล้วทำ snapshot อีก ก็จะได้สามารถขยาย Core system ที่เราคิดจะติดตั้งได้ง่ายๆ

อ่อ Virtual Box อันนี้รันได้ทั้งบน Linux, Windows และ Mac นะครับ เรียกได้เลยว่าครบเครื่อง พอๆ กับ VM Ware สนใจดูได้ที่ http://www.virtualbox.org/

Update (Feb 13, 2008): ไปเจอลิงค์รีวิวเปรียบเทียบโปรแกรม virtualization นี้มาจากเว็บคุณโสธร http://www.techthrob.com/tech/linux_virtualization.php พบว่า VirtualBox ดีจริง ทำงานเร็วปรี๊ดเทียบเท่า VMWare และมีปัญหาไม่มากนักด้วย

## Friday, February 01, 2008

### Suppressing First-chance Exception in Visual C++ 2005

(Feb 1, 2008)

I encountered a lot first-chance exceptions in my program when I debugged my program in Visual C++ 2005. Exception messages in the output window can be annoying if they cloud other important messages. After searching the Internet for a while, I found a simple solution about this on http://www.helixoft.com/blog/archives/24 . I can tell a window output not to show 'exception messages' by right clicking within the output window and uncheck 'Exeption Messages'.

## Thursday, January 31, 2008

### Plotting big and small data in the same graph

(Jan 31, 2008)

Today, I helped Justin to help his friend (Jen Han?) to plot an Excel diagram with big and small data. If we use default settings, small data will just lie on the x-axis. To solve this, we need to add a secondary axis. We can do it as follows.

From a chart with default settings, try selecting a small data series. If we cannot select it, just select any thing in the chart and keep pressing arrow keys up or down to circulate highlight until we reach the small data series. Then, right click and choose 'Format Data Series...'. Next, look for an axis option and plot the small series on a secondary axis.

We will get a result like what I show below

Figure 1. An Excel plot with two y-axes (the right one is referred to as a secondary axis in Excel)

Credit: thank you ProjectWoman whom I got the information from

## Wednesday, January 30, 2008

### We should try to reduce initialization task ourselves

(Jan 30, 2008)

I tried implement an efficient way to build an isotropic image. For a long time, I thought a compiler optimization will handle initialization overhead automatically, but for Visual C++ 2005, it does not.

Consider the following code:

for( int z = 0; z < y =" 0;" x =" 0;"> arVoxels[8];
NVImage_t arValues[8]; // keep H.U. values of relevant voxels

In fact, we can move all declarations outside the most outer loop (z) as follows:

float fX, fY, fZ; // for true position
float fa, fb, fc; // relative voxel distance as in 2.1.
NVVoxel arVoxels[8];
NVImage_t arValues[8]; // keep H.U. values of relevant voxels

for( int z = 0; z < y =" 0;" x =" 0;" z =" 0;" y =" 0;" x =" 0;"> arVoxels[8];
NVImage_t arValues[8]; // keep H.U. values of relevant voxels

We can see that for each z, there will be two threads. Hence, if we move declarations to the most outer loop, two threads will use the same variable storage, and that is not correct. What we should do is moving these declarations just one step outer as shown below:

#pragma omp parallel
for( int z = 0; z < y =" 0;"> arVoxels[8];
NVImage_t arValues[8]; // keep H.U. values of relevant voxels

for( int x = 0; x < nNewSizeX-2; x++ ) {

From my experiment, this makes things much faster since array initialization is expensive. Note: we can even reduce initialization further if we divide the loop ourselves and create 'multiple sections'. For each section, declare its own variables. I, however, will not do this since the code will be clutter, and we have to know the number of sections before hand, which is normally equal to the number of physical cores in a system. Thus, changing CPU may cause some performance issue. Using OpenMP in this way, nonetheless, is very flexible regarding to system configurations.

### Associativity in Modern CPU Cache

(Jan 30, 2008)

Recently, I have used OpenMP to perform multi-processing a lot. However, OpenMP may cause 'false share' often if we are not careful. False share is a situation that two threads write in a different memory locations, but unfortunately, the two memory locations are assigned the same cache slot. If this situation happens, performance will be degraded significantly.

Cache associativity will play an important role on this issue, especially if we have 8 cores or more.
So, let's look at cache associativity for some modern CPUs.

AMD Athlon 64 X2 has 2-way associative L1 cache and 16-way for L2 cache (ref).
AMD Phenom has 2-way associative L1 cache, 16-way for L2 and 32-way for L3 cache s (ref-page 4)

Intel Core 2 E4000 and E6000 series: 8-way associative L1 cache (ref-page 9) and from what I got from CPU-Z, it has 16-way associative L2 cache.

Intel Core 2 E8000 series: 8-way associative L1 cache and 24-way associative L2 cache (from CPU-Z).

So, I think CPUs from both manufactures should do well in scaling, but from what I got from Tom's hardware, Phenom scales very well and better than Core 2 Quad. I, however, cannot confirm this until both platform are more matured and more serious evaluation are available.

## Tuesday, January 29, 2008

### New line positioning problem in Visual Studio 2005

(Jan 29, 2008)

I encountered a curious problem about new line positioning in Visual Studio 2005, specifically Visual C++, from time to time. The issue is when I press enter to insert a new line. The cursor will not move down to a new line, but stick to the same line.

Today, I noticed that code folding may cause some issue about this. If the last function in a file is folded, this problem may occur.

(see Processor3.cpp)

## Friday, January 25, 2008

### Display ampersand in MFC controls

(Jan 25, 2008)

I tried to display an ampersand (&) in MFC controls (Visual C++ 2005), specifically tab controls. The problem is a literal "A & B" was displayed "A B" in MFC controls.

To fix this, we have to replace & with &&. Namely, use "A && B", instead of "A & B".

source: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1597754&SiteID=1

## Wednesday, January 23, 2008

### How to fix "Insufficient system resources to complete the API"

(Jan 23, 2008)

There is a blog complaining about this. It shows some reasons that this issue is a major problem for a laptop. I agree with him, although mine is a desktop.

As of Jan 23, 2008, Microsoft does not have a patch for this issue, but hotfix is available from here

### Mysterious MFC Compile Error

(Jan 23, 2008)

I got a mysterious compile error today. It said one of a resource ID, IDD_SUP_VENA_CAVA is not defined / declared in this line:

// Dialog Data
enum { IDD = IDD_SUP_VENA_CAVA };

Dr. Yu suggested me include resource.h. I did and it worked fine, but I really don't understand why I don't need such includes in other places. That's why I think it's mysterious.

## Saturday, January 19, 2008

### MFC: Practice using tab control

(Jan 19, 2008)

After try using MFC's tab control (CTabCtrl) from http://www.forteach.net/Programming/c/26492.html
and
http://www.ucancode.net/faq/CTabCtrl-VC-SetWindowPos.htm

The first one seems to give more concise and be easier to follow.

There are also some important points I'd like to note:
1. Do not forget to change 'style' of a tab sheet from 'popup' to 'child'. If you do not make such change, the position of a tab sheet may be at the top left corner of the screen.

2. Tab sheet should be set to have no border (Border = none).

3. CTabCtrl must be derived. It seems there is no simpler way for this, although initialization code for our derived class may be very common as used in http://www.forteach.net/Programming/c/26492.html

4. Tab control must have this message map,

ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange).

Otherwise, changing tab is impossible.

5. As usual before a dialog which has a derived tab control in it can be shown, we need to 'Create' it. Declaration does not mean 'Create' at all.

m_myDialog.Create( IDD_MAIN_DLG );
m_myDialog.ShowWindow( SW_SHOW );

6. Properties for a common tab sheet are shown in the following images:

## Monday, January 14, 2008

### Blood system in the mediastinum

(Jan 14, 2008)

I found an image of major blood vessels in mediastinum. It tells me about the names of blood vessels I want to know, especially, azygos vein, right and left innominate veins.

## Sunday, January 13, 2008

### Folder Listing in Apache

Default configuration value for folder listing in recent Apache servers seems to change. Now, by default, we cannot list folder contents without an index file. To allow folder listing without an index file, we need to set an option properly. If we start from a fresh installation of Apache 2.2, the default option is

Options FollowSymLinks

We can change it to

Options Indexes FollowSymLinks
And, directory listing will work just fine. Note: 'Deny from all' directive may still prevent us from viewing a page. We can delete or comment out the directive to view contents.To make folder listing looks better, we should also employ fancy style by uncomment the second following line:# Fancy directory listings#Include conf/extra/httpd-autoindex.conf

## Saturday, January 12, 2008

### Web folder ของ Thai Club

If we want to access a web folder of an organization in Penn State, we need to know its path on a server. To find what it is, we can go to www.work.psu.edu, log in and choose 'Add More Space (Quota Manager)'. Then, we will see a folder path in a drop-down menu. We can use the path to access our web folder.

And of Thai Club, the path is /:/services/www/clubs/wwwroot/up/thai

## Tuesday, January 01, 2008

### เพลงสู้ต่อไป

เคยได้ยินเพลงนี้มาประมาณสิบปีแ้ล้วตั้งแต่อยู่ที่ไทย พยายามค้นอยู่นานว่ามันคือเพลงอะไร แต่ก็ไม่เจอเพราะเคยถามเพื่อนแล้วเพื่อนเข้าใจผิดว่าเป็นเพลงเปลวไฟในไอหมอก แต่ท่จริงแล้วมันชื่อว่าเพลง 'สู้ต่อไป' ของศิลปินที่เรียกตัวเองว่าชาร์ค http://www.oknation.net/blog/print.php?id=90571

(keywords ที่ใช้ค้นแล้วเจอคือ มองไม่เห็นทาง โลกสลัว
แต่ก่อนเราค้นด้วยคำว่า 'แม้จะมองไม่เห็นทาง' และ/หรือ 'โลกสลัวไร้แสงสว่าง' แต่ก็ค้นไม่เจอ

วันปีใหม่นี้ลองค้นอีกทีด้วยตัดคำโน้นคำนี้ออก สุดท้ายก็ค้นเจอ งงเหมือนกันว่ากูเกิลทำดัชนีการค้นหายังไงกันแน่)

ขอคัดลอกเนื้อร้องไว้สักหน่อย กลับไทยไปแล้วคิดว่าจะหามาซื้อเก็บไว้เหมือนกัน นาน ๆ ถึงจะมีเพลงที่เราคิดถึงอยู่บ่อย ๆ

สู้ต่อไป
ร้อง : ชาร์ค (Shark)
เนื้อเร้อง : ชาร์ค
ทำนอง : ชาร์ค & กันต์
โปรดิวเซอร์ : พลรักษ์ โอชกะ
สังกัด : ไนน์ตี้ไนน์ โปรโมชั่น

********************

เดินก้าวไปบนทาง ที่แสนลำบาก
ใจและกายเหนื่อยจน หมดแรงอ่อนล้า
จำต้องทนฝืนทุกข์ตรม ไม่หมดลมหายใจต้องสู้
สู้ต่อไป..สู้ต่อ..ฮ้าฮา

เดินต่อไปเถอะเดิน แม้ไม่เห็นทาง
อะไรกีดขวางบอกใจ ต้องข้ามให้ไหว
แม้อาจล้มลุกคลุกคลาน ไม่ว่านานแสนนานจะสู้
ก็รู้ทั้งรู้ไม่สู้ ไม่เหลืออะไร

แม้จะมองไม่เห็นทาง โลกสลัวไร้แสงสว่าง
ไร้คนช่วยนำทาง..ฮ้าฮา
แต่ใจบอกตัวไม่ต้องกลัว เกิดเป็นคนชีวิตต้องสู้
สู้จนยิบตา ดูให้ดี

จะมองแต่โลกในแง่ดี ชีวิตนี้แสนมีคุณค่า
ที่ผ่านมายิ่งทำให้เรา แกร่งแข็ง
สักวันชะตาต้องหมุนเวียน เปลี่ยนแปรผันทุกข์ตรมคลี่คลาย
และฝันที่เราฝันใฝ่ จะกลายเป็นจริง