-
Notifications
You must be signed in to change notification settings - Fork 2
/
healpix_doc
executable file
·343 lines (277 loc) · 7.87 KB
/
healpix_doc
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#! /bin/sh
test_pdf_viewer () {
if [ "$VIEWER" = "" ]; then
for DIR in `echo $PATH | sed 's/:/ /g'`; do
if [ -f "$DIR/$1" ]; then
VIEWER=$1
fi
done
fi
}
open_pdf_viewer () {
# adapted from IDL's online_help_pdf (May 2010)
# added gv
# added evince 2012-02-29
this_code=open_pdf_viewer
# If viewer is not specified by the environment variable, choose a default
# VIEWER=$IDL_ONLINE_HELP_PDF_VIEWER
VIEWER=$HEALPIX_PDF_VIEWER
if [ \( "$VIEWER" = "" \) -a \( `uname` = "Darwin" \) ]; then
VIEWER=darwin_open
fi
# try general purpose file opener (Linux)
test_pdf_viewer "xdg-open"
# try general purpose file opener (Gnome)
test_pdf_viewer "gnome-open"
# If we see Adobe's acroread, we'll default to it.
test_pdf_viewer "acroread"
# If we didn't find acroread, then try the free Xpdf viewer
test_pdf_viewer "xpdf"
# fall back on evince # (Gnome)
test_pdf_viewer "evince"
# fall back on okular # (KDE)
test_pdf_viewer "okular"
# fall back on foxit #
test_pdf_viewer "foxit"
# fall back on sumatra (Windows)
test_pdf_viewer "sumatra"
# fall back on gv
test_pdf_viewer "gv"
if [ "x$VIEWER" = "x" ]; then
# No view in evidence.
echo "PDF viewer (xdg-open, gnome-open, acroread, xpdf, evince, okular, foxit, sumatra, gv) not found in user's PATH" 1>&2
aboutCustomization
exit 1
fi
case $VIEWER in
darwin_open)
open $1 &
;;
xdg-open*|gnome-open*)
$VIEWER $1 > /dev/null 2>&1 &
;;
acroread*|xpdf*|evince*|okular*|foxit*|gv*)
$VIEWER $1 &
;;
sumatra*)
$VIEWER $1 &
;;
*)
$VIEWER $1 &
;;
esac
}
# ======================================================================
test_html_browser () {
if [ "$BROWSER" = "" ]; then
found=`which $1 2> /dev/null`
[ "$found" ] && BROWSER=$1
fi
}
open_html_browser () {
# adapted from IDL's online_help_html (May 2010)
# If browser is not specified by the environment variable, then use the default
BROWSER=$HEALPIX_HTML_BROWSER
if [ "$BROWSER" = "" ]; then
if [ `uname` = "Darwin" ]; then
BROWSER=darwin_open
else
test_html_browser "xdg-open"
test_html_browser "gnome-open"
test_html_browser "firefox"
test_html_browser "mozilla"
test_html_browser "netscape"
test_html_browser "opera"
test_html_browser "lynx"
if [ "x$BROWSER" = "x" ]; then
# No browser in evidence.
echo "HMTL browser (xdg-open, gnome-open, firefox, mozilla, netscape, opera, lynx) not found in user's PATH" 1>&2
aboutCustomization
exit 1
fi # empty
fi # Darwin
fi # $BROWSER
case "$BROWSER" in
"darwin_open")
href="\"file://$1\""
osascript -e 'open location '$href
;;
"xdg-open"|"gnome-open")
$BROWSER $1 > /dev/null 2>&1 &
;;
"lynx")
xterm -e lynx "$1" &
;;
"mozilla"|"firefox")
$BROWSER -remote "openURL(file:$1, new-tab)" 2>/dev/null # try to open tab in existing session
if [ $? != 0 ]; then # if it fails, start a fresh session
$BROWSER "file:$1" &
fi
;;
"netscape")
$BROWSER -remote "openURL(file:$1)" 2>/dev/null
if [ $? != 0 ]; then
$BROWSER "$1" &
fi
;;
"opera")
$BROWSER -remote "openURL(file:$1)" & # open existing or new session
;;
*)
$BROWSER "$1"
;;
esac
}
# ======================================================================
test_epub_viewer () {
if [ "$EPUB_VIEWER" = "" ]; then
found=`which $1 2> /dev/null`
[ "$found" ] && EPUB_VIEWER=$1
fi
}
open_epub_viewer () {
this_code=open_epub_viewer
# If viewer is not specified by the environment variable, choose a default
EPUB_VIEWER=$HEALPIX_EPUB_VIEWER
if [ \( "$EPUB_VIEWER" = "" \) -a \( `uname` = "Darwin" \) ]; then
EPUB_VIEWER=darwin_open
fi
test_epub_viewer "ebook-viewer"
test_epub_viewer "FBReader"
test_epub_viewer "fbreader"
test_epub_viewer "okular"
test_epub_viewer "lucidor"
test_epub_viewer "buka"
if [ "x$EPUB_VIEWER" = "x" ]; then
# No view in evidence.
echo "EPUB viewer (ebook-viewer, FBReader, okular, lucidar, buka) not found in user's PATH" 1>&2
aboutCustomization
exit 1
fi
case $EPUB_VIEWER in
darwin_open)
open $1 &
;;
*)
$EPUB_VIEWER $1 &
;;
esac
}
# ======================================================================
aboutCustomization(){
echo ""
echo "By default, $0 will look for PDF and EPUB viewers and HTML browser among the standard ones,"
echo "unless the variables \$HEALPIX_PDF_VIEWER, \$HEALPIX_EPUB_VIEWER and \$HEALPIX_HTML_BROWSER are set by the user."
echo "Currently: "
echo "HEALPIX_EPUB_VIEWER = $HEALPIX_EPUB_VIEWER"
echo "HEALPIX_PDF_VIEWER = $HEALPIX_PDF_VIEWER"
echo "HEALPIX_HTML_BROWSER = $HEALPIX_HTML_BROWSER"
echo ""
}
# ======================================================================
testDocLocation(){
docdir=""
# try $HEALPIXDOC (custom installation)
[ "x${HEALPIXDOC}" != "x" ] && docdir=${HEALPIXDOC}
# try $HEALPIX/doc (standard installation)
if [ "x${docdir}" = "x" ]; then
if [ "x${HEALPIX}" = "x" ]; then
echo ""
echo "WARNING: \$HEALPIX variable not set"
echo " It must be defined before running Healpix"
echo ""
else
docdir=${HEALPIX}/doc
fi
fi
# try around current script (standard, but unfinished, installation)
if [ ! -d "${docdir}" ]; then
thiscode=$0
# poor man's emulation of recursive 'readlink -f'
[ -L "${thiscode}" ] && thiscode=$( readlink ${thiscode} ) # follow link, if applicable
[ -L "${thiscode}" ] && thiscode=$( readlink ${thiscode} ) # follow link again
thispath=$( dirname ${thiscode} )
topdir=$( cd ${thispath} && pwd )
docdir=${topdir}/doc
fi
# try current directory (desperate)
[ ! -d ${docdir} ] && docdir=./doc
# test final value of $docdir
if [ ! -d ${docdir} ]; then
echo "Can not find local HEALPIX documentation"
echo "(expected to be in \${HEALPIX}/doc/ or in \${HEALPIXDOC}/)"
exit 1
# echo "Will try to use remote HEALPIX documentation"
# docdir="http://healpix.sourceforge.net/doc"
fi
}
# ======================================================================
verbose=0 # set to 1 to know which tool is used
# find documentation location
testDocLocation
file=""
#[ ${#} -eq 1 ] && file=$1
[ ${#} -ge 2 ] && file=$2
type=0
while [ ${type} -le 0 ]; do
if [ ${#} = 0 -o ${type} = -1 ]; then
echo " Healpix on line documentation "
echo
echo " healpix_doc [-e|-h|-p] "
echo " -e: view EPUB documentation "
echo " -h: browse HTML documentation "
echo " -p: view PDF documentation "
echo
printf " Enter your choice: e, h, p, ? (getting help) or 0 (to exit): "
read answer
if [ "x$answer" = "x0" ]; then
echo "Bye ..."
exit 0
fi
[ "x$answer" = "xE" -o "x$answer" = "xe" ] && type=3
[ "x$answer" = "xH" -o "x$answer" = "xh" ] && type=1
[ "x$answer" = "xP" -o "x$answer" = "xp" ] && type=2
if [ "x$answer" = "x?" ]; then
aboutCustomization
exit 0
fi
if [ $type -le 0 ] ; then
echo "unkwnown answer ..."
exit 1
fi
else
type=-1
[ "${1:0:2}" = "-e" ] && type=3
[ "${1:0:2}" = "-h" ] && type=1
[ "${1:0:2}" = "-p" ] && type=2
fi
done
##echo $file
case $type in
1)
echo "opening HEALPIX HTML documention"
deffile=${docdir}/html/main.htm
[ "x$file" != "x" ] && deffile=${file}
open_html_browser ${deffile}
[ ${verbose} -eq 1 ] && echo "browser: ${BROWSER}"
;;
2)
echo "opening HEALPIX PDF documention"
deffile=${docdir}/pdf/pdf_index.pdf
[ "x$file" != "x" ] && deffile=${file}
open_pdf_viewer ${deffile}
[ ${verbose} -eq 1 ] && echo "viewer: ${VIEWER}"
;;
3)
echo "opening HEALPIX EPUB documention"
deffile=${docdir}/epub/HEALPixDocumentation.epub
[ "x$file" != "x" ] && deffile=${file}
open_epub_viewer ${deffile}
[ ${verbose} -eq 1 ] && echo "viewer: ${EPUB_VIEWER}"
;;
*)
echo "Unknown option"
exit 1
;;
esac
exit 0