#!/bin/sh
#
# dopopplots:
#
# Copyright (c) 2003 Chris Lightfoot. All rights reserved.
# Email: chris@ex-parrot.com; WWW: http://www.ex-parrot.com/~chris/
#
# $Id:$
#

for when in 0 10 20 30 40 50 ; do
    title="$when years from now"
    if [ $when = 0 ] ; then
        title="now"
    fi

    gnuplot <<EOF
set term png color small
set size 0.4,1
set output "population-pyramid-$when.png"
set xrange [0:1]
set yrange [0:110]
set xtics 0.25
set xlabel "population (millions)"
set ylabel "age (years)"
set nokey
set title "$title"
plot "<POPMODEL_PYRAMIDS=1 ./popmodel 1 1" index $when using (\$1/1e6):0 with lines
EOF

done

gnuplot <<EOF
set term png color small
set output "population-ratio-1-1.png"
set size 1,0.75
set xrange [0:100]
set yrange [2.75:4.4]
set xtics 25
set xlabel "time (years from now)"
set ylabel "working population / retired population"
set nokey
plot "<./popmodel 1 1" using 0:5 with lines
EOF

gnuplot <<EOF
set term png color small
set output "population-ratio-birthrates.png"
set size 1,0.75
set xrange [0:100]
set yrange [2.75:4.4]
set xtics 25
set xlabel "time (years from now)"
set ylabel "working population / retired population"
set data style lines
plot "<./popmodel 1 1" using 0:5 title "current birth rate", "<./popmodel 1 1.05" using 0:5 title "5% higher birth rate", "<./popmodel 1 1.10" using 0:5 title "10% higher birth rate", "<./popmodel 1 1.15" using 0:5 title "15% higher birth rate"
EOF

>x
for rate in $( seq 1 0.05 1.5 ) ; do
    echo -n "$rate " >> x
    ./popmodel 1 $rate > /dev/null 2>> x
done

cat x

gnuplot <<EOF
set term png color small
set output "population-ratio-change-birthrates.png"
set size 1,0.75
set xrange [0:40]
set yrange [2.75:4.4]
set xtics 10
set xlabel "percentage increase in birth rate"
set ylabel "minimum working population / retired population"
set nokey
set data style lines
plot "x" using (100. * ($1 - 1.)):3
set output "/dev/null"
EOF

gnuplot <<EOF
set term png color small
set output "population-ratio-immigration.png"
set size 1,0.75
set xrange [0:100]
set yrange [2.75:4.4]
set xtics 25
set xlabel "time (years from now)"
set ylabel "working population / retired population"
set data style lines
plot "<./popmodel 1 1" using 0:5 title "current immigration rate", "<./popmodel 2 1" using 0:5 title "2 x current immigration rate", "<./popmodel 3 1" using 0:5 title "3 x current immigration rate"
EOF


>y
for rate in 1 2 3 4 5 ; do
    echo -n "$rate " >> y
    ./popmodel $rate 1 > /dev/null 2>> y
done

gnuplot <<EOF
set term png color small
set output "population-ratio-change-immigration.png"
set size 1,0.75
set xrange [1:5]
set yrange [2.75:4.4]
set xtics 1
set xlabel "immigration as a factor of 2001 immigration"
set ylabel "minimum working population / retired population"
set nokey
set data style lines
plot "y" using 1:3
set output "/dev/null"
EOF

