FISH Syntax Example Data File

 1; fname : ballexample.dat
 2;
 3;  Illustrate basic usage of the ball.pos FISH intrinsic function
 4; =============================================================================
 5model new
 6
 7fish define get_ball_position_vector(bid)
 8  ; retrieve the vector position of the ball with ID bid
 9  local b = ball.find(bid) ; get address of ball with ID bid
10  local v = ball.pos(b)   ; read access to the position of ball with address b
11  get_ball_position_vector = v
12end
13
14fish define set_ball_position_component(bid,idir,val)
15  ; retrieve the idir component vector position of the ball with ID bid
16  local b = ball.find(bid) ; get address of ball with ID bid
17  ball.pos(b,idir) = val ; write access to the idir-component position
18end
19
20; set the model domain and create a ball
21model domain extent -1 1
22ball create id 1 position-x 0.0 position-y 0.0 radius 0.1
23
24; create the global FISH variable vp1, execute the get_ball_position_vector 
25; function and store the program return value in vp1
26[global vp1 = get_ball_position_vector(1)]
27fish list [vp1]  ; output the value of vp1 in the console pane
28
29; execute the set_ball_position_component function to assign a new x-component
30[set_ball_position_component(1,1,0.1)]
31
32; execute the set_ball_position_component function to assign a new y-component
33[set_ball_position_component(1,2,0.2)]
34
35; use inline FISH to create the global FISH variable vp2, execute the 
36; get_ball_position_vector function and store the program return value in vp2
37[vp2 = get_ball_position_vector(1)]
38fish list [vp2]  ; output the value of vp2 in the console pane
39
40program return