1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#!/bin/bash
# **************************** LICENSE START ***********************************
#
# Copyright 2013 ECMWF and INPE. This software is distributed under the terms
# of the Apache License version 2.0. In applying this license, ECMWF does not
# waive the privileges and immunities granted to it by virtue of its status as
# an Intergovernmental Organization or submit itself to any jurisdiction.
#
# ***************************** LICENSE END ************************************
# ---------------------------------------------------------
# Script to run RTTOV from within Metview
# ---------------------------------------------------------
set -x
print_err()
{
echo ${text_ERR} $* >> "${f_LOG}"
}
text_ERR="Script `basename $0` FAILED> "
#Get args
if [ $# -ne 9 ] ; then
echo "Invalid number of arguments specified for script $0 ! (" $# " instead of 9)"
exit 1
fi
d_WORK=$1
f_EXE=$2
f_INPUT=$3
NLEV=$4
SENSOR=$5
f_CHANNEL=$6
f_COEFF=$7
f_LOG=$8
f_RES=$9
#Some init
do_SOLAR=0 # 0 = solar off / 1 = solar on
do_OZONE=0 # 0 = microwave 1 = infrared ozone input
#Define executable
if [ "$f_EXE" = "_UNDEF_" ] ; then
exe_RTTOV=${MV_RTTOV_EXE}
else
exe_RTTOV=${f_EXE}
fi
#-------------------------------------------
# Set-up predefined channels and coeff
#-------------------------------------------
if [ "$SENSOR" != "CUSTOM" ] ; then
RTTOV_CHANNELS_FILES_PATH="${RTTOV_CHANNELS_FILES_PATH:=/home/graphics/cgx/model_files/rttov}"
case "$SENSOR" in
"AMSUA")
f_CHANNEL="${RTTOV_CHANNELS_FILES_PATH}/amsua_channels"
f_COEFF="${RTTOV_CHANNELS_FILES_PATH}/rtcoef_metop_2_amsua.dat"
do_SOLAR=0
do_OZONE=0
;;
"IASI")
f_CHANNEL="${RTTOV_CHANNELS_FILES_PATH}/iasi_channels"
f_COEFF="${RTTOV_CHANNELS_FILES_PATH}/rtcoef_metop_2_iasi.dat"
do_SOLAR=0
do_OZONE=1
;;
*) print_err "Unsupported sensor type:" "$SENSOR"; exit 1 ;;
esac
fi
#-------------------------------
# Go to working directory
#-------------------------------
if [ ! -d "$d_WORK" ] ; then
print_err "No working directory found: " $d_WORK
exit 1
fi
cd $d_WORK
#-------------------------------
# Checks
#-------------------------------
if [ x"$exe_RTTOV" = "x" ] ; then
print_err "No RTTOV executable is defined. Please define it via env variable MV_RTTOV_EXE."
exit 1
fi
if [ ! -f "$exe_RTTOV" ] ; then
print_err "No RTTOV executable found: " $exe_RTTOV
exit 1
fi
if [ ! -x "$exe_RTTOV" ] ; then
print_err "RTTOV executable cannot be run! Permission is missing. " $exe_RTTOV
exit 1
fi
if [ ! -f "$f_INPUT" ] ; then
print_err "No RTTOV input profile file is found: " $f_INPUT
exit 1
fi
if [ ! -r "$f_INPUT" ] ; then
print_err "RTTOV input profile file cannot be read! Permission is missing. " $f_INPUT
exit 1
fi
if [ ! -f "$f_CHANNEL" ] ; then
print_err "No RTTOV channels file is found: " $f_CHANNEL
exit 1
fi
if [ ! -r "$f_CHANNEL" ] ; then
print_err "RTTOV channels file cannot be read! Permission is missing. " $f_CHANNEL
exit 1
fi
if [ ! -f "$f_COEFF" ] ; then
print_err "No RTTOV coefficient file is found: " $f_COEFF
exit 1
fi
if [ ! -r "$f_COEFF" ] ; then
print_err "RTTOV coefficient file cannot be read! Permission is missing. " $f_COEFF
exit 1
fi
#-------------------------------
# Prepare input profile
#-------------------------------
ln -sf "${f_INPUT}" rttov_input_data.txt
#--------------------------------------
# Prepare channels and coefficient file
#---------------------------------------
ln -sf "${f_CHANNEL}" channel
ln -sf "${f_COEFF}" coeff
#-------------------------------
# Prepare option input files
#-------------------------------
cat > options_input << EOF
coeff, Coefficient filename
rttov_input_data.txt , Input profile filename
1 , Number of profiles
${NLEV} , Number of levels
${do_SOLAR} , Turn solar radiation on/off
${do_OZONE} , Turn ozone radiation on/off
EOF
cat options_input channel > input
#-------------------------------
# Run RTTOV
#-------------------------------
$exe_RTTOV < input > "${f_LOG}" 2>&1
outCode=$?
#-----------------------------------
# Check log
#-----------------------------------
if [ -f "${f_LOG}" ] ; then
if [ `grep -c -i WARNING "$f_LOG"` -ne 0 ] ; then
outCode=255
elif [ `grep -c -i ERROR "$f_LOG"` -ne 0 ] ; then
outCode=1
elif [ $outCode -ne 0 ] ; then
outCode=$outCode
fi
fi
#-----------------------------------
# Check results
#-----------------------------------
f_OUT=output_example_fwd.dat
if [ ! -f $f_OUT ] ; then
print_err "RTTOV ouput file was not generated!"
exit 1
fi
cp -f ${f_OUT} "${f_RES}"
exit $outCode
|