#!/bin/csh
#calculating zonal overturning with ferret slice by slice
#glueing it together in order to identify subpolar gyre transports 
# time of linwind forking: 1980  == l=43 for reference (lI = `expr 43 - 1` || eI=103)
# linwind setting (lI = `expr 1 - 1` || eI=45)

#clean
 rm ../tmp/*
 rm ../../data/processed/zoneTr_refer.nc

#define time indices to cylce over
 set lI = `expr 1 - 1`
 set eI = 90 

while ( $lI < $eI )
 set lI   = `expr $lI + 1`
 set ofiI = `expr $lI + 10000`
 set outfil = ../tmp/moc_tmp_$ofiI".nc"
 echo $outfil

ferret -server -batch -gif << EndOfFerret
 cancel da/all
 cancel re/all
 se mem/size=10000
 use "/Volumes/MOMSO/data/reference/yearly/physic.des"

 !calculate zonal interals
  let new_u=missing(u[d=1],0)
  let zoneTr_ref = new_u[y=@iin,z=@din]/1e6
  set variable/units="Sv" zoneTr_ref 
  save/clobber/file="$outfil" zoneTr_ref[l="$lI"]

 quit
EndOfFerret
end

ncrcat ../tmp/moc_tmp_10???.nc ../../data/processed/zoneTr_refer.nc
exit
