|
@@ -4,27 +4,46 @@
|
|
|
# -- Date : 30 Jan 2015
|
|
|
# -- At : IC3, Barcelona
|
|
|
# -- Modified : 19 Jan 2016, omar.bellprat@bsc.es
|
|
|
-#
|
|
|
+# November 2017, francois.massonnet@uclouvain.be
|
|
|
# -- Purpose: Generation of an arbitrary number of NEMO oceanic restarts that are copies of a reference, plus a perturbation
|
|
|
#
|
|
|
# -- Method : The reference file is duplicated in this script, then read by a R script. The perturbation is introduced and finally written to this latter file.
|
|
|
-# The script must be placed into the restart directory (e.g. NEMO_Restart_23). The generated restarts have to be renamed after generation. This
|
|
|
-# script has been tested on MareNostrum3.
|
|
|
-#
|
|
|
-# -- Input : NEMO ocean restart from an EC-Earth 3.1 run
|
|
|
-# -- Output : N restarts with the same name,but with an index fc0, fc1, ... fcN-1 appended
|
|
|
-#
|
|
|
-# -- Limitations: Only the surface conditions are perturbed (level index: 1) but this can be changed in the R script
|
|
|
|
|
|
module load R
|
|
|
|
|
|
set -o errexit
|
|
|
set -o nounset
|
|
|
-set -x
|
|
|
+#set -x
|
|
|
|
|
|
|
|
|
if [ $# == 0 ] ; then
|
|
|
- echo "gener_perturbation.bash ocean_restart_file Nmembers"
|
|
|
+ echo ""
|
|
|
+ echo " Usage: gener_perturb_restart.bash NETCDF-file NUMBER-members"
|
|
|
+ echo " PURPOSE : "
|
|
|
+ echo " Creates NUMBER-members copies of the input NETCDF-file file"
|
|
|
+ echo " and adds for each copy a white noise to sea surface"
|
|
|
+ echo " temperature (standard deviation: 10^(-4) K)"
|
|
|
+ echo " This script can be used to generate ensemble members"
|
|
|
+ echo " for coupled simulations"
|
|
|
+ echo " ARGUMENTS : "
|
|
|
+ echo " NETCDF-file : Restart file of NEMO (NetCDF format). The file"
|
|
|
+ echo " must contain a variable named tn"
|
|
|
+ echo " NUMBER-members : number of perturbed restarts to generate"
|
|
|
+ echo " OUTPUT : "
|
|
|
+ echo " NUMBER-members copies of the original files with perturbed"
|
|
|
+ echo " variable tn. The file names are the same as the input files"
|
|
|
+ echo " but with suffix pertXX where XX = 01, 02, 03, ..."
|
|
|
+ echo " EXAMPLE : "
|
|
|
+ echo " ./gener_perturb_restart.bash EC04_00046752_restart_oce_0005.nc 5"
|
|
|
+ echo " --> will create:"
|
|
|
+ echo " EC04_00046752_restart_oce_0005_pert01.nc"
|
|
|
+ echo " EC04_00046752_restart_oce_0005_pert02.nc"
|
|
|
+ echo " EC04_00046752_restart_oce_0005_pert03.nc"
|
|
|
+ echo " EC04_00046752_restart_oce_0005_pert04.nc"
|
|
|
+ echo " EC04_00046752_restart_oce_0005_pert05.nc"
|
|
|
+ echo " HELPDESK : "
|
|
|
+ echo " francois.massonnet@uclouvain.be"
|
|
|
+ echo ""
|
|
|
exit
|
|
|
fi
|
|
|
|
|
@@ -39,17 +58,18 @@ per=0.0001 # Standard deviation of gaussian perturbation to be applied,
|
|
|
|
|
|
cp $filein ${filein}.backup # Do a backup
|
|
|
|
|
|
-for jmemb in `seq 0 $(( $nmemb -1 ))`
|
|
|
+for jmemb in `seq 1 $nmemb`
|
|
|
do
|
|
|
- echo $jmemb
|
|
|
+ echo "Doing copy $jmemb out of $nmemb"
|
|
|
+ jmemb=$(printf "%02d" $jmemb)
|
|
|
# 1. Make a copy of the original file, with the new name
|
|
|
- filenew="${filein%.nc}_fc${jmemb}.nc"
|
|
|
+ filenew="${filein%.nc}_pert${jmemb}.nc"
|
|
|
cp $filein $filenew
|
|
|
|
|
|
# 2. Prepare the R script
|
|
|
|
|
|
echo "#!/usr/bin/env Rscript
|
|
|
- library(ncdf)
|
|
|
+ library(ncdf4)
|
|
|
|
|
|
# François Massonnet, 30 Jan 2015
|
|
|
# Adds a gaussian perturbation at the first level of a 3D field
|
|
@@ -59,10 +79,10 @@ do
|
|
|
|
|
|
varname='$var'
|
|
|
filein <- '$filenew'
|
|
|
- ex.nc <- open.ncdf(filein,write=TRUE)
|
|
|
+ ex.nc <- nc_open(filein,write=TRUE)
|
|
|
spert <- $per
|
|
|
|
|
|
- myvar <- get.var.ncdf(ex.nc, varname)
|
|
|
+ myvar <- ncvar_get(ex.nc, varname)
|
|
|
myvarpert <- myvar
|
|
|
for (i in seq(1,dim(myvar)[1])){
|
|
|
for (j in seq(1,dim(myvar)[2])){
|
|
@@ -72,8 +92,8 @@ do
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- put.var.ncdf(ex.nc,varname,myvarpert)
|
|
|
- close.ncdf(ex.nc)" > Rtmpfile.R
|
|
|
+ ncvar_put(ex.nc,varname,myvarpert)
|
|
|
+ nc_close(ex.nc)" > Rtmpfile.R
|
|
|
|
|
|
chmod 744 Rtmpfile.R
|
|
|
|