GRAPES MESO模式学习笔记02——脚本运行之资料预处理

目录

资料预处理包含背景场资料处理和常规观测资料处理,业务中也把标准初始化(si)模块归为资料预处理,而介绍模式的文档将这两者分开,为了简便,我一个一个尝试。

大尺度背景场资料预处理(data_proc)

将获取到的大尺度背景场资料处理成 GRAPES 前处理系统可以读写的格式,支持NCEP-GFS资料和T639资料。
我只使用T639数据。该模块从T639 grib2格式资料(背景资料)中抽取需要的变量层次并转换成grads格式。
源码脚本参见:/data_proc/T639_proc/grib2bin.sh
源代码中使用12小时前的资料,目前业务中使用6小时前的资料。

流程

使用wgrib2抽取需要的变量、层次
使用read_for_grapes.exe改变格点数据存放顺序。

IO

输入

T639 grib2产品

输出

背景场bckg文件,grads格式

脚本

改写自GRAPES原始脚本

#!/bin/ksh
#====================================================================
#- Purpose: To transform T639 data from GRIB format to BINARY format
#====================================================================
set -x
set -e
set -u
DATA_TIME=2013041012
BASE_DIR=./nwp/system/grapes_meso/my_grapes_meso/
BASE_SOURCE_DIR=./nwp/system/grapes_meso/GRAPES_MESO3.3.2.4/
DATA_DIR=/cma/g3/nwp_ex/share/test/rfs/data/T639_data
RUN_DIR=${BASE_DIR}/run/bckg
while getopts "t:d:r:" arg
do
    case $arg in
        t)
            DATA_TIME=$OPTARG
            ;;
        d)
            DATA_DIR=$OPTARG
            ;;
        r)
            RUN_DIR=$OPTARG
            ;;
    esac
done
#######################################
# directory
#######################################
# directory
set_directory(){
    # data directory
    # input T639 data
    T639_GMFS=${DATA_DIR}
    # output background data
    RUN_DIR=${RUN_DIR}
    # program path
    # newdate
    NEWDATE_BIN=${BASE_SOURCE_DIR}/data_proc/T639_proc/newdate
    # wgrib2
    WGRIB2_BIN=wgrib2
    # read_for_grapes
    READ_FOR_GRAPES_BIN=${BASE_SOURCE_DIR}/data_proc/T639_proc/read_for_grapes.exe
}
set_directory
#######################################
# parameter for wgrib2
#######################################
# date
DATE=echo $DATA_TIME |cut -c1-8
TIME=echo $DATA_TIME |cut -c9-10
set_parameter(){
    #==========================#
    levels="10 20 30 50 70 100 150 200 250 300 400 500 600 700 850 925 1000"
    #==========================#
    forecast_time="012 015 018 021 024 027 030 033 036 039 042 045 048 051 054 057 060"
    endian="little_endian"
    if [ $endian = "big_endian" ];then
       FMT='-ieee'
    else
       FMT='-bin'
    fi
    #==========================#
    #---multiply levels ----
    HGT=':HGT:'
    TMP=':TMP:'
    UGRD=':UGRD:'
    VGRD=':VGRD:'
    SPFH=':SPFH:'
    #RH=':RH:'
    #---single level ----
    PS=':PRES:surface:'
    TS=':TMP:surface:'
    TMP2M=':TMP:2 m above'
    UGRD10M=':UGRD:10 m above'
    VGRD10M=':VGRD:10 m above'
    RH2M=':RH:2 m above'
    PRMSL=':PRMSL:'
    SOILT_1=':TMP:0-0.07 m below'
    SOILT_2=':TMP:0.07-0.28 m below'
    SOILT_3=':TMP:0.28-1 m below'
    SOILT_4=':TMP:1-2.55 m below'
    SOILW_1=':SPFH:0-0.07 m below'
    SOILW_2=':SPFH:0.07-0.28 m below'
    SOILW_3=':SPFH:0.28-1 m below'
    SOILW_4=':SPFH:1-2.55 m below'
    TERRAIN=':HGT:surface:'
    LAND='LAND:surface:'
}
set_parameter
# working directory
test -d $RUN_DIR || mkdir -p $RUN_DIR
cd $RUN_DIR
#
# ---- to get boundary 12 hours before -----
#
BDYTIME=$(${NEWDATE_BIN} $DATE$TIME -12)
for TTT in $forecast_time
do
    BDY=${T639_GMFS}/gmf.639.${BDYTIME}${TTT}.grb2
    if [ ! -s $BDY ];then
      echo "${BDY}: not found!"
      error
    fi
    updateBDYTIME=${NEWDATE_BIN} $BDYTIME +$TTT
    temp_file_name=T639_$updateBDYTIME
    test -s ${temp_file_name} && rm -f ${temp_file_name}
#---- for multiply levels-----------
    for lev in $levels
    do
      ${WGRIB2_BIN} $BDY | grep "${HGT}${lev} mb:"     | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    done
    for lev in $levels
    do
      ${WGRIB2_BIN} $BDY | grep "${TMP}${lev} mb:"     | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    done
    for lev in $levels
    do
      ${WGRIB2_BIN} $BDY | grep "${UGRD}${lev} mb:"    | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    done
    for lev in $levels
    do
      ${WGRIB2_BIN} $BDY | grep "${VGRD}${lev} mb:"    | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    done
    for lev in $levels
    do
      ${WGRIB2_BIN} $BDY | grep "${SPFH}${lev} mb:"    | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    done
#--- for single level ----
    ${WGRIB2_BIN} $BDY | grep "$PS"      | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "$TS"      | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "$TMP2M"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "$UGRD10M" | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "$VGRD10M" | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "$RH2M"    | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "$PRMSL"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILT_1}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILT_2}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILT_3}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILT_4}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILW_1}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILW_2}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILW_3}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ${WGRIB2_BIN} $BDY | grep "${SOILW_4}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
#    ${WGRIB2_BIN} $BDY | grep "${TERRAIN}"   | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
#    ${WGRIB2_BIN} $BDY | grep "${LAND}"      | ${WGRIB2_BIN} $BDY -i -order we:ns -no_header -append $FMT ${temp_file_name}
    ######### execute file for grapes_si #######
    echo
    echo " Date converting is: --> $updateBDYTIME "
    ${READ_FOR_GRAPES_BIN} $updateBDYTIME
    ## delete the tmp-file
    echo "Delete the tmp file:"
    echo "                       "${temp_file_name}
    rm -f ${temp_file_name}
done
set +x
set +u
set +e

观测资料预处理

目前只支持同化常规观测资料(ObsGts)。
ObsGts模块生成分析系统需要的探空(TEMP),地面报(SYNOP),船舶报(SHIPS),飞机报(AIREP),云导风(SATOB)资料。

流程

修改namelist.obsproc
运行ObsGts.exe
修改输出文件名

IO

输入

aob文件

输出

AIREP201304101200
AIREP_latlon
SATOB
SATOB_latlon
SHIPS201304101200
SHIPS_latlon
SYNOP201304101200
SYNOP_latlon
TEMP201304101200
TEMP_latlon
obs_num2013041012

脚本

#!/bin/sh
################
# head
################
set -x
set -e
set -u
###############
#   param
###############
BASE_DIR=./nwp/system/grapes_meso/my_grapes_meso
BASE_SOURCE_DIR=./nwp/system/grapes_meso/GRAPES_MESO3.3.2.4
RUN_DIR=${BASE_DIR}/run/obs
DATA_TIME=2013041012
OBS_DIR=/cma/g2/COMMDATA/obs/aob/2013
BACKGRD_DIR=${BASE_DIR}/my_grapes_meso/run/bckg
OBS_PROC_BIN=${BASE_SOURCE_DIR}/4dvar/preproc/ObsGts/ObsProc.exe
while getopts "t:d:b:r:" arg
do
    case $arg in
        t)
            DATA_TIME=$OPTARG
            ;;
        d)
            OBS_DIR=$OPTARG
            ;;
        b)
            BACKGRD_DIR=$OPTARG
            ;;
        r)
            RUN_DIR=$OPTARG
    esac
done
begintime=$DATA_TIME
test -d ${RUN_DIR} | mkdir -p ${RUN_DIR}
cd ${RUN_DIR}
rm -f  ${RUN_DIR}/*
cd ${RUN_DIR}
######################
# namelist.obsproc
######################
cat > namelist.obsproc <<EOF
&record1
! for hlafs area but have 1 more grid at both x & y direction
 tkminlat= 15.0,
 tkmaxlat= 64.5,
 tkminlon= 70.0,
 tkmaxlon= 145.0 /
&record2
 unit_in_buffs = 50,
! file_buffs = '${OBS_DIR}/aob${begintime}n.dat' /
 file_buffs = '${OBS_DIR}/aob${begintime}.dat' /
&record3
 unit_out_obs = 60,
 file_out = '${RUN_DIR}/',
 file_obs_num = '${RUN_DIR}/obs_num${begintime}' /
&record4
 opt_checkwrite = 0,
 opt_wndwrite = 0,
 opt_msswrite = 0 /
 &record5
  AirepTopP=150.,
  AirepLowP=925.,
  SoundRhTop=100.,
  RhMin=5. /
EOF
################
# ObsProc.exe
################
${OBS_PROC_BIN}
sleep 10
#################
# rename outputs
#################
cd ${RUN_DIR}
cp TEMP TEMP${begintime}00
cp SYNOP SYNOP${begintime}00
cp SHIPS SHIPS${begintime}00
cp AIREP AIREP${begintime}00
#################
# clean up
#################
################
# tail
################
set +x
set +e
set +u