Index: TOOLS/MOSAIX/CreateWeightsMask.bash
===================================================================
--- TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3633)
+++ TOOLS/MOSAIX/CreateWeightsMask.bash	(revision 3639)
@@ -45,6 +45,6 @@
 # Defines models
 # ==============
-OCE=ORCA2.3
-#OCE=eORCA1.2
+#OCE=ORCA2.3
+OCE=eORCA1.2
 #OCE=ORCA025
 
@@ -126,5 +126,5 @@
 ## ===========================================================================
 cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  .
-cp ${R_IN}/ATM/${ATM}/${ATM}_grid.nc .
+cp ${R_IN}/ATM/GRID/${ATM}_grid.nc .
 
 ln -s ${OCE}_coordinates_mask.nc  oce_grid.nc
@@ -163,6 +163,6 @@
 where (OceFrac <  0.0 )  OceFrac=0.0 ; 
 EOF
-ncap2 -h --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder.nc tmp_dia_t${oce}_to_t${atm}_1storder.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder.nc
-ncatted -h -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder.nc
+ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder.nc tmp_dia_t${oce}_to_t${atm}_1storder.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder.nc
+ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder.nc
 
 ##
@@ -170,7 +170,7 @@
 ## ===========================================================================
 cp dia_t${oce}_to_t${atm}_1storder.nc  dia_t${oce}_to_t${atm}_1storder_mask.nc
-ncks -h --overwrite -v OceFrac dia_t${oce}_to_t${atm}_1storder_mask.nc  ${ATM}_grid_maskFrom_${OCE}.nc
-ncks -h --append    -v aire    atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
-[[ ${atm} = *ico* ]] && ncks -h --append -v bounds_lon,bounds_lat atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
+ncks --alphabetize --history --overwrite -v OceFrac dia_t${oce}_to_t${atm}_1storder_mask.nc  ${ATM}_grid_maskFrom_${OCE}.nc
+ncks --alphabetize --history --append    -v aire    atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
+[[ ${atm} = *ico* ]] && ncks --alphabetize --history --append -v bounds_lon,bounds_lat atm_grid.nc                              ${ATM}_grid_maskFrom_${OCE}.nc
 
 cat <<EOF > creation_masque.nco
@@ -178,8 +178,8 @@
 where (OceFrac <= 0.0 )  OceFrac=0 ;
 EOF
-ncap2 -h --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc dia_t${oce}_to_t${atm}_1storder_mask.nc
-ncrename -h -v OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc
-
-ncks -h --append  -v OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
+ncap2 --history --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc dia_t${oce}_to_t${atm}_1storder_mask.nc
+ncrename --history -v OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc
+
+ncks --alphabetize --history --append  -v OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc   ${ATM}_grid_maskFrom_${OCE}.nc
 
 
@@ -263,5 +263,5 @@
     if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then
 	mv ${InFile} tmp_${InFile}
-	ncks --fl_fmt=${FL_FMT} -h  tmp_${InFile}  ${InFile}
+	ncks --alphabetize --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile}
     fi
 done
@@ -277,7 +277,7 @@
 OceMask [time_counter,cell] = OceMask (:) ;
 EOF
-    ncap2 -O -h -S add_time.nco   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
-    ncks -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
-    ncatted -h \
+    ncap2 -O --history --script-file add_time.nco   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+    ncks --alphabetize -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted --history \
 	    -a coordinates,OceFrac,c,c,"time_counter cell" \
             -a coordinates,OceMask,c,c,"time_counter cell" \
@@ -290,7 +290,7 @@
 OceMask [time_counter,lat,lon] = OceMask (:,:) ;
 EOF
-    ncap2 -O -h -S add_time.nco   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
-    ncks -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
-    ncatted -h \
+    ncap2 -O --history --script-file add_time.nco   ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+    ncks --alphabetize -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc
+    ncatted --history \
 	    -a coordinates,OceFrac,c,c,"time_counter lat lon" \
             -a coordinates,OceMask,c,c,"time_counter lat lon" \
@@ -306,5 +306,5 @@
 PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" )
 for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do
-    ncatted -h \
+    ncatted --history \
 	    --attribute uuid,global,d,,                                           \
 	    --attribute LongName,global,d,,                                       \
@@ -354,20 +354,20 @@
 for file in rmp_*${oce}_to_*${atm}_*.nc rmp_*${atm}_to_*${oce}_*.nc ; do
     mv ${file} xios_${file}
-    ncap2 --fl_fmt=${FL_FMT} -h --script-file add_dim.nco xios_${file} ${file}
+    ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${file} ${file}
     
-    ncrename -h --dimension n_weight,num_links   ${file}
-    ncrename -h --variable  src_idx,src_address  ${file}
-    ncrename -h --variable  dst_idx,dst_address  ${file}
-    ncrename -h --variable  weight,remap_matrix  ${file}
+    ncrename --history --dimension n_weight,num_links   ${file}
+    ncrename --history --variable  src_idx,src_address  ${file}
+    ncrename --history --variable  dst_idx,dst_address  ${file}
+    ncrename --history --variable  weight,remap_matrix  ${file}
     case ${file} in
-	( *1storder.nc ) ncatted -h --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${file} ;;
-	( *2ndorder.nc ) ncatted -h --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${file} ;;
+	( *1storder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order"  ${file} ;;
+	( *2ndorder.nc ) ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order"  ${file} ;;
     esac
-    ncatted -h --attribute conventions,global,o,c,"SCRIP"   ${file}
-    ncatted -h --attribute normalization,global,o,c,"none"  ${file}
+    ncatted --history --attribute conventions,global,o,c,"SCRIP"   ${file}
+    ncatted --history --attribute normalization,global,o,c,"none"  ${file}
     
     case ${file} in
 	( rmp_*${oce}_to_t${atm}_* )
-	ncatted -h \
+	ncatted --history \
 		--attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \
 		--attribute source_grid,global,o,c,"${oce_domain_type}" \
@@ -376,5 +376,5 @@
 	;;
 	( rmp_*${atm}_to_*${oce}_* )
-	ncatted -h \
+	ncatted --history \
 		--attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \
 		--attribute source_grid,global,o,c,"${atm_domain_type}" \
@@ -383,4 +383,120 @@
 	;;
     esac
+done
+
+##
+## Add missing variables in rmp files
+## ===========================================================================
+for OGRID in ${ListOCEGRID} ; do
+    for order in ${Listorder} ; do
+	ogrid=${OGRID~}
+	agrid=t
+	
+	file_o_to_a=rmp_${ogrid}${oce}_to_${agrid}${atm}_${order}order.nc
+	file_a_to_o=rmp_${agrid}${atm}_to_${ogrid}${oce}_${order}order.nc
+	
+	cat <<EOF >add_varoce.nco
+defdim ("src_grid_size"   , \$x_grid_${OGRID}.size*\$y_grid_${OGRID}.size) ;
+defdim ("src_grid_corners", 4) ;
+defdim ("src_grid_rank"   , 2) ;
+//
+src_grid_dims[src_grid_rank] = { \$y_grid_${OGRID}.size, \$x_grid_${OGRID}.size } ;
+//
+src_grid_center_lat [src_grid_size] =  0.0d ;
+src_grid_center_lon [src_grid_size] =  0.0d ;
+src_grid_center_lat (:) = nav_lat_grid_${OGRID}(:,:)   ;
+src_grid_center_lon (:) = nav_lon_grid_${OGRID}(:,:)   ;
+//
+src_grid_corner_lat [src_grid_size, src_grid_corners] = 0.0d ;
+src_grid_corner_lon [src_grid_size, src_grid_corners] = 0.0d ;
+src_grid_corner_lat(:,:) = bounds_lat_grid_${OGRID}(:,:,:) ;
+src_grid_corner_lon(:,:) = bounds_lon_grid_${OGRID}(:,:,:) ;
+//
+src_grid_imask [src_grid_size] =    0 ;
+src_grid_area  [src_grid_size] = 0.0d ;
+src_grid_frac  [src_grid_size] = 1.0d ;
+src_grid_imask (:) = 1 - mask_${OGRID}(:,:) ;
+src_grid_imask.int() ;
+src_grid_area  (:) = area_grid_${OGRID}(:,:) ;
+EOF
+
+	ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_o_to_a}
+	sed --in-place "s/src_/dst_/g" add_varoce.nco
+	ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${file_a_to_o}
+
+	if [[ ${atm} = ico ]] ; then
+	    cat <<EOF >add_varatm.nco
+defdim ("dst_grid_size"   , \$cell.size) ;
+defdim ("dst_grid_corners", 6) ;
+defdim ("dst_grid_rank"   , 2) ;
+//
+dst_grid_dims[dst_grid_rank] = { \$cell.size, 1 } ;
+//
+dst_grid_center_lat [dst_grid_size] =  0.0d ;
+dst_grid_center_lon [dst_grid_size] =  0.0d ;
+dst_grid_center_lat (:) = lat(:)   ;
+dst_grid_center_lon (:) = lon(:)   ;
+//
+dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ;
+dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
+dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
+dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
+//
+dst_grid_imask [dst_grid_size] =    0 ;
+dst_grid_area  [dst_grid_size] = 0.0d ;
+dst_grid_frac  [dst_grid_size] = 1.0d ;
+dst_grid_imask (:) = 1 - OceMask(0,:) ;
+dst_grid_imask.int() ;
+dst_grid_area  (:) = aire(:) ;
+EOF
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
+	    sed --in-place "s/dst_/src_/g" add_varatm.nco
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
+	    
+	    ncks --alphabetize --history --overwrite  -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc
+	    mv rmp_tmp.nc ${file_o_to_a}
+	    ncks --alphabetize --history --overwrite  -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc
+	    mv rmp_tmp.nc ${file_a_to_o}
+
+	fi
+	if [[ ${atm} = lmd ]] ; then
+	    cat <<EOF >add_varatm.nco
+defdim ("dst_grid_size"   , \$lon.size*\$lat.size) ;
+defdim ("dst_grid_corners", 4) ;
+defdim ("dst_grid_rank"   , 2) ;
+//
+dst_grid_dims[dst_grid_rank] = { \$lat.size, \$lon.size } ;
+//
+dst_grid_center_lat [dst_grid_size] =  0.0d ;
+dst_grid_center_lon [dst_grid_size] =  0.0d ;
+lat0lon[lat,lon] = lat(:)+0*lon(:) ; 
+lon0lat[lat,lon] = lon(:)+0*lat(:) ;
+dst_grid_center_lat (:) = lat0lon(:,:)   ;
+dst_grid_center_lon (:) = lon0lat(:,:)   ;
+//
+//dst_grid_corner_lat [dst_grid_size, dst_grid_corners] = 0.0d ; // Not available for LMDZ lon/lat grid
+//dst_grid_corner_lon [dst_grid_size, dst_grid_corners] = 0.0d ;
+//dst_grid_corner_lat(:,:) = bounds_lat(:,:) ;
+//dst_grid_corner_lon(:,:) = bounds_lon(:,:) ;
+//
+dst_grid_imask [dst_grid_size] =    0 ;
+dst_grid_area  [dst_grid_size] = 0.0d ;
+dst_grid_frac  [dst_grid_size] = 1.0d ;
+dst_grid_imask (:) = 1 - OceMask(0,:,:) ;
+dst_grid_imask.int() ;
+dst_grid_area  (:) = aire(:,:) ;
+dst_grid_frac (:)  = OceFrac(0,:,:) ;
+EOF
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_o_to_a}
+	    sed --in-place "s/dst/src/g" add_varatm.nco
+	    ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${file_a_to_o}
+
+	    ncks --alphabetize --history --overwrite  -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_area,dst_grid_imask ${file_o_to_a} rmp_tmp.nc
+	    mv rmp_tmp.nc ${file_o_to_a}
+	    ncks --alphabetize --history --overwrite  -v src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${file_a_to_o} rmp_tmp.nc
+	    mv rmp_tmp.nc ${file_a_to_o}
+
+	fi
+    done
 done
 
