0

I'm trying to create a live animation with gnu plot using the reread command.

my main program outputs a series of data files like

 0.0000000.dat
 0.1000000.dat 
 10.500000.dat

etc. and I want the script to serially plot each of these files and stop when it runs out of file (pause on the last one).

This is what I have so far. Get_File_Name is a bash function which formats the file names properly.

source ~/Source_Me/*.sh

shopt -s expand_aliases

### Process input parameters
if [ "$1"  ];
then
        Time=$1
else
        echo "No start time detected, starting at 0.0"
        Time=0.0
fi

if [ "$2"  ];
then
        Increment=$2
else
        echo "No time increment specified. choosing 0.1" 
        Increment=0.1
fi

if [ "$3" ];
then
        FrameDelay=$3
else
        echo "No frame delay time specified, choosing 0.25 s"
        FrameDelay=0.35
fi



FileName=$(Get_File_Name $Time orbs)
        # Do this from command line
        #Do the plotting
gnuplot << EOF
t = $Time       
print t
        set pm3d map
        splot "$(Get_File_Name $Time orbs)" u 1:2:8


        pause 1 
       ### Increment the time somehow
       ### reread conditionally upon the existence of the next file
EOF

I know that you can call a bash function within gnu plot using

system "<command>"

but this creates a new environment which can't manipulate existing variables. I can't figure out how to manipulate the bash variables within the gnu plot block.

    gnuplot << EOF
     EOF

How can I increment the time and filename variable within the gnuplot block?

Mr.Weathers
  • 398
  • 1
  • 5
  • 19
  • Not sure I understand. Your question implies the `gnuplot` is within a `bash` loop yet it doesn't appear to be. – Mark Setchell May 26 '17 at 22:02
  • If I put the `gnuplot` inside a `bash` loop then the plot window would close between each iteration. This is unacceptably slow. If I used the native `gnuplot` command `reread` then the same plot window would remain open and the displayed data would change. As I understand it `reread` would loop back to the `gnuplot << EOF` every time it is hit. If I put `reread` in a conditional statement as indicated in the `###`, this would effectively give me a while loop inside `gnuplot` – Mr.Weathers May 30 '17 at 16:27
  • to clarify, my issue is that I don't know how to implement `Time+= $Increment` inside the `gnuplot < – Mr.Weathers May 30 '17 at 16:30

1 Answers1

0

I found this relevant question:

Loop structure inside gnuplot?

which gave me a workable solution. Rather than updating the file name, it is sufficient to build a list of file names using

list = system('ls -1B *orbs.dat | sort -n ')

I think using system() rather than system "" allows me to save the output of the bash line as a gnuplot variable.

Mr.Weathers
  • 398
  • 1
  • 5
  • 19