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
# Created in November 2012 Author : vguemas@ic3.cat #
# #
###############################################################################
function interp3d {
typeset var nz=`ncdump -h $1|grep 'deptht'|head -1|cut -f3 -d" "`
ln -sf /cfu/pub/scripts/interpolation/scrip_use scrip_use
for lev in $(seq 1 $nz) ; do
ncks -d deptht,$((lev-1)) -v $2 $1 tmp_${lev}.nc
ncwa -O -h -a deptht tmp_${lev}.nc tmp_${lev}.nc
ln -sf /cfu/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc
cat > scrip_use_in <<EOF
&remap_inputs
remap_wgt = 'rmp_${NEMOVERSION}_to_regular_lev${lev}.nc'
infile = 'tmp_${lev}.nc'
invertlat = FALSE
var = '$2'
fromregular = FALSE
outfile = 'tmp_$(printf "%02d" $lev).nc'
/
EOF
./scrip_use
ncecat -O -h tmp_$(printf "%02d" $lev).nc tmp_$(printf "%02d" $lev).nc
ncrename -h -O -d record,deptht tmp_$(printf "%02d" $lev).nc tmp_$(printf "%02d" $lev).nc
done
ncrcat -n $nz,2,1 -v $2 tmp_01.nc tmpout.nc
ncpdq -O -h -a time,deptht tmpout.nc tmp2out.nc
ncks -A -v deptht $1 tmp2out.nc
cdo setgrid,t106grid tmp2out.nc tmp3out.nc
orca_res=`echo $NEMOVERSION | cut -c 7-9`
if ((${orca_res} \= "O25")); then
cdo invertlatdata tmp3out.nc $3
else
cp tmp3out.nc $3
fi
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
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
rm -f tmp_* tmpout.nc tmp2out.nc tmp3out.nc rmp_${NEMOVERSION}_to_regular_lev* scrip_use scrip_use_in
}
###############################################################################
# #
# Set minimum and maximum attributes #
# #
# $1 : input file #
# $2 : input vars provided as a list #
# #
# 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}
}