Index: TOOLS/CPLRESTART/CreateRestartAtm4Oasis.bash
===================================================================
--- TOOLS/CPLRESTART/CreateRestartAtm4Oasis.bash	(revision 4265)
+++ TOOLS/CPLRESTART/CreateRestartAtm4Oasis.bash	(revision 4289)
@@ -156,7 +156,6 @@
     mv tmp_flxat_fields_notime.nc flxat_fields_notime.nc
     (( dim_lat = dim_lat - 1 ))
-    #ATM=lmdz${dim_lon}x${dim_lat}
     ATM=LMD${dim_lon}${dim_lat}
-    (( n_lat = dim_lat-1 ))
+    (( n_lat = dim_lat - 1 ))
 cat<<EOF > lonlat2xyz.nco
 // Value at North Pole for LMDZ lon/lat grid
Index: TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash
===================================================================
--- TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash	(revision 4265)
+++ TOOLS/CPLRESTART/CreateRestartOce4Oasis.bash	(revision 4289)
@@ -26,6 +26,15 @@
 #  $HeadURL$
 
-# Usage exemples :
-# CreateRestartOce4Oasis.bash /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc/ccc/store/c# CreateRestartOce4Oasis.bash /ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc
+## Usage exemples :
+#
+# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc --icefile /ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/ICE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_icemod.nc --icefrc ice_pres --icetem tsice --icealb ialb
+#
+# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc --icefrc siconc
+
+# CreateRestartOce4Oasis.bash --ocefile /ccc/store/cont003/gen7451/personr/IGCM_OUT/ORCA025_LIM3_PISCES/DEVT/ORCA025ia/eOR025L3P-IA-REF07-MUSCL/OCE/Output/MO/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_grid_T.nc
+#
+# CreateRestartOce4Oasis.bash --ocefile /ccc/work/cont003/gencmip6/p48ethe/ICMC-TOOLS/DATA/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_grid_T.nc --icefile /ccc/work/cont003/gencmip6/p48ethe/ICMC-TOOLS/DATA/eOR025L3P-IA-REF07-MUSCL_20090101_20091231_1M_icemod.nc --icefrc siconc/oce --icetem sistem
+# 
+# 
 ## ===========================================================================
 ##
@@ -39,21 +48,51 @@
 # Default values
 Comment="Preliminary attempt - Do not trust !"
-##IceVar=ice_pres # siconc #> Variable containing sea ice fraction [0-1]
-IceVar=siconc #> Variable containing sea ice fraction [0-1]
+#
+# --ocefile : file in which sea surface temperature is read
+# --icefile : file in which sea ice fraction, albedo and surface temperature are read.
+#             if not specified, these variables are readed in the ocean file
+#
+## Variable in ocean file :
+OceSst=tos      #> Variable containing sea surface temperature (Â°C) : --ocesst tos
+## Variables in ice file
+IceFrc=ice_pres #> Variable containing sea ice fraction [0-1]       : --icefrc ice_pres
+IceAlb=none     #> Variable containing sea ice albedo [0-1]. If 'none', set to 0.65         : --icealb ialb
+IceTem=none     #> Variable containing sea ice surface temperature (Â°C). If 'none', set to -20Â°C : --icetem tsice
+
+# Complementary syntaxes for variables names
+# --icefrc siconc/oce means that siconc variable should be taken in the ocean file ...
+# --icealb ialb/oce
+# --icetem tsice/oce
+
+## Filling
+# If the ocean in the coupled model has a different geometry that the one in the files.
+# In general, the forced ocean does run with no closed sea, when the coupled model does.
+# This step is he mandatory
+Fill=yes # If yes, fill the continents. --fill / --nofill
+
+# nperio parameter for ORCA. Normally guess from name or dimensions. For ORCA2, set to nperio=4, but should be set to nperio=6 for some paleo configs
+# --nperio 4
+
+DefaultIceAlb=0.65
+DefaultIceTem=-20.0
+
+#OceFile=/ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc
+#OceFile=/ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc
+#
 
 #
 # Defines computer
 # ================
-if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi
 if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi
 
 case ${arch} in
-    ( curie | irene )
+    ( irene )
     set +vx
     module unload cdo nco ferret
     module unload netcdf hdf5
     module load python # /2.7.12
-    module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS
+    #module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS
     module load nco
+    module load python3
     R_IN=$(ccc_home -u igcmg --cccwork)/IGCM
     TMPDIR=${SCRATCHDIR}/TMP
@@ -68,10 +107,19 @@
 set -e
 
+Nperio=""
+
 while [[ ${1} = -* ]] ; do
     case ${1} in
 	( -- ) shift ; break ;;
-	( -c   | --comment  ) shift ; Comment=${1} ;;
-	( -i   | --ice      ) shift ; IceVar=${1}  ;;
-	( -a   | --alb      ) shift ; AlbVar=${1}  ;;
+	( -c   | --comment  ) shift ; Comment=${1}  ;;
+	( --ocefile         ) shift ; OceFile=${1}  ;;
+	( --icefile         ) shift ; IceFile=${1}  ;;
+	( --ocesst          ) shift ; OceSst=${1}   ;;
+	( --icefrc          ) shift ; IceFrc=${1}   ;;
+	( --icetem          ) shift ; IceTem=${1}   ;;
+	( --icealb          ) shift ; IceAlb=${1}   ;;
+	( --fill            ) Fill="yes" ;;
+	( --nofill          ) Fill="no"  ;;
+	( --nperio          ) shift ; Nperio="--nperio ${1}" ;;
 	( -v | --verbose    ) set -o verbose   ;;
 	( -x | --xtrace     ) set -o xtrace    ;;
@@ -82,14 +130,9 @@
 	( -XV | -VX         ) set +o xtrace verbose    ;;
 	( -E                ) set +e           ;;
-	( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; return 1 ;;
+	( -* ) echo ${Bold}"Unknown option : ${1}"${Norm} ; exit 1 ;;
     esac
     shift
 done
 
-OceFile=${1:-/ccc/store/cont003/dsm/p25sepul/IGCM_OUT/IPSLCM5A2/PROD/piControl/CM5A2.1.pi.00/OCE/Output/MO/CM5A2.1.pi.00_40100101_40191231_1M_grid_T.nc}
-
-#OceFile=${1:-/ccc/store/cont003/gencmip6/p86mart/IGCM_OUT/IPSLCM6/DEVT/pdControl/CM6010.2.rivgeo-LR-pdCtrl/OCE/Output/MO/CM6010.2.rivgeo-LR-pdCtrl_22400101_22491231_1M_grid_T.nc}
-#
-
 #
 # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits
@@ -100,13 +143,52 @@
 ## Defines associated sea ice file
 ## ===========================================================================
-###IceFile=$(echo ${OceFile} | sed 's=/OCE/=/ICE/=' | sed 's=grid_T=icemod=')
-IceFile=${OceFile}
+if [[ -z ${IceFile} ]] ; then IceFile=${OceFile} ; fi
+IceFrcFile=${IceFile}
+IceTemFile=${IceFile}
+IceAlbFile=${IceFile}
+
+## Select file for each variable
+OceSstFile=${OceFile}
+if [[ ${OceSst} = */ice ]] ; then
+    OceSstFile=${IceFile}
+    OceSst=${OceSst%%/*}
+fi
+
+
+if [[ ${IceAlb} = */oce ]] ; then
+    IceAlbFile=${OceFile}
+    IceAlb=${IceFrc%%/*}
+fi
+if [[ ${IceFrc} = */oce ]] ; then
+    IceFrcFile=${OceFile}
+    IceFrc=${IceFrc%%/*}
+fi
+if [[ ${IceTem} = */oce ]] ; then
+    IceTemFile=${OceFile}
+    IceTem=${IceTem%%/*}
+fi
+
+
+echo "Oce sst         - Variable ${OceSst} - File ${OceSstFile}"
+echo "Ice fraction    - Variable ${IceFrc} - File ${IceFrcFile}"
+echo "Ice albedo      - Variable ${IceAlb} - File ${IceAlbFile}"
+echo "Ice temperature - Variable ${IceTem} - File ${IcetemFile}"
+
 
 ##
 ## Extract variables
 ## ===========================================================================
-ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceVar} ${IceFile} sstoce_fields.nc
-ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable tos       ${OceFile} oce_fields.nc
-ncks --append --fl_fmt=${FL_FMT} --history oce_fields.nc   sstoce_fields.nc
+ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceFrc} ${IceFrcFile} sstoce_fields.nc
+ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${OceSst} ${OceSstFile} oce_sst.nc
+
+ncks --append    --fl_fmt=${FL_FMT} --history oce_sst.nc   sstoce_fields.nc
+if [[ "X${IceAlb}" != "Xnone" ]] ; then
+    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceAlb} ${IceAlbFile} ice_alb.nc
+    ncks --append    --fl_fmt=${FL_FMT} --history ice_alb.nc   sstoce_fields.nc
+fi
+if [[ "X${IceTem}" != "Xnone" ]] ; then
+    ncks --overwrite --fl_fmt=${FL_FMT} --history -d time_counter,0,0 --variable ${IceTem} ${IceTemFile} ice_tem.nc
+    ncks --append    --fl_fmt=${FL_FMT} --history ice_tem.nc   sstoce_fields.nc
+fi
 ncwa --overwrite --fl_fmt=${FL_FMT} --history --average time_counter sstoce_fields.nc sstoce_fields_notime.nc # Remove time dimension
 ncatted --history --attribute history,global,d,c,""  sstoce_fields_notime.nc           # Clean attributes
@@ -115,25 +197,49 @@
 ## Find ocean name
 ## ===========================================================================
-dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | awk '{print $3}' )
+dim_y=$(ncdump -h sstoce_fields_notime.nc | grep "y *=" | grep -v "nvertex" | awk '{print $3}' )
 dim_x=$(ncdump -h sstoce_fields_notime.nc | grep "x *=" | grep -v "nvertex" | awk '{print $3}' )
 echo ${dim_x} ${dim_y}
 
-[[ ${dim_x} = 182 && ${dim_y} = 149 ]] && OCE=ORCA2.3
-[[ ${dim_x} = 362 && ${dim_y} = 332 ]] && OCE=eORCA2.1
+[[ ${dim_x} =  182 && ${dim_y} =  149 ]] && OCE=ORCA2.3
+[[ ${dim_x} =  362 && ${dim_y} =  332 ]] && OCE=eORCA1.2
 [[ ${dim_x} = 1442 && ${dim_y} = 1207 ]] && OCE=eORCA025.1
 
-
 ##
 ## Creates sstoce file
 ## ===========================================================================
-
 cat <<EOF > create_sstoce.nco
-OIceFrc[y,x]   = double ( ${IceVar}(:,:) ) ; 
-//tos.simple_fill_miss(tos)               ;
-O_SSTSST[y,x]  = double ( (tos   (:,:) + 273.15d) * (1.0d-OIceFrc(:,:)) ) ;
-//O_AlbIce[y,x]  = double ( ialb   (:,:)            * OIceFrc(:,:)   ) ;
-//O_TepIce[y,x]  = double ( (tsice (:,:) + 273.15d) * OIceFrc(:,:)   ) ;
-O_AlbIce[y,x]  = double (   0.65d            * OIceFrc(:,:)   ) ;
-O_TepIce[y,x]  = double ( (-20.0d + 273.15d) * OIceFrc(:,:)   ) ;
+*OceSst[y,x]    = double ( ${OceSst}(:,:) + 273.15d ) ;
+OIceFrc[y,x]   = double ( ${IceFrc}(:,:) ) ; 
+//
+EOF
+
+if [[ "X${IceAlb}" != "Xnone" ]] ; then
+    cat <<EOF >> create_sstoce.nco
+*IceAlb[y,x]  = double ( ${IceAlb}(:,:) ) ;
+//
+EOF
+else
+     cat <<EOF >> create_sstoce.nco
+*IceAlb[y,x] = double ( ${DefaultIceAlb}d ) ;
+//
+EOF
+fi
+
+if [[ "X${IceTem}" != "Xnone" ]] ; then
+    cat <<EOF >> create_sstoce.nco
+*IceTem[y,x] = double ( ${IceTem}(:,:) + 273.15d ) ;
+//
+EOF
+else
+     cat <<EOF >> create_sstoce.nco
+*IceTem[y,x] = double ( ${DefaultIceTem}d + 273.15d ) ;
+//
+EOF
+fi
+
+cat <<EOF >>  create_sstoce.nco
+O_SSTSST[y,x]  = OceSst (:,:) * (1.0d-OIceFrc(:,:)) ;
+O_AlbIce[y,x]  = IceAlb (:,:)       * OIceFrc(:,:)  ;
+O_TepIce[y,x]  = IceTem (:,:)       * OIceFrc(:,:)  ;
 O_OCurx1[y,x]  = 0.0d ;
 O_OCury1[y,x]  = 0.0d ;
@@ -143,10 +249,28 @@
 ncap2 --overwrite --fl_fmt=${FL_FMT} --history --script-file create_sstoce.nco sstoce_fields_notime.nc tmp_sstoc.nc
 ncks --fl_fmt=${FL_FMT} --overwrite --history --variable OIceFrc,O_SSTSST,O_AlbIce,O_TepIce,O_OCurx1,O_OCury1,O_OCurz1 tmp_sstoc.nc sstoc.nc
-ncatted --history --attribute comment,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          sstoc.nc
-ncatted --history --attribute comment,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          sstoc.nc
-ncatted --history --attribute comment,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc
-
-##
-## Add some information in file headers
+ncatted --history --attribute long_name,O_SSTSST,o,c,"SST weighted by fraction of open ocean"          sstoc.nc
+ncatted --history --attribute long_name,O_AlbIce,o,c,"Albedo weighted by fraction of sea ice"          sstoc.nc
+ncatted --history --attribute long_name,O_TepIce,o,c,"Ice temperature weighted by fraction of sea ice" sstoc.nc
+
+ncatted --history --attribute comment,O_SSTSST,o,c,"Variable ${OceSst} taken in ${OceSstFile}"  sstoc.nc
+ncatted --history --attribute comment,OIceFrc,o,c,"Variable ${IceFrc} taken in ${IceFrcFile}"   sstoc.nc
+
+if [[ ${IceAlb} = none ]] ; then  ncatted --history --attribute comment,O_AlbIce,o,c,"Set to ${DefaultIceAlb}"  sstoc.nc
+else                              ncatted --history --attribute comment,O_AlbIce,o,c,"Variable ${IceAlb} taken in ${IceAlbFile}"  sstoc.nc
+fi
+if [[ ${IceTem} = none ]] ; then  ncatted --history --attribute comment,O_TepIce,o,c,"Set to ${DefaultIceTem}"  sstoc.nc
+else                              ncatted --history --attribute comment,O_TepIce,o,c,"Variable ${IceTem} taken in ${IceTemFile}"  sstoc.nc
+fi
+
+##
+## Filling the fields
+## ===========================================================================
+if [[ ${Fill} = yes ]] ; then
+    mv sstoc.nc sstoc_nofilled.nc
+    python3 FillOceRestart.py --input sstoc_nofilled.nc --output sstoc.nc ${Nperio}
+fi
+
+##
+## Add some information in file header
 ## ===========================================================================
 
@@ -183,5 +307,5 @@
 ## Cleaning
 ## ===========================================================================
-rm -f sstoce_fields.nc sstoce_fields_notime.nc tmp_flxat.nc oce_fields.nc
+#rm -f sstoce_fields.nc sstoce_fields_notime.nc tmp_sstoce.nc oce_fields.nc
 
 mv sstoc.nc sstoc_${OCE}.nc
Index: TOOLS/CPLRESTART/FillOceRestart.py
===================================================================
--- TOOLS/CPLRESTART/FillOceRestart.py	(revision 4265)
+++ TOOLS/CPLRESTART/FillOceRestart.py	(revision 4289)
@@ -50,5 +50,5 @@
  -o <file>    | --output=<file>        : output file (default : build a name form input file)
  -r           | --replace              : replace input file by new file with filled variables
- -v <varlist> | --variable=<variables> : list of variable to fill (defautlt: all variable in file)
+ -v <varlist> | --variable=<variables> : list of variable to fill (default: all variable in file)
  -x           | --exclude              : fills all variable in files, except those given in -v|--variable
  -n <perio>   | --perio=<perio> : periodicity type (default: try to guess)
@@ -92,6 +92,6 @@
             sys.exit(1)
         else :
-            if Debug : print ("Out file set to "+OuFile)
             OuFile   = myval ;
+            if Debug : print ("Out file set to " + OuFile)
     elif myopt in [ '-r', '--replace' ] :
         if OuFile != None :
@@ -111,8 +111,9 @@
             ListExclude = ListVarName
             ListVarName  = None
- 
+
 if OuFile == None :
+    print ( 'Definition OuFile' )
     OuFile = InFile.replace ( ".nc", "_filled.nc" )
-    print ("Creates output file name: "+OuFile)
+    print ("Creates output file name: " + OuFile)
 
 # Copy the input file if needed
@@ -131,27 +132,30 @@
     print ("Grid dimensions: ("+str(jpoj)+", "+str(jpoi)+")")
     if   'ORCA2' in InFile :
+        nperio=4
         print ("ORCA 2 grid found from file name: nperio may vary for this configuration")
-        print ("Choosen nperio=4")
+        print ("Choosen nperio=" + str(nperio) )
     elif 'ORCA1' in InFile :
-        if 'eORCA1' in InFile : 
-            print ("eORCA 1 grid found from file name, nperio=6")
+        if 'eORCA1' in InFile :
+            nperio=6
+            print ("eORCA 1 grid found from file name, nperio=" + str(nperio))
         else :
-            print ("ORCA 1 grid found from file name, nperio=6")
+            nperio=6
+            print ("ORCA 1 grid found from file name, nperio=" + str(nperio))
     elif (jpoj, jpoi) == (149, 182) :
+        nperio = 4
         print ("ORCA 2 grid found from dimension: nperio may vary for this configuration")
-        print ("Choosen nperio=4")
-        nperio = 4
+        print ("Choosen nperio=" + str(nperio))
     elif (jpoj, jpoi) == (332, 292) :
         nperio = 6
-        print ("ORCA1 grid found from dimensions, nperio=6" )
+        print ("ORCA1 grid found from dimensions, nperio" + str(nperio) )
     elif (jpoj, jpoi) == (332, 362) :
         nperio = 6
-        print ("eORCA1 grid found from dimensions, nperio=6" )
+        print ("eORCA1 grid found from dimensions, nperio" + str(nperio) )
     elif (jpoj, jpoi) == (1021, 1442) :
-        nperio = 4
-        print ("ORCA025 grid found from dimensions, nperio=6" )
+        nperio = 6
+        print ("ORCA025 grid found from dimensions, nperio" + str(nperio) )
     elif (jpoj, jpoi) == (1207, 1442) :
-        nperio = 4
-        print ("eORCA025 grid found from dimensions, nperio=6" )
+        nperio = 6
+        print ("eORCA025 grid found from dimensions, nperio=" + str(nperio) )
         
 if nperio == None :
