#!/bin/csh -f

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

set outfile = "list.tmp"

setenv MSP /${MSROOT}/${CASENAME}/ocn/hist
setenv MSPY /${MSROOT}/${CASENAME}/ocn/proc/tavg/annual 

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

@ yr = $yr0
@ s = 0

if (-e $outfile) rm $outfile
printf "Blank\n" >> $outfile

while ($yr <= $yr1)

   set year = `printf "%04d" $yr`   
   hsi -P "ls ${MSPY}/${CASENAME}.pop.h.${year}.nc"
   if ($status == 0)then
        set filename1 = "${workdir}/${CASENAME}.pop.h.${year}.nc"
        set filename2 = "${MSROOT}/${CASENAME}.pop.h.${year}.nc"
        if !(-e ${filename1}) then
          printf "${CASENAME}.pop.h.${year}.nc\n" >> $outfile
          @ s++
        endif
   endif
@ yr++
end

if ($s == 0) printf " \n" >> $outfile
cp $outfile $finalout


