Permalink
Browse files

update ex013

  • Loading branch information...
1 parent 6f06ea6 commit 6ef0b7c55338e14878afa832dca552bec1d2c4ce @seisman seisman committed Apr 16, 2016
Showing with 29 additions and 18 deletions.
  1. +12 −3 _includes/ex013.sh
  2. +5 −12 _posts/2016-03-26-ex013.md
  3. +12 −3 ex013/ex013.sh
View
@@ -1,19 +1,28 @@
#!/bin/bash
+# 绘制2D矢量场以及矢量场的等值线
#
-# Purpose: Illustrate vectors and contouring
-# GMT progs: grdmath, grdcontour, grdvector, pstext
-# Unix progs: echo, rm
+# GMT模块 : grdmath, grdcontour, grdvector, pstext
+# Unix命令: echo, rm
#
ps=ex013.ps
+
+# 生成 z = x exp(-x^2-y^2)
gmt grdmath -R-2/2/-2/2 -I0.1 X Y R2 NEG EXP X MUL = z.nc
+# 计算X和Y方向的偏导
gmt grdmath z.nc DDX = dzdx.nc
gmt grdmath z.nc DDY = dzdy.nc
+# 绘制X方向偏导的等值线
gmt grdcontour dzdx.nc -JX3i -B1 -BWSne -C0.1 -A0.5 -K -P -Gd2i -S4 -T+d0.1i/0.03i > $ps
+# 绘制Y方向偏导的等值线
gmt grdcontour dzdy.nc -J -B -C0.05 -A0.2 -O -K -Gd2i -S4 -T+d0.1i/0.03i -Xa3.45i >> $ps
+# 绘制Z等值线
gmt grdcontour z.nc -J -B -C0.05 -A0.1 -O -K -Gd2i -S4 -T+d0.1i/0.03i -Y3.45i >> $ps
+# 绘制Z等值线
gmt grdcontour z.nc -J -B -C0.05 -O -K -Gd2i -S4 -X3.45i >> $ps
+# 绘制矢量场
gmt grdvector dzdx.nc dzdy.nc -I0.2 -J -O -K -Q0.1i+e+n0.25i -Gblack -W1p -S5i \
--MAP_VECTOR_SHAPE=0.5 >> $ps
+# 加标题
echo "3.2 3.6 z(x,y) = x@~\327@~exp(-x@+2@+-y@+2@+)" \
| gmt pstext -R0/6/0/4.5 -Jx1i -F+f40p,Times-Italic+jCB -O -X-3.45i >> $ps
rm -f z.nc dzdx.nc dzdy.nc
@@ -8,18 +8,11 @@ figure: ex013.png
data: []
---
-In many areas, such as fluid dynamics and elasticity, it is desirable to
-plot vector fields of various kinds. GMT provides a way to illustrate
-2-component vector fields using the
-:doc:`grdvector </grdvector>` utility. The two
-components of the field (Cartesian or polar components) are stored in
-separate grid files. In this example we use
-:doc:`grdmath </grdmath>` to generate a surface
-:math:`z(x, y) = x \cdot \exp(-x^2 -y^2)` and to calculate
-:math:`\nabla z` by returning the *x*- and *y*-derivatives separately.
-We superpose the gradient vector field and the surface *z* and also plot
-the components of the gradient in separate windows. A
-:doc:`pstext </pstext>` call to place a header finishes the plot
+GMT中的 `grdvector` 可用于绘制2D矢量场。2D矢量场的两个分量(笛卡尔坐标系
+下的X和Y分量,或极坐标系下的r和theta分量)分别保存在单独的网格文件中。
+
+本例中,首先使用 `grdmath` 命令生成了函数 `z(x, y) = x \cdot \exp(-x^2 -y^2)`
+并通过计算Z在X和Y方向的偏导得到了Z的梯度。图中绘制了Z矢量场、梯度场以及梯度的两个分量。
{% highlight bash %}
{% include {{page.script}} %}
View
@@ -1,19 +1,28 @@
#!/bin/bash
+# 绘制2D矢量场以及矢量场的等值线
#
-# Purpose: Illustrate vectors and contouring
-# GMT progs: grdmath, grdcontour, grdvector, pstext
-# Unix progs: echo, rm
+# GMT模块 : grdmath, grdcontour, grdvector, pstext
+# Unix命令: echo, rm
#
ps=ex013.ps
+
+# 生成 z = x exp(-x^2-y^2)
gmt grdmath -R-2/2/-2/2 -I0.1 X Y R2 NEG EXP X MUL = z.nc
+# 计算X和Y方向的偏导
gmt grdmath z.nc DDX = dzdx.nc
gmt grdmath z.nc DDY = dzdy.nc
+# 绘制X方向偏导的等值线
gmt grdcontour dzdx.nc -JX3i -B1 -BWSne -C0.1 -A0.5 -K -P -Gd2i -S4 -T+d0.1i/0.03i > $ps
+# 绘制Y方向偏导的等值线
gmt grdcontour dzdy.nc -J -B -C0.05 -A0.2 -O -K -Gd2i -S4 -T+d0.1i/0.03i -Xa3.45i >> $ps
+# 绘制Z等值线
gmt grdcontour z.nc -J -B -C0.05 -A0.1 -O -K -Gd2i -S4 -T+d0.1i/0.03i -Y3.45i >> $ps
+# 绘制Z等值线
gmt grdcontour z.nc -J -B -C0.05 -O -K -Gd2i -S4 -X3.45i >> $ps
+# 绘制矢量场
gmt grdvector dzdx.nc dzdy.nc -I0.2 -J -O -K -Q0.1i+e+n0.25i -Gblack -W1p -S5i \
--MAP_VECTOR_SHAPE=0.5 >> $ps
+# 加标题
echo "3.2 3.6 z(x,y) = x@~\327@~exp(-x@+2@+-y@+2@+)" \
| gmt pstext -R0/6/0/4.5 -Jx1i -F+f40p,Times-Italic+jCB -O -X-3.45i >> $ps
rm -f z.nc dzdx.nc dzdy.nc

0 comments on commit 6ef0b7c

Please sign in to comment.