Debian Codegraph @

bin/ascii2ps

raw
1 #!/bin/csh -f
2 ### ascii2ps -- Generate postscript from 3 column ascii file.
3 ### Example script to generate grd file from phi lambda height
4 ### output of Doris InSAR software.
5 ### Ramon Hanssen, Bert Kampes, 07-Dec-2000.
6 ### a good idea would be to use gmtconvert instead of the ascii input.
7 ### $Id: ascii2ps,v 1.6 2004/09/15 10:49:03 kampes Exp $
8 ### MCC - some GMT v4 compatiblity
9 ################################################################
10 set PRG = `basename "$0"`
11 set VER = "v1.1 Doris software"
12 #set AUT = "bert kampes, (c)1999-2003"
13 set AUT = "TUDELFT, (c)1999-2009"
14 echo "$PRG $VER, $AUT"
15 echo " "
16
17
18
19 ### Handle wrong input
20 set WRONG = "0"
21
22 ### Input files: 3 column ascii lon/lat/hei triplets.
23 set XYZFILE = "$1"
24 if ( $#argv < 1 ) set WRONG = "1"
25 if ( $WRONG == "1" ) then
26 cat << __EOFHD
27 USAGE:
28 $PRG 3col_asciifile
29
30 Create a postscript file of the data in the 3 column ASCII input file
31 containing "lon lat hei" triplets (output of lonlathei2ascii
32 program). GMT is used to interpolate these irregularly distributed
33 data to a grid.
34
35 This script is intended to be transparent and understandable.
36 Please adapt this script to your own needs. (lambda=longitude).
37 For example, here one could easily set the correct approximate
38 height of the terrain.
39
40 The output is a postscript file named "temp.ps".
41
42 The steps foreseen to be taken are:
43 [before running this, create a three column ascii file with lon lat hei
44 using philamh2ascii program.
45 AND optionally convert this 3 column file to UTM coordinates
46 using ascii2ascii_UTM
47 ]
48 2) Call GMT program xyz2grd to perform interpolation of this data.
49 the number of points in the output grid is 300.
50 3) call GMT program cpt to create a color table
51 4) call GMT program to create a postscript file
52 5) call ghostview to view output.
53
54 This script can serve as an example. If you want to have another resolution
55 output grid, for example exactly 100x100 meters, then you will have
56 to change this script.
57 With the public domain software PROJ.4, you can easily convert the
58 WGS coordinates (Doris output) to X,Y values, and then use this script.
59 See the script ascii2ascii_UTM for an example how to do this for WGS
60 to UTM coordinates conversion.
61
62
63 DEPENDENCIES:
64 GMT tools (gmtset, minmax, xyz2grd, grd2cpt, psbasemap
65 psscale, grdgradient, psmask, grdimage, pscoast)
66 standard UNIX (echo, csh, rm, etc.)
67 ghostview
68
69 EXAMPLE:
70 $PRG lonlathei.dat
71
72 $PRG xyz_UTM.dat
73
74 SEE ALSO:
75
76 cpxfiddle, http://gmt.soest.hawaii.edu/
77
78 __EOFHD
79 exit 1
80 endif
81
82
83 ### Program variables.
84 set CMAP = sealand
85 set CPTFILE = temp.cpt
86 set GRDFILE = temp.grd
87 set PSFILE = temp.eps
88 #use paper=a4+ for eps, a4 for ps
89 rm -f $PSFILE
90 rm -f $CPTFILE $GRDFILE
91
92 #---------------------------
93 # GMT defaults override
94 #---------------------------
95 gmtset MEASURE_UNIT cm \
96 PAPER_MEDIA a4+ \
97 PAGE_ORIENTATION portrait \
98 ANOT_FONT Helvetica \
99 ANOT_FONT_SIZE 10p \
100 ANOT_OFFSET 0.2c \
101 BASEMAP_AXES WeSn \
102 LABEL_FONT Helvetica \
103 LABEL_FONT_SIZE 10 \
104 UNIX_TIME_POS -2c/-2c
105 #---------------------------
106
107
108 #### program philamh2ascii replaces code below
109 #### if file temp.xyz exists already, maybe you do not want to wait again?
110 #### but for now, always recompute it.
111 #if ( "1" == "2" ) then
112 #### Convert binary files to ascii row; trick cpxfiddle with -w1.
113 #echo " Convert LONGITUDES in binary real4 file" \"${LON}\" "to ascii table"
114 # #cpxfiddle -w1 -qnormal -fcr4 $LON | awk '{printf "%3.4f\n%3.4f\n",$1,$2}' > qlon
115 # # using new r4 option to cpxfiddle
116 # cpxfiddle -w1 -qnormal -fr4 $LON > qlon
117 #echo " Convert LATITUDES in binary real4 file" \"${LAT}\" "to ascii table"
118 # cpxfiddle -w1 -qnormal -fr4 $LAT > qlat
119 #echo " Convert HEIGHTS in binary real4 file" \"${HEI}\" "to ascii table"
120 # cpxfiddle -w1 -qnormal -fr4 $HEI > qhei
121 #
122 #### Create xyz file, delete temp files.
123 #echo "Paste LAT/LON/HEI to xyzfile" \"${XYZFILE}\"
124 # paste qlon qlat qhei > $XYZFILE.tmp
125 #echo "removing -999 from input (unwrap problem, or other problem)"
126 # grep -v '\-999' $XYZFILE.tmp > $XYZFILE
127 # rm -f qlon qlat qhei $XYZFILE.tmp
128 #endif
129
130
131 ### Get min/max and increment from data itselves.
132 ### Assume lat/lon is formatted as %7.4f?
133 ### Not robust yet?
134 echo "finding out minmax in ascii column data"
135 set minmax = `minmax $XYZFILE`
136 echo minmax $minmax
137 set WEST = `echo $minmax | cut -d '<' -f2 | cut -d'/' -f1`
138 set EAST = `echo $minmax | cut -d '<' -f2 | cut -d'/' -f2 | cut -d'>' -f1`
139 set SOUTH = `echo $minmax | cut -d '<' -f3 | cut -d'/' -f1`
140 set NORTH = `echo $minmax | cut -d '<' -f3 | cut -d'/' -f2 | cut -d'>' -f1`
141 set MINHEI = `echo $minmax | cut -d '<' -f4 | cut -d'/' -f1`
142 set MAXHEI = `echo $minmax | cut -d '<' -f4 | cut -d'/' -f2 | cut -d'>' -f1`
143 echo " "
144
145 ### handle 1e+06 format gracefully?
146 #set EAST = `echo $EAST | awk '{printf "%.20f", $1}'`
147 #set WEST = `echo $WEST | awk '{printf "%.20f", $1}'`
148 #set SOUTH = `echo $SOUTH | awk '{printf "%.20f", $1}'`
149 #set NORTH = `echo $NORTH | awk '{printf "%.20f", $1}'`
150 echo "Using the following parameters:"
151 echo "-------------------------------"
152 echo "WEST: $WEST"
153 echo "EAST: $EAST"
154 echo "SOUTH: $SOUTH"
155 echo "NORTH: $NORTH"
156 echo "MINHEI: $MINHEI"
157 echo "MAXHEI: $MAXHEI"
158
159 ### try to figure out if we have UTM coordinates
160 ### assume utm if north is big.. or small
161 set CARTESIAN = `echo "$NORTH $SOUTH" | awk '{if(($1>200)||($2<-200)){print"1"}else{print"0"}}'`
162 echo "CARTESIAN = $CARTESIAN"
163 #
164 # numgrd should be multiple of 100?
165 # number of points in output grid in 1 direction
166 set NUMGRD = "200"
167 #set IX = `echo $WEST $EAST $NUMGRD | awk '{print ($2-$1)/($3-1)}'`
168 #set IX = `echo $WEST $EAST $NUMGRD | awk '{print ($2-$1)/$3}'`
169 #set IY = `echo $SOUTH $NORTH $NUMGRD | awk '{print ($2-$1)/$3}'`
170 ### report of Bruno Crippa that awk is not precise enough, use bc:
171 #%// BK 24-Nov-2002
172 #set IX = `echo "scale=20; ( $EAST - $WEST ) / $NUMGRD" | bc -l`
173 #set IY = `echo "scale=20; ( $NORTH - $SOUTH ) / $NUMGRD" | bc -l`
174 # but why not? (awk handles at least 1.2342e+06)
175 set IX = `echo $WEST $EAST $NUMGRD | awk '{printf "%.20f", ($2-$1)/$3}'`
176 set IY = `echo $SOUTH $NORTH $NUMGRD | awk '{printf "%.20f", ($2-$1)/$3}'`
177 #
178 #set RANGE = `minmax -I$IX/$IY $XYZFILE`
179 set RANGE = "-R$WEST/$EAST/$SOUTH/$NORTH"
180 set IXkm = `echo "scale=3; $IX * 40000 / 360" | bc -l`
181 set IYkm = `echo "scale=3; $IY * 40000 / 360" | bc -l`
182 echo "RANGE: " $RANGE
183 if ( "$CARTESIAN" == "1" ) then
184 echo "Sample interval X: $IX degrees, or $IXkm km at equator"
185 echo "Sample interval Y: $IY degrees, or $IYkm km at equator"
186 else
187 echo "Sample interval X: $IX m"
188 echo "Sample interval Y: $IY m"
189 endif
190
191
192
193 ### OR, use minmax to get range, much better...
194 #set IX = 200
195 #set IY = 200
196 #set RANGE = `minmax -I$IX $XYZFILE`
197 #echo "IX = $IX [m]"
198 #echo "IY = $IY [m]"
199 #echo "RANGE = $RANGE"
200
201
202
203 ### Create grd file with xyz2grd (better use surface).
204 echo "do xyz2grd"
205 xyz2grd $XYZFILE -G$GRDFILE -I$IX/$IY $RANGE
206 #awk '{print $1, $2, $3+1000.0}' $XYZFILE | surface -G$GRDFILE -I$IX/$IY $RANGE -T0.75
207 #surface $XYZFILE -G$GRDFILE -I$IX/$IY $RANGE -T0.75
208
209
210 #echo "for unwrapped ifg, converting to cm slant range displacement"
211 #grdmath $GRDFILE 1.4 MUL PI DIV = temp.grd2; mv temp.grd2 $GRDFILE
212
213
214
215 #echo "setting min_z --> 0"
216 #echo "you may not want this"
217 # grdmath $GRDFILE $MINHEI SUB = temp.grd2; mv temp.grd2 $GRDFILE
218 #set MINHEI = 0.0
219 #set MAXHEI = `echo $MINHEI $MAXHEI | awk '{printf "%f", $2 - $1}'`
220
221
222 ### Create colormap from data with grd2cpt.
223 #set CPTFILE = /home/fmr/d4/hanssen/gmt_scripts/colortables/minpipi.cpt
224 #set CPTFILE = /home/fmr/d4/hanssen/gmt_scripts/colortables/mass.cpt
225 echo "creating colormapping..."
226 set INCHEI = `echo $MINHEI $MAXHEI 255 | awk '{print($2-$1)/$3}'`
227
228 echo "grd2cpt $GRDFILE -C$CMAP -Z -S$MINHEI/$MAXHEI/$INCHEI"
229 #grd2cpt $GRDFILE -C$CMAP -Z -S$MINHEI/$MAXHEI/$INCHEI >! $CPTFILE
230 grd2cpt $GRDFILE -C$CMAP -Z >! $CPTFILE
231
232
233 ### Actually start GMT plotting.
234 # proj better use correct scaling for x/y
235 set proj = "-JX15"
236 set ticks = "-Bf0.1a1.0/f0.1a1.0"
237 if ( "$CARTESIAN" == "1" ) set ticks = "-Bf5000.0a40000.0/f5000.0a40000.0"
238 echo "proj = $proj"
239 echo "ticks = $ticks"
240 echo "psbasemap $proj $RANGE $ticks -U -K "
241 psbasemap $proj $RANGE $ticks -U -K >! $PSFILE
242 echo "psscale -I1 -D12.5/-1.2/5/0.4h -C$CPTFILE -B1000:a:/:m: -O -K "
243 psscale -I1 -D12.5/-1.2/5/0.4h -C$CPTFILE -B1000:a:/:m: -O -K >> $PSFILE
244 echo "grdgradient"
245 grdgradient $GRDFILE -A0 -Nt -G$GRDFILE.gradient
246 echo "skipping psmask"
247 #echo "psmask"
248 #psmask $XYZFILE -I$IX $proj $RANGE -K -O -S100 >> $PSFILE
249 echo "grdimage"
250 grdimage $GRDFILE $proj -I$GRDFILE.gradient -C$CPTFILE -R -B -K -O >> $PSFILE
251 echo "pscoast (last call)"
252 pscoast $proj -R -B -Dh -W1 -S0/0/255 -O >> $PSFILE
253
254
255
256
257 ############################################################################
258 ### View result
259 #if ( $PSFILE > 1kb ) ...
260 #set GV = ghostview
261 set GV = gv
262 echo "using gv to view file: $PSFILE"
263 #echo "using ghostview to view file: $PSFILE"
264 $GV $PSFILE
265
266
267 ### EOF.
268