#/bin/csh -f
#
# Setup needed softlinks to actual data....
#
cd /fis/cgd/cseg/csm/inputdata/lnd/clm2/NCEPDATA.Qian.T62.c051024
set dir=/cgd/tss/NCEPDATA.Qian.T62.c051024.lns

# Copy readme file
\cp -f $dir/readme.CLMF .
#Soft link actual data
foreach decade ( 1940 1950 1960 1970 1980 1990 2000 )
   foreach year ( 0 1 2 3 4 5 6 7 8 9 )
      @ actual_year = $decade + $year
      foreach month ( 01 02 03 04 05 06 07 08 09 10 11 12 )
         # If file exists has size > zero and is NOT a symbolic link than link to it
         if ( -s "$dir/$actual_year-$month.nc" && (! -l "$dir/$actual_year-$month.nc") )then
            echo "Link to: $dir/$actual_year-$month.nc"
            \ln -sf $dir/$actual_year-$month.nc $actual_year-$month.nc
            if ( $status != 0 ) exit 1
         endif
      end
   end
end

#
# Link 1000 year dates to 1948
#

@ actual_year = 1948
foreach year ( 1000 1001 1002 1003 1004 )
  foreach month ( 01 02 03 04 05 06 07 08 09 10 11 12 )
     echo "Link: $dir/$actual_year-$month.nc to $year-$month.nc"
     \ln -sf $actual_year-$month.nc $year-$month.nc
     if ( $status != 0 ) exit 2
  end
  @ actual_year = $actual_year + 1
end

exit

