Yearly Archives: 2007

Qt for VS c++ 2005 EE

Qt 4.3.2 已经支持 Visual Studio C++ 2005 Express Edition了,但不提供Integration,要使用的话,大概使用makefile project再加一点定制,比如使用qmake .pro来生成makefile,通过一些配置,Qt就可以使用VS这个稳定和强大的平台了(比如Intellisense, Debug等都比其它如Eclipse出色,毕竟是商业的)

To install it, download Qt 4.3.2 open source from its ftp at ftp.trolltech.com, configure it using a -platform win32-msvc2005, then compile/link by running nmake.

One thing to be noted is we have to install Windows Core SDK, IE SDK (If no IE SDK, prompting by missing shlwapi.h), and optionally MDAC SDK if you are going to install ODBC, prior to configure Qt. VC++ 2005 Express Edition does not come with SDK. We should install SDK seperately. One way is to install this package by appropriate customing.  

After installation, configure vcvar32.bat under "C:Program FilesMicrosoft Visual Studio 8Common7Tools" by adding "C:Program FilesMicrosoft Platform SDK for Windows Server 2003 R2Bin", "C:Program FilesMicrosoft Platform SDK for Windows Server 2003 R2Include",  and  "C:Program FilesMicrosoft Platform SDK for Windows Server 2003 R2Lib" to #path, #include and #lib respectively. Otherwise the compilation will complain it cannot find necessary header files.

完成了一个雷达数据到水文模型时间序列的转换程序包

这边的一个韩国同事前面写了一个Python版本的,在Linux下可以运行。我在Windows下对它进行了改进,并做了一些优化。结果在正式计算的时候,发现Ohio流域的一个子流域(2560个HRAP网格)10年逐小时估计要花上233天以上,同时需要空间也达100G以上。所以尽管该Python可用,但基本上对于大流域属于不实用的。为了完成工作,与梁讨论了以后,决定结合GIS和自己写代码,大概Coding了两周吧,现在终于完成了好几个小工具。在性能上进行了大量的优化(前一版本在转换到一半的时候出现内存不够,所以调试要花十分多的时间)。
我写了一个Instruction,大概从原始下载过来的XMRG二进制文件到可用的水文模型(如VIC)的时间序列大概要经过近10个步骤。不过实现了一个有意思的内插方法(与前Python算法相同),从HRAP网格到1/8度的转换时,由于每个1/8度网格覆盖多个HRAP格子,这个算法使用了面积加权来计算1/8度网格的平均降水。
现在完成上述任务大概需要2天。大家就可以在自己的桌面机器上用了,而不必一定要使用服务器(有大内存)。
没有时间做多线程或者并行优化,估计那样异步或并行处理性能会得到更好的提升。

Install Boost c++ library

 
1. get Boost source code from its official web site.
2. download bjam source codes, which is required to build Boost binaries.
3. build bjam. In my environment, mingw compiler is used. type:
 build.bat mingw
 actually the build.bat is smart enough to detect the right compiler
 at this point, we get bjam at it’s bin.ntx86 dir.
4. build boost. enter boost’s source dir, type:
  bjam –toolset=gcc
  make bjam compiled above, can be accessedwe should specifiy toolset as
  it will be msvc by default that’s not what we expect.
5. to enable content assist, it would better change indexer to full.

Days without pirate software

As University does not allow installing any illegal software to computers, I have to try other
developement tools rather than those I used in China. Fortunately, there are many GNU
tools available, which can substutite commercial tools to some extent. As more understanding
to GNU tools, I come to know they are also very powerful in development. They can do everything
that you have to be done with commerical earlier. Some aspects are even better than commercial.
 
Why not have a try? 
 
c++: Eclipse-CDT/MinGW/Qt/Boost
c#: Visual studio C# 2005 express (not GNU, but free)
Python, PyQt
 
 
 

Eclipse CDT MinGW debug error: error creating session

When I run as debug, the CDT says error creating session, then launching failed.
 
This is araised from missing of gdb. For best integration, I download MinGW gdb binary from MinGW’s download repository.
Then install it to MinGW’s same location. It works. 
 
Nov 29 2007: MinGW GDB debugger is bad; I have suffered various problems in debugging.

GeneratePolygonsByPoints utility

Purpose: to generate polygons (rectangles) by connecting neighboring points

Author: Zhuotong Nan
Email: [email protected]
Date: Nov 21, 2007

ver: 1.0.0

Usage: GeneratePolygonsByPoints [data_file_name] {output shapefile name}
Rows*Cols (for ex, 260*250): (enter numbers of rows and cols for the source data file with
a format rows*cols. Incorrect input will stop the tool.)

data_file_name: source data file name; path can be included.
output shapefile name: optional, as its literal stated. path can be includes.

Supporting environment: Microsoft dotnet framework 2.0, ArcGIS 9.2 with dotnet assemblies, as
well as a valid ArcInfo license.

Remarks: Data file should be organized row by row (you should know exact row and column
number, which will be required to be entered after starting), starting from lower left corner.
In my initial case, the data file is generated by a modified Read_XMRG2 utility for XMRG
radar data file. The modified Read_XMRG2 will generate data with geographical coordinates
instead of HRAP coordinates as does original Read_XMRG2. Anyway, GeneratePolygonsByPoints
will also run against data file generated by original Read_XMRG2, however, with output
shapefile being in HRAP coordination.

Data file content looks like following:

-121.177570 37.897155 0.000000
-121.132468 37.907464 0.000000
-121.087345 37.917746 0.000000
-121.042201 37.928001 0.000000
-120.997037 37.938229 0.000000

The first column is longitude, second latitude, and the third precipitation value. The first
two columns represent that cells’ lower left coordinations. The first row indicates the lower
left cell; second is the next cell right to the first cell; after finishing a row, then begin
a row up the first row, and move upwards.

Output shapefile will be of geographic NAD83 datum. The first two columns will be converted
to points’ geographic location. Values (precp value in above example) will be lost. A new
field named "Index" will be generated to record this polygon’s lower left corner’s coordination
with a format of "lat_lon", for ex. 37.897155_-121.177570 for the first created cell. However,
you cannot depend on this field to link original source data file. In order to do link, you can
"ID" field in shapefile attribute table, which increases by one in consitence with source data
file.

As stated above, each cell is referred by its lower left corner’s coordination. The most upper
cells cannot be generated due to missing of necessary points (we only have lower edge’s
coord). Likewise, the most right cells are also missed.

The distribution also includes a test data file: xmrg0101199900z.out, with a 39*48 (rows*cols)
dimension.

For more information, please contact the author at [email protected].

Thanksgiving

今天是感恩节,有4天的假期。外面小雨。中午本已经吃了点饭,朋友又叫出去,到China Star又吃了点。餐馆老板也是兰大校友。据说今天晚上很多人会去各大商场排队,很多东西会有special price。很多人年前开始计划要买的东西,都要等要今天去。从今天开始到元旦是Shopping season。
在吃饭的时候听朋友讲了很多football的事情,我此前从不知道football,只是刚来的时候W告诉我Pitt有一只叫Steeler的球队,这里的local people都很狂热。一起吃饭的朋友对这东西也很懂了,讲了很多规矩和有趣的故事。Steeler的票据说已经卖到10年以后了,这意味着你现在买只能买10年以后的比赛门票。但也有其它方法,比如Steeler外出纽约比赛,因为纽约队很糟糕,所以纽约本地人不大看,Steeler fans就可以跟过去看。football球迷比soccer要文明,动手打架相对要少。football据说是最美国式的运动,也是现代化装备最好的运动。

solution: 不能在space上发表日志

我前面经常遇到登陆进去后,却不能发表日志,发表日志的链接是灰的。前面有过调查,大致归因于中国的服务器好像有问题,一些js脚本可能无法传到我的机器。到美国后,同时用的一个台式机访问和发表空间日志没有任何问题,但笔记本仍有同样问题,有时候能发表,大部分时间却不能,很不稳定。无奈我前面都是通过email来发表日志,但总归是比较麻烦,一些信息通过email过去好像要审查,无法发布出来。
刚才在下班之后突然想来,如果我改成英语,那么将直接从美国这边的服务器下载,可能就没有问题了。
1)在浏览器的语言选项里(Internet Options/Lanugages)加入英语(美国),并移到最上面;重新打开Google时,发现Google的界面已经是英语。但登陆到空间,发现仍是中文,发表日志仍无效。
2)找到一个帖子,说可以更改space的默认语言,点击 http://spaces.live.com/?mkt=en-us 进去,发现果然是英语了。退出,再打开,还是英语,没变回来。估计在Cookie里存储下来了。
3)再进去发现果然发表日志的链接可用了。
前面跟人讨论说到这个问题,总怀疑我的机器中毒或有木马,因为我习惯是不打开杀毒程序。但自己感觉机器还是比较干净,应该问题不在这。现在这个结果表明,是国内的服务器有问题(或者是那个什么Great Wall Firewall等东东在搞破坏)。

Nov 29, 2007: I also found installed IE 7 will also solve this problem.

Make MinGW dll to be used by MSVC application

Make MinGW dll to be used by MSVC application
Zhuotong Nan, [email protected]

1. We cannot directly use dynamic libararies generated by MinGW in MSVC application
2. To enable this, it’s easy. In eclipse, open project property window, go to the MinGW c++ settings page, and enable –output-def by giving a def name.
3. Compile, this time it will generate a def file along with the dll file.
4. In msvc command window, type "lib /machine:x86 /def:def_file.def". It will create a lib file and a exp file.
5. In msvc ide, import this lib file as the common dll generated by MSVC.
6. The above described for only C functions, or c++ functions with extern "C" keywords. all c++ functions and any functions inside c++ class cannot be called by MSVC in this means. For information to address this so-called ABI (Application Binary Interface) issues between c++ compilers, please google with "ABI C++". In a short word, there is no easy way to do the interoperation. But there might be some workarounds.

Reference:
1. http://www.mingw.org/MinGWiki/index.php/MSVC-MinGW-DLL

下雪了

来之后,第二次下雪,雪不大,有点风,冷。
中午12点有个seminar,请了生态水文的一个名家,来自Princeton U的Professor
Ignacio Rodríguez-Iturbe,号称是father of ecohydrology by some。不过一口
Venezuela口音的英语,听起来十分费劲。