#!/bin/csh
#interpolates momba data onto bsh temporal grid and
#bsh datd onto momba spacial grid
limit stacksize unlimited
limit datasize unlimited


#///////////////////////////////////////////////////////////
 #where am i
 set pwdir = `pwd`

 #paths
  set idir_bsh = "../data/obs/bsh"
  set idir_mom = "../data/processed/noed"
  set odir = "../data/processed/noed"


#//////////////////////////////////////////////////////////

 set styr     = 1989
 set enyr     = 1999
 set cyr      = $styr
while ( $cyr <  $enyr )
 set cyr     = `expr $cyr + 1`
 set bshfil  = $idir_bsh/"sst_"$cyr".nc"
 set momfil  = $idir_mom/"sst_"$cyr".nc"
 set outfil  = $odir/"ObsModSST_"$cyr".nc"


#----------- interpolate model onto temporal observational grid ------------
ferret -server -batch -gif << EndOfFerret
 set memory/size=800
 use "$bshfil"
 use "$momfil"

 let mod_sst = sst[d=2,gt=sst[d=1]]
 set variable/title="longrun I MOMBA SST" mod_sst
 set variable/units="degC"                mod_sst

 save/clobber/file="$outfil" mod_sst
 quit
EndOfFerret
rm ferret.*

#----------- interpolate observations onto spacial grid of observations -----
ferret -server -batch -gif << EndOfFerret
 set memory/size=800
 use "$bshfil"
 use "$momfil"

 let obs_sst = sst[d=1,gx=sst[d=2],gy=sst[d=2]]
 set variable/title="BSH SST on MOMBA grid" obs_sst
 set variable/units="degC"                  obs_sst


 save/append/file="$outfil" obs_sst
 quit
EndOfFerret
rm ferret.*



end

exit

