Newer
Older
# rm -f ${files}*
save_final_output $varnew $output
done # loop over variables
}
# for maximum and minimum temperature (manipulate daily data files)
function maxmin(){
for VAR in ${VAR_LST_MXMN[@]}; do
new_name $VAR
echo "llll" $SDATE
output=${VAR}_${SDATE}.nc
cp $DATADIR/${EXPID}/daily/$VAR/${VAR}_${SDATE}_*.nc.gz .
gunzip ${VAR}_${SDATE}_*.nc.gz
pabretonniere
committed
SDATE1=$(echo ${SDATE}|cut -c1-6)
cdo timmean ${VAR}_${SDATE}_${SDATE1}.nc ${output} ; rm -f ${VAR}_${SDATE}_${SDATE1}.nc
pabretonniere
committed
files="$(find . -maxdepth 1 -name "${VAR}_${SDATE}_*.nc" | sed -e 's/\.\///g' )"
cdo timmean $f toto.nc;rm -f $f
ncrcat -O -h ${output} toto.nc ${output};rm -f toto.nc
ncrename -h -d lev,ensemble ${output}
ncrename -O -h -v lev,kaka ${output} #delete lev var
ncks -O -h -x -v kaka ${output} ${output} #delete lev var
ncks -h -A header.nc ${output}
#
# Get the CFU standard attributes to be written in the variable
#
pabretonniere
committed
variables="$(cat ${HEAD_DIR}/table_of_variable | cut -f$idx -d'|' | sed -e 's/ /@/g')"
cfustandard_name="$(echo $variables | cut -f2 -d' ' | sed -e 's/@/ /g')" # variable standard name
cfulong_name="$(echo $variables | cut -f3 -d' ' | sed -e 's/@/ /g')" # variable long name
cfucell_methods="$(echo $variables | cut -f4 -d' ' | sed -e 's/@/ /g')" # variable cell methods
cfuunit="$(echo $variables | cut -f5 -d' ' | sed -e 's/@/ /g')" # variable unit
cfuunit_long="$(echo $variables | cut -f6 -d' ' | sed -e 's/@/ /g')" # variable unit long name
cfulevel_number="$(echo $variables | cut -f7 -d' ' | sed -e 's/@/ /g')" # variable level
cfulevel_type="$(echo $variables | cut -f8 -d' ' | sed -e 's/@/ /g')" # variable level type
cfulevel_units="$(echo $variables | cut -f9 -d' ' | sed -e 's/@/ /g')" # variable level unit
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
#
# Adding the variable level
#
ncap2 -s level_${varnew}="$cfulevel_number" ${output} -h -O ${output}
#
# Removing unnecessary attributes
#
for att in GRID_TYPE ; do
ncatted -O -h -a ${att},${varnew},d,c, ${output}
done
#
# Adding and modifying the {varnew}iable attributes
#
ncatted -O -h -a standard_name,${varnew},o,c,"$cfustandard_name" ${output} # {varnew}iable standard name
ncatted -O -h -a long_name,${varnew},o,c,"$cfulong_name" ${output} # {varnew}iable long name
ncatted -O -h -a cell_methods,${varnew},o,c,"$cfucell_methods" ${output} # {varnew}iable cell methods
ncatted -O -h -a data_type,level_${varnew},o,c,"$cfulevel_type" ${output} # {varnew}iable level type
ncatted -O -h -a units,level_${varnew},o,c,"$cfulevel_units" ${output} # {varnew}iable level units
ncatted -O -h -a coordinates,${varnew},o,c,"longitude latitude reftime leadtime time_bnd experiment_id source realization institution level_${varnew}" ${output}
#
# Adding variable axis
#
ncatted -O -h -a axis,longitude,o,c,"X" ${output} # variable longitude axis
ncatted -O -h -a axis,latitude,o,c,"Y" ${output} # variable latitude axis
ncatted -O -h -a axis,level_${varnew},o,c,"Z" ${output} # variable level axis
# delete history
ncatted -h -a history,global,d,, $output
# change institution name
ncatted -h -a institution,global,m,c,"IC3" $output
# create a script to change the EXPID, insitutution, ensember, source and realiazation
i=0 # index
for mem in ${LISTMEMB[@]}; do
cat>modify_ncvalue<<EOF
ncap2 -O -h -s 'experiment_id($i,0:3)="$EXPID";realization($i)=$MEM;institution($i,0:$(( ${#INSTITUTION} -1 )))="$INSTITUTION";source($i,0:$(( ${#SOURCE} -1 )))="$SOURCE"' \$1 \$1
EOF
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
cat modify_ncvalue
bash modify_ncvalue $output; rm modify_ncvalue
i=$((i+1))
done
##
save_final_output $varnew $output
done # loop for variables
}
#### End of the User Defined Functions ####
###################################
#### Main Part of the Script ####
###################################
# NCO and CDO must be available in $PATH
date
config_file=$1
check_args $@
#read config_file and initialize variables
#check config file syntaxis problems
sed -i -e 's/= /=/g' ${config_file}
pabretonniere
committed
export WORKDIR
FACTOR=$((NFRP*3600))
ENSEMBLE=${#MEM_LST[@]}
pabretonniere
committed
if [[ $ENSEMBLE -eq 0 ]]; then
MEM_LST=( $( ls ${DATADIR}/${EXPID}/${SDATE} ) )
ENSEMBLE=${#MEM_LST[@]}
echo "Warning: you passed an empty member list. By default, it will treat all the available members: " ${MEM_LST[@]}
fi
LISTMEMB=( $(echo ${MEM_LST[@]} | sed -e 's/fc//g') ) #member list without "fc"
echo ${MEM_LST[0]}
echo $LISTMEMB
echo ${LISTMEMB[0]}
echo ${LISTMEMB[${#LISTMEMB[@]}-1]}
echo ${#LISTMEMB[@]}
mkdir -p ${WORKDIR}
if [[ ! -d ${WORKDIR} ]]; then
exit 1
fi
cd ${WORKDIR}
if [[ ! -d ${DATADIR}/${EXPID} ]]; then
[[ -d /esarchive/exp/ecearth/${EXPID} ]] && DATADIR=/esarchive/exp/ecearth
fi
base_path=${DATADIR}/${EXPID}/${SDATE}
mkdir -p ${SAVEDIR}/${EXPID}; # chmod -R 775 $SAVEDIR/${EXPID}
pabretonniere
committed
#exit stop
get_leadtime
header $SDATE
extract
echo "after extract"
if [ -z ${VAR_LST_2D[@]} ]; then
pabretonniere
committed
# GG=$(ls *GG* | head -1)
GG="$(find . -maxdepth 1 -name "*GG*" | head -1 | sed -e 's/\.\///g' )"
pabretonniere
committed
# SH=$(ls *SH* | head -1)
SH="$(find . -maxdepth 1 -name "*SH*" | head -1 | sed -e 's/\.\///g' )"
rm -f /scratch/Earth/${USER}/pp/VAR_LST_2D.txt
VAR_LST_2D=$(echo ${VAR_LST_2D_GG} ${VAR_LST_2D_SH} 'PRECIP')
echo $VAR_LST_2D >> /scratch/Earth/${USER}/pp/VAR_LST_2D.txt
pabretonniere
committed
VAR_LST_3D=$(echo ${VAR_LST_3D_GG} ${VAR_LST_3D_SH})
rm -f /scratch/Earth/${USER}/pp/VAR_LST_3D.txt
else
VAR_LST_3D_SH_DEFAULT='T U V W Z'
VAR_LST_3D_GG_DEFAULT='Q CC CIWC CLWC'
VAR_LST_2D_GG_DEFAULT='T2M D2M SSTK MSL PRECIP SSR STR TTR TSR TSRC TTRC SLHF SSHF U10M V10M SSRD CP SF E SSRU SSRC STRU STRD TCC'
#if list of variables read from config_file, separation between GG and SH variables
for var in ${VAR_LST_3D[@]}
do
for var_sh in ${VAR_LST_3D_SH_DEFAULT[@]}
do
pabretonniere
committed
[ $var == $var_sh ] && VAR_LST_3D_SH=$(echo $VAR_LST_3D_SH $var)
done
for var_gg in ${VAR_LST_3D_GG_DEFAULT[@]}
do
pabretonniere
committed
[ $var == $var_gg ] && VAR_LST_3D_GG=$(echo $VAR_LST_3D_GG $var)
done
done
for var in ${VAR_LST_2D[@]}
do
for var_gg in ${VAR_LST_2D_GG_DEFAULT[@]}
do
pabretonniere
committed
[ $var == $var_gg ] && VAR_LST_2D_GG=$(echo $VAR_LST_2D_GG $var)
echo $YEARF - $YEAR0 - $MONF - 10#$MONF - $MON0
echo "before surface"
echo "after surface"
combine_3d
regrid2x2
upper
if [[ ${#VAR_LST_MXMN[@]} > 0 ]]; then
maxmin
pabretonniere
committed
#else
# echo "" #empty line to avoid trap issue
cd ~/; rm -rf $WORKDIR # clean up
pabretonniere
committed
trap - EXIT
![Pierre-Antoine Bretonnière Pierre-Antoine Bretonnière's avatar](/gitlab/uploads/-/system/user/avatar/4/avatar.png?width=36)
Pierre-Antoine Bretonnière
committed
#### End of the Main Part of Script ####