星期三, 8月 03, 2005

A Starry Night

Oh, no. It's not what I'm doing. I'm now in a ESL program, so that I had some assignments. And this is one of them. Our teacher brought a pile of magazines full of pictures and asked us to choose one and write an imaginary story. I chose one which is just a night sky. But the sky is full of stars; also it includes the Milky Way. They should have taken it through telescope.
Though the story is a imaginary one, it's really what I was thinking. The teacher said that it's "Very lyrical, ??? (I can't recognize this word) this a lot." But some people, including me, don't like the ending which was written when I was really tiry. I apologize for it.

- - -

Lying on the ground with my body totally surrounded by sand, my face is up with eyes open and looking at the sky, the clear sky without a moon, without other lights, with only the star, the cold air, and me.

There is no light nearby. More precisely, there is no light in my sight scope; from here to the skyline on every direction, there is only sand stretching to horizon. And I am lying at the center of the world with only me, sand, stars and wind in the cold air.

It is not so long after sunset so that the sand are still worm enough that I can use it to resist the cold wind. Up in the sky, stars are shining as they do every night. The Milky Way goes across the sky from one end of the desert to another end just like a bridge connecting the two sides. But I am under the bridge by only myself lying helplessly.

% % %

It was a normal afternoon. Just as every day, a few customers did not like what they got, some did not know the usage, several complained about the quality and we had some misunderstanding with a customer on their request.

I got off the car in front of my home unable to wait for dinner. I shut the door of the driver seat and stepped on the sidewalk – at least I think that I should step on the sidewalk. But my foot sank two inches into the soft sand. The trees on the sidewalk disappeared. The car was no longer behind me. The garden around the house had no more plants, neither fences nor grass. And I was heading my long long shadow produced by the setting sun lay on the place which was my home, my original destination.

The air is dry and the sun is boiling. I can hear no sound of car or bird but only the sound of sand when I step on it. Also, the wind blows up sands which form a dune and makes a loud sound. Those are all I can hear and see – wind, sands and sun. I am now in a desert thousands miles away from home after just a single step out of my car.

Fortunately, I have my bag with me which contains half a bottle of water and some snack I just bought for the night. But I can see nothing but sand, no people, no animal, no oasis, no clue about what should I do or where should I go to get back. However, it won't get better if I just stand here waiting, so I decide to walk. Though I don't know the correct direction, there might even be no correct way I can go to survive, I just head some way which looks good to me.

May be there are some thing behind the sand dune and I will see hope when I get on top of it. After telling myself this sentence nine or ten times, I stopped hoping for that but still keep walking. I can now see my foot prints line up extending to sky line behind me. Nothing else can I do but I'm now full of energy and willing to do something.

% % %

I stopped and lay on the sand after the sun totally sank on the right of me. The sunset was so beautiful that I found that I started to love this place. After the last ray disappeared and the sky turned from red to black, I stopped and closed my eyes to memorize the beauty of the nightfall. Then, when I opened my eyes again, I found that the sky was not dark any more. The shining stars made me drunk. I sat down and finally lay down to look at all the stars.

I can now see the Milky Way hanging on the sky of summer night. The center of the galaxy, which is the most beautiful part of the Milky Way, located between Scorpio and Sagittarius. I can see the red star, the heart of the Scorpio, beating. I can even hear the beating of the Scorpio echoing with mine, a Scorpion on the ground. The only difference between us is that it is in the sky with other 87 constellations but I am here lying on the sand alone.

Then I look up along the Milky Way to northern part and easily find the Lyra and the Aquila. With the Cygnus, they form the triangle of summer. The Lyra and the Aquila sit on two sides of the Milky Way. What grab my sight are the two stars in the two constellations. The Vega belongs to the Lyra and the Altair belongs to the Aquila. In Chinese legend, they are a couple. The Vega is a girl from a rich family and the Altair is a poor male farmer. They loved each other and eloped but were finally found. God permitted the marriage but made them live on two sides of the river. They can only see each other across the river when doing their own work. Vega was a weaver and Altair became a cow herder. On every July 7th of lunar calendar, magpies will come and make a bridge going across the Milky Way for them to meet each other. That's the only day they can meet in the whole year and their tears become the rain. It always rains on July 7th of lunar calendar.

The lunar calendar is usually about a month behind Gregorian calendar. And this year, it will be August 11th in Gregorian calendar. The Chinese Valentines' day is then coming soon but I am still lying here doing nothing to get back!

I jumped up and tried to yell out some words but failed. I could open my mouth but could not squeeze any voice out. Only hoarse sounds came out from my dry throat. Suddenly, my head hit something. It is hard so that my head hurt, what strange is that as soon as I was hit, there was a trumpet which started from far to near. Then I found myself sitting on the driver seat with my seat belt unfastened. I was sleeping and finally fell on the handle pressing the speaker.

I turned off the air conditioner which was continuously blowing cold air on my face, and shut down my car. It was not a usual afternoon any more. It was an afternoon of exhaustion which made me fell asleep and it was an amazing afternoon which gave me a dream which let me think about something I had stopped thinking about for a long time. It is a memorable afternoon that I finally knew what my favorite thing to do is.

I opened the door again, stepped out and shut the door behind me. I am sure that this time I am awake and heading somewhere I know. The sun is still in a low position in the sky so that my shadow is still very long.

Finally I am home. But I am not going to be bored tonight, not as all other days. My snack is going to be eaten outdoors when I turn off all the lights I can and lie on the grass looking at all the stars shining down on me and welcoming me to come to join them again.

- The End -

星期日, 7月 31, 2005

Loooooooong time

I can say only "ouch" about my absent from blogger for a long time. I don't even know what I did in these period. Any way, I'm now attending a summer ESL (English as Second Language) program in Tufts University in Medford near Boston. I love the circumstance as well as the weather here. But I just can't wait for two weeks to go back to Taiwan.

星期日, 2月 27, 2005

Pugs and Perl 6

Pugs 是 Perl 6 interpreter (直譯器) 計畫, 位於 http://pugscode.org 現由 Autrijus (唐宗漢) 主持. 也由於他的熱心, 台灣已有不少人加入了此一計畫. 如他在 irc.tw.freebsd.org, #elixus channel 上所言, "台灣已經變成 Perl 6 重鎮了" (2005/2/26).

Pugs 首頁簡單明瞭, 其中參與方式在最下方, 可以訂閱 mailing list (寄信至perl6-compiler-subscribe@perl.org) 也可以直接看 NNTP archive. 另外歡迎加入 freenode (irc.freenode.org) 上的 #perl6 channel.

程式碼是以 GPL2 公開的, 主要是以 Haskell 撰寫, 但是正如 overview 裡所言, 就算不會 Haskell 一樣有許多工作可以參與, 事實上許多 committer 本身並不會 Haskell.
autrijus> 可以寫範例程式, 寫 unit test, 寫 library
autrijus> 就像你 hack perl / cpan 也不一定要會 C 是一樣的道理
整個計畫是在 2005 年 2 月開始的, 程式碼以 subversion 管理, 至今 (2005/2/27 凌晨) 只有 316 個 revision, 但是已經有基本功能以及許多 unit test. Channel 上人也相當多, autrijus 之外, clkao, gugod 甚至 Ingy 都在上面!

希望這個計畫順利運行, 同時也希望大家有機會多多參與!

星期三, 2月 23, 2005

Xj3D's SAI support

I. Forward
I had spent some time dealing with x3d and SAI these days. As web3d web site said:
X3D is an Open Standards XML-enabled 3D file format to enable real-time communication of 3D data across all applications and network applications. It has a rich set of features for use in engineering and scientific visualization, CAD and Architecture, Medical visualization, Training and simulation, multimedia, entertainment, educational, and more.

3D modeling is not my major, and what I dealt with was not about 3D modeling, either. I mainly focus on the scene access interface (SAI) and trying to make it work on x3d browsers.

In x3d specification, we can write a special kind of node named "script." Usually these scrpts are written in javascript or so called ECMAscript. But as specification said, java byte code is also a valid choose. After several trials, I found that one of the commercial product -- maybe the most widely used one -- BS Contact does not fully support those feature. In fact, in version 6.1, the "url" field is not implemented so that it's impossible to write external script. In version 6.2, external script is supported but java byte code is still absent.

Another x3d browser implementation, Xj3D, is an open source software written in Java. As itself is written is Java, support of java byte code is great and complete. A shortage is that it hasn't support some complex node and can't process some x3d files. Another shortage is lake of documentation. Even though there are some implementation details and architecture documents, comments in source code is also well written, I found only few documents on using and hardly found any document on written SAI code. So this article is about these issues.

II. Xj3D usage
Installation of Xj3D version M10 is easy and smooth. After
download the installing jar file, simply run
  java -jar Xj3D-M10-RC2-platform.jar

and every will be fine. Not quite sure if it's necessary (since Xj3D can run with OpenGL scene), I installed Java3D before installing Xj3D.

To run the browser itself, using browser.bat on Windows or browser.sh on Unix. Don't be surprise that it spends all your CPU time and make your fan running faster -- it always does on my computer, either Windows or Linux. On Windows, it makes system slow down and makes me unable to do any thing else. It seems that it can have some improvement in this issue since on BS Contact, the same script needs little CPU time.

III. SAI and java byte code script for script node
The way to write java scripts is fairly simple -- compare to the effort I took on discovering it. The javadoc of the library Xj3D provided is available
online. According to x3d specification, all the compononts about SAI are defined in package org.web3d.x3d.sai.

First of all, in order to make Xj3D accept the byte code, the class should implement interface org.web3d.x3d.sai.X3dSriptImplementation, and, quite obvious but I forgot at first, should be public. As the javadoc said, there are several motheds should be implemented but only one of them is important
  public void setField(X3DScriptNode externalView, java.util.Map fields)

Where 'fields' will be a map from string to object, with the name of each field mapped to it's corresponding value class -- classes who implemented X3DField.

To use the fields we get from the parameter of setField, Xj3D provided a EventListener architecture. Interface X3DField defined a method
  public void addX3DEventListener(X3DFieldEventListener l)

So we can make our class implement X3DFieldEventListener as well as X3dScriptImplementation to handle the value changing.

Below is a sample code:
(X3d file)

<script DEF="MoverUsingExternalScriptFile" url="Script.class">
<field name="set_fraction" type="SFFloat" accessType='inputOnly'/>
<field name='value_changed' type='SFVec3f' accessType='outputOnly'/>
</script>


(Script.java)

public class Script implements X3DScriptImplementation, X3DFieldEventListener{
public void readableFieldChanged(X3DFieldEvent evt){
value_changed.setValue(new float[]{
set_fraction.getValue(), 0.0f, 0.0f
});
}
public void setFields(X3DScriptNode externalView, Map map){
set_fraction = (SFFloat) map.get("set_fraction");
value_changed = (SFVec3f) map.get("value_changed");
set_fraction.setX3DEventListener(this);
}
public void eventProcessed(){}
public void initializet(){}
public void setBrowser(Browser browser){}
public void shutdown(){}

private SFFloat set_fraction;
private SFVec3f value_changed;
}

星期日, 2月 06, 2005

Apache, Tomcat & Axis (on windows)

為了幫朋友研究些關於 Java web service 的東西要把 server 架起來. 又因為 client 端只有 windows 版的, 在只有一台機器的情況下, 只好在 windows 上把 server 架起來. 事實上步驟不難, 找對東西下載然後點幾下就好了.

要裝的東西包括:
1. Apache for windows, 我用的是 2.0.52 (最新的 stable).
    http://httpd.apache.org/download.cgi
2. Apache Jakarta Tomcat 5.5.7.
    http://jakarta.apache.org/site/binindex.cgi 搜尋 tomcat
3. Apache Webservises project Axis 1.2RC2
    (這是用 java 的, 如果要用 C++ 則是 Axis C++).
    http://ws.apache.org/axis/
4. Sun JDK 5.0 (1.5) update 1.
    http://java.sun.com/j2se/1.5.0/download.jsp
5. JavaBeans Activation Framework, JAK 1.0.2.
    http://java.sun.com/products/javabeans/glasgow/jaf.html

其中 dependency 是:
1. independent.
2. depend on 1. and 4.
3. depend on 2. and 5. (但安裝時只要 2.)
4. independent.
5. depend on 4.

所以以下是建議安裝順序:
1) 下載 1. 和 4.
2) 因為 jdk 很大, 所以 Apache 一定先抓完, 就順手裝起來.
3) 然後可以來抓 2. 和 3. 等到 jdk 裝起來就把 Tomcat 裝起來, 接著裝 Axis.
4) 最後抓 5. 在 JAF 裝起來之前 Tomcat 就可以動了, 可以稍微玩一下.
    用 browser 連到 localhost:8080
    (Tomcat 預設 port 為 8080, 有自行更改請改到相應的地方).
5) JAF 抓下來是 zip 檔. 把其中的 activation.jar 移到 Axis 所在目錄的 WEB-INF\lib 下就好了.
6) 開 browser 連到 localhost:8080/Axis 應該就會看到 Axis 的起始畫面. 點 Validate (http://localhost:8080/Axis/happyaxis.jsp), 核心元件 (core component) 應該都裝起來了, 要裝兩個選擇性元件的話再去頁面上给的 link 抓.
8) 回到 Axis 起始畫面, 點 Call a local endpoint, 可能會出現一個 xml, 其中有一行
java.lang.RuntimeException: No compiler found in your classpath! (you may need to add 'tools.jar')
那就代表碰上了和我同樣的問題. 解決的方法是在右下角圖示中找出 Apache Tomcat, 按右鍵選 configure, 在跳出的視窗中選 Java 頁面, 在 Java Classpath 的後面加上到 tools.jar 的路境. 以下是我的設定:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\bootstrap.jar;C:\Program Files\Java\jdk1.5.0_01\lib\tools.jar
回到這個設定視窗的 General 頁面, 按 Stop 之後按 Start 重新啟動 Tomcat 就可以正常運作了.

要注意的幾點:
1. jdk 安裝檔和裝起來都很佔空間, 所以要留夠多硬碟.
2. Axis 抓下來也是一個 zip, 只要把 webapps\axis 整個目錄移到 Tomcat 的 webapps 下就可以了. 其他 document 和 sample 可以留在別的地方.
3. 如果 用 Tomcat 4.x 和 jdk 1.4 那 activation.jar 要放在 Tomcat 目錄的 common/lib 下 (happyaxis.jsp 上特別註明).

因 為我還必須同時讓 IIS 執行 (做別的事), 所以 Apache 不能聽 port 80 而改到 8080. 可是這是 Tomcat 的預設 port 造成 Tomcat 執行失敗. 在找不到設定工具的情況下直接去改設定檔. 幸好設定檔都是 xml, 格式不難, 只要把 Tomcat 目錄下 conf\server.xml 其中一個 tag <Connector port="8080" ... > 改成要的 port 就好了.

星期一, 1月 31, 2005

核心傾印, core dump

本文重點是第三節 III. Generating core without fatel error. 前兩節為 core dump 之背景介紹, 熟悉這套機制的人大可略去不看, 不影響對第三節的理解.

I. What's core dump?
core dump 是 Unix 上程式執行發生錯誤時, 將記憶體裡的內容做 snap shot, 存到檔案裡. 以方便 debug. 尤其是如程式區段錯誤 (Segmentation fault) 之類的錯因為經常難以重現, 在缺少 core file 的情況下很難解決. 程式設計師對於 core file 只能說是又愛又恨. 因為出現了代表有錯, 少了它又難以除蟲.

II. How to use it?
許 多系統上平常就算程式發生錯誤同樣不會產生 core file. 這是因為不是人人都用得到, 而且 core file 的大小通常不小, 普通使用者用不到沒注意到相當佔硬碟空間. 要開啟 core dump 要使用 limit (tcsh) 或 ulimit (bash, ksh).
tcsh$ limit
cputime unlimited
filesize unlimited
datasize unlimited
stacksize 8192 kbytes
coredumpsize 0 kbytes
memoryuse unlimited
vmemoryuse unlimited
descriptors 1024
memorylocked unlimited
maxproc unlimited
tcsh$ limit coredumpsize 8192

bash&ksh$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 8189
virtual memory (kbytes, -v) unlimited
bash&ksh$ ulimit -c 8192
這樣會將 core file 的大小限制在 8M 以下. 這樣執行有問題的程式時:
$ cat t.c
#include

int main(){
int* p = NULL;
scanf(" %d", p);
return 0;
}
$ gcc -g t.c
$ ./a.out
1
Segmentation fault (core dumped)
$ ls
t.c a.out core
$ gdb -q a.out core
...
#0 0xb7eff18e in _IO_vfscanf_internal () from /lib/tls/libc.so.6
(gdb) where
#0 0xb7eff18e in _IO_vfscanf_internal () from /lib/tls/libc.so.6
#1 0xb7f09458 in scanf () from /lib/tls/libc.so.6
#2 0x080483ae in main () at t.c:5
就很容易確定問題出在哪裡了.

III. Generating core without fatel error.
這 次 blog 的重點其實在這一節. 不知道為了什麼原因, in2 想讓一支程式產生 core file 但是正常運行. 如果不是這樣的話, 把 limit 打開, 然後 kill -SIGABRT 就足以產生 core file 了. 事實上 FreeBSD 上很容易做到, 只要用 gcore(1) 就可以了:
$ cat t.cpp
#include
#include

int main(){
int a;
std::cin >> a;
sleep(10);
std::cout <<>
return 0;
}
$ g++ -g t.cpp
$ ./a.out
1
^Z
[1]+ Stopped ./a.out
$ ps
PID TT STAT TIME COMMAND
59960 p1 Ss 0:00.05 -bash (bash)
59996 p1 T 0:00.00 ./a.out
59997 p1 R+ 0:00.00 ps
$ gcore 59996
$ fg
./a.out
1
$ gdb a.out core.59996
...
#0 0x481361b4 in nanosleep () from /usr/lib/libc.so.4
(gdb) where
#0 0x481361b4 in nanosleep () from /usr/lib/libc.so.4
#1 0x48101a26 in sleep () from /usr/lib/libc.so.4
#2 0x80486d8 in main () at t.cpp:7
(gdb) up
#1 0x48101a26 in sleep () from /usr/lib/libc.so.4
(gdb) up
#2 0x80486d8 in main () at t.cpp:7
7 sleep(10);
(gdb) list
2 #include
3
4 int main(){
5 int a;
6 std::cin >> a;
7 sleep(10);
8 std::cout <<>
9 return 0;
10 }
(gdb) output a
1(gdb) q
可 以看到, 用 gcore 就可以產生 core file 同時讓原程式正常執行. 而事實上他要的是 Linux 上的 solution. 在沒有直接一支 gcore 程式的情況下, google 了一陣發現 Linux 幾個 distribution 裡的 gdb 原始碼都有出現 gcore 的內容, 可是都沒有編譯出獨立的程式. 於是估且一試:
(gdb) help gcore
Save a core file with the current state of the debugged process.
Argument is optional filename. Default filename is 'core.'.
(gdb)
全部用法:
$ cat t.cpp
#include

int main(){
int a;
std::cin >> a;
std::cout << a << std::endl;
return 0;
}
$ g++ -g t.cpp
$ gdb -q a.out
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) b 6
Breakpoint 1 at 0x8048777: file t.cpp, line 6.
(gdb) r
Starting program: /tmp/a.out
23

Breakpoint 1, main () at t.cpp:6
6 std::cout << a << std::endl;
(gdb) gcore
Saved corefile core.20251
(gdb) cont
Continuing.
23

Program exited normally.
(gdb) q
$ gdb -q a.out core.20251
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Failed to read a valid object file image from memory.
Core was generated by `/tmp/a.out'.
Program terminated with signal 5, Trace/breakpoint trap.
...
#0 main () at t.cpp:6
6 std::cout << a << std::endl;
(gdb) output a
23(gdb) q

星期日, 1月 30, 2005

晚睡

身體似乎漸漸習慣了這種睡眠時間. 前幾天聊天、寫程式弄到兩點、四點都會昏昏沉沉的. 可是今天很自然地就醒到現在. 這看來不是好事, 至少可以毫無目標地在 irc, bbs, 信箱和 bug tracking system 之間晃上幾個小時並不是優點.