Basilisk source code (http://basilisk.fr/src/)

root / src / bview.page

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
#!/bin/bash

:<<'DOC'
# Interactive Basilisk View

This shell script provides a simple way to start the Interactive
Basilisk View interface. 

Note that two versions of the script are provided depending on the
number of dimensions: `bview2D` and `bview3D`.

The server [bview-server.c]() can be run on the local machine or on a
distant server. The client [bview-client.py]() runs on the local
machine and provides graphical display and interaction.

The server's input pipe is connected both to the graphical interface
of the client and to the standard input on the local machine, so that
commands can be sent to the server either through the GUI or by typing
[drawing
commands](view.h#load-read-drawing-commands-from-a-file-or-buffer) on
standard input.

## Command-line arguments

Basilisk [dump files](output.h#dump-basilisk-snapshots) or [view
files](view.h#load-read-drawing-commands-from-a-file-or-buffer) (with
extension `.bv`) can be given as command-line arguments.

If a `.bv` file is given, the script also watches for any
modifications of this file. If changes are made, the current view is
cleared and the file is reloaded. Editing this file with a text editor
thus gives another way of interacting with the server.

## Installation

Note that the servers need to be
[installed](bview-server.c#installation) separately before using
`bview`.

You also need to check that the
[dependencies](bview-client.py#dependencies) of the Python client are
verified.

## Examples

A typical session could look like:

~~~bash
popinet@aldebaran:~$ bview3D
restore ("dump");
# t = 0.01, fields = { u.x u.y u.z g.x g.y g.z f rhov }
box ();
draw_vof ("f");
clear ();
box ();
squares ("f", min = 0, max = 1);
show ();
view (fov = 24, quat = {-0.242493,0.267956,0.0538964,0.930855}, \
   tx = 0, ty = 0, bg = {0.3,0.4,0.6}, width = 800, height = 800, samples = 4);
box ();
squares ("f", min = 0, max = 1);
save ("view.bv");
~~~

or

~~~bash
popinet@aldebaran~:$ touch view.bv && emacs view.bv & bview3D dump view.bv
# t = 0.01, fields = { u.x u.y u.z g.x g.y g.z f rhov }
~~~

Followed by editing (and saving) the `view.bv` file.

![A typical bview session.](figures/bview.png)

# Implementation
DOC

dimension=`echo -n $0 | tail -c 2`

watched=""
while test $# -gt 0; do
    case $1 in
	*@*) remote=$1 ;;
	*.bv) watched="$watched $1"; args="$args $1" ;;
	*) args="$args $1" ;;
    esac
    shift
done

fifo=`mktemp -u -t bview.XXXXXX`
mkfifo $fifo
if test -z "$remote"; then
    bview-server$dimension $args < $fifo | \
	python2.7 $BASILISK/bview-client.py > $fifo &
else
    ssh $remote bview-server$dimension $args < $fifo | \
	python2.7 $BASILISK/bview-client.py > $fifo &
fi
pids=$!

function ctrl_c() {
    rm -f $fifo
    kill $pids %1 $(jobs -p) 2> /dev/null
}

trap 'ctrl_c' SIGINT

modtime() {
    if test -f $1; then
	find $1 -printf "%TY/%Tm/%Td %TH:%TM:%.2TS\n"
    fi
}

watchbv() {
    time=`modtime $1`
    while true; do
	time1=`modtime $1`
	if [[ "$time1" != "$time" ]] ; then
	    echo "interactive (false);"
	    echo "clear();"
	    cat $1
	    echo
	    echo "interactive (true);"
	    echo "display();"
	    time="$time1"
	fi
	sleep 1
    done
}

for f in $watched; do
    watchbv $f > $fifo &
done

cat > $fifo

ctrl_c