-
2008-12-31
编写bash脚本提高工作效率 - [软件与系统]
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://feizf.blogbus.com/logs/33188594.html
情况是这样的,通过电子学系统将探测器数据送到计算机,最终保存在一个文件中data.dat. 这个文件包含若干个通道的数据,每一个通道对应一个能谱。要做的工作就是从data.dat中分离出各个通道数据(demo.exe程序完成),分别进行描点绘出能谱,并保存在一个图像文件中供物理参考。如果用传统的origin导入文件、选择数据、设置参数、画图、导出图形,会做很多重复工作。我选择使用gnuplot程序进行绘图,尝试写了下面的脚本(work.bash), 只要在cygwin命令行下输入./work.bash,所有的工作都会在短时间内自动完成, 效果很好。
========================================
#!/bin/bash######## decalre functions #########
do_backup()
{
BKUP_DIR="bk_$(date|sed 's/://g' |awk '{print $6$2$3"_"$4}')"
echo "backup old data and jpgs in dir $BKUP_DIR .."
mkdir $BKUP_DIR
if [ $(ls|grep chn|wc -w) -gt 0 ] ; then
mv chn_* $BKUP_DIR
fi
if [ -e "data.dat" ]; then
cp data.dat $BKUP_DIR
fi
}
################## main work ###############
do_backup
if [ $1 = "clean" ]; then
exit 0
fi./demo
echo
echo "Now prepare gnuplot script file for our draw work.."
######## create gnuplot script file #########GNUPLOT_BAT="gnuplot.gnu"
MAX_CHN=36
chn=0if [ -e $GNUPLOT_BAT ] ; then
rm $GNUPLOT_BAT
fiecho "#This script create time AT $(date)" >>$GNUPLOT_BAT
echo
echo "set terminal jpeg" >>$GNUPLOT_BAT
echo "set xrange [0:1024]" >>$GNUPLOT_BATwhile [ $chn -lt $MAX_CHN ]
do
if [ -e "chn_${chn}.txt" ]; then
echo "find file chn_${chn}.txt"
echo "set output \"chn_${chn}.jpg\"" >>$GNUPLOT_BAT
echo "plot \"chn_${chn}.txt\"" >>$GNUPLOT_BAT
fi
chn=$(($chn+1))
doneecho
echo "--------------------------------------"
echo "Now I drawing the pictures, please wait....."
gnuplot $GNUPLOT_BAT
echo "ok, finish all work!"
==============================================随机文章:
Ubuntu 9.04 -- how many days to go 2009-04-11Linux与windows远端桌面连接 2008-11-29human-theme_0.14_all.deb on ubuntu 8.04 2008-11-19shellcode /bin/sh 2008-11-16ubuntu 8.04建立mysql C开发环境 2008-10-27
收藏到:Del.icio.us
引用地址:







