#! /bin/csh -f

set echo on

cd SSMI

foreach YEAR (2000 2001 2002 2003 2004)
#oreach YEAR (2000 )
   echo working on year = $YEAR =============================================================
foreach VAR  (ifrac         )
   echo working on variable = $VAR ---------------------------------------------------------

   set DOMFILE = /fis/cgd/cseg/csm/inputdata/ice/dice7/SSMI/reformat_scripts/multi_year/domain.T62.nc
   set TIMFILE = /fis/cgd/cseg/csm/inputdata/ice/dice7/SSMI/reformat_scripts/multi_year/time_daily.nc 
   set ORGFILE = orig/aice.$YEAR.nc
   set NEWFILE = ssmi.$VAR.gx1v3.$YEAR.nc

   echo --- copy fields ---
   cp                     $ORGFILE  $NEWFILE
   ncks -h -A -v time     $TIMFILE  $NEWFILE

   echo --- fix time coordinates ---
   ncatted -h -O -a      units,time,o,c,"days since $YEAR-01-01 00:00:00"         $NEWFILE

   echo --- fix domain data ---
   # make separate domain file
  
   echo --- fix variable attributes ---
   ncatted -h -O -a          units,$VAR,d,c,                      $NEWFILE
   ncatted -h -O -a        comment,$VAR,o,c,"fractional coverage" $NEWFILE

   echo --- fix global attributes ---
   ncatted -h -O -a     history,global,a,c," \nCF-1.0 time axis added by by `whoami`, `date`"   $NEWFILE
   ncatted -h -O -a Conventions,global,o,c,"CF-1.0"                                       $NEWFILE
   ncatted -h -O -a      domain,global,a,c,"POP gx1v3 "   $NEWFILE

end
end
