Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
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
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
# Created in May 2012 Author : vguemas@ic3.cat #
###############################################################################
function setminmax {
cdo fldmax -timmax $1 intmax.nc
cdo fldmin -timmin $1 intmin.nc
typeset var listvars=""
typeset args=("$@")
typeset var ind
for ((ind=1;ind<$#;ind++)) ; do
listvars=$listvars" "${args[$ind]}
done
typeset name
for name in ${listvars[@]} ; do
typeset var var_max=`ncdump -v $name intmax.nc | tail -2 | head -1 | awk '{print $1}'`
ncatted -h -a valid_max,$name,m,f,$var_max $1
typeset var var_min=`ncdump -v $name intmin.nc | tail -2 | head -1 | awk '{print $1}'`
ncatted -h -a valid_min,$name,m,f,$var_min $1
done
rm -f intmax.nc intmin.nc
}
###############################################################################
# #
# Concatenate with a weight of the results obtained #
# on partial years #
# #
# $1 : input file 1 #
# $2 : input file 2 #
# $3 : ending month file 1 #
# $4 : output file #
# #
# Created in May 2012 Author : vguemas@ic3.cat #
###############################################################################
function concat {
typeset var wgt=$((10#${3}%12))
typeset var ntimes=`cdo ntime $1`
ncks -O -d time,$(($ntimes-1)) $1 part1.nc
ncks -O -d time,0 $2 part2.nc
cdo mulc,$wgt part1.nc part1_bis.nc
cdo mulc,$((12-$wgt)) part2.nc part2_bis.nc
cdo add part1_bis.nc part2_bis.nc tmp2_bis.nc
cdo divc,12 tmp2_bis.nc tmp2.nc
lstdims=`ncdump -h tmp2.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'`
if [[ ${lstdims/lev} != ${lstdims} ]] ; then
ncrename -d lev,ensemble tmp2.nc
else
ncecat -O -h tmp2.nc tmp2.nc
ncrename -h -O -d record,ensemble tmp2.nc tmp2.nc
ncpdq -O -h -a time,ensemble tmp2.nc tmp2.nc
fi
rm -f part1.nc part2.nc part1_bis.nc part2_bis.nc tmp2_bis.nc
ncks -O -d time,0,$((ntimes-2+10#${3}/12)) $1 tmp1.nc
ncks -O -d time,1, $2 tmp3.nc
ncrcat -O tmp1.nc tmp2.nc tmp3.nc $4
rm -f tmp1.nc tmp2.nc tmp3.nc
}
###############################################################################
# #
# Gather the members in a single netcdf file #
# #
# $1 : prefix netcdf file name for all the members #
# $2 : suffix netcdf file name for all the members #
# $3 : output file name #
# #
# Created in May 2012 Author : vguemas@ic3.cat #
###############################################################################
function gather_memb {
typeset var lstfiles1=`ls ${1}*${2}`
typeset var file
typeset var ind=1
typeset var lstfiles2=""
for file in ${lstfiles1[@]} ; do
typeset var lstvars=`cdo showvar $file`
typeset var lstexclude="nav_lon nav_lat"
for varex in $lstexclude ; do
if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then
ncks -O -x -v ${varex} $file $file
fi
done
if [[ ! -z "`ncdump -h ${file} | grep ensemble | head -1 | awk '{print $3}' | grep [0-9]`" ]] ; then
typeset var nrec=`ncdump -h ${file} | grep ensemble | head -1 | awk '{print $3}' | grep [0-9]`
typeset var jrec
for jrec in $(seq 1 $nrec) ; do
ncks -d ensemble,$((jrec-1)) $file tmp_record_${ind}.nc
ncwa -O -a ensemble tmp_record_${ind}.nc tmp_record_${ind}.nc
lstfiles2=${lstfiles2}" "tmp_record_${ind}.nc
ind=$((ind+1))
done
else
lstfiles2=${lstfiles2}" "$file
fi
done
ncecat -h ${lstfiles2} ${3}
rm -f tmp_record_*.nc
ncrename -h -O -d record,ensemble ${3} ${3}
ncpdq -O -h -a time,ensemble ${3} ${3}
}