getnewest () {
newfile=`ls -t ~/goesdata/goes16/non-cmip/fd/$1/*/* | head -1`
cp $newfile $1.png
}

genimg () {
width=`identify -format %w $1.png`; \
factor=`echo "scale=4; ${width}/5424" | bc`
height=`echo "scale=4; 1+${factor}*200" | bc`
shift=`echo "scale=4; ${factor}*60" | bc`
convert -background '#0008' -fill lightgray -gravity center -size ${width}x${height} \
         caption:"$2" \
         $1.png +swap -gravity south -geometry +0+${shift} -composite $1s.png
}

cd /media/ramdisk
mkdir -p montage2
cd montage2

getnewest acha
getnewest acht
getnewest dsi
getnewest lst
getnewest rrqpe
getnewest sst
getnewest tpw

convert lst.png -alpha off -fill black -opaque white -alpha on lst2.png
#convert rrqpe.png -alpha off -fill black -opaque "#fefefe" -alpha on rrqpe2.png
convert sst.png -alpha off -fill black -opaque "#fffafa" -alpha on sst2.png
convert sst2.png -alpha off -fill black -opaque white -alpha on sst3.png
convert tpw.png -alpha off -fill black -opaque "#fefefe" -alpha on tpw2.png

convert lst2.png -resize 5424x5424 +repage lstr.png
convert sst3.png lstr.png -fx 'max(u[0],u[1])' st.png

genimg acha "Average Cloud Height Altitude"
genimg acht "Average Cloud Height Temperature"
genimg dsi "Derived Stability Index"
#genimg lst "Land Surface Temperature"
genimg rrqpe "Rain Rate"
#genimg rrqpe2 "Rain Rate"
#genimg sst "Sea Surface Temperature"
genimg st "Surface Temperature"
genimg tpw2 "Total Precipitable Water"

montage achas.png achts.png dsis.png rrqpes.png sts.png tpw2s.png -geometry 600x600 ../latest_NONCMIP.png
#montage achas.png achts.png dsis.png rrqpe2s.png sts.png tpw2s.png -geometry 600x600 ../latest_NONCMIP.png

cd ..
#rm -rf montage2

