2012年7月3日火曜日

コントロールファイルの作成


#! /bin/tcsh -f

#type yyyymmddhhhh start and end time
: ${start:=200103131200}
: ${end:=200103280000}
#: ${end:=200001051200}
year=`echo ${start} | cut -c 1-4`
month=`echo ${start} | cut -c 5-6`
day=`echo ${start} | cut -c 7-8`
hour=`echo ${start} |cut -c 9-10`
h=00

echo start time ${year} ${month} ${day} ${hour} ${h}
echo end   time ${end}

: ${time:=${start}}

#timestep
timestep=6

#para
: ${xgrid:=557} 
: ${ygrid:=335} 
: ${slon:=-50}   
: ${slat:=-30.06}   

i=0
while [ ${time} -le ${end} ]
do

##decide m
if [ ${month} -eq 01 ]; then
    m=JAN
elif  [ ${month} -eq 02 ]; then
    m=FEB
elif  [ ${month} -eq 03 ]; then
    m=MAR
elif  [ ${month} -eq 04 ]; then
    m=APR
elif  [ ${month} -eq 05 ]; then
    m=MAY
elif  [ ${month} -eq 06 ]; then
    m=JUN
elif  [ ${month} -eq 07 ]; then
    m=JUL
elif  [ ${month} -eq 08 ]; then
    m=AUG
elif  [ ${month} -eq 09 ]; then
    m=SEP
elif  [ ${month} -eq 10 ]; then
    m=OCT
elif  [ ${month} -eq 11 ]; then
    m=NOV
elif  [ ${month} -eq 12 ]; then
    m=DEC
fi

##decide m

#echo $hour
time=${year}${month}${day}${hour}${h}
#echo yoshiyoshi
echo time $time
echo month $m
##mk_ctl
~/Nhm/NHM1.2/Tools/nus2grads/nus2grads fcst_p.nus/PPSTD1/${time}

# Write ctl file
cat <<EOF > _NHMMRPPFCSVSTD1_${time}.ctl
***output grads ctl file ***
dset _NHMMRPPFCSVSTD1_${time}.dat
title convert from NuSDaS
OPTIONS big_endian sequential yrev
undef 9.990000e+20
xdef  ${xgrid} linear ${slon} 0.18
ydef  ${ygrid} linear ${slat} 0.18
zdef  18 levels 1000  975  950  925  900  850  800  700  600  500  400  300  250  200  150  100   75   50 
tdef  1  linear  ${hour}z${day}${m}${year} 1mn
vars  21
Usrf          0 99 Usrf      
U            18 99 U         
Vsrf          0 99 Vsrf      
V            18 99 V         
Tsrf          0 99 Tsrf      
T            18 99 T         
TTDsrf        0 99 TTDsrf    
TTD          18 99 TTD       
Z            18 99 Z         
W            18 99 W         
OMG          18 99 OMG       
VOR          18 99 VOR       
CVR          18 99 CVR       
CWC          18 99 CWC       
PSEA          0 99 PSEA      
P             0 99 P         
RAIN          0 99 RAIN      
SMQR          0 99 SMQR      
SMQS          0 99 SMQS      
SMQG          0 99 SMQG      
SMQH          0 99 SMQH      

endvars

EOF

echo "GrADS files,  _NHMMRPPFCSVSTD1_${time}.ctl  are created."






#echo "yoshiyoshi"
i=`expr $i + 1`
#echo $i

#### next time step
#hour=`expr $hour + 1`
hour=`expr $hour + $timestep`
hour=`echo ${hour} | awk '{printf("%02d",$1)}'`


if [ $hour -eq 24 ]; then
    hour=00
#    day=`expr $day + 1`
        day=`echo ${day} | awk '{printf("%02d",$1+1)}'`
    
    if [ $day -ge 32 ];then
        day=01
#        month=`expr $month + 1`
        month=`echo ${month} | awk '{printf("%02d",$1+1)}'`
    
        if [ $month -ge 13 ];then
            month=01
            year=`expr $year + 1`

        fi    
    fi    
fi

time=${year}${month}${day}${hour}${h}

done

0 件のコメント:

コメントを投稿