-
Notifications
You must be signed in to change notification settings - Fork 3
/
fltdat2cquad
executable file
·143 lines (137 loc) · 3.55 KB
/
fltdat2cquad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/ksh
#
# reads flt patch geometry and slip from flt.dat and geom.in
# and writes to a geomview cquad file
#
# $Id: fltdat2cquad,v 1.1 2002/12/03 17:24:55 becker Exp becker $
#
# types of output:
# 1: absolute slip value
# 2: normal stress
# 3: shear (strike) stress
type=${1-1}
# cutoff, fraction of max
coff=${2-0.25}
# geometry
gfile=${3-geom.in}
# flt slip and stress data
fsfile=${4-flt.dat}
# fix max value?
fixmax=${5-0}
if [[ ! -s $gfile || ! -s $fsfile ]];then
echo $0: $gfile or $fsfile not found
exit
fi
tmpn=/tmp/$USER.$HOST.$$.pfd
trap "rm -f $tmpn.* ; exit" 0 1 2 15
#
# extract corners and vectors
#
cat $gfile | patch2xyzvec > $tmpn.cvec 2> /dev/null
# extract values: slip: strike, dip, normal absolute
# stress: strike dip normal
gawk '{if((substr($1,1,1)!="#")&&(NF>8))\
print($6,$8,$7,sqrt($6*$6+$8*$8+$7*$7),$9,$11,$10)}' \
$fsfile > $tmpn.val
# determine extrema of values
minmax -C $tmpn.val > $tmpn.ex
read usmin usmax udmin udmax unmin unmax uamin uamax ssmin ssmax sdmin sdmax snmin snmax < $tmpn.ex
# determine mean of values
gawk -f meanallcol.awk $tmpn.val > $tmpn.mean
read usmean udmean unmean uamean ssmean sdmean snmean < $tmpn.mean
# check file length
npatch=`lc $tmpn.cvec`
if [[ $npatch -ne `lc $tmpn.val` ]];then
echo $0: length mismatch
echo $0: cvec: `lc $tmpn.cvec`
echo $0: slip: `lc $tmpn.val`
exit
else
echo $0: $npatch patches
fi
if [ $type -eq 1 ];then # absolute slip
name=uabs
use=25
min=$uamin;max=$uamax;mean=$uamean
label="u@-abs@-"
# ls=a.5f.05
ls=a1f.1
elif [ $type -eq 2 ];then # normal stress
name=snorm
use=28
min=$snmin;max=$snmax;mean=$snmean
label="@~s@~@-n@-"
ls=a.2f.02
elif [ $type -eq 3 ];then # shear stress
name=sstr
use=26
min=$ssmin;max=$ssmax;mean=$ssmean
label="@~s@~@-s@-"
ls=a.2f0.02
else
echo $0: type $type not implemented
exit
fi
#
# readjust min and max
#
echo $min $max $coff $mean | \
gawk '{r=$2-$1;mi=$4-r*$3;ma=$4+r*$3;if(mi<$1)mi=$1;if(ma>$2)ma=$2;
print(mi,ma)}' > \
$tmpn.rem
read min max < $tmpn.rem
if [ $fixmax -ne 0 ];then
min=0;max=$fixmax
fi
echo $0: type: $type min: $min max: $max
#
# output
#
paste $tmpn.cvec $tmpn.val | \
# cvec x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 sx sy sz dx dy dz nx ny nz ustrike udip unormal uabs sstrike sdip snormal
# 1 4 7 10 13 16 19 21 22 23 24 25 26 27 28
gawk --assign use=$use --assign min=$min --assign max=$max \
'BEGIN{
range=max-min;\
print("CQUAD");\
}\
{\
x=($(use)-min)/range;\
col[1]=x;col[2]=1-((x-.5)**2)*4.;col[3]=1.0-x;\
for(i=1;i<=3;i++){\
if(col[i]<0)col[i]=0.0;\
if(col[i]>1)col[i]=1.0;\
}\
for(i=1;i<=4;i++)
printf("%g %g %g %g %g %g 1.0\n",
$((i-1)*3+1),$((i-1)*3+2),$((i-1)*3+3),
col[1],col[2],col[3]);
}' > flt.$name.cquad
#
# colorbar
#
dy=0.05
gawk --assign min=$min --assign max=$max --assign steps=150 \
--assign dy=$dy \
'BEGIN{\
range=max-min;\
dx=range/steps;\
xs=min+0.5*dx;
for(x=min;x<max;x+=dx){\
xp=(xs-min)/range;\
col[1]=xp;col[2]=1-((xp-.5)**2)*4.;col[3]=1.0-xp;\
for(i=1;i<=3;i++){\
col[i] *= 255;
if(col[i]<0)col[i]=0;\
if(col[i]>255)col[i]=255;\
}\
printf("> -G%i/%i/%i \n",col[1],col[2],col[3]);\
print(x,0);print(x+dx,0);print(x+dx,dy);print(x,dy);
xs+=dx;
}\
}' > $tmpn.cb
psxy $tmpn.cb -R$min/$max/0.001/$dy -JX4.6/.5 \
-B$ls/f100:.$label:weSn -P -N -M > flt.$name.cb.ps
modifybb flt.$name.cb.ps 65 40 405 170 > /dev/null
bbtofront flt.$name.cb.ps
echo $0: output in flt.$name.cquad and flt.$name.cb.ps