#
set dir1 = nov2003_heelis_TN_zp+2_movie
set dir2 = nov2003_weimer_TN_zp+2_movie
set dirout = nov2003_TN_zp+2_movie

if (! -d $dir1) then
  echo ">>> Could not find dir1 directory $dir1"
  exit
endif
if (! -d $dir2) then
  echo ">>> Could not find dir2 directory $dir2"
  exit
endif
if (! -d $dirout) then
  echo "Making output directory $dirout.."
  mkdir -p $dirout 
endif

@ iframe = 0
foreach file1 ($dir1/*.png) 
  set file2 = $dir2/$file1:t
  if (! -f $file2) then
    echo ">>> Could not find file2 $file2 (file1 = $file1)"
    exit
  endif

  if ($iframe <= 9) set fileout = $dirout/frame000${iframe}.png
  if ($iframe <= 99 && $iframe > 9) set fileout = $dirout/frame00${iframe}.png
  if ($iframe <= 999 && $iframe > 99) set fileout = $dirout/frame0${iframe}.png
  if ($iframe <= 9999 && $iframe > 999) set fileout = $dirout/frame${iframe}.png
  
  echo  "Writing $fileout.."
  montage -geometry 450x450 $file1 $file2 $fileout
  @ iframe++
end
