forked from SHYFEM-model/shyfem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgps
executable file
·327 lines (269 loc) · 6.43 KB
/
gps
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/bin/sh
#
#------------------------------------------------------------------------
#
# Copyright (C) 1985-2018 Georg Umgiesser
#
# This file is part of SHYFEM.
#
#------------------------------------------------------------------------
#
# handle postscript files
#
# needed programs:
#
# parr (with option -A)
# gps2eps
# psresetbb.sh
# gifcrop (needs netpbm routines)
#
# epstopdf (/usr/bin/epstopdf)
#
# convert (Imagemagick)
# gifsicle (gifsicle)
#
# 02.05.2013 ggu allow for single pages to be extracted
#
######################################################### copyright
copy2="gps - shell for generation of plot files"
copy3="Copyright (c) 1998-2002 Georg Umgiesser - ISDGM/CNR"
copy4="e-mail: georg@isdgm.ve.cnr.it"
######################################################### help - usage
Copy()
{
echo "$copy2"
echo "$copy3"
}
Usage()
{
echo "Usage: gps [ -h | -help ] [ -options ] file[s]"
}
FullUsage()
{
echo ""
Copy
echo ""
Usage
echo ""
echo "Available options:"
echo " -h|-help this help"
echo " -verbose be verbose"
echo " -quiet be quiet"
echo " -split split ps file into single pages"
echo " -pages range extract single pages (range: 1,3,4-8)"
echo " -eps convert ps files into eps files"
echo " -pdf convert (e)ps files into pdf files"
echo " -gif convert files into gif files"
echo " -jpg convert files into jpg files"
echo " -png convert files into png files"
echo " -bmp convert files into bmp files"
echo " -dpi # for raster files use this resolution in dpi"
echo ""
}
ErrorOption()
{
echo "No such option : $1"
}
Extension()
{
file=$1
ext=`echo $file | sed -e 's/^.*\././'`
echo $ext
}
Basename()
{
file=$1
ext=`Extension $file`
base=`basename $file $ext`
echo $base
}
CleanExtra()
{
# cleans up files like "plot.png.1" etc...
name=$1
if [ -f $name.0 ]; then
mv $name.0 $name
rm -f $name.[1-9]*
fi
}
RotateEps()
{
name=$1
ext=$2
if [ $ext = ".eps" -o $ext = ".ps" ]; then
grep "^%%Orientation: Landscape" $name > /dev/null
status=$?
#echo "eps or ps: $name - $status"
if [ $status -eq 0 ]; then
echo "-rotate 90"
fi
else
echo ""
fi
}
ReduceGif()
{
# this has to be done since convert creates too big GIF files
# this also eliminates the second (useless) frame from a gif image
newext=".gif"
for file in $*
do
base=`Basename $file`
target=$base$newext
[ $quiet = "NO" ] && echo "reducing $target"
#gifcrop -o $target > tmp.gif
#[ $? -eq 0 ] && mv tmp.gif $target
#gifsicle $target '#0' > tmp.gif
#[ $? -eq 0 ] && mv tmp.gif $target
done
}
Convert()
{
# in $format is the file type if needed (only for jpeg...)
newext=$1
shift
for file in $*
do
base=`Basename $file`
ext=`Extension $file`
source=$base$ext
target=$base$newext
[ $quiet = "NO" ] && echo "$source -> $target"
#echo "options: $dpi $rotate $format"
rotate=`RotateEps $source $ext` # this rotates Landscape ps/eps files
CleanExtra $target
convert $dpi $rotate $source $format$target
CleanExtra $target
done
}
ConvertPDF()
{
newext=$1
shift
for file in $*
do
base=`Basename $file`
ext=`Extension $file`
source=$base$ext
target=$base$newext
[ $quiet = "NO" ] && echo "$source -> $target"
epstopdf $source
done
}
######################################################### end
#########################################################################
#########################################################################
#########################################################################
#########################################################################
#########################################################################
######################################################### defaults
verbose="NO"
quiet="NO"
split="NO"
pages=""
eps="NO"
pdf="NO"
gif="NO"
jpg="NO"
png="NO"
bmp="NO"
dpi=""
######################################################### read options
while [ -n "$1" ]
do
case $1 in
-quiet) quiet="YES";;
-verbose) verbose="YES";;
-split) split="YES";;
-pages) pages=$2; shift;;
-eps) eps="YES";;
-pdf) pdf="YES";;
-gif) gif="YES";;
-jpg) jpg="YES";;
-png) png="YES";;
-bmp) bmp="YES";;
-dpi) dpi=$2; shift;;
-h|-help) FullUsage; exit 0;;
-*) ErrorOption $1; exit 1;;
*) break;;
esac
shift
done
if [ -n "$dpi" ]; then
dpi="-units PixelsPerInch -density $dpi"
fi
######################################################### no file -> write help
if [ $# -le 0 ]; then
Usage
exit 1;
fi
######################################################### split files
newfiles=""
if [ $split = "YES" -o -n "$pages" ]; then
for file in $*
do
filename=`basename $file .ps`
rm -f $filename.[0-9]*.ps
if [ $split = "YES" ]; then
parr -A $file
else
parr -A -o $pages $file
fi
newfile=`ls -m $filename.[0-9]*.ps`
[ $quiet = "NO" ] && echo "$file -> $newfile"
newfiles="$newfiles $newfile"
done
else
newfiles=`ls -m $*`
fi
newfiles=`echo $newfiles | sed -e 's/,/ /g' | sed -e 's/ */ /g'`
[ $verbose = "YES" ] && echo "$newfiles"
######################################################### look for 0 size files
auxfiles=""
for file in $newfiles
do
if [ -s $file ]; then
auxfiles="$auxfiles $file"
else
echo "file $file has size 0 ... ignoring"
fi
done
newfiles=$auxfiles
######################################################### ps -> eps
if [ $eps = "YES" ]; then
auxfiles=""
for file in $newfiles
do
basefile=`Basename $file`
ext=`Extension $file`
psfile=$basefile$ext
epsfile=$basefile.eps
[ $quiet = "NO" ] && echo "$psfile -> $epsfile"
#ps2eps $psfile -o$epsfile 2> /dev/null
gps2eps $psfile > $epsfile
psresetbb.sh $epsfile
auxfiles="$auxfiles $epsfile"
done
newfiles=$auxfiles
fi
# $newfiles -> files to convert
#########################################################
if [ $gif = "YES" ]; then
Convert ".gif" $newfiles
ReduceGif $newfiles
fi
if [ $jpg = "YES" ]; then
format="jpeg:"
Convert ".jpg" $newfiles
format=""
fi
if [ $png = "YES" ]; then
Convert ".png" $newfiles
fi
if [ $bmp = "YES" ]; then
Convert ".bmp" $newfiles
fi
if [ $pdf = "YES" ]; then
ConvertPDF ".pdf" $newfiles
fi
######################################################### end