#!/usr/bin/env python

import sys

def main():
    window = 5*3000000
    #window = 250000
    max_range = 49
    ndopplers=16
    gifs = []
    samplerate=320000
    secs_per_timestep=2
    samples_per_timestep=samplerate*secs_per_timestep
    ntimesteps=int((30000000 - window -320000)/samples_per_timestep)-2
    sys.stdout.write("#!/bin/sh \n")
    for t in range(0,ntimesteps, 1):
        #sim_fn  = "mdvh_bingo4_sim.%04d" % (t,)
        real_fn  = "bingo_320ksps.raw" 
        xref_fn = "mdvh_bingo4_xref.%04d" % (t,)
        ppm_fn  = "mdvh_bingo4_i.%04d.ppm" % (t,)
        gif_fn  = "mdvh_bingo4_i.%04d.gif" % (t,)
        gifs.append(gif_fn)
        skipsamples=samples_per_timestep*t+320000
        #sys.stdout.write("./sim-airplane3 bingo_320ksps.raw -o %s -S %d\n" % (sim_fn, t))
        sys.stdout.write("./mdvh-xambi-autocorr -o %s -s %d -S 0 -M %d -w %d -n %d -d 0.0001 %s %s\n" % (
            xref_fn, skipsamples,max_range, window,ndopplers,real_fn,real_fn))
        sys.stdout.write("./plot_xambi_tool_log.m %s %s\n" % (xref_fn, ppm_fn))
        sys.stdout.write("convert -resize 800%% %s %s\n" % (ppm_fn, gif_fn))

    sys.stdout.write("gifsicle -d 50 %s >mdvh_bingo4_animated.gif\n" % (' '.join(gifs)))

if __name__ == '__main__':
    main()
