- use strict;
- use warnings;
- my %hash;
- while (<DATA>) {
- if (!$hash{$_}) {
- print;
- $hash{$_} += 1;
- }
- }
2017年12月11日 星期一
2017年12月6日 星期三
gnuplot
* 一些設定說明:
- set logscale {x,y}:設定X或Y軸或是兩者為logscale 取消:unset logscale
- set xrange [a:b] 設定X軸範圍從a到b(Y軸亦可);若是看不到圖形,可用set autoscale 自動調回
- set xlabel "XXX", a,b: 設定X軸的名稱為 XXX (Y軸亦同), 從預設向右移動a,向上移動b
- set xlabel "XX" font "Times-Italic,26":設定X軸的名稱為XX,以Times-Italic字型大小26顯示
- set xlabel "XX" font "Times-Roman,24":設定X軸的名稱為XX,以Times-Roman字型顯示
- set xlabel "XX" textcolor lt 4: 以linetype 4 顯示XX
- set title "GGG": 設定圖形標題為GGG
- set xtics a: 設定顯示的X軸座標與刻度, 每次增加 a ;在logscale時,預設的設定會沒有小刻度
- set xtics a,b: 設定顯示的X軸座標與刻度 起始值a,每次增加b
- set mxtics a: 顯示X座標軸上的小刻度,每個大刻度間隔除以a的大小顯示一次
- set xtics (a,b,c): 設定顯示的X軸座標a ,b ,c 與刻度(Y軸亦同)
- set format y "10^{%L}":Y軸的值以10的L次方顯示
- set format x "%a.bf": X軸的值以總長a位數,小數點以下b位顯示
- set format x "%a.be":以科學記號顯示
- set format x "%g":預設顯示
- set format x "":不顯示X軸的座標值
- set key Q,W Left reverse:將圖示與曲線標題倒過來放在圖上座標(Q,W)處,ex: xy1 +++ ---> +++ xy1
- set key spacing D:設定圖示間的寬度增加D倍
- set key title "XXX":設定圖示的名稱
- set label "SSS" at Q,W:設定SSS這三個字出現在座標(Q,W)處 (網頁上的demo有例子)
- set label "XX" textcolor lt 2: 以linetype 2 顯示XX
- set arrow from a,b to c,d:從座標(a,b)畫個箭頭到(c,d),編號第一條箭頭 (可用lw,ls改樣式)
- set noarrow 1:除去第一號箭頭
- set arrow from a,b to c,d nohead:畫沒箭頭的箭頭 (疑?那是啥?就是線啦)
- set term postscript (eps) enhanced color:嵌入一些文字外掛並設定輸出為ps或eps
特殊文字的表示法可以在下載的gnuplot程式中找到教學文件或是見PS1
- set label "{/Symbol n}={/Italic l}" at Q,W font "Times-Roman,24"
- set grid: 在各主要刻度畫出格子
- set grid xtics ytics mxtics mytics:在各刻度畫出格子
- set grid noxtics x2tics:以上邊的X軸刻度畫出格子(參考實例2)
- load "FFF.txt": 載入FFF.txt 中的指令,這是相當好用的畫圖方法,畫錯了只要改檔案重畫就行
PS: 檔案中若是有 # 符號 那這一列就不會被讀取
- X@^2_{A} : 同時設定某一符號的上下標
- set datafile missing "Nan": 不要讀(畫)出字串Nan
- plot "data" u 1:(log($4)): 畫data檔案中的第1行為x,第4行取log值為y
* 實例1:把兩張圖上下疊在一起
以下為指令:
set term post eps enh color
set out "test.ps"
set multiplot <--進入multiplot模式
set key 0.5,1 Left reverse <--設定圖示座標為(0.5,1)並倒過來
set key spacing 2
#Figure 1 <--#之後不會被讀取 可以用來寫說明
set xrange [-1:1]
set yrange [-1:3]
set xtics (-1,-0.75,-0.5,0.25,0,0.5,1) <--設定要顯示的X軸座標
set ytics (-1,-0.5,0,0.5,1,1.5,2,2.5)
set tmar 0 <--因為要把第二張圖貼在第一張上緣,所以上面邊界設為0,但是只有這樣作的話,下面那張會比小,因為下面那張的的座標部份也算在邊界界內,所以最好的方法是將所有的邊界都設為0
set bmar 0
set rmar 0
set lmar 0
set size 0.7, 0.5 <--設定圖的大小:X軸變為0.7倍 Y軸變0.5倍 (縮小比例可讓圖示標題看起來變大)
set origin 0.1, 0.0 <--設定圖的原點 0.1,0 (不是圖上的座標而是整個圖的座標),若沒有引入eps功能 邊界可能會被切掉,所以原點稍微向右移
set title "test1" 0,-4 font "Times-Roman,30" <--圖形標題為test1 由原來位置移動(0,-4)到新位置 (0,-4不是圖上座標,是相對原始位置的座標)
set xla "{/Symbol F^a}" font "Times-Italic,25"
set yla "{/Symbol S}" font "Times-Roman,25" <--設定一些符號並改變字型與大小
plot "abc.txt" u 1:2 w lp ti "{/Symbol n_1}" pt 5 <--以abc.txt檔案中,第一行為X軸,第二行為Y軸<u 1:2>畫出來,並把資料的點標出來且連線<lp>,點的形式是第五種 <pt 5>,曲線的標題為{/Symbol n_1} <ti "{/Symbol n_1}">
rep "abc.txt" u 1:3 w lp ti "{/Symbol b_2}" pt 7
#Figure 2
set size 0.7, 0.5 <--size 要跟第一張圖一樣才會和稱
set origin 0.1, 0.5 <--第二張的原點 因為要貼在第一張的上面 所以要跟第一張的設定配合
set bmar 0 <--下緣邊界設為0
set format x "" <--X軸沒有座標顯示
set ytics (-1,0,0.5,1,2,2.5,3)
set xla "" <--X軸沒有名稱
set yla "{/Symbol S}" font "Times-Roman,25"
set title "test2" 0,-4 font "Times-Roman,30"
plot "abc.txt" u 1:2 w lp ti "{/Symbol n_1}" pt 6
rep "abc.txt" usi 1:4 w lp ti "{/Symbol b_2_3}" pt 8
rep "abc.txt" w l lt 1 lc rgb "blue" lw 7 <-- linetype=1, linewidth=7,linecolor=blue(4.2版以後)
set nomultiplot <--離開multiplot模式
*實例2:兩個不同Y值的座標軸在同一張圖(參考gnuplot-tips)
<span style="color: #339966;">set xr [0:2*pi]
set yr [-1:1] <span style="color: #000000;"><--左邊Y軸範圍</span>
set y2range [0:1] <span style="color: #000000;"><--右邊Y軸範圍</span>
plot sin(x) axis x1y1, \
sin(x)**2 axis x1y2 <span style="color: #000000;"> <--畫sin(x)以左邊Y軸當基準,畫sin(x)平方以右邊Y軸當基準</span></span>
<span style="color: #339966;">set ytics nomirror</span> <--設定左邊Y的刻度不要鏡射到右邊軸 <span style="color: #339966;">
set y2tics 0, 0.2 <span style="color: #000000;"><--設定Y2的顯示值與刻度 </span></span>
* 有關含Error bars的作圖:
http://t16web.lanl.gov/Kawano/gnuplot/datafile-e.html#2dim
http://gnuplot.sourceforge.net/demo/mgr.html 上面兩個網頁有一些例子與說明
The number of data column required for data plotting depend on a kind of figure, which is summarized below
* 實例1:把兩張圖上下疊在一起
以下為指令:
set term post eps enh color
set out "test.ps"
set multiplot <--進入multiplot模式
set key 0.5,1 Left reverse <--設定圖示座標為(0.5,1)並倒過來
set key spacing 2
#Figure 1 <--#之後不會被讀取 可以用來寫說明
set xrange [-1:1]
set yrange [-1:3]
set xtics (-1,-0.75,-0.5,0.25,0,0.5,1) <--設定要顯示的X軸座標
set ytics (-1,-0.5,0,0.5,1,1.5,2,2.5)
set rmar 0
set lmar 0
set origin 0.1, 0.0 <--設定圖的原點 0.1,0 (不是圖上的座標而是整個圖的座標),若沒有引入eps功能 邊界可能會被切掉,所以原點稍微向右移
set title "test1" 0,-4 font "Times-Roman,30" <--圖形標題為test1 由原來位置移動(0,-4)到新位置 (0,-4不是圖上座標,是相對原始位置的座標)
set xla "{/Symbol F^a}" font "Times-Italic,25"
set yla "{/Symbol S}" font "Times-Roman,25" <--設定一些符號並改變字型與大小
rep "abc.txt" u 1:3 w lp ti "{/Symbol b_2}" pt 7
#Figure 2
set size 0.7, 0.5 <--size 要跟第一張圖一樣才會和稱
set origin 0.1, 0.5 <--第二張的原點 因為要貼在第一張的上面 所以要跟第一張的設定配合
set bmar 0 <--下緣邊界設為0
set format x "" <--X軸沒有座標顯示
set ytics (-1,0,0.5,1,2,2.5,3)
set xla "" <--X軸沒有名稱
set yla "{/Symbol S}" font "Times-Roman,25"
set title "test2" 0,-4 font "Times-Roman,30"
plot "abc.txt" u 1:2 w lp ti "{/Symbol n_1}" pt 6
rep "abc.txt" usi 1:4 w lp ti "{/Symbol b_2_3}" pt 8
set nomultiplot <--離開multiplot模式
*實例2:兩個不同Y值的座標軸在同一張圖(參考gnuplot-tips)
http://t16web.lanl.gov/Kawano/gnuplot/datafile-e.html#2dim
http://gnuplot.sourceforge.net/demo/mgr.html 上面兩個網頁有一些例子與說明
The number of data column required for data plotting depend on a kind of figure, which is summarized below
Data Format | Column | using | with |
---|---|---|---|
(X,Y) data | X Y | 1:2 | lines, points, steps, linespoints, boxes, etc. |
Y has an error of dY | X Y dY | 1:2:3 | yerrorbars |
X has an error of dX | X Y dX | 1:2:3 | xerrorbars |
Y has an error of dY, and X has an error of dX | X Y dX dY | 1:2:3:4 | xyerrorbars |
Y has a range of [Y1,Y2] | X Y Y1 Y2 | 1:2:3:4 | yerrorbars |
X has a range of [X1,X2] | X Y X1 X2 | 1:2:3:4 | xerrorbars |
Y has a range of [Y1,Y2], and X has a range of [X1,X2] | X Y X1 X2 Y1 Y2 | 1:2:3:4:5:6 | xyerrorbars |
例子:
plot "abc.txt" usi 1:2:3:4 with yerrorbars <---第三跟第四行是Y軸上面與下面的數據點值
plot "abc.txt" usi 1:2:($2+$3):($2-$4) with error <---第三跟第四行是Y軸誤差的上下量
ps: origin作圖只接受誤差量
plot "abc.txt" usi 1:2:3 with error <---Y軸只有一種誤差量
* 使用Gnuplot來fitting:
http://www.duke.edu/~hpgavin/gnuplot.html
參考上述網頁即可 以下是主要的指令
f1(x) = a1*tanh(x/b1) <--定義要用來fitting的函數與參數
a1 = 300; b1 = 0.005; <--猜的a1與b1初始值
fit f1(x) 'force.dat' using 1:2 via a1, b1 <--fitting
plot "abc.txt" usi 1:2:3:4 with yerrorbars <---第三跟第四行是Y軸上面與下面的數據點值
plot "abc.txt" usi 1:2:($2+$3):($2-$4) with error <---第三跟第四行是Y軸誤差的上下量
ps: origin作圖只接受誤差量
plot "abc.txt" usi 1:2:3 with error <---Y軸只有一種誤差量
* 使用Gnuplot來fitting:
http://www.duke.edu/~hpgavin/gnuplot.html
參考上述網頁即可 以下是主要的指令
f1(x) = a1*tanh(x/b1) <--定義要用來fitting的函數與參數
a1 = 300; b1 = 0.005; <--猜的a1與b1初始值
fit f1(x) 'force.dat' using 1:2 via a1, b1 <--fitting
PS1:特殊符號表:
ALPHABET | SYMBOL | ALPHABET | SYMBOL | alphabet | symbol | alphabet | symbol |
---|---|---|---|---|---|---|---|
A | Alpha | N | Nu | a | alpha | n | nu |
B | Beta | O | Omicron | b | beta | o | omicron |
C | Chi | P | Pi | c | chi | p | pi |
D | Delta | Q | Theta | d | delta | q | theta |
E | Epsilon | R | Rho | e | epsilon | r | rho |
F | Phi | S | Sigma | f | phi | s | sigma |
G | Gamma | T | Tau | g | gamma | t | tau |
H | Eta | U | Upsilon | h | eta | u | upsilon |
I | iota | W | Omega | i | iota | w | omega |
K | Kappa | X | Xi | k | kappa | x | xi |
L | Lambda | Y | Psi | l | lambda | y | psi |
M | Mu | Z | Zeta | m | mu | z | zeta |
PS2:各種線與點的顏色跟大小 (下次再補)
gnuplot script
- 設定
- 還有更多設定可以自由變換組合,下面提供較為常見的設定
#
: 註解行reset
: 重新設定set term png enhanced font 'Verdana,10'
: 設定圖片類型set output 'runtime.png'
: 存檔名稱set logscale {x,y}
: 設定 X 或 Y 軸或是兩者為 logscaleset xrange [a:b]
: 設定 X 軸範圍從 a 到 b (Y 軸亦可);若是看不到圖形,可用 set autoscale 自動調回set xlabel "XXX", a,b
: 設定 X 軸的名稱為 XXX (Y 軸亦同), 從預設向右移動 a,向上移動 bset xlabel "XX" font "Times-Italic,26"
: 設定X軸的名稱為 XX,以 Times-Italic 字型大小 26set title "GGG"
: 設定圖形標題為 GGGset xtics a
: 設定顯示的 X 軸座標與刻度, 每次增加 a ;在 logscale 時,預設的設定會沒有小刻度set xtics a,b
: 設定顯示的 X 軸座標與刻度 起始值 a,每次增加 bset format y "10^{%L}"
:Y 軸的值以 10 的 L 次方顯示set format x "%a.bf"
: X 軸的值以總長 a 位數,小數點以下 b 位顯示set format x "%a.be"
: 以科學記號顯示set format x ""
: 不顯示X軸的座標值set key Q,W Left reverse
: 將圖例與曲線標題倒過來放在圖上座標 (Q,W) 處set key spacing D
: 設定圖例間的寬度增加 D 倍set key title "XXX"
: 設定圖例的名稱set label "SSS" at Q,W
: 設定 SSS 這三個字出現在座標(Q,W)處set label "XX" textcolor lt 2
: 以linetype 2 顯示 XXset grid
: 在各主要刻度畫出格子
2017年11月21日 星期二
grep
grep MB8 client_* | grep Thread | grep parl1 | awk '{print $1}' | sort -u
找出netlist裡面最多R跟C的電路
grep -c "^C" *spi | sed "s#:# #g" | sort -n -r -k 2 | more
grep -c "^R" *spi | sed "s#:# #g" | sort -n -r -k 2 | more
找出netlist裡面最多R跟C的電路
grep -c "^C" *spi | sed "s#:# #g" | sort -n -r -k 2 | more
grep -c "^R" *spi | sed "s#:# #g" | sort -n -r -k 2 | more
2017年11月15日 星期三
Bisection time calculation
#!/usr/bin/perl
$FILE_NAME = $ARGV[0];
open(SearchFile,"<$FILE_NAME");
while(<SearchFile>){
chop $_;
@ary=split("=",$_);
if ($ary[0] eq "CD_p4_t7") {
$CD7 = $ary[1] ;
$CD7f = 1;
}
if ($ary[0] eq "CD_p4_t8") {
$CD8 = $ary[1] ;
$CD8f = 1;
}
if ($ary[0] eq "RETN_p11_t7") {
$RETN7 = $ary[1] ;
$RETN7f = 1;
}
if ($ary[0] eq "RETN_p11_t8") {
$RETN8 = $ary[1] ;
$RETN8f = 1;
}
if ($CD7f eq "1" && $CD8f eq "1" && $RETN7f eq "1" && $RETN8f eq "1") {
$CDtp = (($CD8 + $CD7)/2);
$RETNtp = (($RETN8 + $RETN7)/2);
$Constraint = ($CDtp -$RETNtp);
print "CD time point is $CDtp \n";
print "RETN time point is $RETNtp \n";
print "Alignment time is $Constraint \n";
$CD7f =0; $CD8f =0; $RETN7f=0; $RETN8f=0;
}
}
$FILE_NAME = $ARGV[0];
open(SearchFile,"<$FILE_NAME");
while(<SearchFile>){
chop $_;
@ary=split("=",$_);
if ($ary[0] eq "CD_p4_t7") {
$CD7 = $ary[1] ;
$CD7f = 1;
}
if ($ary[0] eq "CD_p4_t8") {
$CD8 = $ary[1] ;
$CD8f = 1;
}
if ($ary[0] eq "RETN_p11_t7") {
$RETN7 = $ary[1] ;
$RETN7f = 1;
}
if ($ary[0] eq "RETN_p11_t8") {
$RETN8 = $ary[1] ;
$RETN8f = 1;
}
if ($CD7f eq "1" && $CD8f eq "1" && $RETN7f eq "1" && $RETN8f eq "1") {
$CDtp = (($CD8 + $CD7)/2);
$RETNtp = (($RETN8 + $RETN7)/2);
$Constraint = ($CDtp -$RETNtp);
print "CD time point is $CDtp \n";
print "RETN time point is $RETNtp \n";
print "Alignment time is $Constraint \n";
$CD7f =0; $CD8f =0; $RETN7f=0; $RETN8f=0;
}
}
## Raw data
CD_p4_t7=1.5240779e-08
CD_p4_t8=1.5240939e-08
RETN_p11_t7=4.1999999e-10
RETN_p11_t8=4.9999999e-10
RETN_p11_t7=8.3999996e-13
RETN_p11_t8=9.9999995e-13
CD_p4_t7=1.5555811e-08
CD_p4_t8=1.5635811e-08
RETN_p11_t7=4.1999999e-10
RETN_p11_t8=4.9999999e-10
CD_p4_t7=2.6843051e-10
CD_p4_t8=2.6859051e-10
RETN_p11_t7=1.4861649e-10
RETN_p11_t8=1.4877649e-10
CD_p4_t7=4.1999999e-10
CD_p4_t8=4.9999999e-10
......
## Results
CD time point is 1.5240859e-08
RETN time point is 4.5999999e-10
Alignment time is 1.478085901e-08
CD time point is 1.5595811e-08
RETN time point is 9.19999955e-13
Alignment time is 1.5594891000045e-08
CD time point is 2.6851051e-10
RETN time point is 4.5999999e-10
Alignment time is -1.9148948e-10
C shell scripts
What is a Shell Script?
- A shell script is an executable file which contains shell commands. The script acts as a "program" by sequentially executing each command in the file.
- Each of the 5 common shells has its own scripting language. There are similarities between the languages, but also differences.
- A scripting language consists of control structures, shell commands, expressions and variables.
- If a shell script written in a given scripting language must run under the appropriate shell, the first line of the script should specify the shell it must run under. For example, a C shell script should have as the first line:
#!/bin/csh
- Script files should be given "execute" file permission with the chmod command:
chmod u+x myscript
- A simple shell script which will run under any of the 5 shells appears below. This script simply displays a greeting and the date/time. Comments are preceeded with a pound sign (#):
#Simple Script # echo 'Welcome to the world of script files' date
- Begin the Shell Scripts Exercises
Expressions
- Expressions are statements, composed of constants, variables and operators, which are evaluated to determine a result. Expressions can be either mathematical or logical.Example 1: Mathematical expression, where "a" and "t" are variables, "3" and "4" are constants, and "=" and "+" are operators.
a = 3 + 4t
Example 2: Logical expression, which evaluates to either "true" or "false". The string "exit" is a constant, "var" is a variable, and "(", ")" and "==" are operators.
($var == exit)
- Shell scripts commonly use expressions. Each shell has its own rules for writing expressions, however.
- The C Shell recognizes the following operators, in order of precedence.
() - parenthesis - change order of evaluation - - unary minus/negation ~ - one's complement ! - logical negation % - remainder / - divide * - multiply - - subtract + - addition >> - shift right << - shift left > - greater than < - less than >= - greater than or equal <= - less than or equal != - not equal to (strings) == - equal to (strings) & - bitwise AND ^ - bitwise exclusive OR | - bitwise inclusive OR && - logical AND || - logical OR
- Continue the Shell Scripts Exercises
Control Structures
Script languages make use of programming control structures, such as "if" statements and "loops". Those for C Shell are described below.if
- Used to test an expression and then conditionally execute a command. If the specified expression evaluates true, then the single command with arguments is executed. Command must be a simple command, not a pipeline, a command list, or a parenthesized command list.
Syntax:
if (expr) command [arguments]Example:
#!/bin/csh if ($#argv == 0) echo There are no argumentsIn addition to the C Shell's logical expressions, you can use expressions that return a value based upon the status of a file. For example:
if (-e myfile) echo myfile already existsThe possible file status expressions are:
d - file is a directory e - file exists f - file is an ordinary file o - user owns the file r - user has read access to the file w - user has write access to the file x - user has execute access to the file z - file is zero bytes long
if / then / else
- Used to test multiple conditions and to execute more than a single command per condition. If the specified expr is true then the commands to the first else are executed; otherwise if expr2 is true then the commands to the second else are executed, etc. Any number of else-if pairs are possible; only one endif is needed. The else part is likewise optional.
The words else and endif must appear at the beginning of command lines; the if must appear alone on its command line or immediately after an else.
Syntax:
if (expr) then commands else if (expr2) then commands else commands endifExample:
#!/bin/csh if ($#argv == 0) then echo "No number to classify" else if ($#argv > 0) then set number = $argv[1] if ($number < 0) then @ class = 0 else if (0 <= $number && $number < 100) then @ class = 1 else if (100 <= $number && $number < 200) then @ class = 2 else @ class = 3 endif echo The number $number is in class $class endif
foreach / end
- The foreach statement is a type of loop statement. The variable name is successively set to each member of wordlist and the sequence of commands until the matching end statement are executed. Both foreach and end must appear alone on separate lines.
Syntax:
foreach name (wordlist) commands endExample:
#!/bin/csh foreach color (red orange yellow green blue) echo $color end
while / end
- The while statement is another type of loop statement. Statements within the while/end loop are conditionally executed based upon the evaluation of the expression. Both while and end must appear alone on separate lines.
Syntax:
while (expression) commands endExample:
#!/bin/csh set word = "anything" while ($word != "") echo -n "Enter a word to check (Return to exit): " set word = $< if ($word != "") grep $word /usr/share/dict/words end
break
Used to interrupt the execution of a foreach or while loop. Transfers control to the statement after the end statement, thus terminating the loop. If there are other commands on the same line as a break statement, they will be executed before the break occurs. Multi-level breaks are thus possible by writing them all on one line.- Syntax:
breakExample:
#!/bin/csh foreach number (one two three exit four) if ($number == exit) then echo reached an exit break endif echo $number end
continue
Used to interrupt the execution of a foreach or while loop. Transfers control to the end statement, thus continuing the loop. If there are other commands on the same line as a continue statement, they will be executed before the continue occurs.- Syntax:
continueExample:
#!/bin/csh foreach number (one two three exit four) if ($number == exit) then echo reached an exit continue endif echo $number end
goto
The goto statement transfers control to the statement beginning with label:- Syntax:
goto labelExample:
#!/bin/csh if ($#argv != 1) goto error1 if ($argv[1] < 6) goto error2 goto OK error1: echo "Invalid - wrong number or no arguments" echo "Quitting" exit 1 error2: echo "Invalid argument - must be greater than 5" echo "Quitting" exit 1 OK: echo "Argument = $argv[1]" exit 1
switch / case / breaksw / endsw
- The switch structure permits you to set up a series of tests and conditionally executed commands based upon the value of a string. If none of the labels match before a `default' label is found, then the execution begins after the default label.
Each case label and the default label must appear at the beginning of a line. The command breaksw causes execution to continue after the endsw. Otherwise control may fall through case labels and default labels. If no label matches and there is no default, execution continues after the endsw.
Syntax:
switch (string) case str1: commands breaksw case str2: commands breaksw ... default: commands breaksw endswExample:
#!/bin/csh if ($#argv == 0 ) then echo "No arguments supplied...exiting" exit 1 else switch ($argv[1]) case [yY][eE][sS]: echo Argument one is yes. breaksw case [nN][oO]: echo Argument one is no. breaksw default: echo Argument one is neither yes nor no. breaksw endsw endif
Interrupt handling
The onintr statement transfers control when you interrupt (CTRL-C) the shell script. Control is transferred to the statement beginning with label:Can be useful for gracefully cleaning up temporary files and exiting a program should it be interrupted.
- Syntax:
onintr labelExample:
#!/bin/csh onintr close while (1 == 1) echo Program is running sleep 2 end close: echo End of program
Miscellaneous
Miscellaneous tasks for C Shell programming are described below.Using quotes
- The shell uses both single (') quotes and double (") quotes. They have different effects.Single quotes:
- allow inclusion of spaces
- prevent variable substitution
- permit filename generation
- allow inclusion of spaces
- permit variable substitution
- permit filename generation
#!/bin/csh set opt=-l set x1='ls $opt' echo $x1 set x2="ls $opt" echo $x2 Will produce the output: ls $opt ls -lExample 2: Filename generation
#!/bin/csh set ls1='some files: [a-z]*' echo $ls1 set ls2="some files: [a-z]*" echo $ls2 Sample output (identical): some files: csh.html images man misc other.materials some files: csh.html images man misc other.materials
Storing the output of a command
The shell uses backquotes to obtain the output of the command enclosed within the backquotes. This output can be stored within an array variable. Each element can then be indexed and processed as required.- Syntax:
set variable = `command`Example:
#!/bin/csh set date_fields=`date` echo $date_fields echo $date_fields[1] echo $date_fields[2] foreach field(`date`) echo $field end Sample output: Thu Mar 9 22:25:45 HST 1995 Thu Mar Thu Mar 9 22:25:45 HST 1995
Reading user input
Depending on your system, you can use either "$<" or the output of the "head -1" command to read stdin into a variable. Note that if you use the "head -1" command, it must be enclosed in backquotes.Note: Be careful on making sure that you use "$<" and not "<$". The latter case will usually cause your script to fail.
- Syntax:
set variable = $< - or - set variable = `head -1`Example:
#!/bin/csh echo -n Input your value: set input = $< echo You entered: $input - or - #!/bin/csh echo -n Input your value: set input = `head -1` echo You entered: $input
This concludes the tutorial. Return to the Table of Contents
LSF
1.To kill all of your pending jobs
bkill `bjobs -u mwang |grep PEND |cut -f1 -d" "`
2.bhosts
The “bhosts” command checks the availability of machines in the LSF cluster. If a host is “ok” then it has one or more job slots available for accepting submitted jobs.
3.bjobs
The “bjobs” command displays the current status of one or more jobs. If used without any options, it displays all of the pending, running or suspended jobs that you own on the cluster. If you want to check the status of a specific job, use “bjobs JobID” where JobID refers to the job’s ID number.
ie:
bjobs
bjobs ID
bjobs -l ID
bjobs –u all ## To get a listing of all the jobs on the cluster
2017年8月24日 星期四
Calculate and sort timing for sigma calculation
$index_X = $ARGV[0];
$start_analysis=0; $i=0; $total_slew=0; $total_delay=0;
open(h2,"results.log");
open(h3,"sort.log");
open(XFile,"<$index_X");
while(<XFile>){
chop $_;
@M_DATA=split(" ",$_);
if($start_analysis eq "1"){
@slew[$i]=($M_DATA[2]-$M_DATA[1])*2 ;
@delay[$i]=($M_DATA[4]-$M_DATA[3]) ;
$total_slew=$total_slew+@slew[$i];
$total_delay=$total_delay+@delay[$i];
print h2 "The $i slew is $slew[$i] \n";
print h2 "The $i delay is $delay[$i] \n";
print h2 "The total_slew is $total_slew \n";
print h2 "The $i delay is $total_delay \n";
$start_analysis=0; $i=0; $total_slew=0; $total_delay=0;
open(h2,"results.log");
open(h3,"sort.log");
open(XFile,"<$index_X");
while(<XFile>){
chop $_;
@M_DATA=split(" ",$_);
if($start_analysis eq "1"){
@slew[$i]=($M_DATA[2]-$M_DATA[1])*2 ;
@delay[$i]=($M_DATA[4]-$M_DATA[3]) ;
$total_slew=$total_slew+@slew[$i];
$total_delay=$total_delay+@delay[$i];
print h2 "The $i slew is $slew[$i] \n";
print h2 "The $i delay is $delay[$i] \n";
print h2 "The total_slew is $total_slew \n";
print h2 "The $i delay is $total_delay \n";
$i++;
}
if(/^index/){
$start_analysis="1"'}
}
## Sort slew/delay data
@sort_slew=sort {$a <=> $b} @slew;
@sort_delay=sort {$a <=> $b} @delay;
print h3 "print out sort slew data \n";
for ($j=0; $j<=$#sort_slew; $j++) {
print h3 "$sort_slew[$j]\n";
}
print h3 "print out sort delay data \n";
for ($j=0; $j<=$#sort_delay; $j++) {
print h3 "$sort_delay[$j]\n";
}
$average_slew=$total_slew/($i+1);
$average_delay=$total_delay/($i+1);
print h2 "The average slew is $average_slew \n";
print h2 "The average delay is $average_delay \n";
foreach $slewdata (@slew) {
if($slewdata>$average_slew){
$sum_late_slew=$sum_late_slew+(($slewdata-$average_slew)**2);
$late_slew_index++;}
if($slewdata<$average_slew){
$sum_early_slew=$sum_early_slew+(($average_slew-$slewdata)**2);
$early_slew_index++;}
}
print h2 "The late slew index is $late_slew_index \n";
print h2 "The early slew index is $early_slew_index \n";
$slew_late_sigma=sqrt($sum_late_slew/($late_slew_index));
$slew_early_sigma=sqrt($sum_early_slew/($early_slew_index));
print h2 "The late slew sigma is $slew_late_sigma \n";
print h2 "The early slew sigma is $slew_early_sigma \n";
2017年5月25日 星期四
2017年4月6日 星期四
將目錄A底下的檔案內容複製到目錄B相對應的檔案中
$dirname1 = "/remote/amscae35/chihwang/TSMC/Eval2017/TSMC_F_reK/control";
$dirname2 = "/remote/amscae35/chihwang/TSMC/Eval2017/testcase/tcbn28hpcplusbwp30p140oppulvt_150a/INST_F";
opendir(DIR, $dirname1) or die "can't opendir $dirname1: $!";
while (defined($file = readdir(DIR))) {
$dut = $dirname1."/".$file;
$target = $dirname2."/".$file;
## print $dut."\n";
open(h1, "<$dut");
open(h2, ">>$target");
while(<h1>){
if($i eq "1"){
print h2 $_;
$i = 0 ;
}
## adding liberty attributes
if(/set_liberty_attribute/){
print h2 $_;
}
## adding slew/load index
if(/from/){
$escape_loop = 1;}
if(/to/){
$escape_loop = 1;}
if($escape_loop eq "0"){
if(/-- explicit_points_load/){
print h2 $_;
$i = 1 ;
}
if(/-- explicit_points_slew/){
print h2 $_;
$i = 1 ;
}}
$escape_loop = 0;
## adding liberty_timing_type
if($save_liberty_timing_type ge "1"){
print h2 $_;
$save_liberty_timing_type = $save_liberty_timing_type - 1 ;
}
if(/create_parameter liberty_timing_type/){
print h2 $_;
$save_liberty_timing_type =4
}
}
}
closedir(DIR);
$dirname2 = "/remote/amscae35/chihwang/TSMC/Eval2017/testcase/tcbn28hpcplusbwp30p140oppulvt_150a/INST_F";
opendir(DIR, $dirname1) or die "can't opendir $dirname1: $!";
while (defined($file = readdir(DIR))) {
$dut = $dirname1."/".$file;
$target = $dirname2."/".$file;
## print $dut."\n";
open(h1, "<$dut");
open(h2, ">>$target");
while(<h1>){
if($i eq "1"){
print h2 $_;
$i = 0 ;
}
## adding liberty attributes
if(/set_liberty_attribute/){
print h2 $_;
}
## adding slew/load index
if(/from/){
$escape_loop = 1;}
if(/to/){
$escape_loop = 1;}
if($escape_loop eq "0"){
if(/-- explicit_points_load/){
print h2 $_;
$i = 1 ;
}
if(/-- explicit_points_slew/){
print h2 $_;
$i = 1 ;
}}
$escape_loop = 0;
## adding liberty_timing_type
if($save_liberty_timing_type ge "1"){
print h2 $_;
$save_liberty_timing_type = $save_liberty_timing_type - 1 ;
}
if(/create_parameter liberty_timing_type/){
print h2 $_;
$save_liberty_timing_type =4
}
}
}
closedir(DIR);
2017年3月23日 星期四
read_lib for all libraries in directory
#! /bin/csh
module load lc
set lib_name=`ls *.lib`
echo $lib_name
foreach name ($lib_name)
echo $name
lc_shell <<!
redirect -tee $name.log {read_lib $name}
quit
!
end
module load lc
set lib_name=`ls *.lib`
echo $lib_name
foreach name ($lib_name)
echo $name
lc_shell <<!
redirect -tee $name.log {read_lib $name}
quit
!
end
2017年1月31日 星期二
Introducing Points of discussion 表達詞語介紹
Introducing visual information:
"let's take a look at" 可用來將注意力吸引到一些視覺資訊上,例如圖表、註記、報告或圖形上。
該詞語後面要接名詞片語或疑問詞子句。
Let's take a look at the figures.
Let's take a look at the report.
Let's consider John for a promotion.
Introducing something to be reviewed:
"let's go over" 可用來引介特定的事物以供審閱。
該詞語後面要接名詞片語或疑問詞子句。
Let's go over the specifics of the contract.
Let's go over our three main options.
Let's go over the agenda.
Let's go over what we decided at the last meeting.
Introducing something to be analyzed:
這些片語可用來引介需要嚴格審閱的事物。
該詞語後面要接名詞片語或疑問詞子句。
Let's analyze the profit report.
Let's analyze the direct marketing results.
Let's analyze how our product is selling.
Let's evaluate our progress so far.
Let's evaluate the success of our development team.
"let's figure out" 表示 "let's think about something until we find a solution or understand it."(讓我們想想,直到找出解決方案或瞭解為止)之意。
"figure out" 為可分隔的片語動詞,後面可接名詞片語或疑問詞子句。
Let's figure out our expenses for the business trip tomorrow.
Let's figure that out soon.
Reminding the listener of an idea:
這些片語可用來提醒聽者某個想法或意見。
後面可接名詞片語或 ("that") + S + V(或疑問詞子句)。
Let's not forget the reason we're here.
Let's not forget that she's the best designer.
Let's not overlook the possibility of hiring a contractor.
Let's not overlook all the support they've shown us.
完整說明
"let's take a look at" 可用來將注意力吸引到一些視覺資訊上,例如圖表、註記、報告或圖形上。
該詞語後面要接名詞片語或疑問詞子句。
Let's take a look at the figures.
Let's take a look at the report.
Let's take a look at what we've created so far.
Introducing an idea or topic:
"let's consider" 可用來引入或將注意力吸引至某個想法或主題上。它代表 "let's think carefully about ..."(讓我們仔細想想...)之意。
該詞語後面要接名詞片語或疑問詞子句。
Let's consider the issues.
Let's consider what he's saying.Introducing an idea or topic:
"let's consider" 可用來引入或將注意力吸引至某個想法或主題上。它代表 "let's think carefully about ..."(讓我們仔細想想...)之意。
該詞語後面要接名詞片語或疑問詞子句。
Let's consider the issues.
Let's consider John for a promotion.
Introducing something to be reviewed:
"let's go over" 可用來引介特定的事物以供審閱。
該詞語後面要接名詞片語或疑問詞子句。
Let's go over the specifics of the contract.
Let's go over our three main options.
Let's go over the agenda.
Let's go over what we decided at the last meeting.
Introducing something to be analyzed:
這些片語可用來引介需要嚴格審閱的事物。
該詞語後面要接名詞片語或疑問詞子句。
Let's analyze the profit report.
Let's analyze the direct marketing results.
Let's analyze how our product is selling.
Let's evaluate our progress so far.
Let's evaluate the success of our development team.
"let's figure out" 表示 "let's think about something until we find a solution or understand it."(讓我們想想,直到找出解決方案或瞭解為止)之意。
"figure out" 為可分隔的片語動詞,後面可接名詞片語或疑問詞子句。
Let's figure out our expenses for the business trip tomorrow.
Let's figure that out soon.
Reminding the listener of an idea:
這些片語可用來提醒聽者某個想法或意見。
後面可接名詞片語或 ("that") + S + V(或疑問詞子句)。
Let's not forget the reason we're here.
Let's not forget that she's the best designer.
Let's not overlook the possibility of hiring a contractor.
Let's not overlook all the support they've shown us.
完整說明
"let's take a look at" 可用來將注意力吸引到一些視覺資訊上,例如圖表、註記、報告或圖形上。
該詞語後面要接名詞片語或疑問詞子句。
該詞語後面要接名詞片語或疑問詞子句。
"let's consider" 可用來引入或將注意力吸引至某個想法或主題上。它代表 "let's think carefully about ..."(讓我們仔細想想...)之意。
該詞語後面要接名詞片語或疑問詞子句。
該詞語後面要接名詞片語或疑問詞子句。
"let's go over" 可用來引介特定的事物以供審閱。
該詞語後面要接名詞片語或疑問詞子句。
該詞語後面要接名詞片語或疑問詞子句。
這些片語可用來引介需要嚴格審閱的事物。
該詞語後面要接名詞片語或疑問詞子句。
該詞語後面要接名詞片語或疑問詞子句。
"let's figure out" 表示 "let's think about something until we find a solution or understand it."(讓我們想想,直到找出解決方案或瞭解為止)之意。
"figure out" 為可分隔的片語動詞,後面可接名詞片語或疑問詞子句。
"figure out" 為可分隔的片語動詞,後面可接名詞片語或疑問詞子句。
這些片語可用來提醒聽者某個想法或意見。
後面可接名詞片語或 ("that") + S + V(或疑問詞子句)。
後面可接名詞片語或 ("that") + S + V(或疑問詞子句)。
2017年1月28日 星期六
片語
"stumbling block"(名詞片語)是指一個會阻撓後續進程或目標的問題。
Let's figure out what stumbling blocks we might run into.
Resistance from management might be a stumbling block to an agreement.
"rest assured"(動詞片語)是用來告訴某人某件事是真實的,且不需要煩惱。"rest assured" 後面要加上 ("that") + S + V。"that" 則可有可無。
There is no fog at Heathrow Airport, so we can rest assured that we will land in London on time.
You can rest assured that we want to acquire companies that we can grow.
"track record"(名詞片語)是指某個人或某件事成功或失敗的表現記錄。
We only seek out companies that have an impressive track record.
I'm not sure we should use that airline since it has a pretty bad track record.
"put in writing"(動詞片語)表示將某事正式列入文件中。"put in writing" 要與受詞合用,受詞通常置於 "put" 和 "in writing" 之間。
I'm not sure that we can put any guarantees in writing.
The offer isn't official until they put it in writing.
Let's figure out what stumbling blocks we might run into.
Resistance from management might be a stumbling block to an agreement.
"rest assured"(動詞片語)是用來告訴某人某件事是真實的,且不需要煩惱。"rest assured" 後面要加上 ("that") + S + V。"that" 則可有可無。
There is no fog at Heathrow Airport, so we can rest assured that we will land in London on time.
You can rest assured that we want to acquire companies that we can grow.
"track record"(名詞片語)是指某個人或某件事成功或失敗的表現記錄。
We only seek out companies that have an impressive track record.
I'm not sure we should use that airline since it has a pretty bad track record.
"put in writing"(動詞片語)表示將某事正式列入文件中。"put in writing" 要與受詞合用,受詞通常置於 "put" 和 "in writing" 之間。
I'm not sure that we can put any guarantees in writing.
The offer isn't official until they put it in writing.
疑問詞子句
疑問詞子句為名詞子句的一種。名詞子句包含一個主詞及一個動詞,在句子中的作用與單數名詞相同。
Let's ask the secretary where we should go.
The manager told us what to do.
I wish I knew why she left the company.
His story was interesting. --> What he said was interesting.
I don't know the teacher. --> I don't know who she is.
疑問詞子句可為動詞的主詞或受詞。
What he said was interesting. 當主詞
I don't know who she is. 當受詞
下列字詞經常用作疑問詞子句的開頭。
Words used to begin question-word clauses : when, where, why, how, who, what
一般而言,疑問詞子句的句型如下:
疑問詞 + 主詞 + 動詞。
We discussed how the meeting went.
how the meeting went
S V
I don't know who the manager is.
who the manager is
S V
使用疑問詞來形成問句時,助動詞 "do"、"does" 和 "did" 通常直接置於疑問詞後面。
用疑問詞來形成疑問詞子句時,則不要將這些助動詞置於疑問詞後面。
使用疑問詞來形成問句 : What did they announce at the meeting?
用疑問詞來形成疑問詞子句 : What they announced at the meeting surprised everyone.
使用疑問詞來形成問句 : Why do they change the policy every year?
用疑問詞來形成疑問詞子句 : Nobody knows why they change the policy every year.
Question-word clauses with what or who
"what" 或 "who" 可用來作為疑問詞子句的主詞。
當 "what" 或 "who" 作為疑問詞子句的主詞時,會使用下列的句型:
"what/who" + V。
I want to know what happened.
S V
I don't know who is in the office.
S V
例句:
1. Devon: How long has Mark worked in this industry?
2. Devon: When did Mark first come to Japan?
Devon wants to know when Mark first came to Japan
Let's ask the secretary where we should go.
The manager told us what to do.
I wish I knew why she left the company.
His story was interesting. --> What he said was interesting.
I don't know the teacher. --> I don't know who she is.
疑問詞子句可為動詞的主詞或受詞。
What he said was interesting. 當主詞
I don't know who she is. 當受詞
下列字詞經常用作疑問詞子句的開頭。
Words used to begin question-word clauses : when, where, why, how, who, what
一般而言,疑問詞子句的句型如下:
疑問詞 + 主詞 + 動詞。
We discussed how the meeting went.
how the meeting went
S V
I don't know who the manager is.
who the manager is
S V
使用疑問詞來形成問句時,助動詞 "do"、"does" 和 "did" 通常直接置於疑問詞後面。
用疑問詞來形成疑問詞子句時,則不要將這些助動詞置於疑問詞後面。
使用疑問詞來形成問句 : What did they announce at the meeting?
用疑問詞來形成疑問詞子句 : What they announced at the meeting surprised everyone.
使用疑問詞來形成問句 : Why do they change the policy every year?
用疑問詞來形成疑問詞子句 : Nobody knows why they change the policy every year.
Question-word clauses with what or who
"what" 或 "who" 可用來作為疑問詞子句的主詞。
當 "what" 或 "who" 作為疑問詞子句的主詞時,會使用下列的句型:
"what/who" + V。
I want to know what happened.
S V
I don't know who is in the office.
S V
例句:
1. Devon: How long has Mark worked in this industry?
Devon wants to know how long Mark has worked in this industry
解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
Devon wants to know when Mark first came to Japan
解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
去掉助動詞 動詞時態要改變
3. Devon: Why is Mark interested in this position?
Devon wants to know why Mark is interested in this position
Devon wants to know why Mark is interested in this position
解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
4. Devon: What are Mark's salary requirements?
Devon wants to know what Mark's salary requirements are解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
Devon wants to know what Mark's salary requirements are解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
5. Devon: Who told Mark about the position?
Devon wants to know who told Mark about the position解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
Devon wants to know who told Mark about the position解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
6. Devon: Where did Mark work in Germany?
Devon wants to know where Mark worked in Germany解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
去掉助動詞 動詞時態要改變
Devon wants to know where Mark worked in Germany解釋:上述答案是正確的。疑問詞子句是動詞 know 的受詞。在疑問詞子句中,主詞要置於動詞之前。
去掉助動詞 動詞時態要改變
訂閱:
文章 (Atom)
標籤
- 大盤 (6)
- 未分類資料夾 (2)
- 英文 (28)
- 書刊雜誌 (11)
- Perl (25)
- TCL (10)
- Uncategoried (1)
- UNIX Linux (43)