#!/usr/bin/ksh93 compound c=( compound tty=( integer max_x integer max_y ) compound sample_data=( float -a vals float min=0 float max=0 ) float min_data_shift float max_data_shift float data_scale_to_tty_max_y ) integer i # # get terminal info # (( c.tty.max_x=$(tput cols)-2 )) (( c.tty.max_y=$(tput lines)-2 )) # # collect samples data # integer max_i=${c.tty.max_x} for ((i=0 ; i < max_i ; i++ )) ; do (( c.sample_data.vals[i]=sin(i/5.) )) done # # get minimum/maximum value of all data samples # # we use $ for i in "${!@}" instead of $ for ((i=0 ; i < ... ; i++ )) # syntax # here so we can handle sparse data/sparse arrays # for i in "${!c.sample_data.vals[@]}" ; do (( c.sample_data.min=fmin(c.sample_data.vals[i], c.sample_data.min) )) (( c.sample_data.max=fmax(c.sample_data.vals[i], c.sample_data.max) )) done # # calculations for output scaling etc # (( c.min_data_shift = c.sample_data.min * -1.0 )) (( c.max_data_shift = c.min_data_shift + c.sample_data.max )) (( c.data_scale_to_tty_max_y = c.tty.max_y / c.max_data_shift )) # # output # tput clear for i in "${!c.sample_data.vals[@]}" ; do tput cup $(( int( c.data_scale_to_tty_max_y * (c.min_data_shift+c.sample_data.vals[i]) ) )) $i printf '.' done # move cursor to bottom, and then print a newline tput cup ${c.tty.max_y} ${c.tty.max_x} ; print #print -v c # EOF.