#!/bin/csh -f

set CASENAME = $1
set workdir = $2
@ yr0 = $3
@ yr1 = $4
set finalout = $5

set outfile = "list.tmp"

set year0 = `printf "%04d" $yr0`
set year1 = `printf "%04d" $yr1`

@ yr = $yr0

if (-e $outfile) rm $outfile
touch $outfile

setenv ALL_FOUND 1

while ($yr <= $yr1)

   set year = `printf "%04d" $yr`   
   set filename1 = "${workdir}/${CASENAME}.pop.h.${year}.nc"
   if !(-e ${filename1}) then
     printf $yr"\n" >> $outfile
     setenv ALL_FOUND 0
   endif
@ yr++
end

if ($ALL_FOUND == 1) then
  printf "ALL FOUND" >> $outfile
endif

cp $outfile $finalout

