#! /bin/csh -f
### Change these to your own site and user directory! 
### You will need to create a Makefile Macro in bld/ and a run_ice script 
### in input_templates/.

setenv SITE UQAM
#setenv SITE CCCma.ax
#setenv SITE LANL.coyote
#setenv SITE NAVO.kraken
#setenv SITE NCAR.bluevista
#setenv SITE LLNL.atlas

### SYSTEM_USERDIR is predefined on ORNL machines
setenv SYSTEM_USERDIR /data/local/WORKCICE

### Grid resolution
setenv GRID 1440x1020

set NXGLOB = `echo $GRID | sed s/x.\*//`
set NYGLOB = `echo $GRID | sed s/.\*x//`

# Recommendations:
#   NTASK equals nprocs in ice_in 
#   use processor_shape = slenderX1 or slenderX2 in ice_in
#   one per processor with distribution_type='cartesian' or
#   squarish blocks with distribution_type='rake'
# If BLCKX (BLCKY) does not divide NXGLOB (NYGLOB) evenly, padding 
# will be used on the right (top) of the grid.
setenv NTASK      255      # total number of processors
setenv BLCKX      480      # x-dimension of blocks ( not including 1440/jpni )
setenv BLCKY       12      # y-dimension of blocks (  ghost cells  1020/jpnj )

# may need to increase MXBLCKS with rake distribution or padding
@ a = $NXGLOB * $NYGLOB ; @ b = $BLCKX * $BLCKY * $NTASK  
@ m = $a / $b ; setenv MXBLCKS $m ; if ($MXBLCKS == 0) setenv MXBLCKS 1
#setenv MXBLCKS 37 # if necessary (code will print proper value)
#setenv MXBLCKS 0 ; if ($MXBLCKS == 0) setenv MXBLCKS 1 # (CCCma)

### Specialty code
setenv CAM_ICE  no        # set to yes for CAM runs (single column) 
setenv SHRDIR   csm_share # location of CCSM shared code
setenv NETCDF   yes       # set to no if netcdf library is unavailable
setenv DITTO    no        # reproducible diagnostics
setenv CCCMA    no        # set to yes if model data in CCCma format and grid
setenv CMC      yes       # set to yes if model data in CMC format and grid

setenv SRCDIR $SYSTEM_USERDIR/cice4.0_cmc
setenv CBLD   $SRCDIR/bld
setenv EXEDIR $SRCDIR/EXECDIR/${TRUE_HOST}
setenv OBJDIR $SRCDIR/compile/${TRUE_HOST}
setenv NEMO $SRCDIR/NEMO

cp -f $CBLD/Makefile.std $CBLD/Makefile

cd $OBJDIR

if ($NTASK == 1) then
   setenv COMMDIR serial
else
   setenv COMMDIR mpi 
endif

setenv DRVDIR hadgem3

### List of source code directories (in order of importance).
cat >! Filepath << EOF
$SRCDIR/drivers/$DRVDIR
$SRCDIR/source
$SRCDIR/cmc
$SRCDIR/$COMMDIR
$SRCDIR/$SHRDIR
EOF

cc -o makdep $CBLD/makdep.c                         || exit 2

setenv MAKE make
${MAKE}    VPFILE=Filepath EXEC=$EXEDIR/cice \
           NXGLOB=$NXGLOB NYGLOB=$NYGLOB \
           BLCKX=$BLCKX BLCKY=$BLCKY MXBLCKS=$MXBLCKS \
      -f  $CBLD/Makefile MACFILE=$CBLD/Macros.${BASE_ARCH}.${SITE} || exit 2

setenv libcice cice
ar rv lib${libcice}.a *.o
mv lib${libcice}.a ${NEMO}/
cp *.mod           ${NEMO}/
#/bin/rm -f $EXEDIR/cice

cd ..
pwd                                         
echo NTASK = $NTASK
echo "global N, block_size" 
echo "x    $NXGLOB,    $BLCKX"
echo "y    $NYGLOB,    $BLCKY"
echo max_blocks = $MXBLCKS

