Wednesday, December 05, 2007

one balladry

没钱的时候,养猪
有钱的时候,养狗。
没钱的时候,在家里吃野菜
有钱的时候,在酒店吃野菜。
没钱的时候,在马路上骑自行车
有钱的时候,在客厅里骑自行车。
没钱的时候想结婚,
有钱的时候想离婚
没钱的时候老婆兼秘书,
有钱的时候秘书兼老婆
没钱的时候假装有钱,
有钱的时候假装没钱

人啊,都不讲实话:
说股票是毒品,都在玩;
说金钱是罪恶,都在捞;
说美女是祸水,都想要;
说高处不胜寒,都在爬;
说烟酒伤身体,就不戒;
说天堂最美好,都不去!!!
当今社会,穷吃肉,富吃虾,领导干部吃王八;
男想高,女想瘦,
狗穿衣裳人露肉;
过去把第一次留给丈夫
现在把第一胎留给丈夫;
乡下早晨鸡叫人,
城里晚上人叫鸡;
旧社会戏子卖艺不卖身,
新社会演员卖身不卖艺

工资真的要涨了
心里更加爱党了
能给孩子奖赏了
见到老婆敢嚷了
敢尝海鲜鹅掌了
闲时能逛商场了
遇见美女心痒了
结果物价又涨了一切都他妈白想

Sunday, October 07, 2007

安装itunes的问题

虽然ipod看起来很酷,但是要往里面加歌或者删歌,就必须要用到apple自己的软件itune。但是itunes又要和quick time捆绑在一起,所以,如果你不小心将quick time搞得有些毛病的话 (quick time竟然被windows作为一个组件,可以在控制面板看到),比如如果安装暴风影音默认情况下是要装quick time,如果你卸载暴风的话,就会影响到quick time,造成quick time卸载不干净。这时,很不幸,itunes就会拒绝工作。这种情况下,即使你卸载itues重新安装也不work的。

关键是要将quick time卸载干净。推荐一个软件,“完美卸载”。 我就是用这种办法搞定的。喜欢用apple的东西,就要承受一定的痛苦和麻烦。呵呵

Monday, October 01, 2007

install matlab in Linux

问题:
1. 点击运行install,不运行,无反应
2. 使用install -t 提示找不到libXp.so.6
解决方法:把cd1/update/bin/glnx86/libmwins.so复制到/usr/lib下,并更名为libXp.so.6
3. 安装完后,必须在bash终端中启动matlab

安装步骤:
<我是直接把iso中的文件拷贝出来在root下装的,下面参考一般的做法吧>

1. 切换到root用户,bash中也行;
su
2. 挂载光盘;
mkdir /cd1
mount -t iso9660 Dir_of_CD1 /cd1 -o loop
3. 建立Matlab安装目录,即准备把Matlab安装在何处;
mkdir /usr/local/matlab71
4. 拷贝license.dat;
cp /cd1/crack/license.dat /usr/local/matlab71/
5.拷贝文件libXp.so.6,此文件Matlab安装盘中有,即是/cd1/update/bin/glnx86/libmwins.so文件,把此文件拷贝至/usr/lib/目录下,并更名为libXp.so.6即可;在bash中执行命令
cp /cd1/update/bin/glnx86/libmwins.so /usr/lib/libXp.so.6
6, 然后进入matlab安装目录,# /cd1/./install -t
就开始安装了,选择yes,然后中间有换盘的。
7,转完后,运行matlab目录下的install_matlab,一路yes,选择目录下去
8,终于装完了,在终端 # matlab
就可以运行了

Sunday, September 30, 2007

9月的最后

这里很久都没有写了。。。杂草重生了,今天好歹除下草。在Pasadena快两个礼拜了,orientation还不错,有吃有喝还有玩,不过下周就要忙着courses了。。。good luck to myself 。。。
最近又开始学linux了,所以,又要帖一些文章了,见谅~~~
sorry ahead

非常好的BASH脚本编写教程(转)

这里有个老American写的 BASH脚本编写教程,非常不错,至少没接触过BASH的也能看懂!

建立一个脚本

  Linux中有好多中不同的shell,但是通常我们使用bash (bourne again shell) 进行shell编程,因为bash是免费的并且很容易使用。所以在本文中笔者所提供的脚本都是使用bash(但是在大多数情况下,这些脚本同样可以在 bash的大姐,bourne shell中运行)。
  如同其他语言一样,通过我们使用任意一种文字编辑器,比如nedit、kedit、emacs、vi
  等来编写我们的shell程序。
  程序必须以下面的行开始(必须方在文件的第一行):
#!/bin/sh
  符号#!用来告诉系统它后面的参数是用来执行该文件的程序。在这个例子中我们使用/bin/sh来执行程序。
  当编辑好脚本时,如果要执行该脚本,还必须使其可执行。
  要使脚本可执行:
chmod +x filename
  然后,您可以通过输入: ./filename 来执行您的脚本。
注释
  在进行shell编程时,以#开头的句子表示注释,直到这一行的结束。我们真诚地建议您在程序中使用注释。如果您使用了注释,那么即使相当长的时间内没有使用该脚本,您也能在很短的时间内明白该脚本的作用及工作原理。
变量
  在其他编程语言中您必须使用变量。在shell编程中,所有的变量都由字符串组成,并且您不需要对变量进行声明。要赋值给一个变量,您可以这样写:
变量名=值
  取出变量值可以加一个美元符号($)在变量前面:
#!/bin/sh
#对变量赋值:
a="hello world"
# 现在打印变量a的内容:
echo "A is:"
echo $a
  在您的编辑器中输入以上内容,然后将其保存为一个文件first。之后执行chmod +x first
  使其可执行,最后输入./first执行该脚本。
  这个脚本将会输出:
A is:
hello world
  有时候变量名很容易与其他文字混淆,比如:
num=2
echo "this is the $numnd"
  这并不会打印出"this is the 2nd",而仅仅打印"this is the ",因为shell会去搜索变量numnd的值,但是这个变量时没有值的。可以使用花括号来告诉shell我们要打印的是num变量:
num=2
echo "this is the ${num}nd"
  这将打印: this is the 2nd
  有许多变量是系统自动设定的,这将在后面使用这些变量时进行讨论。
  如果您需要处理数学表达式,那么您需要使用诸如expr等程序(见下面)。
  除了一般的仅在程序内有效的shell变量以外,还有环境变量。由export关键字处理过的变量叫做环境变量。我们不对环境变量进行讨论,因为通常情况下仅仅在登录脚本中使用环境变量。
Shell命令和流程控制
  在shell脚本中可以使用三类命令:
1)Unix 命令:
  虽然在shell脚本中可以使用任意的unix命令,但是还是由一些相对更常用的命令。这些命令通常是用来进行文件和文字操作的。
常用命令语法及功能
  echo "some text": 将文字内容打印在屏幕上
  ls: 文件列表
  wc –l filewc -w filewc -c file: 计算文件行数计算文件中的单词数计算文件中的字符数
  cp sourcefile destfile: 文件拷贝
  mv oldname newname : 重命名文件或移动文件
  rm file: 删除文件
  grep 'pattern' file: 在文件内搜索字符串比如:grep 'searchstring' file.txt
  cut -b colnum file: 指定欲显示的文件内容范围,并将它们输出到标准输出设备比如:输出每行第5个到第9个字符cut -b5-9 file.txt千万不要和cat命令混淆,这是两个完全不同的命令
  cat file.txt: 输出文件内容到标准输出设备(屏幕)上
  file somefile: 得到文件类型
  read var: 提示用户输入,并将输入赋值给变量
  sort file.txt: 对file.txt文件中的行进行排序
  uniq: 删除文本文件中出现的行列比如: sort file.txt | uniq
  expr: 进行数学运算Example: add 2 and 3expr 2 "+" 3
  find: 搜索文件比如:根据文件名搜索find . -name filename -print
  tee: 将数据输出到标准输出设备(屏幕) 和文件比如:somecommand | tee outfile
  basename file: 返回不包含路径的文件名比如: basename /bin/tux将返回 tux
  dirname file: 返回文件所在路径比如:dirname /bin/tux将返回 /bin
  head file: 打印文本文件开头几行
  tail file : 打印文本文件末尾几行
  sed: Sed是一个基本的查找替换程序。可以从标准输入(比如命令管道)读入文本,并将结果输出到标准输出(屏幕)。该命令采用正则表达式(见参考)进行搜索。 不要和shell中的通配符相混淆。比如:将linuxfocus 替换为 LinuxFocus :cat text.file | sed 's/linuxfocus/LinuxFocus/' > newtext.file
  awk: awk 用来从文本文件中提取字段。缺省地,字段分割符是空格,可以使用-F指定其他分割符。cat file.txt | awk -F, '{print $1 "," $3 }'这里我们使用,作为字段分割符,同时打印第一个和第三个字段。如果该文件内容如下: Adam Bor, 34, IndiaKerry Miller, 22, USA命令输出结果为:Adam Bor, IndiaKerry Miller, USA
2) 概念: 管道, 重定向和 backtick
  这些不是系统命令,但是他们真的很重要。
  管道 (|) 将一个命令的输出作为另外一个命令的输入。
grep "hello" file.txt | wc -l
  在file.txt中搜索包含有”hello”的行并计算其行数。
  在这里grep命令的输出作为wc命令的输入。当然您可以使用多个命令。
  重定向:将命令的结果输出到文件,而不是标准输出(屏幕)。
  > 写入文件并覆盖旧文件
  >> 加到文件的尾部,保留旧文件内容。
反短斜线
 使用反短斜线可以将一个命令的输出作为另外一个命令的一个命令行参数。
  命令:
find . -mtime -1 -type f -print
  用来查找过去24小时(-mtime –2则表示过去48小时)内修改过的文件。如果您想将所有查找到的文件打一个包,则可以使用以下脚本:
#!/bin/sh
# The ticks are backticks (`) not normal quotes ('):
tar -zcvf lastmod.tar.gz `find . -mtime -1 -type f -print`
  3) 流程控制
  "if" 表达式 如果条件为真则执行then后面的部分:
if ....; then
  ....
elif ....; then
  ....
else
  ....
fi
  大多数情况下,可以使用测试命令来对条件进行测试。比如可以比较字符串、判断文件是否存在及是否可读等等…
  通常用" [ ] "来表示条件测试。注意这里的空格很重要。要确保方括号的空格。
[ -f "somefile" ] :判断是否是一个文件
[ -x "/bin/ls" ] :判断/bin/ls是否存在并有可执行权限
[ -n "$var" ] :判断$var变量是否有值
[ "$a" = "$b" ] :判断$a和$b是否相等
  执行man test可以查看所有测试表达式可以比较和判断的类型。
  直接执行以下脚本:
#!/bin/sh
if [ "$SHELL" = "/bin/bash" ]; then
 echo "your login shell is the bash (bourne again shell)"
else
 echo "your login shell is not bash but $SHELL"
fi
  变量$SHELL包含了登录shell的名称,我们和/bin/bash进行了比较。
快捷操作符
  熟悉C语言的朋友可能会很喜欢下面的表达式:
[ -f "/etc/shadow" ] && echo "This computer uses shadow passwors"
  这里 && 就是一个快捷操作符,如果左边的表达式为真则执行右边的语句。您也可以认为是逻辑运算中的与操作。上例中表示如果/etc/shadow文件存在则打印” This computer uses shadow passwors”。同样或操作(||)在shell编程中也是可用的。这里有个例子:
#!/bin/sh
mailfolder=/var/spool/mail/james
[ -r "$mailfolder" ]' '{ echo "Can not read $mailfolder" ; exit 1; }
echo "$mailfolder has mail from:"
grep "^From " $mailfolder
  该脚本首先判断mailfolder是否可读。如果可读则打印该文件中的"From" 一行。如果不可读则或操作生效,打印错误信息后脚本退出。这里有个问题,那就是我们必须有两个命令:
  -打印错误信息
  -退出程序
  我们使用花括号以匿名函数的形式将两个命令放到一起作为一个命令使用。一般函数将在下文提及。
  不用与和或操作符,我们也可以用if表达式作任何事情,但是使用与或操作符会更便利很多。
  case表达式可以用来匹配一个给定的字符串,而不是数字。
case ... in
...) do something here ;;
esac
  让我们看一个例子。 file命令可以辨别出一个给定文件的文件类型,比如:
file lf.gz
  这将返回:
lf.gz: gzip compressed data, deflated, original filename,
last modified: Mon Aug 27 23:09:18 2001, os: Unix
 我们利用这一点写了一个叫做smartzip的脚本,该脚本可以自动解压bzip2, gzip 和zip 类型的压缩文件:
#!/bin/sh
ftype=`file "$1"`
case "$ftype" in
"$1: Zip archive"*)
  unzip "$1" ;;
"$1: gzip compressed"*)
  gunzip "$1" ;;
"$1: bzip2 compressed"*)
  bunzip2 "$1" ;;
*) error "File $1 can not be uncompressed with smartzip";;
esac
  您可能注意到我们在这里使用了一个特殊的变量$1。该变量包含了传递给该程序的第一个参数值。也就是说,当我们运行:
smartzip articles.zip
$1 就是字符串 articles.zip
  select 表达式是一种bash的扩展应用,尤其擅长于交互式使用。用户可以从一组不同的值中进行选择。
select var in ... ; do
 break
done
.... now $var can be used ....
下面是一个例子:
#!/bin/sh
echo "What is your favourite OS?"
select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
    break
done
echo "You have selected $var"
  下面是该脚本运行的结果:
What is your favourite OS?
1) Linux
2) Gnu Hurd
3) Free BSD
4) Other
#? 1
You have selected Linux
  您也可以在shell中使用如下的loop表达式:
while ...; do
....
done
  while-loop 将运行直到表达式测试为真。will run while the expression that we test for is true. 关键字"break" 用来跳出循环。而关键字”continue”用来不执行余下的部分而直接跳到下一个循环。
  for-loop表达式查看一个字符串列表 (字符串用空格分隔) 然后将其赋给一个变量:
for var in ....; do
 ....
done
  在下面的例子中,将分别打印ABC到屏幕上:
#!/bin/sh
for var in A B C ; do
 echo "var is $var"
done
  下面是一个更为有用的脚本showrpm,其功能是打印一些RPM包的统计信息:
#!/bin/sh
# list a content summary of a number of RPM packages
# USAGE: showrpm rpmfile1 rpmfile2 ...
# EXAMPLE: showrpm /cdrom/RedHat/RPMS/*.rpm
for rpmpackage in $*; do
 if [ -r "$rpmpackage" ];then
  echo "=============== $rpmpackage =============="
  rpm -qi -p $rpmpackage
 else
  echo "ERROR: cannot read file $rpmpackage"
 fi
done
  这里出现了第二个特殊的变量$*,该变量包含了所有输入的命令行参数值。如果您运行showrpm openssh.rpm w3m.rpm webgrep.rpm
  此时 $* 包含了 3 个字符串,即openssh.rpm, w3m.rpm and webgrep.rpm.
引号
  在向程序传递任何参数之前,程序会扩展通配符和变量。这里所谓扩展的意思是程序会把通配符(比如*)替换成合适的文件名,它变量替换成变量值。为了防 止程序作这种替换,您可以使用引号:让我们来看一个例子,假设在当前目录下有一些文件,两个jpg文件, mail.jpg 和tux.jpg。

#!/bin/sh
echo *.jpg
  这将打印出"mail.jpg tux.jpg"的结果。
  引号 (单引号和双引号) 将防止这种通配符扩展:
#!/bin/sh
echo "*.jpg"
echo '*.jpg'
  这将打印"*.jpg" 两次。
  单引号更严格一些。它可以防止任何变量扩展。双引号可以防止通配符扩展但允许变量扩展。
#!/bin/sh
echo $SHELL
echo "$SHELL"
echo '$SHELL'
  运行结果为:
/bin/bash
/bin/bash
$SHELL
  最后,还有一种防止这种扩展的方法,那就是使用转义字符——反斜杆:
echo *.jpg
echo $SHELL
  这将输出:
*.jpg
$SHELL
Here documents
  当要将几行文字传递给一个命令时,here documents(译者注:目前还没有见到过对该词适合的翻译)一种不错的方法。对每个脚本写一段帮助性的文字是很有用的,此时如果我们四有那个 here documents就不必用echo函数一行行输出。 一个 "Here document" 以 << 开头,后面接上一个字符串,这个字符串还必须出现在here document的末尾。下面是一个例子,在该例子中,我们对多个文件进行重命名,并且使用here documents打印帮助:
#!/bin/sh
# we have less than 3 arguments. Print the help text:
if [ $# -lt 3 ] ; then
cat <
ren -- renames a number of files using sed regular expressions
USAGE: ren 'regexp' 'replacement' files...
EXAMPLE: rename all *.HTM files in *.html:
 ren 'HTM$' 'html' *.HTM
HELP
 exit 0
fi
OLD="$1"
NEW="$2"
# The shift command removes one argument from the list of
# command line arguments.
shift
shift
# $* contains now all the files:
for file in $*; do
  if [ -f "$file" ] ; then
   newfile=`echo "$file" | sed "s/${OLD}/${NEW}/g"`
   if [ -f "$newfile" ]; then
    echo "ERROR: $newfile exists already"
   else
    echo "renaming $file to $newfile ..."
    mv "$file" "$newfile"
   fi
  fi
done
  这是一个复杂一些的例子。让我们详细讨论一下。第一个if表达式判断输入命令行参数是否小于3个 (特殊变量$# 表示包含参数的个数) 。如果输入参数小于3个,则将帮助文字传递给cat命令,然后由cat命令将其打印在屏幕上。打印帮助文字后程序退出。 如果输入参数等于或大于3个,我们就将第一个参数赋值给变量OLD,第二个参数赋值给变量NEW。下一步,我们使用shift命令将第一个和第二个参数从 参数列表中删除,这样原来的第三个参数就成为参数列表$*的第一个参数。然后我们开始循环,命令行参数列表被一个接一个地被赋值给变量$file。接着我 们判断该文件是否存在,如果存在则通过sed命令搜索和替换来产生新的文件名。然后将反短斜线内命令结果赋值给newfile。这样我们就达到了我们的目 的:得到了旧文件名和新文件名。然后使用mv命令进行重命名。
函数
  如果您写了一些稍微复杂一些的程序,您就会发现在程序中可能在几个地方使用了相同的代码,并且您也会发现,如果我们使用了函数,会方便很多。一个函数是这个样子的:
functionname()
{
# inside the body $1 is the first argument given to the function
# $2 the second ...
body
}
  您需要在每个程序的开始对函数进行声明。

  下面是一个叫做xtitlebar的脚本,使用这个脚本您可以改变终端窗口的名称。这里使用了一个叫做help的函数。正如您可以看到的那样,这个定义的函数被使用了两次。
#!/bin/sh
# vim: set sw=4 ts=4 et:
help()
{
  cat <
xtitlebar -- change the name of an xterm, gnome-terminal or kde konsole
USAGE: xtitlebar [-h] "string_for_titelbar"
OPTIONS: -h help text
EXAMPLE: xtitlebar "cvs"
HELP
  exit 0
}
# in case of error or if -h is given we call the function help:
[ -z "$1" ] && help
[ "$1" = "-h" ] && help
# send the escape sequence to change the xterm titelbar:
echo -e "33]0;$107"
#
  在脚本中提供帮助是一种很好的编程习惯,这样方便其他用户(和您)使用和理解脚本。
命令行参数
  我们已经见过$* 和 $1, $2 ... $9 等特殊变量,这些特殊变量包含了用户从命令行输入的参数。迄今为止,我们仅仅了解了一些简单的命令行语法(比如一些强制性的参数和查看帮助的-h选项)。 但是在编写更复杂的程序时,您可能会发现您需要更多的自定义的选项。通常的惯例是在所有可选的参数之前加一个减号,后面再加上参数值 (比如文件名)。
  有好多方法可以实现对输入参数的分析,但是下面的使用case表达式的例子无遗是一个不错的方法。
#!/bin/sh
help()
{
 cat <
This is a generic command line parser demo.
USAGE EXAMPLE: cmdparser -l hello -f -- -somefile1 somefile2
HELP
 exit 0
}
while [ -n "$1" ]; do
case $1 in
  -h) help;shift 1;; # function help is called
  -f) opt_f=1;shift 1;; # variable opt_f is set
  -l) opt_l=$2;shift 2;; # -l takes an argument -> shift by 2
  --) shift;break;; # end of options
  -*) echo "error: no such option $1. -h for help";exit 1;;
  *) break;;
esac
done

echo "opt_f is $opt_f"
echo "opt_l is $opt_l"
echo "first arg is $1"
echo "2nd arg is $2"
  您可以这样运行该脚本:
cmdparser -l hello -f -- -somefile1 somefile2
  返回的结果是:
opt_f is 1
opt_l is hello
first arg is -somefile1
2nd arg is somefile2
  这个脚本是如何工作的呢?脚本首先在所有输入命令行参数中进行循环,将输入参数与case表达式进行比较,如果匹配则设置一个变量并且移除该参数。根据unix系统的惯例,首先输入的应该是包含减号的参数。
实例
  一般编程步骤
  现在我们来讨论编写一个脚本的一般步骤。任何优秀的脚本都应该具有帮助和输入参数。并且写一个伪脚本(framework.sh),该脚本包含了大多数脚本都需要的框架结构,是一个非常不错的主意。这时候,在写一个新的脚本时我们只需要执行一下copy命令:
cp framework.sh myscript
 然后再插入自己的函数。
  让我们再看两个例子:
  二进制到十进制的转换
  脚本 b2d 将二进制数 (比如 1101) 转换为相应的十进制数。这也是一个用expr命令进行数学运算的例子:
#!/bin/sh
# vim: set sw=4 ts=4 et:
help()
{
 cat <
b2h -- convert binary to decimal
USAGE: b2h [-h] binarynum
OPTIONS: -h help text
EXAMPLE: b2h 111010
will return 58
HELP
 exit 0
}
error()
{
  # print an error and exit
  echo "$1"
  exit 1
}
lastchar()
{
  # return the last character of a string in $rval
  if [ -z "$1" ]; then
    # empty string
    rval=""
    return
  fi
  # wc puts some space behind the output this is why we need sed:
  numofchar=`echo -n "$1" | wc -c | sed 's/ //g' `
  # now cut out the last char
  rval=`echo -n "$1" | cut -b $numofchar`
}

chop()
{
  # remove the last character in string and return it in $rval
  if [ -z "$1" ]; then
    # empty string
    rval=""
    return
  fi
  # wc puts some space behind the output this is why we need sed:
  numofchar=`echo -n "$1" | wc -c | sed 's/ //g' `
  if [ "$numofchar" = "1" ]; then
    # only one char in string
    rval=""
    return
  fi
  numofcharminus1=`expr $numofchar "-" 1`
  # now cut all but the last char:
  rval=`echo -n "$1" | cut -b 0-${numofcharminus1}`
}
while [ -n "$1" ]; do
case $1 in
  -h) help;shift 1;; # function help is called
  --) shift;break;; # end of options
  -*) error "error: no such option $1. -h for help";;
  *) break;;
esac
done
# The main program
sum=0
weight=1
# one arg must be given:
[ -z "$1" ] && help
binnum="$1"
binnumorig="$1"

while [ -n "$binnum" ]; do
  lastchar "$binnum"
  if [ "$rval" = "1" ]; then
    sum=`expr "$weight" "+" "$sum"`
  fi
  # remove the last position in $binnum
  chop "$binnum"
  binnum="$rval"
  weight=`expr "$weight" "*" 2`
done
echo "binary $binnumorig is decimal $sum"
#
  该脚本使用的算法是利用十进制和二进制数权值 (1,2,4,8,16,..),比如二进制"10"可以这样转换成十进制:
0 * 1 + 1 * 2 = 2
  为了得到单个的二进制数我们是用了lastchar 函数。该函数使用wc –c计算字符个数,然后使用cut命令取出末尾一个字符。Chop函数的功能则是移除最后一个字符。
  文件循环程序
  或许您是想将所有发出的邮件保存到一个文件中的人们中的一员,但是在过了几个月以后,这个文件可能会变得很大以至于使对该文件的访问速度变慢。下面的 脚本rotatefile 可以解决这个问题。这个脚本可以重命名邮件保存文件(假设为outmail)为outmail.1,而对于outmail.1就变成了outmail.2 等等等等...
#!/bin/sh
# vim: set sw=4 ts=4 et:
ver="0.1"
help()
{
  cat <
rotatefile -- rotate the file name

USAGE: rotatefile [-h] filename

OPTIONS: -h help text
EXAMPLE: rotatefile out
This will e.g rename out.2 to out.3, out.1 to out.2, out to out.1
and create an empty out-file
The max number is 10
version $ver
HELP
  exit 0
}

error()
{
  echo "$1"
  exit 1
}
while [ -n "$1" ]; do
case $1 in
  -h) help;shift 1;;
  --) break;;
  -*) echo "error: no such option $1. -h for help";exit 1;;
  *) break;;
esac
done
# input check:
if [ -z "$1" ] ; then
error "ERROR: you must specify a file, use -h for help"
fi
filen="$1"
# rename any .1 , .2 etc file:
for n in 9 8 7 6 5 4 3 2 1; do
  if [ -f "$filen.$n" ]; then
    p=`expr $n + 1`
    echo "mv $filen.$n $filen.$p"
    mv $filen.$n $filen.$p
  fi
done
# rename the original file:
if [ -f "$filen" ]; then
  echo "mv $filen $filen.1"
  mv $filen $filen.1
fi
echo touch $filen
touch $filen
  这个脚本是如何工作的呢?在检测用户提供了一个文件名以后,我们进行一个9到1的循环。文件9被命名为10,文件8重命名为9等等。循环完成之后,我们将原始文件命名为文件1同时建立一个与原始文件同名的空文件。
调试
  最简单的调试命令当然是使用echo命令。您可以使用echo在任何怀疑出错的地方打印任何变量值。这也是绝大多数的shell程序员要花费80%的时间来调试程序的原因。Shell程序的好处在于不需要重新编译,插入一个echo命令也不需要多少时间。
  shell也有一个真实的调试模式。如果在脚本"strangescript" 中有错误,您可以这样来进行调试:
sh -x strangescript
  这将执行该脚本并显示所有变量的值。
  shell还有一个不需要执行脚本只是检查语法的模式。可以这样使用:
sh -n your_script
  这将返回所有语法错误。

Friday, September 28, 2007

tar用法

Linux压缩打包命令使用方法

tar命令
[root@linux ~]# tar [-cxtzjvfpPN] 文件与目录 ....
参数:
-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!
因为不可能同时压缩与解压缩。
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
   例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成
   『 tar -zcvPf tfile sfile』才对喔!
-p :使用原文件的原来属性(属性不会依据使用者而变)
-P :可以使用绝对路径来压缩!
-N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!
--exclude FILE:在压缩的过程中,不要将 FILE 打包!
范例:
范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar
[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==仅打包,不压缩! [root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc <==打包后,以 gzip 压缩 [root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc <==打包后,以 bzip2 压缩 # 特别注意,在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 # 如果加 z 参数,则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar file ~ # 如果加 j 参数,则以 .tar.bz2 来作为附档名啊~ # 上述指令在执行的时候,会显示一个警告讯息: # 『tar: Removing leading `/' from member names』那是关於绝对路径的特殊设定。 范例二:查阅上述 /tmp/etc.tar.gz 文件内有哪些文件? [root@linux ~]# tar -ztvf /tmp/etc.tar.gz # 由於我们使用 gzip 压缩,所以要查阅该 tar file 内的文件时, # 就得要加上 z 这个参数了!这很重要的! 范例三:将 /tmp/etc.tar.gz 文件解压缩在 /usr/local/src 底下 [root@linux ~]# cd /usr/local/src [root@linux src]# tar -zxvf /tmp/etc.tar.gz # 在预设的情况下,我们可以将压缩档在任何地方解开的!以这个范例来说, # 我先将工作目录变换到 /usr/local/src 底下,并且解开 /tmp/etc.tar.gz , # 则解开的目录会在 /usr/local/src/etc 呢!另外,如果您进入 /usr/local/src/etc # 则会发现,该目录下的文件属性与 /etc/ 可能会有所不同喔! 范例四:在 /tmp 底下,我只想要将 /tmp/etc.tar.gz 内的 etc/passwd 解开而已 [root@linux ~]# cd /tmp [root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd # 我可以透过 tar -ztvf 来查阅 tarfile 内的文件名称,如果单只要一个文件, # 就可以透过这个方式来下达!注意到! etc.tar.gz 内的根目录 / 是被拿掉了! 范例五:将 /etc/ 内的所有文件备份下来,并且保存其权限! [root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc # 这个 -p 的属性是很重要的,尤其是当您要保留原本文件的属性时! 范例六:在 /home 当中,比 2005/06/01 新的文件才备份 [root@linux ~]# tar -N '2005/06/01' -zcvf home.tar.gz /home 范例七:我要备份 /home, /etc ,但不要 /home/dmtsai [root@linux ~]# tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc 范例八:将 /etc/ 打包后直接解开在 /tmp 底下,而不产生文件! [root@linux ~]# cd /tmp [root@linux tmp]# tar -cvf - /etc | tar -xvf - # 这个动作有点像是 cp -r /etc /tmp 啦~依旧是有其有用途的! # 要注意的地方在於输出档变成 - 而输入档也变成 - ,又有一个 | 存在~ # 这分别代表 standard output, standard input 与管线命令啦! # 这部分我们会在 Bash shell 时,再次提到这个指令跟大家再解释啰! gzip, zcat 命令 [root@linux ~]# gzip [-cdt#] 档名 [root@linux ~]# zcat 档名.gz 参数: -c :将压缩的资料输出到萤幕上,可透过资料流重导向来处理; -d :解压缩的参数; -t :可以用来检验一个压缩档的一致性~看看文件有无错误; -# :压缩等级,-1 最快,但是压缩比最差、-9 最慢,但是压缩比最好!预设是 -6 ~ 范例: 范例一:将 /etc/man.config 複制到 /tmp ,并且以 gzip 压缩 [root@linux ~]# cd /tmp [root@linux tmp]# cp /etc/man.config . [root@linux tmp]# gzip man.config # 此时 man.config 会变成 man.config.gz ! 范例二:将范例一的文件内容读出来! [root@linux tmp]# zcat man.config.gz # 此时萤幕上会显示 man.config.gz 解压缩之后的文件内容!! 范例三:将范例一的文件解压缩 [root@linux tmp]# gzip -d man.config.gz 范例四:将范例三解开的 man.config 用最佳的压缩比压缩,并保留原本的文件 [root@linux tmp]# gzip -9 -c man.config > man.config.gz



bzip2, bzcat 命令
[root@linux ~]# bzip2 [-cdz] 档名
[root@linux ~]# bzcat 档名.bz2
参数:
-c :将压缩的过程产生的资料输出到萤幕上!
-d :解压缩的参数
-z :压缩的参数
-# :与 gzip 同样的,都是在计算压缩比的参数, -9 最佳, -1 最快!
范例:
范例一:将刚刚的 /tmp/man.config 以 bzip2 压缩
[root@linux tmp]# bzip2 -z man.config
# 此时 man.config 会变成 man.config.bz2 !
范例二:将范例一的文件内容读出来!
[root@linux tmp]# bzcat man.config.bz2
# 此时萤幕上会显示 man.config.bz2 解压缩之后的文件内容!!

范例三:将范例一的文件解压缩
[root@linux tmp]# bzip2 -d man.config.bz2

范例四:将范例三解开的 man.config 用最佳的压缩比压缩,并保留原本的文件
[root@linux tmp]# bzip2 -9 -c man.config > man.config.bz2



compress 命令
[root@linux ~]# compress [-dcr] 文件或目录
参数:
-d :用来解压缩的参数
-r :可以连同目录下的文件也同时给予压缩呢!
-c :将压缩资料输出成为 standard output (输出到萤幕)
范例:
范例一:将 /etc/man.config 複制到 /tmp ,并加以压缩
[root@linux ~]# cd /tmp
[root@linux tmp]# cp /etc/man.config .
[root@linux tmp]# compress man.config
[root@linux tmp]# ls -l
-rw-r--r-- 1 root root 2605 Jul 27 11:43 man.config.Z
范例二:将刚刚的压缩档解开
[root@linux tmp]# compress -d man.config.Z

范例三:将 man.config 压缩成另外一个文件来备份
[root@linux tmp]# compress -c man.config > man.config.back.Z
[root@linux tmp]# ll man.config*
-rw-r--r-- 1 root root 4506 Jul 27 11:43 man.config
-rw-r--r-- 1 root root 2605 Jul 27 11:46 man.config.back.Z
# 这个 -c 的参数比较有趣!他会将压缩过程的资料输出到萤幕上,而不是写入成为
# file.Z 文件。所以,我们可以透过资料流重导向的方法将资料输出成为另一个档名。
# 关於资料流重导向,我们会在 bash shell 当中详细谈论的啦!



dd 命令
[root@linux ~]# dd if="input_file" of="outptu_file" bs="block_size" \
count="number"
参数:
if :就是 input file 啰~也可以是装置喔!
of :就是 output file 喔~也可以是装置;
bs :规划的一个 block 的大小,如果没有设定时,预设是 512 bytes
count:多少个 bs 的意思。
范例:
范例一:将 /etc/passwd 备份到 /tmp/passwd.back 当中
[root@linux ~]# dd if=/etc/passwd of=/tmp/passwd.back
3+1 records in
3+1 records out
[root@linux ~]# ll /etc/passwd /tmp/passwd.back
-rw-r--r-- 1 root root 1746 Aug 25 14:16 /etc/passwd
-rw-r--r-- 1 root root 1746 Aug 29 16:57 /tmp/passwd.back
# 仔细的看一下,我的 /etc/passwd 文件大小为 1746 bytes,因为我没有设定 bs ,
# 所以预设是 512 bytes 为一个单位,因此,上面那个 3+1 表示有 3 个完整的
# 512 bytes,以及未满 512 bytes 的另一个 block 的意思啦!
# 事实上,感觉好像是 cp 这个指令啦~

范例二:备份 /dev/hda 的 MBR
[root@linux ~]# dd if=/dev/hda of=/tmp/mbr.back bs=512 count=1
1+0 records in
1+0 records out
# 这就得好好瞭解一下啰~我们知道整颗硬盘的 MBR 为 512 bytes,
# 就是放在硬盘的第一个 sector 啦,因此,我可以利用这个方式来将
# MBR 内的所有资料都纪录下来,真的很厉害吧! ^_^

范例三:将整个 /dev/hda1 partition 备份下来。
[root@linux ~]# dd if=/dev/hda1 of=/some/path/filenaem
# 这个指令很厉害啊!将整个 partition 的内容全部备份下来~
# 后面接的 of 必须要不是在 /dev/hda1 的目录内啊~否则,怎么读也读不完~
# 这个动作是很有效用的,如果改天你必须要完整的将整个 partition 的内容填回去,
# 则可以利用 dd if=/some/file of=/dev/hda1 来将资料写入到硬盘当中。
# 如果想要整个硬盘备份的话,就类似 Norton 的 ghost 软体一般,
# 由 disk 到 disk ,嘿嘿~利用 dd 就可以啦~厉害厉害!



cpio 命令
[root@linux ~]# cpio -covB > [file|device] <==备份 [root@linux ~]# cpio -icduv < [file|device] <==还原 参数: -o :将资料 copy 输出到文件或装置上 -i :将资料自文件或装置 copy 出来系统当中 -t :查看 cpio 建立的文件或装置的内容 -c :一种较新的 portable format 方式储存 -v :让储存的过程中文件名称可以在萤幕上显示 -B :让预设的 Blocks 可以增加至 5120 bytes ,预设是 512 bytes !    这样的好处是可以让大文件的储存速度加快(请参考 i-nodes 的观念) -d :自动建立目录!由於 cpio 的内容可能不是在同一个目录内, 如此的话在反备份的过程会有问题! 这个时候加上 -d 的话, 就可以自动的将需要的目录建立起来了! -u :自动的将较新的文件覆盖较旧的文件! 范例: 范例一:将所有系统上的资料通通写入磁带机内! [root@linux ~]# find / -print | cpio -covB > /dev/st0
# 一般来说,使用 SCSI 介面的磁带机,代号是 /dev/st0 喔!
范例二:检查磁带机上面有什么文件?
[root@linux ~]# cpio -icdvt < /dev/st0 [root@linux ~]# cpio -icdvt < /dev/st0 > /tmp/content
# 第一个动作当中,会将磁带机内的档名列出到萤幕上面,而我们可以透过第二个动作,
# 将所有的档名通通纪录到 /tmp/content 文件去!

范例三:将磁带上的资料还原回来~
[root@linux ~]# cpio -icduv < /dev/st0 # 一般来说,使用 SCSI 介面的磁带机,代号是 /dev/st0 喔! 范例四:将 /etc 底下的所有『文件』都备份到 /root/etc.cpio 中! [root@linux ~]# find /etc -type f | cpio -o > /root/etc.cpio
# 这样就能够备份啰~您也可以将资料以 cpio -i < /root/etc.cpio # 来将资料捉出来!!!!

Monday, July 30, 2007

上善如水

 我国先秦道家学说的创立者、哲学家老子十分推崇"上善如水"。意思是说人类最美好的品行就应该如水一样。
  
  乍一看来,似乎颇为费解,但仔细咀嚼揣摩,就能领略到其含义的深刻精妙。水对我们有哪些启迪呢?

  其一,水往低处流。

  启迪我们做人,尤其是握有一定权力的人,要眼睛向下,时刻关注最基层群众的切身利益,特别是那些至今连温饱都尚未解决的群众,设身处地为他们着想,为他们排忧解难,尽快使他们摆脱贫困,步入小康。

  其二,水溶万物而不争。

  水与千千万万种物质,溶为一体,构成了人们生活中不可缺少的茶水、药水、墨水等物质,在这诸种物质的排名中,水都居于第二位。

  然而,如果没有了水,这些茶水、药水、墨水等还会存在吗?水的这种不争之德,启迪我们应该不争名不争利,将个人的价值体现在默默的奉献之中。

  其三,水随遇而安。

  无论石缝岩隙,还是沼泽碱滩,水都能顽强地生存。即便只是一滴露珠儿,它也会笑迎朝霞,熠熠闪光。

  水的这种豁达顽强的精神,启迪我们即使是处于艰苦的环境,也要安贫乐道,恪尽职守,有一分热、发一分光。

  其四,水遇寒而结为冰。

  水的三态(固态、液态、气态)变化,体现了水极大的灵活性。

  尤其是水遇寒而结为冰,更是启迪我们在越是困难的时候,越是要增强凝聚力、向心力,万众一心,精诚团结,只有这样,才能克服困难,夺取胜利。

  其五,水质透明,清澈见底。

  水的这种鲜明特性,启迪我们做人要光明磊落,襟怀坦白。"君子坦荡荡",城府深不可测者很难觅到挚友良朋。我们应做一个清纯如水的人,洁身自好,纤尘不染,永远保持健康的肌体。

  其六,水的公平。

  水是最公平的,些许倾斜都会破坏水面。因此,我们常常希望掌权者要"把一碗水端平"。公平、公正是社会文明进步的根本体现,也是我们做人做事的基本准测。只有"端平一碗水",才能赢得民心。

  水是博大精深的。

  它对我们的启迪还有许多,如"滴水穿石",启迪我们对事业的追求要锲而不舍;"千条江河归大海",启迪我们一旦认准一个目标,就要有一往无前的勇气和坚定执著的精神;"海纳百川,有容乃大",启迪我们要有恢宏的气度,博大的胸怀。水对我们的启迪是如此丰厚广博,难怪先哲要发出"上善如水"的赞叹!

  "上善如水"堪为我们的座右铭。 (《上海法治报》鲁克) 
--
========================
Xin Hu
lanxin0106@gmail.com

Wednesday, June 20, 2007

string和int间的类型转换 ZZ

*int 转换 string*
string int2str( int num)
{
if (num == 0 )
return " 0 " ;

string str = "" ;
int num_ = num > 0 ? num : - 1 * num;

while (num_)
{
str = ( char )(num_ % 10 + 48 ) + str;
num_ /= 10 ;
}

if (num < 0 )
str = " - " + str;

return str;
}
*string 转换 int
*
int str2int( string str)
{
int i,len = str.size(),num = 0 ;

i = 0 ;
if (str[ 0 ] == ' - ' )
i = 1 ;

while (i < len)
{
num = num * 10 + ( int )(str[i] - ' 0 ' );
i ++ ;
}

if (str[ 0 ] == ' - ' )
num *= - 1 ;

return num;
}

string和int间是可以自己写函数实现类型转换的,但是string和double就不太方
便了,stirng转换double可以自定义函数实现,但是,double转换string就需要使
用库函数了,如sprintf

Tuesday, June 19, 2007

STL vector容器介绍(转载)

在CSDN上看到一篇关于介绍vector的文章,觉得还不错,里面对于vector的成员函
数和简单用法介绍的还蛮清楚的,于是转过来作为备用,方便以后查找vector的一
些方法。(一下内容转自CSDN中masterlee的专栏)
  
  介绍std::vector,并且讨论它在STL中的算法和条件函数remove_if()。
  
  介绍
  这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等
操作。本文中还讨论了条件函数和函数指针在迭代算法中使用,如在 remove_if()
和for_each()中的使用。通过阅读这篇文章读者应该能够有效地使用vector容器,
而且应该不会再去使用C类型的动态数组了。
  
  Vector总览
  vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数
据结构和算法的模板类和函数库。vector之所以被认为是一个容器,是因为它能够
像容器一样存放各种类型的对象,简单地说,vector是一个能够存放任意类型的动
态数组,能够增加和压缩数据。
  为了可以使用vector,必须在你的头文件中包含下面的代码:#include
  vector属于std命名域的,因此需要通过命名限定,如下完成你的代码:
   using std::vector;
   vector vInts;
  或者连在一起,使用全名:std::vector vInts;
  建议使用全局的命名域方式:using namespace std;
  在后面的操作中全局的命名域方式会造成一些问题。vector容器提供了很多接
口,在下面的表中列出vector的成员函数和操作。
  
  Vector成员函数
  函数 表述
  c.assign(beg,end):将[beg; end)区间中的数据赋值给c。
  c.assign(n,elem):将n个elem的拷贝赋值给c。
  c.at(idx):传回索引idx所指的数据,如果idx越界,抛出out_of_range。
  c.back():传回最后一个数据,不检查这个数据是否存在。
  c.begin():传回迭代器重的可一个数据。
  c.capacity():返回容器中数据个数。
  c.clear():移除容器中所有数据。
  c.empty():判断容器是否为空。
  c.end():指向迭代器中的最后一个数据地址。
  c.erase(pos):删除pos位置的数据,传回下一个数据的位置。
  c.erase(beg,end):删除[beg,end)区间的数据,传回下一个数据的位置。
  c.front():传回地一个数据。
  get_allocator:使用构造函数返回一个拷贝。
  c.insert(pos,elem):在pos位置插入一个elem拷贝,传回新数据位置。
  c.insert(pos,n,elem):在pos位置插入n个elem数据。无返回值。
  c.insert(pos,beg,end):在pos位置插入在[beg,end)区间的数据。无返回值。
  c.max_size():返回容器中最大数据的数量。
  c.pop_back():删除最后一个数据。
  c.push_back(elem):在尾部加入一个数据。
  c.rbegin():传回一个逆向队列的第一个数据。
  c.rend():传回一个逆向队列的最后一个数据的下一个位置。
  c.resize(num):重新指定队列的长度。
  c.reserve():保留适当的容量。
  c.size():返回容器中实际数据的个数。
  c1.swap(c2):将c1和c2元素互换。
  swap(c1,c2):同上操作。
  vector c:创建一个空的vector。
  vector c1(c2):复制一个vector。
  vector c(n):创建一个vector,含有n个数据,数据均已缺省构造产生。
  vector c(n, elem):创建一个含有n个elem拷贝的vector。
  vector c(beg,end):创建一个以[beg;end)区间的vector。
  c.~ vector ():销毁所有数据,释放内存。
  
  Vector操作
  函数 描述
  operator[]:返回容器中指定位置的一个引用。
  
  创建一个vector
  vector容器提供了多种创建方法,下面介绍几种常用的。创建一个Widget类型
的空的vector对象:
  vector vWidgets;
  
  创建一个包含500个Widget类型数据的vector:
  vector vWidgets(500);
  
  创建一个包含500个Widget类型数据的vector,并且都初始化为0:
  vector vWidgets(500, Widget(0));
  
  创建一个Widget的拷贝:
  vector vWidgetsFromAnother(vWidgets);
  
  向vector添加一个数据
  vector添加数据的缺省方法是push_back()。push_back()函数表示将数据添加
到vector的尾部,并按需要来分配内存。例如:向vector中添加10个数据,需要如
下编写代码:
  for(int i= 0;i<10; i++)
   vWidgets.push_back(Widget(i));
  
  获取vector中制定位置的数据
  很多时候我们不必要知道vector里面有多少数据,vector里面的数据是动态分
配的,使用push_back()的一系列分配空间常常决定于文件或一些数据源。如果你
想知道vector存放了多少数据,你可以使用empty()。获取vector的大小,可以使
用size()。例如,如果你想获取一个vector v的大小,但不知道它是否为空,或者
已经包含了数据,如果为空想设置为-1,你可以使用下面的代码实现:
  int nSize = v.empty() ? -1 : static_cast(v.size());
  
  访问vector中的数据
  使用两种方法来访问vector。
  1、 vector::at()
  2、 vector::operator[]
  operator[]主要是为了与C语言进行兼容。它可以像C语言数组一样操作。但at
()是我们的首选,因为at()进行了边界检查,如果访问超过了 vector的范围,将
抛出一个例外。由于operator[]容易造成一些错误,所有我们很少用它,下面进行
验证一下:
  
  分析下面的代码:
  vector v;
  v.reserve(10);
  for(int i=0; i<7; i++)
   v.push_back(i);
  try
  {
   int iVal1 = v[7]; // not bounds checked - will not throw
   int iVal2 = v.at(7); // bounds checked - will throw if out of range
  }
  catch(const exception& e)
  {
   cout << e.what();
  }
  我们使用reserve()分配了10个int型的空间,但并不没有初始化。也就是说
vector容器中前7个元素已经被初始化,分别是0、1、2、 3、4、5、6;但其后三
个元素只是分配了int型空间,但是并没有被初始化。
  你可以在这个代码中尝试不同条件,观察它的结果,但是无论何时使用at(),
都是正确的。
  
  删除vector中的数据
  vector能够非常容易地添加数据,也能很方便地取出数据,同样vector提供了
erase(),pop_back(),clear()来删除数据,当你删除数据的时候,你应该知道要
删除尾部的数据,或者是删除所有数据,还是个别的数据。在考虑删除等操作之前
让我们静下来考虑一下在STL中的一些应用。
  
  Remove_if()算法
  现在我们考虑操作里面的数据。如果要使用remove_if(),我们需要在头文件
中包含如下代码::
  #include
  Remove_if()有三个参数:
  1、 iterator _First:指向第一个数据的迭代指针。
  2、 iterator _Last:指向最后一个数据的迭代指针。
  3、 predicate _Pred:一个可以对迭代操作的条件函数。
  
  条件函数
  条件函数是一个按照用户定义的条件返回是或否的结果,是最基本的函数指
针,或者是一个函数对象。这个函数对象需要支持所有的函数调用操作,重载
operator()()操作。remove_if()是通过unary_function继承下来的,允许传递数
据作为条件。
  例如,假如你想从一个vector中删除匹配的数据,如果字串中包含了一个值,
从这个值开始,从这个值结束。首先你应该建立一个数据结构来包含这些数据,类
似代码如下:
  #include
  enum findmodes
  {
   FM_INVALID = 0,
   FM_IS,
   FM_STARTSWITH,
   FM_ENDSWITH,
   FM_CONTAINS
  };
  typedef struct tagFindStr
  {
   UINT iMode;
   CString szMatchStr;
  }FindStr;
  typedef FindStr* LPFINDSTR;
  
  然后处理条件判断:
  class FindMatchingString : public std::unary_function
  {
  public:
  
   FindMatchingString(const LPFINDSTR lpFS) : m_lpFS(lpFS) {}
   bool operator()(CString& szStringToCompare) const
   {
   bool retVal = false;
   switch(m_lpFS->iMode)
   {
   case FM_IS:
   {
   retVal = (szStringToCompare == m_lpFDD->szMatchStr);
   break;
   }
   case FM_STARTSWITH:
   {
   retVal = (szStringToCompare.Left(m_lpFDD->szMatchStr.GetLength())
   == m_lpFDD->szWindowTitle);
   break;
   }
   case FM_ENDSWITH:
   {
   retVal = (szStringToCompare.Right(m_lpFDD->szMatchStr.GetLength())
  
   == m_lpFDD->szMatchStr);
   break;
   }
   case FM_CONTAINS:
   {
   retVal = (szStringToCompare.Find(m_lpFDD->szMatchStr) != -1);
   break;
   }
   }
   return retVal;
   }
  private:
   LPFINDSTR m_lpFS;
  };
  通过这个操作你可以从vector中有效地删除数据:
  // remove all strings containing the value of
  // szRemove from vector vs.
  FindStr fs;
  fs.iMode = FM_CONTAINS;
  fs.szMatchStr = szRemove;
  vs.erase(std::remove_if(vs.begin(), vs.end(),
FindMatchingString(&fs)), vs.end());
  
  Remove_if()能做什么?
  你可能会疑惑,对于上面那个例子在调用remove_if()的时候还要使用erase()
呢?这是因为大家并不熟悉STL中的算法。Remove (),remove_if()等所有的移出操
作都是建立在一个迭代范围上的,那么不能操作容器中的数据。所以在使用
remove_if(),实际上操作的时容器里数据的上面的。思考上面的例子:
  1、 szRemove = "o".
  2、 vs的结果,说明remove_if()实际上是根据条件对迭代地址进行了修改,
在数据的后面存在一些残余的数据,那些需要删除的数据。剩下的数据的位置可能
不是原来的数据,但他们是不知道的。
  调用erase()来删除那些残余的数据。注意上面例子中通过erase()删除
remove_if()的结果和vs.enc()范围的数据。
  
  压缩一个臃肿的vector
  很多时候大量的删除数据,或者通过使用reserve(),结果vector的空间远远
大于实际需要的。所有需要压缩vector到它实际的大小。 resize()能够增加
vector的大小。Clear()仅仅能够改变缓存的大小,所有的这些对于vector释放内
存等九非常重要了。如何来解决这些问题呢,让我们来操作一下。
  我们可以通过一个vector创建另一个vector。让我们看看这将发生什么。假定
我们已经有一个vector v,它的内存大小为1000,当我们调用size()的时候,它的
大小仅为7。我们浪费了大量的内存。让我们在它的基础上创建一个vector。
  std::vector vNew(v);
  cout << vNew.capacity();
  vNew.capacity()返回的是7。这说明新创建的只是根据实际大小来分配的空
间。现在我们不想释放v,因为我们要在其它地方用到它,我们可以使用swap()将v
和vNew互相交换一下?
   vNew.swap(v);
   cout << vNew.capacity();
   cout << v.capacity();
  有趣的是:vNew.capacity()是1000,而v.capacity()是7。
  现在是达到我的目的了,但是并不是很好的解决方法,我们可以像下面这么写:
   std::vector(v).swap(v);
  你可以看到我们做了什么?我们创建了一个临时变量代替那个命名的,然后使
用swap(),这样我们就去掉了不必要的空间,得到实际大小的v。
  
  结论
  我希望这个文档可以给那些使用STL vector容器的开发者很有价值的参考。我
也希望通过阅读这篇文章你可以放心地使用vector来代替C语言中的数据了。
  
  参考
  Plauger, P.J. Standard C++ Library Reference. February, 2003. MSDN.
  Schildt, Herbert. C++ from the Ground Up, Second Edition. Berkeley:
1998.
  Sutter, Herb. More Exceptional C++. Indianapolis: 2002.

Another reject

from UNC(The University of North Carolina at Chapel Hill), received
several days ago, although I have withdrawn the application several
months ago :-) . The following is the details:

Dear Xin,

Your application for admission to graduate study at The University of
North Carolina at Chapel Hill has now been reviewed by The Graduate
School and the Department of Mathematics. We regret being unable to
offer you admission. Although your qualifications appear to be above our
usual minimum standards for admission, the number of highly qualified
applicants in your area of interest exceeds our facilities to train them
adequately. Consequently, we must limit new admissions rather severely.

We appreciate your interest in The University of North Carolina at
Chapel Hill and the opportunity you have given us to consider your
application. We are sorry we could not select you for admission and wish
you success in finding a suitable situation in which to continue your
education.

Sincerely yours,

Linda Dykstra
Dean of the Graduate School

Monday, June 18, 2007

C++文件操作 ZZ

在C++中,有一个stream这个类,所有的I/O都以这个"流"类为基础的,包括我
们要认识的文件I/O,stream这个类有两个重要的运算符:

1、插入器(<<)
  向流输出数据。比如说系统有一个默认的标准输出流(cout),一般情况下就是
指的显示器,所以,cout<<"Write Stdout"<<'\n';就表示把字符串"Write
Stdout"和换行字符('\n')输出到标准输出流。

2、析取器(>>)
  从流中输入数据。比如说系统有一个默认的标准输入流(cin),一般情况下就
是指的键盘,所以,cin>>x;就表示从标准输入流中读取一个指定类型(即变量x的
类型)的数据。

  在C++中,对文件的操作是通过stream的子类fstream(file stream)来实现
的,所以,要用这种方式操作文件,就必须加入头文件fstream.h。下面就把此类
的文件操作过程一一道来。

一、打开文件
  在fstream类中,有一个成员函数open(),就是用来打开文件的,其原型是:

void yWXz(const char* filename,int mode,int access);

参数:

filename:  要打开的文件名
mode:    要打开文件的方式
access:   打开文件的属性
打开文件的方式在类ios(是所有流式I/O类的基类)中定义,常用的值如下:

ios::app:   以追加的方式打开文件
ios::ate:   文件打开后定位到文件尾,ios:app就包含有此属性
ios::binary:  以二进制方式打开文件,缺省的方式是文本方式。两种方式的区
别见前文
ios::in:    文件以输入方式打开
ios::out:   文件以输出方式打开
ios::nocreate: 不建立文件,所以文件不存在时打开失败 
ios::noreplace:不覆盖文件,所以打开文件时如果文件存在失败
ios::trunc:  如果文件存在,把文件长度设为0
  可以用"或"把以上属性连接起来,如ios::out|ios::binary

  打开文件的属性取值是:

0:普通文件,打开访问
1:只读文件
2:隐含文件
4:系统文件
  可以用"或"或者"+"把以上属性连接起来 ,如3或1|2就是以只读和隐含属性打
开文件。

  例如:以二进制输入方式打开文件c:\config.sys

  fstream file1;
  file1.open("c:\\config.sys",ios::binary|ios::in,0);

  如果open函数只有文件名一个参数,则是以读/写普通文件打开,即:

  file1.open("c:\\config.sys");<=>file1.open("c:\\config.sys",
ios::in|ios::out,0);

  另外,fstream还有和open()一样的构造函数,对于上例,在定义的时侯就可
以打开文件了:

  fstream file1("c:\\config.sys");

  特别提出的是,fstream有两个子类:ifstream(input file stream)和
ofstream(outpu file stream),ifstream默认以输入方式打开文件,而ofstream
默认以输出方式打开文件。

  ifstream file2("c:\\pdos.def");//以输入方式打开文件
  ofstream file3("c:\\x.123");//以输出方式打开文件

  所以,在实际应用中,根据需要的不同,选择不同的类来定义:如果想以输入
方式打开,就用ifstream来定义;如果想以输出方式打开,就用 ofstream来定
义;如果想以输入/输出方式来打开,就用fstream来定义。

二、关闭文件
  打开的文件使用完成后一定要关闭,fstream提供了成员函数close()来完成此
操作,如:file1.close();就把file1相连的文件关闭。

三、读写文件
  读写文件分为文本文件和二进制文件的读取,对于文本文件的读取比较简单,
用插入器和析取器就可以了;而对于二进制的读取就要复杂些,下要就详细的介绍
这两种方式

  1、文本文件的读写
  文本文件的读写很简单:用插入器(<<)向文件输出;用析取器(>>)从文件输
入。假设file1是以输入方式打开, file2以输出打开。示例如下:

  file2<<"I Love You";//向文件写入字符串"I Love You"
  int i;
  file1>>i;//从文件输入一个整数值。

  这种方式还有一种简单的格式化能力,比如可以指定输出为16进制等等,具体
的格式有以下一些

操纵符 功能 输入/输出
dec 格式化为十进制数值数据 输入和输出
endl 输出一个换行符并刷新此流 输出
ends 输出一个空字符 输出
hex 格式化为十六进制数值数据 输入和输出
oct 格式化为八进制数值数据 输入和输出
setpxecision(int p) 设置浮点数的精度位数 输出

  比如要把123当作十六进制输出:file1<<<123;要把3.1415926以5位精度输
出:FILE1<< <3.1415926。

  2、二进制文件的读写
①put()
  put()函数向流写入一个字符,其原型是ofstream &put(char ch),使用也比
较简单,如file1.put('c');就是向流写一个字符'c'。

②get()
  get()函数比较灵活,有3种常用的重载形式:

  一种就是和put()对应的形式:ifstream &get(char &ch);功能是从流中读取
一个字符,结果保存在引用ch中,如果到文件尾,返回空字符。如file2.get(x);
表示从文件中读取一个字符,并把读取的字符保存在x中。

  另一种重载形式的原型是: int get();这种形式是从流中返回一个字符,如
果到达文件尾,返回EOF,如x=file2.get();和上例功能是一样的。

  还有一种形式的原型是:ifstream &get(char *buf,int num,char
delim='\n');这种形式把字符读入由 buf 指向的数组,直到读入了 num 个字符
或遇到了由 delim 指定的字符,如果没使用 delim 这个参数,将使用缺省值换行
符'\n'。例如:

  file2.get(str1,127,'A');//从文件中读取字符到字符串str1,当遇到字符
'A'或读取了127个字符时终止。

③读写数据块
  要读写二进制数据块,使用成员函数read()和write()成员函数,它们原型如下:

    read(unsigned char *buf,int num);
    write(const unsigned char *buf,int num);

  read()从文件中读取 num 个字符到 buf 指向的缓存中,如果在还未读入 num
个字符时就到了文件尾,可以用成员函数 int gcount();来取得实际读取的字符
数;而 write() 从buf 指向的缓存写 num 个字符到文件中,值得注意的是缓存的
类型是 unsigned char *,有时可能需要类型转换。

例:

    unsigned char str1[]="I Love You";
    int n[5];
    ifstream in("xxx.xxx");
    ofstream out("yyy.yyy");
    out.write(str1,strlen(str1));//把字符串str1全部写到yyy.yyy中
    in.read((unsigned char*)n,sizeof(n));//从xxx.xxx中读取指定个整
数,注意类型转换
    in.close();out.close();

四、检测EOF
  成员函数eof()用来检测是否到达文件尾,如果到达文件尾返回非0值,否则返
回0。原型是int eof();

例:  if(in.eof())ShowMessage("已经到达文件尾!");

五、文件定位
  和C的文件操作方式不同的是,C++ I/O系统管理两个与一个文件相联系的指
针。一个是读指针,它说明输入操作在文件中的位置;另一个是写指针,它下次写
操作的位置。每次执行输入或输出时,相应的指针自动变化。所以,C++的文件定
位分为读位置和写位置的定位,对应的成员函数是 seekg()和 seekp(),seekg()
是设置读位置,seekp是设置写位置。它们最通用的形式如下:

    istream &seekg(streamoff offset,seek_dir origin);
    ostream &seekp(streamoff offset,seek_dir origin);

  streamoff定义于 iostream.h 中,定义有偏移量 offset 所能取得的最大
值,seek_dir 表示移动的基准位置,是一个有以下值的枚举:

ios::beg:  文件开头
ios::cur:  文件当前位置
ios::end:  文件结尾
  这两个函数一般用于二进制文件,因为文本文件会因为系统对字符的解释而可
能与预想的值不同。

例:

     file1.seekg(1234,ios::cur);//把文件的读指针从当前位置向后移1234
个字节
     file2.seekp(1234,ios::beg);//把文件的写指针从文件开头向后移1234
个字节

在BCB中也提供了文件操作的函数,这些函数的功能和前面所介绍的大致相同,但
这类函数和BCB关系紧密,能使用BCB中的AnsiString等数据类型,在BCB中用这种
方式的文件操作是最方便的,下面我就把这种文件操作详细介绍。

  在BCB提供的这组文件操作函数中,可分为三种类型,就是:1、文件名函数,
2、文件管理函数;3、文件I/O函数。

VISA cleared

and also received last weekend...

Monday, June 04, 2007

fixed helicopter test-fly

Perform excellent, but entangled with a kite. The tail-airscrew was lost. Fortunately, I found it this morning. Hehe~~~ So I need more practice...

示范反手后场高远球等 zz

反手后场高远球
http://www.inforknow.com/viewthread.php?tid=927&extra=page%3D1
反手后场高吊球
http://www.inforknow.com/viewthread.php?tid=926&extra=page%3D1
羽毛球跳杀动作分解
http://www.jokedm.com/v/78957c6bbe82ec1096fd57b9dd6d5be0.html

helicopter fixed

On Saturday. Because there is no shop which sells the broken fittings, I had to fix it by myself.

Today, I order DC from joyo, Powershot A 570 IS. Thanks mdf and Guang. When it arrive, I will put photo of my fixed helicopter (electric tool, hehe).

Sunday, June 03, 2007

summer palace revisited

last day. Visiting almost every scenic spot, including 17-hole bridge, foguang ge, Suzhou street. We really had a good time, enjoying the view with friends~~~
but without DC, so no photo...

Friday, June 01, 2007

RMVB AVI RM VCD DVD FC6 ZZ

本方法在 Fedora Core 6 下测试通过:
(注意: 首先确定你能连接 internet)


第一部分:播放器安装

1. 安装 liva 源
# rpm -ivh http://rpm.livna.org/livna-release-6.rpm
# rpm --import http://rpm.livna.org/RPM-LIVNA-GPG-KEY

2. 卸载 totem
# yum -y remove totem

3. 安装 totem-xine, vlc, mplayer
# yum -y install totem-xine vlc xine-lib-extras-nonfree totem-xine-mozplugin mplayer-gui
4. 安装解码器
下载解码器,地址:
http://www4.mplayerhq.hu/MPlayer/rel...061022.tar.bz2
# tar jxvf all-20061022.tar.bz2
# mkdir /usr/lib/codecs
# mv all-20061022/* /usr/lib/codecs
# chmod 755 /usr/lib/codecs/*
# ln -s /usr/lib/codecs /usr/local/lib/codecs (这个给 mplayer 用)
(注:如果你已经安装了 codec,那就只需添加链接就可了)

5. 测试
a. 选择 应用程序 -> 影音 -> 电影播放机
看看能不能播放 real 格式,quicktime 格式的视频
b. 选择 应用程序 -> 影音 -> VLC Media Player
看看播放 dvd, vcd 能行不?
c. 浏览器支持
使用 mozilla 或 firefox 打开
http://www.apple.com/trailers/
选择一个视频就可以用 totem-xine 来播放了。

6. 安装 RealPlayer
安装了linux版本的RealPlayer,播放RMVB,有图象无声音。解决办法,安装最新的 nightly-build 版本:
a. 安装 RealPlayer
下载地址:
http://forms.helixcommunity.org/heli...alplay-current
# rpm -e RealPlayer
# exit (返回普通用户)
$ rm ~/.realplayerrc
# su (再 su 到 root)
# rpm -ivh RealPlayer*

b. 测试播放 rmvb
i. 本地视频播放测试
ii. 浏览器支持
重启 firefox 或 mozilla 打开:
http://www.npr.org/
点击“Hourly Newscast“
然后选择总是使用 /usr/bin/realplay 打开。
这就激活 RealPlayer 的 mozilla, firefox 插件了。

顺便说一个,如果你开着桌面效果(即 compiz)用 RealPlayer,你得把使用 xvideo 的勾去掉
如果在宽屏下使用 mplayer,你得修改
/etc/mplayer/mplayer.conf
把第 63 行前面的 # 去掉。
才能显示正常。

测试在线播放以及下载视频的网站:
http://www.redhat.com/truthhappens/videos/ourfilms.html
http://www.redhat.com/truthhappens/shows/
http://www.apple.com/trailers/
经过上面的安装后,这些视频都可以直接在 firefox 中播放。

Wednesday, May 30, 2007

VISA checked

this morning. After several questions:

1 what do you study?

2. Can I see your offerr latterr?

3. Can I see your resume and study plan?

4. your englissh name is Simon?

so have to wait about 3 weeks to obtain my visa. so bad, but not too bad. Hope everything goes well...

Tuesday, May 29, 2007

texlive2007在fc6下的安装 ZZ

以前一直用的是tetex,已经配置很好了,但是由于tetex不再有人维护,所以转向texlive。按照网上的资料安装了几遍没有成功,贼心不死,今天下午安装成功,欢迎大家测试。
1.准备工作:
#yum remove tetex* (卸载原来的tetex文件。)
下载texlive2007-live (注意:不要下载in文件。)
挂载iso文件:mount -t iso9660 -o loop /home/yourname/Desktop/texlive2007-live-20070212.iso /media/disk-3/
yourname替换成你的用户名称。
./install-tl.sh
选择full
选择安装CJK语言
安装完毕。
修改环境变量:
#vim /root/.bash_profile
修改path为:
PATH=/usr/local/texlive/2007/bin/i386-linux:$PATH:$HOME/bin
注销然后登录使刚刚设置的环境生效。
在用户自己的目录下同样的配置。
这两步很重要,我以前屡次配置不成功就是因为环境变量没有设置好。
2、你的字体所在目录复制字体到/usr/local/texlive/2007/texmf/fonts/truetype/chinese目录下
#cp simfang.ttf simhei.ttf simkai.ttf simsun.ttf simli.ttf /usr/share/texmf/fonts/truetype/chinese/
truetype/chinese目录自己新建。
3、安装CJK
http://cjk.ffii.org/ 下载 cjk-4.7.0.tar.gz
#cd /usr/local/texlive/2007/texmf/tex/latex/
#mkdir CJK
#tar zxvf cjk-4.7.0.tar.gz
把当前cjk-4.7.0中的文件复制到 /usr/local/texlive/2007/texmf/tex/latex/CJK

4 、安装字体生成文件gbkfonts
#cp gbkfonts-linux-0.3.tar.bz2 /usr/local/lib
#cd /use/local/lib
#tar zxvf gbkfonts-linux-0.3.tar.bz2
#rm -fr gbkfonts-linux-0.3.tar.gz
#cd gbkfonts-linux-0.3
#cp gbkfonts /usr/local/bin
#cp appendconf /usr/local/bin
#cp go /usr/local/bin

修改/usr/local/bin/go文件
#cd /usr/local/bin
#vim go
修改下面这一段
gbkfonts ${opts[*]} $dir/simsun.ttf song
gbkfonts ${opts[*]} $dir/simkai.ttf kai
gbkfonts ${opts[*]} $dir/simhei.ttf hei
gbkfonts ${opts[*]} $dir/simfang.ttf fs
gbkfonts ${opts[*]} $dir/fzssjw.ttf fzss
gbkfonts ${opts[*]} $dir/fzs3jw.ttf fzs3
gbkfonts ${opts[*]} $dir/fzxkjw.ttf fzxk
gbkfonts ${opts[*]} $dir/fznbsjw.ttf fznbs
gbkfonts ${opts[*]} $dir/fzfsjw.ttf fzfs
gbkfonts ${opts[*]} $dir/fzktjw.ttf fzkt
gbkfonts ${opts[*]} $dir/fzs3jw.ttf fzs3


将不用的行用#注释掉。我只要前面四个,把后面的注释掉就可以了。
接下来开始生成字体
#cd /usr/share/texmf
#go fonts/truetype/chinese

#cd /usr/local/texlive/2007/texmf/dvips/config
#vim config.ps

o |lpr
前加%注释掉,以及加上这幺一行
p +cjk.map
这样就能使用dvips生成ps文件了。

5.解决不能转换pdf的问题:
#cd /usr/local/texlive/2007/texmf/
#cp cjk.map /usr/local/texlive/2007/texmf/fonts/map/dvips/tetex/
# cd /usr/local/texlive/2007/texmf/web2c/
#vim updmap.cfg
在最后面加上一行:Map cjk.map

6、更新LaTeX系统
使用以下命令更新LaTeX的数据库,使其可以使用新增加的功能。注意:updmap命令后的参数一定要写
#updmap --enable Map=cjk.map
#texhash
#updmap
由于此时是root用户,从终端的输出上可以看出,该命令在/root/目录下生成了.texlive2007目录,以及下级目录,.texmf-var 和.texmf-config两个目录,并且分别向里面添加了一个文件。至此,root用户的latex中文环境就配置完毕了。

对于普通用户,则还需要进行同样的过程:
首先,在终端中输入exit回到普通用户shell,切换到/usr/local/texlive/2007/texmf下,同样输入以上的两个命令:
$updmap --enable Map=cjk.map
$texhash
$updmap
这时,从终端的输出可以看到,在/home/yourname/目录下也生成了.texlive2007目录,以及下级目录,.texmf-var和. texmf-config两个目录,并且分别向里面添加了一个文件。至此,普通用户的latex中文环境也配置完毕了。
把原来的texmf-var和.texmf-config两个目录最好删除。
$rm -fr .texmf-var
$rm -fr .texmf-config
这两个文件是隐藏文件。
7.解决pdf文件不能复制粘贴:
#cd /usr/local/texlive/2007/texmf/fonts/map/dvipdfm/dvipdfmx
#vim cid-x.map
加上 :
gbksong@UGBK@ UniGB-UCS2-H :0:simsun.ttf
gbksongsl@UGBK@ UniGB-UCS2-H :0:simsun.ttf -s .167
gbkfs@UGBK@ UniGB-UCS2-H :0:simfang.ttf
gbkfssl@UGBK@ UniGB-UCS2-H :0:simfang.ttf -s .167
gbkhei@UGBK@ UniGB-UCS2-H :0:simhei.ttf
gbkheisl@UGBK@ UniGB-UCS2-H :0:simhei.ttf -s .167
gbkkai@UGBK@ UniGB-UCS2-H :0:simkai.ttf
gbkkaisl@UGBK@ UniGB-UCS2-H :0:simkai.ttf -s .167

What's NDSlite?

(任天堂的掌上遊戲機).







recommendating a website

which is also listed in my link list on the right....
http://xkcd.com/
xkcd - A webcomic of romance, sarcasm, math, and language.
have fun and enjoy~~~

defense passed

today noon at 1:00. Special thanks to Prof. Tang for his careful and patient guidance of my graduate study. Below is the slide of my defense. On Thu. I will apply for my VISA to US. Good luck to myself and be confident :-)

Monday, May 21, 2007

Wuling Mountain (continued)






Colloquium to be attented

工学院系列报告
发布时间:2007-5-21 13:55:17  点击次数:14
演 讲 者:Mohamed Gad-el-Hak, Virginia Commonwealth University
Richmond, Virginia, U.S.A.
主办单位:北京大学工学院
地 点:北京大学力学大楼434会议室

第一讲:2007年5月24日(周四)下午3:00—4:00
题 目: FLOW PHYSICS IN MICRO AND NANODEVICES
主持人:工学院吴介之教授

第二讲:2007年5月25日(周五)下午3:00—4:00
题 目: THE TAMING OF THE SHREW: WHY IS IT SO DIFFICULT TO CONTROL TURBULENCE?
主持人:工学院院长陈十一教授

第三讲:2007年5月25日(周五)下午4:00—5:00
题 目: THE ART AND SCIENCE OF LARGE-SCALE DISASTERS
主持人:工学院院长陈十一教授

BIOGRAPHICAL SKETCHMohamed Gad-el-Hak received his B.Sc. (summa cum laude) in mechanical engineering from Ain Shams University in 1966 and his Ph.D. in fluid mechanics from the Johns Hopkins University in 1973. Gad-el-Hak has since taught and conducted research at the University of Southern California, University of Virginia, University of Notre Dame, Institut National Polytechnique de Grenoble, Université de Poitiers, Friedrich-Alexander-Universität Erlangen-Nürnberg, Technische Universität München and Technische Universität Berlin, and has lectured extensively at seminars in the United States and overseas. Dr. Gad-el-Hak is currently the Inez Caudill Eminent Professor of Biomedical Engineering and Chair of Mechanical Engineering at Virginia Commonwealth University.Dr. Gad-el-Hak has published over 460 articles, authored/edited 18 books and conference proceedings, and presented 255 invited lectures. He is the author of the book "Flow Control: Passive, Active, and Reactive Flow Management," and editor of the books "Frontiers in Experimental Fluid Mechanics," "Advances in Fluid Mechanics Measurements," "Flow Control: Fundamentals and Practices," "The MEMS Handbook" (first and second editions), "Transition and Turbulence Control," and "Large-Scale Disasters: Prediction, Control and Mitigation."Professor Gad-el-Hak is a fellow of the American Physical Society, the American Society of Mechanical Engineers, and the American Academy of Mechanics.In 1998, Professor Gad-el-Hak was named the Fourteenth ASME Freeman Scholar. In 1999, Gad-el-Hak was awarded the prestigious Alexander von Humboldt Prize, Germany's highest research award for senior U.S. scientists and scholars in all disciplines. In 2002, Gad-el-Hak was named ASME Distinguished Lecturer, as well as inducted into the Johns Hopkins University Society of Scholars.

1. FLOW PHYSICS IN MICRO AND NANODEVICES

Interest in microelectromechanical systems (MEMS) has experienced explosive growth during the past few years. Such small devices typically have characteristic size ranging from 1 mm down to 1 micron, and may include sensors, actuators, motors, pumps, turbines, gears, ducts and valves. Microdevices often involve mass, momentum and energy transport. Modeling gas and liquid flows through MEMS may necessitate including slip, rarefaction, compressibility, intermolecular forces and other unconventional effects. In this presentation, I shall provide a methodical approach to flow modeling for a broad variety of microdevices. The continuum-based Navier-Stokes equations-with either the traditional no-slip or slip-flow boundary conditions-work only for a limited range of Knudsen numbers above which alternative models must be sought. These include molecular dynamics (MD), Boltzmann equation, Direct Simulation Monte Carlo (DSMC), and other deterministic/probabilistic molecular models. The present talk will broadly survey available methodologies to model and compute transport phenomena within microdevices.

2. THE TAMING OF THE SHREW: WHY IS IT SO DIFFICULT TO CONTROL TURBULENCE?

Considering the extreme complexity of the turbulence problem in general and the unattainability of first-principles analytical solutions in particular, it is not surprising that controlling a turbulent flow remains a challenging task, mired in empiricism and unfulfilled promises and aspirations. Brute force suppression, or taming, of turbulence via active control strategies is always possible, but the penalty for doing so often exceeds any potential savings. The artifice is to achieve a desired effect with minimum energy expenditure. Spurred by the recent developments in chaos control, microfabrication and neural networks, efficient reactive control of turbulent flows, where the control input is optimally adjusted based on feedforward or feedback measurements, is now in the realm of the possible for future practical devices. But regardless of how the problem is approached, combating turbulence is always as arduous as the taming of the shrew. The former task will be emphasized during the oral presentation, but for this abstract we reflect on a short verse from the latter.

From William Shakespeare's The Taming of the Shrew.
Curtis (Petruchio's servant, in charge of his country house): Is she so hot a shrew as she's reported?
Grumio (Petruchio's personal lackey): She was, good Curtis, before this frost. But thou know'st winter tames man, woman, and beast; for it hath tamed my old master, and my new mistress, and myself, fellow Curtis.


3. THE ART AND SCIENCE OF LARGE-SCALE DISASTERS

Large-scale disasters adversely affect considerable number of people, devastate sizable geographical area, and tax the resources of local communities and central governments. Disasters can naturally occur, but humans can also cause their share of devastation. There is also the possibility of anthropogenic calamity; human's actions causing a natural disaster to become more damaging than it would otherwise. The art and science of large-scale disasters aim at better prepare scientists, engineers, first responders, and above all politicians to deal with manmade and natural disasters. The last annus horribilis in particular has shown the importance of being prepared for large-scale catastrophes, and how the world can get together to help alleviate the resulting pain and suffering. In this talk, both the art and science of predicting, preventing and mitigating natural and manmade disasters are broadly discussed. The laws of nature govern the evolution of any disaster. In some cases, as for example weather-related disasters, those first-principles laws could be written in the form of field equations, but exact solutions of these often nonlinear differential equations are impossible to obtain particularly for turbulent flows, and heuristic models together with intensive use of supercomputers are necessary to proceed. In other cases, as for example earthquakes, the precise laws are not even known and prediction becomes more or less a black art. Management of any type of disaster is more art than science. Nevertheless, much can be done to alleviate the resulting pain and suffering.

Sunday, May 20, 2007

Colorful weekend

Saturday PKU cup of badmintion competition
Although our team did not win even one game, we have done our best. More important, I enjoyed myselved a lot during the competition and have made many friends by playing badmintion.
Sunday Tour to Wuling Mountain
no need to say even one word. Let's pictures tell you our story ;-)




First rejection letter

from Columbia University. It's too weird that although I have withdrawn my application to this Univ as early as, I think, early March, this Univ. still stick to processing my material and sending me a rejection. Maybe it's only for her dignity or 'face' in Chinese. The following is the full text:

Dear Xin:

After careful evaluation of your application for the Fall 2007 term to Columbia University Fu Foundation School of Engineering and Applied Science, the Committee on Admissions regrets to inform you that your application for graduate study has not been approved.

Admission to Columbia University Foundation School of Engineering and Applied Science is highly selective. Unfortunately, we cannot accommodate the full number of talented applicants who apply each year.

The time and effort you spent in preparing your application and the interest you have demonstrated is very appreciated. The Committee wishes you success in your future educational and professional endeavors.

Sincerely,

***

Wednesday, May 16, 2007

good news today

one tough problem solved today, so I can try kawasaki badminton shoes. Victor shoes suck!!!

Monday, May 14, 2007

Bldg 46 talks to Bldg 47

WLC20


one life left

According to an unconfirmed news, one girl from Tsinghua Univ. killed herself yesterday. How grateful~~~bless her, bless her family... wish her lead a happy life in heaven.

Colloquium attented

5月14日工学院力学与空天技术系学术报告

题目一: Pressing Issues in Reliability and Durability of Aerospace Composites and Modeling Strategy
题目二: Direct Multiscale modeling for Coupled Multiple Damage Evolution in Structural Composites
报告人: Dr. Qingda Yang (杨庆大)
Dept. Mechanical & Aerospace Engineering, University of Miami

主持人:苏先樾 教授
时 间:5月14日(周一)下午2:30
地 点:力学楼434会议室

欢迎广大师生光临!要求力学系没课的研究生必须参加。
联系人:刘才山,62756177

EDUCATION:
Ph. D. University of Michigan, Ann Arbor, Michigan, 2000
M.S. Zhejiang University, Hangzhou, P. R. China, 1994
B. S. Zhejiang University, Hangzhou, P.R. China, 1991
RESEARCH:
Multi-scale, multidisciplinary failure/damage analysis of engineering and biological materials, linear and nonlinear fracture mechanics, structural composite design and analysis; nonlinear fluid-structure interaction.
EXPERIENCE:
2006-present: Assistant Professor, University of Miami
2000-2006: Member of Technical Staff,Rockwell Science Center (RSC)
2000 Spring: Postdoctoral research fellow, University of Michigan (Ann Arbor)
1994-1996: Research Engineer, Institute of Special Engineering Mechanics, Zhejiang University
HONORS:
1) Best IR&D Project Award, Division of Materials Technology, RSC, 2005.
2) Purple Award for excellent performance in a DUST program, RSC, 2004.
3) Golden Award for excellent performance an IR&D program, RSC, 2001.
4) Doris Caddell Award for outstanding student research achievements, Dept. MEAM, University of Michigan, 2000.
5) Ivor K. McIvor Award for outstanding scholastic performance in applied mechanics, College of Engineering, University of Michigan, 1999.
6) A run-up for Alan Gent Best Student Paper Award in the 22nd Annual Meeting of Adhesion Society, 1999.
ABSTRACT
The ever-increasing fuel cost has driven aerospace industry to use more extensively fiber reinforce composites (FRCs) in replace of traditionally used metals. FRCs have long been advocated as excellent alternatives to metals that can offer major weight-savings (efficiency), better damage tolerance (longer service time with less maintenance), stronger resistance to environmental attacks (endurance), and more flexibility in component design. However, despite a huge body of literature on composite studies some key issues remain unresolved, with the most critical ones being 1) lack of proven test methodologies, 2) no reliable durability assessment techniques, and 3) no established certification procedures to satisfy governmental regulation authorities. The primary cause of such significant shortfalls is the lack of understanding of the interplay among the multiple damage processes (matrix cracking, matrix/fiber shear splitting, delamination, local fiber rupture or kinking, etc.) that co-evolve in response to environmental changes and external loading. These damage modes occur in various materials scales at different load levels and are strongly coupled to each other. It is this strongly coupled nonlinear damage evolution that dominates the macroscopic composite properties. To achieve realistic damage tolerance design, the key question of how damage transfers from a lower level scale to a higher one has to be answered. Neither traditional continuum mechanics based composite theories nor micro-mechanics based models are likely to meet the challenge because they cannot address the full spectrum of damage modes occurring at various materials and structural scales. There is an urgent demand from aerospace industry for new approaches that encompass a multi-scale, multi-disciplinary methodology to address the multiple damage evolution in a unified self-consistent way, upon which a realistic damage tolerance design methodology can be established.
In first part of this two-session presentation, the current start-of-art design in composite materials will be reviewed. Focuses will be on the recently developed/developing advanced PMCs and CMCs with 3D integral features. This will be followed by a discussion of the material length scale issues in FRCs and their close relation to various damage modes. Major challenges that must be resolved to achieve realistic damage tolerance design will be highlighted. Existing analytical and computational models will be briefly reviewed and their pros and cons discussed.
In the second part of the presentation, a multi-scale approach the presenter has been developing in an effort to address the coupled damage evolution in aerospace composite materials will then be introduced. The necessity of using nonlinear fracture mechanics models and seeking explicit representation of discrete damage modes will be emphasized and strategies of how to implement explicitly such damage models into standard simulation tools will be presented. Applications of the approach to two common classes of aerospace FRCs, i.e., textile composites and laminate composites will be presented and discussed. It will be demonstrated that with this approach the nonlinear coupling among different damage/fracture modes becomes a nature outcome of the analysis, and results obtained for some important composite problems are far more superior than those obtained using existing methods. For textile composites wherein fiber architecture (interlacing pattern) plays a key role in mechanical performance, a scheme called Binary Model (BM) is developed to explicitly include the spatial fiber tow architecture into the formulation. Failure prediction of BM is achieved through the use of micromechanics-based gage-averaging scheme. The BM formulation and gage-averaging scheme and their successful application to several textile composites will be presented. Finally, future improvement of the multi-scale approach and its possible extension to other engineering and biological materials shall also be discussed before the presentation is concluded.

Sunday, May 13, 2007

One Wrld, One Dream.

同一个世界,同一个梦想???
一个世界一场梦???

Thursday, May 10, 2007

什么是单反相机 ZZ

我们常常听人说“单反相机”,单反究竟是什么呢?单反就是指单镜头反光,即SLR(Single Lens Reflex),这是当今最流行的取景系统,大多数35mm照相机都采用这种取景器。在这种系统中,反光镜和棱镜的独到设计使得摄影者可以从取景器中直接 观察到通过镜头的影像。因此,可以准确地看见胶片即将“看见”的相同影像。该系统的心脏是一块活动的反光镜(如图浅蓝色部分),它呈45°角安放在胶片平 面的前面。进入镜头的光线(如图红色光路)由反光镜向上反射到一块毛玻璃上。早期的SLR照相机必须以腰平的方式把握照相机并俯视毛玻璃取景。毛玻璃上的 影像虽然是正立的,但左右是颠倒的。为了校正这个缺陷,现在的眼平式SLR照相机在毛玻璃的上方安装了一个五棱镜。这种棱镜将光线多次反射改变光路,将影 像其送至目镜,这时地影像就是上下正立且左右校正的了。取景时,进入照相机的大部分光线都被反光镜向上反射到五棱镜,几乎所有SLR照相机的快门都直接位 于胶片的前面(由于这种快门位于胶片平面,因而称作焦平面快门),取景时,快门闭合,没有光线到达胶片。当按下快门按钮时,反光镜迅速向上翻起让开光路, 同时快门打开,于是光线到达胶片,完成拍摄。然后,大多数照相机中的反光镜会立即复位。
反光镜的这一必要的翻起动作同时也带来了一些其他问题:
一、拍摄照片的瞬间,取景器会被挡住。由于被遮挡的时间只是刹那间的事情,因此这对于立即复位的反光镜来说并不是什么主要问题。但是,又引出了一些偶然性问题。例如,在使用频闪光拍摄时,将不能通过取景器看到频闪装置是否闪光正常。
二、反光镜运动的噪声。这在需要安静的场所这可能会成为重要问题。由于测距取景式照相机中没有突然阻挡光路的移动反光镜,所以不会产生这种噪声。
三、相机的震动,即由反光镜的翻起动作所造成的照相机整体的运动。假设用1/500秒的快门速度进行拍摄,那么不必担心。这种震动不至被察觉。但是,如果 以较低的快门速度拍摄一幅精确照片的话,比如在微弱的光线下使用远摄镜头进行拍摄时,这种震动对成像就可能很成问题。
除此之外,使用SLR取景还存在另一个问题。比如我们想使用f/32这样的小光圈进行拍摄,而光圈f/32允许进入镜头的光线是非常微弱的,这会导致取景器中看到的影像也很暗淡,可能会难以聚焦,甚至根本无法进行聚焦。
实际上,SLR的解决方案相当巧妙, 它会先使用镜头的最大孔径让我们完成取景和聚焦,按下快门时,镜头的光圈会立刻收缩到预置的孔径,完成胶片曝光,在曝光完成的瞬间,光圈又会开到它的最大孔径,准备下一次拍摄。
一、选择数码单反的几个理由:
数码单反相机的专业定位,决定了即使是面向普通用户和发烧友的普及型产品也拥有大量过人之处,这是许多发烧友选择数码单反相机的根本原因。我们可以把数码单反的专业特色归结成如下几个方面:
1、图像传感器的优势
对于数码相机来说,感光元件是最重要的核心部件之一,它的大小直接关系到拍摄的效果,要想取得良好的拍摄效果,最有效的办法其实不仅仅是提高像素数,更重 要的是加大CCD或者CMOS的尺寸。无论是采用CCD还是CMOS,数码单反相机的传感器尺寸都远远超过了普通数码相机。因此,数码单反的传感器像素数 不仅比较高(目前最低600万),而且单个像素面积更是民用数码相机的四五倍,因此拥有非常出色的信噪比,可以记录宽广的亮度范围。600万像素的数码单 反相机的图像质量绝对超过采用2/3英寸CCD的800万像素的数码相机的图像质量。
2、丰富的镜头选择
数码相机作为一种光、机、电一体化的产品,光学成像系统的性能对最终成像效果的影响也是相当重要的,拥有一支优秀的镜头对于成像的意义绝不亚于图像传感器 的选择。同时,随着图像传感器、图像引擎和存储器件的成本不断降低,光学镜头在数码相机成本中所占的比重也越来越大。对于数码单反来讲更是如此,在传统单 反相机的选择中,镜头群的丰富程度和成像质量就是影友选择的重要因素,到了数码时代,镜头群的保有率顺理成章地成了品牌竞争的基础。佳能、尼康等品牌都拥 有庞大的自动对焦镜头群,从超广角到超长焦,从微距到柔焦,用户可以根据自己的需求选择配套镜头。同时,由于传感器面积较大,数码单反相机比较容易得到出 色的成像。更重要的是许多摄影发烧友手里,一般都有着一两只,甚至多达十几只的各种专业镜头,这些都是影友用自己的血汗钱购买的,如果购买了数码单反相机 机身,一下子就把镜头盘活了,而且和原来的传统胶片相机构成了互相补充的胶片和数码两个系统。
3、迅捷的响应速度
普通数码相机最大一个问题就是快门时滞较长,在抓拍时掌握不好经常会错过最精彩的瞬间。响应速度正是数码单反的优势,由于其对焦系统独立于成像器件之外, 它们基本可以实现和传统单反一样的响应速度,在新闻、体育摄影中让用户得心应手。目前佳能的EOS1D MARKⅡ和尼康D2H均能达到每秒8张的连拍速度,足以媲美传统胶片相机。
4、卓越的手控能力
虽说如今的相机自动拍摄的功能是越来越强了,但是拍摄时由于环境、拍摄对象的情况是千变万化的,因此一个对摄影有一定要求的用户是不会仅仅满足于使用自动 模式拍摄的。这就要求数码相机同样具有手动调节的能力,让用户能够根据不同的情况进行调节,以取得最佳的拍摄效果。因此具有手动调节功能也就成为数码单反 必须具备的功能,也是其专业性的代表。而在众多的手动功能中曝光和白平衡是两个重要的方面。当拍摄时自动测光系统无法准确地判断拍摄环境的光线情况和色温 时,就需要用户根据自己的经验来进行判断,通过手动来进行强制调整,以取得好的拍摄效果。这也是数码单反专业性的体现,如EOS10D能够以每次100K 为基准调整色温值,帮助使用者得到最佳的效果。
5、丰富的附件
数码单反和普通数码相机一个重要的区别就是它具有很强的扩展性,除了能够继续使用偏振镜等附加镜片和可换镜头之外,还可以使用专业的闪光灯,以及其它的一 些辅助设备,以增强其适应各种环境的能力。比如大功率闪光灯、环型微距闪光灯、电池手柄、定时遥控器,这些丰富的附件让数码单反可以适应各种独特的需求, 而普通的数码相机则大大逊色。

New spot of blog opened

cong~~~ self first :-)

It's weird that I cannot open space.live since late April via firefox, but with IE it works although very slow. So I have to open this blog.

something that has to be recorded about May holiday.
1. bought a new Apple Nano, as imprest birthday gift from mdf. many thanks~~~.
2. lost my key once again. too bad. when we were in Chaoyang park. It must be lost during the game, which seems to be something like popular science termed cosmos tour, but actually roller coaster. So I felt the power of outcry of mdf. hehe~~~
3. watched a movie at Centre Cultruel Francais, thanks Maxee for offering me the tickets~~~


乐队之椅
片长:106分钟

导演:丹尼尔 • 汤普森(Danièle Thompson)

主演:塞西尔 • 德弗朗斯(Cécile de France),瓦莱丽 • 勒梅西埃(Valérie Lemercier),克劳德 • 布拉塞尔(Claude Brasseur)

杰西卡决定象她的外祖母那样到巴黎去试试运气。她在首都的高档社区—蒙田大道找到了一份工作。她将在那遇到一些有名的人物,他们都是聪明人,可他们却很沮丧,因为生活有它残酷的一面……


电影之前放映以下短片:
直到永远
导演:迪迪 • 冯堂(Didier Fontan)

故事片–0小时 8分钟

在寂静的郊区的一所房子里,大雪堵住了汽车的出路,一对夫妇在电视前消磨时光。而这个奇怪的景象给人似曾相识的感觉……

4. a promise: go to Paris at some time (just because of the film)

weblog Part II - tranferred from space.live

4月16日
Task for this week


How time flies! Today is Monday again. This moring, I submitted the application for housing on campus. Hope that the resulte is exactly my expection . This week, the following things should be done on time:

1. preparing for lecturing on the seminar on multiscale modelling.

2. finish the code for QDD
sketch of algorithm:
2.1 given density n, solving Poisson equation, which is rewritten in terms of electric field E, to get the analytical solution E.
2.2 computing \pt E / \pt n, preparing for Newton method.
2.3 utilizing Newton-Ralphson method to update n.

3. make possible plan for this weekend, maybe go to some park or meet some friends.

4. practice badminton on Tue. night from 9 pm to 11 pm.

5. practice in-line skate tonight, from 10:30 pm. more when time is available.

21:55

4月11日
express love in 77 languages


第一种汉语的是:我爱你。
法语:Je t’aime,Je t’adore
德语:Ich liebe Dich
希腊语:S’agapo
犹太语:Ani ohev otach(male or famale),Ani ohevet otcha (male or famale)
匈牙利:Szeretlek
爱尔兰:taim i’ngra leat
爱沙尼亚:Mina armastan sind
芬兰:Min rakastan sinua
比利时佛兰芒语:IK zie u graag
意大利语:ti amo,ti vogliobene
拉丁语:Te amo,Vos amo
拉托维亚:Es tevi Milu
里斯本:lingo gramo-te bue’,chavalinha
立陶宛:Tave Myliu
马其顿:Te sakam
马耳他:Inhobbok
波兰语:Kocham Cie,Ja cie kocham
葡萄牙:Eu amo-te
罗马尼亚:Te iu besc,Te Ador
荷兰:IK hou van jou
英语:I love you
捷克:Miluji te
丹麦:Jeg elsker dig
阿尔萨斯:Ich hoan dich gear
亚美尼亚:Yes Kezi Seeroom yem
巴伐利亚:I mog di narrisch gern
保加利亚:ahs te obicham
西班牙加泰隆语:T’estim
克罗地亚:Volim te
阿塞疆语:Men seni serivem
孟加拉:Ami tomay bhalobashi
缅甸:chit pa de
柬埔寨:Bong salang oun
菲律宾:Mahal Kita,Iniibig Kita
印度古吉拉特语:Hoon tane prem karun chuun
北印度语:main tumse pyar karta hoon
印度尼西亚:Saja kasih saudari
日本:Kimi o aishiteru Sukiyo
朝鲜:Tangshin-i cho-a-yo
爪哇语:aku tresno marang sliromu
老挝:Khoi huk chau
马来语:saya Cinta Mu
马来西亚:Saya Cintamu
蒙古语:bi chamd hairtai
尼泊尔:Ma tumilai maya garchu,Ma timilai man parauchu
波斯语:Tora dost daram
他加禄语:Mahal kita
南非语:Ek het jou lief Ek is lief vir jou
加纳:Me do wo
埃塞俄比亚阿姆哈雷地区:Ene ewedechalu(for ladies) Ene ewedehalwe(for men)
阿拉伯语:Ana Ahebak(to a male) Arabic Ana ahebek(to a female)
瑞士德语:Ich lib Dich
克里奥尔语:Mon kontan ou
豪萨语:Ina sonki
肯尼亚班图语:Nigwedete
马达加斯加语:tiako ianao
印度阿萨姆邦语:Moi tomak bhal pau
南亚泰米尔语:Tamil n’an unnaik kathalikkinren
印度泰卢固语:Neenu ninnu pra’mistu’nnanu
泰国:Ch’an Rak Khun
乌尔都语:Mein tumhay pyar karti hun(woman to man) Mein tumhay pyar karta hun(man to woman)
越南:Em ye’u anh(woman to man) Anh ye’u em(man to woman)
新西兰毛里语:kia hoahai
爱斯基摩:Nagligivaget
格陵兰岛:Asavakit
冰岛:e’g elska tig
阿尔巴尼亚:T Dua Shume
俄罗斯:Ya vas Iyublyu,Ya Tibia Lyublyu
塞尔维亚:Volim Te
斯洛文尼亚语:Ljubim te
西班牙:Te amo,Tequiero
瑞典:Jag lskar dig
土耳其:Seni seviyorum
乌克兰:ja vas kokhaju
威尔士:Rwy’n dy garu di
亚述语:ana bayanookh(female to male) ana bayinakh(male to female)
高加索切尔克斯语:wise cas

16:57

4月9日
Colloquium to be attended


4月10日工学院力学与空天技术系学术报告
题 目:DNS and Modeling of Turbulent Premixed Flames
报告人: Prof. Tatsuya HASEGAWA
EcoTopia Science Institute, Nagoya University, Japan

报告摘要:
Turbulent premixed flames propagating in homogeneous isotropic turbulent flows were directly simulated with different density ratios and with different Lewis numbers. These DNS databases were investigated by analyzing Favre averaged transport equations for turbulent kinetic energy and turbulent scalar flux to study flame-generated turbulence and counter-gradient diffusion. Modeling of important terms in the balance equations of turbulent kinetic energy and turbulent scalar flux were also discussed. These modeled equations were used to simulate turbulent premixed flames with flame-generated turbulence and counter-gradient diffusion. Analyses of turbulent burning velocity were also performed using newly calculated DNS databases with different Lewis numbers.

报告人简介:
Research field:
Combustion, Heat Transfer, Fluid Mechanics, Computational Fluid Dynamics, Environmental Engineering, Mechanical Engineering, Aerospace Engineering
Research subject:
Direct numerical simulation and modeling of turbulent premixed combustion
Reaction mechanism and heat production in hydrothermal processes
Hydrothermal gasification of biowastes and fuels
Highly efficient air conditioning system using HFC and natural refrigerant
Thermoplastic welding by diode laser
Academic career:
1977 B. S. Engineering, Department of Aeronautics, Nagoya University
1983 Dr. Engineering, Nagoya University
1983 Research Associate, Nagoya Institute of Technology
1987 Associate Professor, Nagoya Institute of Technology
2002 Professor, Center for Integrated Research in Science and Engineering, Nagoya University
2004 Professor, EcoTopia Science Institute, Nagoya University

主持人:王健平 教授
时 间:4月10日(周二)下午4点
地 点:力学与空天技术系大风洞会议室

题目:Asymptotic Cohesive Crack Tip Fields, Complete Displacement Field of Hybrid Crack Element and XFEM
报告人: B.L. Karihaloo
School of Engineering, Cardiff University, Cardiff CF24 3AA, UK
主持人:王建祥 教授
时 间:4月16日(周一)下午3点
地 点:北京大学力学楼434会议室
This talk will introduce three recent developments in linear and non-linear fracture mechanics. The first development is the asymptotic fields at the tip of a cohesive crack. The lack of any work on the asymptotic fields at the tipof a cohesive crack is surprising considering the widespread use of cohesivecrack models. This blank has recently been filled by Xiao and Karihaloo (2006) who obtained universal asymptotic expansions at a cohesive crack tip, analogous to Williams’s expansions at a traction-free crack tip. The coefficients of the expansions of course depend nonlinearly on the softening law and theboundary conditions. These universal expansions are valid for any normal cohesion-separation law (i.e. softening law) that can be expressed in a special polynomial form. They demonstrated that many commonly-used cohesion-separation laws, e.g. rectangular, linear, bilinear and exponential, can indeed be expressed very accurately in this special form. They also obtained universal asymptotic expansions when the cohesive crack faces are subjected to Coulomb friction.The hybrid crack element (HCE) is one of the most accurate and convenient finite elements (FEs) for the direct calculation of the stress intensity factor (SIF) and coefficients of the higher order terms of the Williams expansion. This talk will introduce two new developments of the element. Firstly, a leastsquares method (LSM) is introduced to recover the rigid body modes excluded from the HCE formulation, which create jumps between the truncated asymptoticdisplacements and element boundary displacements. The LSM minimises these jumps. Then an approach is introduced to combine the HCE and the extended/generalized finite element method (XFEM). The HCE is used for the crack tip region, while the XFEM is used for modelling crack faces behind the crack tip with jump functions. The coupled method retains the advantages of both HCE and XFEM. Numerical results are presented to illustrate these developments.报告人简介:Professor Bhushan L. Karihaloo is currently the Head of Research Institute ofTheoretical, Applied and Computational Mechanics at Cardiff University. Prior to this position, he held chairs at Aalborg University, Denmark (February 1996 - June 1997), The University of Sydney (February 1986 - February 1996), and The University of Newcastle (October 1983 - February 1986), Australia.Professor Karihaloo has made remarkable contributions to many areas of mechanics, including optimum design of structures made from traditional and advanced composite materials (some of his earliest pioneering papers have now becomeclassics), theoretical fracture mechanics, especially non-planar crack growth which has had the most scientific impact, fracture of quasi-brittle materials, in particular of concrete and fibre-reinforced cementitious composites, micro-mechanics of transformation toughening of zirconia-based ceramics which have helped in the development of tough advanced engineering ceramics, and development of nano-structured materials with unusual mechanical and physical properties. For his continuing contributions, Professor Karihaloo has received many awards and honours. In 2006, he was awarded the very prestigious Griffith Medal ofThe European Structural Integrity Society (2006) for outstanding contributions to Theoretical Fracture Mechanics and Fracture of quasi-brittle materials.He is Honorary Fellow of Czech Society of Mechanics of The Czech Academy of Sciences (1989) for contributions to Structural Optimization and Fracture Mechanics, Honorary Fellow of International Congress on Fracture (2001) for lasting contributions to Fracture Mechanics. He was awarded DSc (Honoris Causa) by St Petersburg University, Russia (2007), and DSc by The University of Sydney. Professor Karihaloo’s international esteem is also demonstrated by his service to the international mechanics community. Among the numerous positions he has held, he is Editor-in-Chief (together with Professor R O Ritchie, UC Berkeley and Dr I Milne) of the recent 10-Volume Comprehensive Reference Work on Structural Integrity, Elsevier, 2003, which was awarded the Best Reference Prize in 2004 by the American Society for Engineering Education. Professor Karihaloo is Member of Editorial Board of 9 International Journals, Associate Editor of Mechanics of Materials and of the International Journal of Fracture. He is Vice-President, International Congress on Fracture, ICF (1997 – 2001, 2005 - ), Chair, The Royal Society UK National Panel of IUTAM (2005 - ), and Member of Congress Committee, International Union of Theoretical and Applied Mechanics, IUTAM (1994 - 96, 2000 - ). Professor Karihaloo has been Chairman and/or Member of Scientific Committees of many International Congresses/Conferences/ Symposia. He has been invited to give keynote/invited talks at numerous International Congresses/Conferences/Symposia.主持人注:Karihaloo教授是国际固体力学领域知名学者、在英国相当于中国力学学会主席、IUTAM大会委员会委员(全球只有36人),与我国许多知名教授、院士等十分熟悉。

17:18

“总理救我”

One women posted it on last Friday when she struggled at her life for her right near the new location of CCTV tower. At least, our nation does not take care of her children well enough. When can we have a 'government of the people, by the people, for the people' ???

14:09

4月5日
happiness


What is the happiness? and what's the key of feeling happy? totally confused or totally understand . In my opinion, happiness crashes into yourself just because you feel satisfied with yourself, with what you have done, what you think, and what you have. Never let your hope goes far beyond your ability or what you can expect to get. Maybe I have that idea because I am not ambitious. In chinese words, I am not highly orientated. Anyway, I am not willing to stuggle to become the guy of type which I or somebody else images or want me to be in 10 or 20 years. I am just me today. I am always quit satisfied with me yesterday and I only want me tomorrow to be slightly better than me today. Just as 宝钗 or someone else in 红楼梦, who I cannot remember exactly, says: 郁郁着一天是一天, 快乐着一天也是一天。 Lin Qingxuan, a taiwanesse writer, also says: 快乐着活在当下。痛并快乐着,既然不能避免痛苦,何不将快乐放大,痛苦自然生存的空间就很小了。。。

PS: today is Qingming festival, the day for memory of people who passed away! bless for people who have gone and also who are still seeking his/her happiness~~~ a little weird....

8:34

4月3日
paper accepted


being informed tonight... but still have to do some modification,esp. on the typeset...
at the starting point of learning le Francais, endeavoring....
many things pending to work on... coding on QDD, reading papers, attending seminars, playing badminton and in-line skating (has been being planned so long )

23:00

3月24日
Coloquium to be attended


3月27日工学院力学与空天技术系学术报告
报告题目
Part A: Phononic band gaps of elastic periodic structures: a homogenization theory study
Part B: A microfluidic nanoliter mixer with grooved structures driven by capillary pumping
报告人 Chien C. Chang(张建成)
Professor, Institute of Applied Mechanics, National Taiwan University
Research Fellow and Executive Director, Center for Mechanics, Research Center
for Applied Sciences, Academia Sinica, Taiwan

主持人: 苏先樾 教授

时 间:3月27日(周二)下午2:30点

地 点:北京大学力学楼四层434会议室


欢迎广大师生光临!要求力学系研究生必须参加。
联系人:刘才山,62756177
Abstract:
Part A: In this talk, we examine the band structures of phononic crystals with particular emphasis on the effects of the mass density ratio and of the contrast of elastic constants. The phononic crystals consist of arrays of different media embedded in a rubber or epoxy. It is shown that the density ratio rather than the contrast of elastic constants is the dominant factor that opens up phononic band gaps. The physical background of this observation is explained by applying the theory of homogenization to investigate the group velocities of the low-frequency bands at the center of symmetry of the first Brillouin zone. The theory is first illustrated for one-dimensional layered structures, which is simple and easy to understand. The two- and three-dimensional theory establishes a more sophisticated connection between the fine periodic microstructures and the group velocities of the lowest-frequency dispersion. Interesting comparisons will be made with band gaps of photonic materials in which the composed materials have different dielectric constants.
Part B: In this talk, I will describe a nano-liter mixer fully driven by capillary force, and explain its mechanics. It is known that surface tension-capillary pumping is an effective driving force in a microchannel, however a power-free mixer that uses only surface tension has not yet been achieved. In the present study, a power-free method is explored to perform mixing in a microchannel without any external active mechanisms such as pumps, valves or external energies like electrostatic or magnetic fields. The mixer is cost effective as the channel is designed to have no sidewalls with the liquid being confined to flow between a bottom hydrophilic stripe and a top-covered hydrophobic substrate. It is found from both theoretical analysis and experiments that for a given channel width, the flow rate solely due to capillary pumping can be maximized at an optimal channel height. The flow rate is in the order of nanoliters per second, for example, the flow rate is 0.65 nL s(-1) at the optimal channel height 13 mu m, given the channel width 100 mu m. It is most crucial to this power-free mixing device that two liquid species must be well mixed before the liquids are transported to exit to a reservoir. For this purpose, asymmetric staggered grooved cavities are optimally arranged on the bottom substrate of the channel to help mixing two different liquid species. It is shown that maximum mixing occurs when the depth of the grooved structures is about two-thirds of the total channel height.

Biography:
Ph.D. Mathematics, University of California, Berkeley (1985)
M.S. Applied Mechanics, National Taiwan University (1982)
B.S. Chemical Engineering, National Taiwan University (1980)
Fields of Interest: Multi-scale Mechanics; Photonics and Plasmonics, Biomedical Mechanics, Multi-body Fluid Mechanics

11:07

3月23日
colloquia attended


北京大学工学院联合学术报告(力学与空天技术系、能源与资源工程系)报告一:Vibrodynamics of ‘solid+fluid’By Professor V.A.Vladimirov,University of York, UK报告二:Modeling of reactive fluid flow and geochemical transport in geological mediaBy Tianfu Xu, Earth Sciences Division, Lawrence Berkeley National Laboratory

报告一摘要:
Vibrational mechanics (vibromechanics) is an active interdisciplinary research area that is closely linked to engineering and many other applied subjects. It studies the motions of various mechanical systems in the presence of high frequency oscillations of their parameters. This lecture is devoted to the vibromechanics of dynamical systems composed of solids and a fluid (`solid+fluid') with the use of the averaging method. First we present the averaging procedure in two forms. For the achieving of maximal transparency we consider the most celebrated example of a pendulum with a vibrating pivot (the Stephenson – Kapitza pendulum). The first form of the averaging procedure operates with the exact governing equations. The second form directly uses the least action principle, in which the averaging procedure appears naturally and the conservation laws follow automatically. The presented results provide the full model for both ‘fast’ and ‘slow’ motions. The main advantage of the ‘least action’ form of the procedure is the substantial reduction in the analytical calculations, which are typically cumbersome for the asymptotic methods. In the second part of the lecture we apply the least action form of the averaging procedure to the dynamics of a solid in an inviscid incompressible fluid that fills a vibrating vessel of an arbitrary shape. The solid can be either homogeneous or inhomogeneous in density. The results include equations for ‘slow’ motions, ‘slow Lagrangian’, the ‘slow energy' and a ‘vibrogenic force’, exerted by a fluid into a solid. The case of N homogeneous solids is also outlined. We describe our calculations, present results in an accessible form, and discuss related examples, properties, and conjectures. The examples of either homogeneous or inhomogeneous spherical solid are considered in details. The connection to the viscous ‘steady streaming theory’ is clarified.

报告二摘要:
A comprehensive coupled program TOUGHREACT for multiphase fluid and heat flow, solute transport, and geochemical processes has been developed at Lawrence Berkeley National laboratory (LBNL), which is widely used for geological and environmental problems. A brief overview of this modeling capability will be given. Several application examples will be used to illustrate the applicability. First example is related to CO2 geological sequestration. CO2 is co-injected with either H2S or SO2 into a Gulf Coast sandstone. Changes in water chemistry, mineral dissolution and precipitation, and amounts of CO2 hydrodynamic, solubility, and mineral trapping are studied using the program. Other examples, dealing with nuclear waste geological disposal, mineral scaling and changes in porosity and permeability in a geothermal field, and environmental and groundwater quality problems, will be also presented.

17:59

3月23号
F1 new season started


these days being busy with learning linux...so, it's a little late to post this...Schumi left, but Kimi still there, support Kimi and his Ferrari