Index: TOOLS/MOSAIX/ComputeNemoCoast.py
===================================================================
--- TOOLS/MOSAIX/ComputeNemoCoast.py	(revision 3723)
+++ TOOLS/MOSAIX/ComputeNemoCoast.py	(revision 3723)
@@ -0,0 +1,131 @@
+### ===========================================================================
+###
+### Compute a mask for coastal point of NEMO domain
+###
+### ===========================================================================
+##
+##  Warning, to install, configure, run, use any of Olivier Marti's
+##  software or to read the associated documentation you'll need at least
+##  one (1) brain in a reasonably working order. Lack of this implement
+##  will void any warranties (either express or implied).
+##  O. Marti assumes no responsability for errors, omissions,
+##  data loss, or any other consequences caused directly or indirectly by
+##  the usage of his software by incorrectly or partially configured
+##  personal.
+##
+## SVN information
+__Author__   = "$Author: $"
+__Date__     = "$Date:  $"
+__Revision__ = "$Revision:  $"
+__Id__       = "$Id: update_xml.py 3671 2018-03-20 15:05:56Z omamce $"
+__HeadURL    = "$HeadURL:  $"
+##
+import netCDF4
+import nemo
+import numpy as np
+import getopt, sys
+
+def usage () :
+    texte = """%(prog)s usage :
+python %(prog)s [-d] [-i <orca grid file>] [-n <perio>]
+ -d         | --debug         : debug
+ -i <file>  | --input=<file>  : input file  (default: none)
+ -n <perio> | --perio=<perio> : periodicity type (default: try to guess)
+    #   1, 4, 6 : Cyclic on i dimension (generaly longitudes)
+    #   2       : Obsolete (was symmetric condition at southern boundary ?)
+    #   3, 4    : North fold T-point pivot (legacy ORCA2)
+    #   5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)
+    If <perio> is no specified,  %(prog)s will try to guess it from the grid dimension 
+example :
+    python %(prog)s -n 4 -i ORCA2.3_coordinates_mask.nc
+    """
+    print ( texte % { 'prog':sys.argv[0] } )
+    
+## Default input parameters
+nperio      = None
+GridFile    = None
+Debug       = False
+
+## Command line options
+try:
+    myopts, myargs = getopt.getopt ( sys.argv[1:], 'i:n:h', [ 'input=', 'nperio=', 'debug=', '--help' ] )
+except getopt.GetoptError as cmdle :
+    print ( "Command line error : "+str(cmdle)+"\n" )
+    usage ()
+    sys.exit(1)
+
+for myopt, myval in myopts :
+    if myopt in [ '-h', '--help'   ] : usage () ; sys.exit (0) ;
+    if myopt in [ '-i', '--input'  ] : GridFile = myval ;
+    if myopt in [ '-n', '--nperio' ] : nperio   = int(myval) ;
+    if myopt in [ '-d', '--debug'  ] : Debug    = True ;
+##
+if GridFile == None :
+    print ("Input grid file not specified\n")
+    usage ( )
+    sys.exit(-1)
+
+print ("Input file  :" + GridFile)   
+
+## Open grid file
+GridFile = netCDF4.Dataset ( GridFile, "r+" )
+
+if nperio == None : # Try to get periodicity for the grid
+    print ("Trying to guess nperio parameter")
+    jpoi = GridFile.dimensions["x_grid_T"].size
+    jpoj = GridFile.dimensions["y_grid_T"].size
+    print ("Grid dimensions: ("+str(jpoj)+", "+str(jpoi)+")")
+    if (jpoj, jpoi) == (149, 182):
+        print ("ORCA 2 grid found: nperio may vary for this configuration")
+    if (jpoj, jpoi) == (332, 292):
+        nperio = 6
+        print ("ORCA1 grid found" )
+    if (jpoj, jpoi) == (332, 362):
+        nperio = 6
+        print ("eORCA1 grid found" )
+####    
+if nperio == None :
+    print ("Periodicity not specified and not found\n")
+    usage ( )
+    sys.exit(-1)
+
+###########################################################
+    
+print ("Periodicity : "+ str(nperio) )
+
+if nperio in  [1, 4, 6] : print ("Cyclic on i dimension (generaly longitudes)")
+if nperio in  [2,     ] : print ("Obsolete (was symmetric condition at southern boundary ?)")
+if nperio in  [3, 4   ] : print ("North fold T-point pivot (legacy ORCA2)")
+if nperio in  [5, 6   ] : print ("North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)")
+
+###    
+OceMask = GridFile.variables["maskutil_T"]
+OceMask = np.array ( OceMask)
+
+OceMask = nemo.lbc ( np.int_(OceMask[:,:]), nperio=nperio, cd_type='T' )
+
+Temp = OceMask*0
+Temp[1:-1, 1:-1] =   \
+       + OceMask[0:-2, 1:-1] + OceMask[2:  , 1:-1] \
+       + OceMask[1:-1, 0:-2] + OceMask[1:-1, 2:  ] \
+       + OceMask[0:-2, 0:-2] + OceMask[1:-1, 0:-2] \
+       + OceMask[1:-1, 1:-1] + OceMask[0:-2, 1:-1] 
+
+CoastCrit = Temp.max()
+print ("Maximum number of neighbors : "+str(CoastCrit) )
+
+
+Temp = nemo.lbc ( Temp,  nperio=4, cd_type='T' )
+
+OceCoastal = np.where (OceMask == 1, True, False) * np.where (Temp < CoastCrit, True, False)
+OceCoastal = np.where (OceCoastal, 1, 0)
+
+varOceCoastal = GridFile.createVariable  ("OceCoastal", "i4", ( "y_grid_T", "x_grid_T") )
+varOceCoastal.cell_measures = "area: area_grid_T"
+varOceCoastal.coordinates   = "nav_lat_grid_T nav_lon_grid_T"
+
+varOceCoastal[:,:] = OceCoastal[:,:]
+
+
+GridFile.sync()
+GridFile.close()
Index: TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3719)
+++ TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3723)
@@ -111,4 +111,8 @@
 esac
 
+case ${OCE} in
+    ( ORCA2.3*         ) OcePerio=4 ;;
+    ( ORCA1* | eORCA1* ) OcePerio=6 ;;
+esac
 #
 # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
@@ -117,6 +121,6 @@
 
 
-cp ${SUBMIT_DIR}/bin/interpol.exe                 .
-cp ${SUBMIT_DIR}/update_xml.py                    .
+cp ${SUBMIT_DIR}/bin/interpol.exe    .
+cp ${SUBMIT_DIR}/*.py                .
 
 ##
@@ -182,8 +186,13 @@
 
 ncks --alphabetize --history --append --variable OceMask dia_t${oce}_to_t${atm}_1storder_false_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
-#rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc
-
-##
-## Creates mask of coastal ATM point
+rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc
+
+##
+## Creates mask of coastal OCE points
+## ===========================================================================
+python ComputeNemoCoast.py  -n ${OcePerio} -i oce_grid.nc
+
+##
+## Creates mask of coastal ATM points
 ## ===========================================================================
 cat <<EOF > coastal.nco
@@ -293,4 +302,5 @@
     python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]'                         -k name  -v ${ATM}_grid_maskFrom_${OCE}
     python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]'   -k name  -v AtmCoastal
+    python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]'   -k name  -v OceCoastal
     python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_c${atm}_to_t${oce}_1storder_${normalize}
     python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_c${atm}_to_t${oce}_1storder_${normalize}.nc
Index: TOOLS/MOSAIX/nemo.py
===================================================================
--- TOOLS/MOSAIX/nemo.py	(revision 3723)
+++ TOOLS/MOSAIX/nemo.py	(revision 3723)
@@ -0,0 +1,92 @@
+### ===========================================================================
+###
+### Periodicity of ORCA fields
+###
+### ===========================================================================
+##
+##  Warning, to install, configure, run, use any of Olivier Marti's
+##  software or to read the associated documentation you'll need at least
+##  one (1) brain in a reasonably working order. Lack of this implement
+##  will void any warranties (either express or implied).
+##  O. Marti assumes no responsability for errors, omissions,
+##  data loss, or any other consequences caused directly or indirectly by
+##  the usage of his software by incorrectly or partially configured
+##  personal.
+##
+## SVN information
+__Author__   = "$Author: $"
+__Date__     = "$Date:  $"
+__Revision__ = "$Revision:  $"
+__Id__       = "$Id: update_xml.py 3671 2018-03-20 15:05:56Z omamce $"
+__HeadURL    = "$HeadURL:  $"
+
+def lbc (ptab, nperio=6, cd_type='T', psgn=1.0) :
+    # nperio    : Type of periodicity
+    #   1, 4, 6 : Cyclic on i dimension (generaly longitudes)
+    #   2       : Obsolete (was symmetric condition at southern boundary ?)
+    #   3, 4    : North fold T-point pivot (legacy ORCA2)
+    #   5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)
+    # ptab     : Input array
+    #   rank 2 at least : patb[[...., lat, lon]
+    # cd_type  : Grid specification : T, U, V or F
+    # psgn     : For change of sign for vector components
+    #
+    # See NEMO documentation for further details
+    
+    jpi = ptab.shape[-1]
+    
+    #
+    #> East-West boundary conditions
+    # --------------------------------
+
+    if nperio in [1, 4, 6] :
+        # ... cyclic
+        ptab [...,:,  0] = ptab [...,:,-2]
+        ptab [...,:, -1] = ptab [...,:, 1]
+   
+    #
+    #> North-South boundary conditions
+    # ----------------------------------
+    if nperio in [3, 4] :  # North fold T-point pivot     
+        if cd_type in [ 'T', 'W' ] : # T-, W-point
+            ptab[..., -1, 1:      ] = psgn * ptab[..., -3, -1:0:-1]      
+            ptab[..., -1, 0]        = psgn * ptab[..., -3, 2]
+            ptab[..., -2, jpi/2:  ] = psgn * ptab[..., -2, jpi/2:0:-1]
+                      
+        if cd_type == 'U' :
+            ptab[..., -1, 0:-1    ] = psgn * ptab[..., -3, -1:0:-1  ]       
+            ptab[..., -1,  0]       = psgn * ptab[..., -3,  1]
+            ptab[..., -1, -1]       = psgn * ptab[..., -3, -2] 
+            ptab[..., -2, jpi/2-1:] = psgn * ptab[..., -2, jpi/2+1:0:-1]
+            
+        if cd_type == 'V' : 
+            ptab[..., -2, 1:      ] = psgn * ptab[..., -3, jpi-1:0:-1]
+            ptab[..., -1, 1:      ] = psgn * ptab[..., -4, -1:0:-1]   
+            ptab[..., -1, 0]        = psgn * ptab[..., -4, 2]
+            
+        if cd_type == 'F' :
+            ptab[..., -2, 0:-1    ] = psgn * ptab[..., -3, -1:0:-1]
+            ptab[..., -1, 0:-1    ] = psgn * ptab[..., -4, -1:0:-1]
+            ptab[..., -1,  0]       = psgn * ptab[..., -4,  1]
+            ptab[..., -1, -1]       = psgn * ptab[..., -4, -2] 
+      
+    if nperio in [5, 6] :            #  North fold F-point pivot  
+        if cd_type in ['T', 'W']  :
+            ptab[..., -1, 0:      ] = psgn * ptab[..., -2, -1::-1]
+                
+        if cd_type == 'U' :
+            ptab[..., -1, 0:-1    ] = psgn * ptab[..., -2, -2::-1]       
+            ptab[..., -1, -1]       = psgn * ptab[..., -2, 0]
+             
+        if cd_type == 'V' :
+            ptab[..., -1, 0:      ] = psgn * ptab[..., -3, -1::-1   ]
+            ptab[..., -2, jpi/2:  ] = psgn * ptab[..., -2, jpi/2-1::-1]
+                             
+        if cd_type == 'F' :
+            ptab[..., -1, 0:-1    ] = psgn * ptab[..., -3, -2::-1]
+            ptab[..., -1, -1]       = psgn * ptab[..., -3, 0]
+            ptab[..., -2, jpi/2:-1] = psgn * ptab[..., -2, jpi/2-2::-1]
+
+    return ptab
+################################
+        
