#! /usr/local/bin/tcsh -f

cd /Projects/NMME/MAPP/NP/

set vars=(thetao so uo vo zoh)
foreach var ($vars)
  foreach year (`seq 2009 1 2010`)
    set yearp1 = $year
    @ yearp1++
    foreach IM (`seq 0 1 11`)
      set IMp1 = $IM
      @ IMp1++
      set nIMp1 = `printf "%02d" $IMp1`
      set nIM = `printf "%02d" $IM`
      echo $nIMp1,$nIM
      if ($IM == 0) then
        set date = ${year}01-${year}12
        echo $date
      else
        set date = ${year}${nIMp1}-${yearp1}${nIM}
        echo $date
      endif
      foreach memb (`seq 1 1 10`)
        set member = r${memb}i1p1
        set link = http://tds.ucar.edu/thredds/fileServer/datazone/nmme/output1/CCCMA/CanCM4/${year}${nIMp1}01/mon/ocean/v20141010/${var}/${var}_Omon_CanCM4_${year}${nIMp1}_${member}_${date}.nc4
          wget ${link}
          ncks -O -F -d lon,157,260 -d lat,79,167 ${var}_Omon_CanCM4_${year}${nIMp1}_${member}_${date}.nc4 ${var}_Omon_CanCM4_${year}${nIMp1}_${member}_${date}.nc4
      end #memb

    end #IM

  end #year

end #var
