[cig-commits] commit: add header information in output of obsrelax.sh; add util script grd2vtk.sh
Mercurial
hg at geodynamics.org
Sun Sep 30 04:30:23 PDT 2012
changeset: 141:51d43e0bbf74
tag: tip
user: Sylvain Barbot <sbarbot at caltech.edu>
date: Sun Sep 30 04:30:18 2012 -0700
files: util/grd2vtk.sh util/obsrelax.sh
description:
add header information in output of obsrelax.sh; add util script grd2vtk.sh
diff -r 56f9a85034ed -r 51d43e0bbf74 util/grd2vtk.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/util/grd2vtk.sh Sun Sep 30 04:30:18 2012 -0700
@@ -0,0 +1,109 @@
+#!/bin/bash
+
+set -e
+self=$(basename $0)
+trap 'echo $self: Some errors occurred. Exiting.; exit' ERR
+
+grd2vtk_header(){
+ SX1=`grdinfo -C $GRDFILE | awk '{print $10}'`
+ SX2=`grdinfo -C $GRDFILE | awk '{print $11}'`
+ N=`echo $SX1 $SX2 | awk '{print $1*$2}'`
+ TITLE=`grdinfo -C $GRDFILE | awk '{print $1}'`
+ NPOLY=`echo $SX1 $SX2 | awk '{print ($1-1)*($2-1)*2}'`
+ NSIDE=`echo $SX1 $SX2 | awk '{print ($1-1)*($2-1)*2*4}'`
+
+ echo "# vtk DataFile Version 3.0"
+ echo $TITLE
+ echo "ASCII"
+ echo "DATASET POLYDATA"
+ echo "POINTS $N float"
+ if [ "$tset" != "1" ]; then
+ grd2xyz $GRDFILE | awk -v d=$depth '{print $2,$1,d}'
+ else
+ grd2xyz $GRDFILE | awk -v d=$depth '{print $2,$1,d-$3}'
+ fi
+ echo ""
+ echo "POLYGONS $NPOLY $NSIDE"
+ echo "" | awk -v SX1=$SX1 -v SX2=$SX2 '{ \
+ for (x2=1;x2<SX2;x2++){ \
+ for (x1=1;x1<SX1;x1++){ \
+ print 3,(x2-1)*SX1+x1-1,(x2-1)*SX1+x1,x2*SX1+x1; \
+ print 3,(x2-1)*SX1+x1-1,x2*SX1+x1-1,x2*SX1+x1 \
+ } \
+ } \
+ }'
+ echo ""
+ echo "POINT_DATA $N"
+}
+
+grd2vtk_footer(){
+ TITLE=`grdinfo -C $GRDFILE | awk '{print $1}'`
+ echo "SCALARS $(basename $TITLE .grd) float"
+ echo "LOOKUP_TABLE default"
+ grd2xyz $GRDFILE | awk '{print $3}'
+}
+
+
+
+usage(){
+ echo "$self converts a list of grd files to a vtk polygon polydata file"
+ echo "in ASCII legacy format for visualization in Paraview."
+ echo ""
+ echo "usage: $self file.grd > file.vtp"
+ echo ""
+ echo "or"
+ echo ""
+ echo " $self file1.grd file2.grd file3.grd > file.vtp"
+ echo ""
+ echo "options:"
+ echo " -d depth provide the uniform depth of the VTK file (0)."
+ echo " -t indicates that z-value is topography."
+ echo " For multiple files, the first file contains the topography."
+ echo " In combination with -d option, topography is shifted by depth."
+ echo ""
+ echo "note: in Paraview, the X axis is north, the Y axis is east,"
+ echo " and the Z axis is depth, forming a right-handed system."
+ echo ""
+}
+
+# print usage is no arguments are supplied or if redirection pipe is detected
+if [ ! -t 0 ] || [ $# -eq 0 ]; then
+ usage
+ exit
+fi
+
+# optional command-line parameters
+while getopts "d:t" flag
+do
+ case "$flag" in
+ r) dset=1;depth=$OPTARG;;
+ t) tset=1;;
+ esac
+done
+for item in $tset $Kset $Oset ;do
+ shift
+done
+for item in $dset ;do
+ shift;shift
+done
+
+if [ "$dset" != "1" ]; then
+ depth=0
+fi
+
+GRDFILE=$1
+grd2vtk_header
+grd2vtk_footer
+shift
+
+# loop over list of files to convert
+while [ $# -ne 0 ];do
+ GRDFILE=$1
+ if [ ! -e $GRDFILE ]; then
+ echo $self: could not find $GRDFILE. exiting. >&2
+ exit 2
+ fi
+ grd2vtk_footer
+ shift
+done
+
diff -r 56f9a85034ed -r 51d43e0bbf74 util/obsrelax.sh
--- a/util/obsrelax.sh Wed Sep 05 17:05:08 2012 -0700
+++ b/util/obsrelax.sh Sun Sep 30 04:30:18 2012 -0700
@@ -41,7 +41,7 @@ while [ "$#" != "0" ]; do
OFILE=$WDIR/$(basename $1 .txt)-relax.txt
echo $self: changing $IFILE to $OFILE
grep -v "#" $IFILE |
- awk '{if (1==NR){i2=$2;i3=$3;i4=$4;i5=$5;i6=$6;i7=$7;i8=$8;i9=$9;i10=$10}; \
+ awk 'BEGIN{print "# t u1 u2 u3 s11 s12 s13 s22 s23 s33"}{if (1==NR){i2=$2;i3=$3;i4=$4;i5=$5;i6=$6;i7=$7;i8=$8;i9=$9;i10=$10}; \
$2=$2-i2;$3=$3-i3;$4=$4-i4;$5=$5-i5;$6=$6-i6;$7=$7-i7;$8=$8-i8;$9=$9-i9;$10=$10-i10;print $0}' > $OFILE
else
# postseismic displacement relative to reference station
@@ -50,7 +50,7 @@ while [ "$#" != "0" ]; do
grep -v "#" $IFILE | awk '{if (1==NR){i2=$2;i3=$3;i4=$4;i5=$5;i6=$6;i7=$7;i8=$8;i9=$9;i10=$10}; \
$2=$2-i2;$3=$3-i3;$4=$4-i4;$5=$5-i5;$6=$6-i6;$7=$7-i7;$8=$8-i8;$9=$9-i9;$10=$10ii10;print $0}' | \
paste - $TMP | \
- awk '{$2=$2-$11;$3=$3-$12;$4=$4-$13;$5=$5-$14;$6=$6-$15;$7=$7-$16;$8=$8-$18;$9=$9-$18;$10=$10-$19; \
+ awk 'BEGIN{print "# t u1 u2 u3 s11 s12 s13 s22 s23 s33"}{$2=$2-$11;$3=$3-$12;$4=$4-$13;$5=$5-$14;$6=$6-$15;$7=$7-$16;$8=$8-$18;$9=$9-$18;$10=$10-$19; \
$11="";$12="";$13="";print $0}' > $OFILE
fi
shift
More information about the CIG-COMMITS
mailing list