Index: TOOLS/MOSAIX/CreateOasisGrids.bash
===================================================================
--- TOOLS/MOSAIX/CreateOasisGrids.bash	(revision 3718)
+++ TOOLS/MOSAIX/CreateOasisGrids.bash	(revision 3901)
@@ -44,6 +44,8 @@
 # Defines computer
 # ================
-if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi
-if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi
+if [[ $(hostname) = curie* ]]    ; then arch=curie ; center=tgcc ; fi
+if [[ $(hostname) = irene* ]]    ; then arch=irene ; center=tgcc ; fi
+if [[ $(hostname) = lsce3005* ]] ; then arch=spip  ; center=spip ; fi
+
 PROGRAM=$(basename ${0})
 
@@ -60,8 +62,13 @@
     SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}}
     ;;
-    ( * )
-    exit -1
-    ;;
+    ( spip )
+    R_IN=${HOME}/Scratch/IGCM
+    TMPDIR=${HOME}/Scratch/TMP
+    SUBMIT_DIR=$(pwd)
+    MPIRUN=/opt/local/bin/mpirun-openmpi-gcc49 -n 2
+    ;; 
+    ( * ) exit -1 ;;
 esac
+
 ##
 ## Command line parameters
@@ -112,5 +119,5 @@
 # Format for OASIS-MCT files : should be NetCDF3 classic or NetCDF3 64 bits
 # ---------------------------------------------------------------------------
-FL_FMT=64bit
+FL_FMT3=64bit
 
 #
@@ -123,15 +130,16 @@
 # Creates NetCDF3 version of input files
 # ----------------------------------------------------------------------------
-ncks --overwrite --fl_fmt=${FL_FMT} --history ${OCE}_coordinates_mask.nc      ${OCE}_coordinates_mask_${FL_FMT}.nc
-ncks --overwrite --fl_fmt=${FL_FMT} --history ${ATM}_grid_maskFrom_${OCE}.nc  ${ATM}_grid_maskFrom_${OCE}_${FL_FMT}.nc
+ncks --overwrite --fl_fmt=${FL_FMT} --history ${OCE}_coordinates_mask.nc      ${OCE}_coordinates_mask_${FL_FMT3}.nc
+ncks --overwrite --fl_fmt=${FL_FMT} --history ${ATM}_grid_maskFrom_${OCE}.nc  ${ATM}_grid_maskFrom_${OCE}_${FL_FMT3}.nc
+
+
 #
 # Creates ocean fields
 # ----------------------------------------------------------------------------
-
-for OCEGRID in T U V ; do
-    ncks --fl_fmt=${FL_FMT} -C --history --append --variable nav_lon_grid_${OCEGRID},nav_lat_grid_${OCEGRID},bounds_lon_grid_${OCEGRID},bounds_lat_grid_${OCEGRID} ${OCE}_coordinates_mask_${FL_FMT}.nc grids_${CplModel}.nc
-    ncks --fl_fmt=${FL_FMT} -C --history --append --variable area_grid_${OCEGRID} ${OCE}_coordinates_mask_${FL_FMT}.nc areas_${CplModel}.nc
+for OCEGRID in T U V C ; do
+    ncks --fl_fmt=${FL_FMT3} -C --history --append --variable nav_lon_grid_${OCEGRID},nav_lat_grid_${OCEGRID},bounds_lon_grid_${OCEGRID},bounds_lat_grid_${OCEGRID} ${OCE}_coordinates_mask_${FL_FMT3}.nc grids_${CplModel}.nc
+    ncks --fl_fmt=${FL_FMT3} -C --history --append --variable area_grid_${OCEGRID} ${OCE}_coordinates_mask_${FL_FMT3}.nc areas_${CplModel}.nc
     # Inverts mask values and switch to integer
-    ncks --fl_fmt=${FL_FMT} --history -C --variable mask_${OCEGRID} ${OCE}_coordinates_mask_${FL_FMT}.nc mask_${OCEGRID}_tmp.nc
+    ncks --fl_fmt=${FL_FMT33} --history -C --variable mask_${OCEGRID} ${OCE}_coordinates_mask_${FL_FMT3}.nc mask_${OCEGRID}_tmp.nc
     ncatted --history \
 	    --attribute coordinates,mask_${OCEGRID},d,,         \
@@ -140,5 +148,6 @@
     mask_${OCEGRID}_tmp.nc
     
-    ncap2 --fl_fmt=${FL_FMT} --history --append --script "mask_${OCEGRID}=int(1-mask_${OCEGRID});"    mask_${OCEGRID}_tmp.nc masks_${CplModel}.nc
+    ncap2 --fl_fmt=${FL_FMT3} --history --append --script "mask_${OCEGRID}=int(1-mask_${OCEGRID});"    mask_${OCEGRID}_tmp.nc masks_${CplModel}.nc
+    rm mask_${OCEGRID}_tmp.nc
     ncatted --history \
 	    --attribute long_name,mask_${OCEGRID},o,c,"Land-sea mask" \
@@ -147,8 +156,9 @@
     mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
     ncpdq --permute nvertex_grid_${OCEGRID},y_grid_${OCEGRID},x_grid_${OCEGRID} grids_${CplModel}_tmp.nc grids_${CplModel}.nc
-done
-
-ncks --history --append --variable lon,lat ${ATM}_grid_maskFrom_${OCE}_${FL_FMT}.nc grids_${CplModel}.nc
-
+    rm grids_${CplModel}_tmp.nc
+done
+
+ncks --history --append --variable lon,lat ${ATM}_grid_maskFrom_${OCE}_${FL_FMT3}.nc grids_${CplModel}.nc
+ 
 #
 # We need to have different names for dimensions and variables
@@ -158,8 +168,8 @@
 
 if [[ ${ATM} = dynamico* || ${ATM} = ICO* ]] ; then 
-    ncks --fl_fmt=${FL_FMT} --history --append --variable bounds_lon,bounds_lat ${ATM}_grid_maskFrom_${OCE}_${FL_FMT}.nc grids_${CplModel}.nc
+    ncks --fl_fmt=${FL_FMT3} --history --append --variable bounds_lon,bounds_lat ${ATM}_grid_maskFrom_${OCE}_${FL_FMT3}.nc grids_${CplModel}.nc
 fi
 
-ncks --fl_fmt=${FL_FMT} --history -C --append --variable aire   ${ATM}_grid_maskFrom_${OCE}_${FL_FMT}.nc areas_${CplModel}.nc
+ncks --fl_fmt=${FL_FMT3} --history -C --append --variable aire   ${ATM}_grid_maskFrom_${OCE}_${FL_FMT3}.nc areas_${CplModel}.nc
 ncatted --history --attribute coordinates,aire,d,,     \
 	--attribute _FillValue,aire,d,,                \
@@ -170,5 +180,5 @@
 	areas_${CplModel}.nc
 
-ncks --fl_fmt=${FL_FMT} --history -C --variable OceMask         ${ATM}_grid_maskFrom_${OCE}_${FL_FMT}.nc OceMask_tmp.nc
+ncks --fl_fmt=${FL_FMT3} --history -C --variable OceMask         ${ATM}_grid_maskFrom_${OCE}_${FL_FMT3}.nc OceMask_tmp.nc
 ncatted --history \
 	--attribute coordinates,OceMask,d,,         \
@@ -177,5 +187,6 @@
 	--attribute missing_value,OceMask,d,,       \
 	OceMask_tmp.nc
-ncap2 --fl_fmt=${FL_FMT} --history --append --script "OceMask=int(1-OceMask)"            OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1
+ncap2 --fl_fmt=${FL_FMT3} --history --append --script "OceMask=int(1-OceMask)"            OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1
+rm OceMask_tmp.nc
 ncatted --history \
 	--attribute long_name,OceMask,o,c,"Land-sea mask"   \
@@ -220,11 +231,13 @@
 EOF
     
-    ncap2 --fl_fmt=${FL_FMT} --history --append --script-file add_dim.nco  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
+    ncap2 --fl_fmt=${FL_FMT3} --history --append --script-file add_dim.nco  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
     
     mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
-    ncap2 --fl_fmt=${FL_FMT} --history --append --script 'defdim("xcell",1) ; OceMask[time_counter,ycell,xcell]=OceMask(:,:)'  masks_${CplModel}_tmp.nc masks_${CplModel}.nc
+    ncap2 --fl_fmt=${FL_FMT3} --history --append --script 'defdim("xcell",1) ; OceMask[time_counter,ycell,xcell]=OceMask(:,:)'  masks_${CplModel}_tmp.nc masks_${CplModel}.nc
 
     mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc
-    ncap2 --fl_fmt=${FL_FMT} --history --append --script 'defdim("xcell",1) ; aire[ycell,xcell]=aire(:) ; '                       areas_${CplModel}_tmp.nc areas_${CplModel}.nc
+    ncap2 --fl_fmt=${FL_FMT3} --history --append --script 'defdim("xcell",1) ; aire[ycell,xcell]=aire(:) ; '                    areas_${CplModel}_tmp.nc areas_${CplModel}.nc
+
+    rm -f grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc
 fi
 
@@ -236,5 +249,6 @@
     # -----------------------------------------------------------------------
     mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
-    ncap2 --fl_fmt=${FL_FMT} --history --append --script "alon[lat,lon]=alon; alat[lat,lon]=alat"  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
+    ncap2 --fl_fmt=${FL_FMT3} --history --append --script "alon[lat,lon]=alon; alat[lat,lon]=alat"  grids_${CplModel}_tmp.nc grids_${CplModel}.nc
+    rm -f grids_${CplModel}_tmp.nc
     ncatted --history \
 	    --attribute long_name,alon,o,c,"Longitude"    \
@@ -271,25 +285,28 @@
 EOF
     mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
-    ncap2 --fl_fmt=${FL_FMT} --history --script-file add_bounds.nco -O grids_${CplModel}_tmp.nc grids_${CplModel}.nc
+    ncap2 --fl_fmt=${FL_FMT3} --history --script-file add_bounds.nco -O grids_${CplModel}_tmp.nc grids_${CplModel}.nc
+    rm grids_${CplModel}_tmp.nc
 fi
 
 #
-# Generates grid "o${atm}e" : same as t${atm} grid, with surfaces set to 1
+# Generates grid "o${atm}", "o" meaning "one": same as t${atm} grid, with surfaces set to 1
 # and mask to 0 (ocean everywhere, to compute integral over the whole grid))
 # This grid is used when field are quantities instead of fluxes (i.e river flow)
 # ----------------------------------------------------------------------------
 mv grids_${CplModel}.nc grids_${CplModel}_tmp.nc
-ncap2 --fl_fmt=${FL_FMT} --history --script "o${atm}_lon=alon; o${atm}_lat=alat; bounds_o${atm}_lon=bounds_lon; bounds_o${atm}_lat=bounds_lat; " grids_${CplModel}_tmp.nc grids_${CplModel}.nc
+ncap2 --fl_fmt=${FL_FMT3} --history --script "o${atm}_lon=alon; o${atm}_lat=alat; bounds_o${atm}_lon=bounds_lon; bounds_o${atm}_lat=bounds_lat; " grids_${CplModel}_tmp.nc grids_${CplModel}.nc
 
 mv areas_${CplModel}.nc areas_${CplModel}_tmp.nc
-ncap2 --fl_fmt=${FL_FMT} --history --script "o${atm}_aire=aire*0.0d+1.0d; "   areas_${CplModel}_tmp.nc areas_${CplModel}.nc
+ncap2 --fl_fmt=${FL_FMT3} --history --script "o${atm}_aire=aire*0.0d+1.0d; "   areas_${CplModel}_tmp.nc areas_${CplModel}.nc
 
 mv masks_${CplModel}.nc masks_${CplModel}_tmp.nc
-ncap2 --fl_fmt=${FL_FMT} --history --script "o${atm}_mask=int(OceMask)*0+0; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc
+ncap2 --fl_fmt=${FL_FMT3} --history --script "o${atm}_mask=int(OceMask)*0+0; " masks_${CplModel}_tmp.nc masks_${CplModel}.nc
+
+rm grids_${CplModel}_tmp.nc areas_${CplModel}_tmp.nc masks_${CplModel}_tmp.nc
 
 #
 # Final renaming
 # ----------------------------------------------------------------------------
-for OCEGRID in T U V
+for OCEGRID in T U V C
 do
     ocegrid=${OCEGRID~} # To lowercase
@@ -336,5 +353,6 @@
     if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then
 	mv ${InFile} tmp_${InFile}
-	ncks --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile}
+	ncks --fl_fmt=${FL_FMT3} --history  tmp_${InFile} ${InFile}
+	rm tmp_${InFile}
     fi
 done
@@ -384,5 +402,5 @@
 ## Cleaning
 ## ===========================================================================
-#rm  *_tmp.nc ${OCE}_coordinates_mask_${FL_FMT}.nc ${ATM}_grid_maskFrom_${OCE}_${FL_FMT}.nc *.nco
+#rm  *_tmp.nc ${OCE}_coordinates_mask_${FL_FMT3}.nc ${ATM}_grid_maskFrom_${OCE}_${FL_FMT3}.nc *.nco
 
 exit
@@ -390,5 +408,5 @@
 # Name of the dimensions ? 
 # ----------------------------------------------------------------------------
-for OCEGRID in T U V ; do
+for OCEGRID in T U V C ; do
     ocegrid=${OCEGRID~} # Downcase name of grids
     ncrename --history --dimension  x_grid_${OCEGRID},x${ocegrid}${oce}         grids_${CplModel}.nc
