#!/bin/csh
#calculating meridional overturning with ferret slice by slice
#glueing it together 
# 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/moc_refer.nc

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

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 global overturning on zlevel
 let moc_ref    = ty_trans[i=@sum,k=@rsum,d=1]
 set variable/title="Meridional Overturning" moc_ref
 set variable/units="Sv" moc_ref
 save/clobber/file="$outfil" moc_ref[l="$lI"]
 quit
EndOfFerret
end

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