forked from NOAA-EMC/global-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaussian_sfcanl.sh
executable file
·230 lines (210 loc) · 7.56 KB
/
gaussian_sfcanl.sh
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#! /usr/bin/env bash
################################################################################
#### UNIX Script Documentation Block
# . .
# Script name: gaussian_sfcanl.sh
# Script description: Makes a global gaussian grid surface analysis file
#
# Author: George Gayno Org: NP23 Date: 2018-01-30
#
# Abstract: This script makes a global gaussian grid surface analysis from
# fv3gfs surface analysis tiles
#
# Script history log:
# 2018-01-30 Gayno initial script
# 2019-1030 Gayno updates to output analysis file in netcdf or nemsio
#
# Usage: gaussian_sfcanl.sh
#
# Imported Shell Variables:
# CASE Model resolution. Defaults to C768.
# DONST Process NST fields when 'yes'. Default is 'no'.
# OUTPUT_FILE Output gaussian analysis file format. Default is "nemsio"
# Set to "netcdf" for netcdf output file
# Otherwise, output in nemsio.
# BASEDIR Root directory where all scripts and fixed files reside.
# Default is /nwprod2.
# HOMEgfs Directory for gfs version. Default is
# $BASEDIR/gfs_ver.v15.0.0}
# FIXam Directory for the global fixed climatology files.
# Defaults to $HOMEgfs/fix/am
# FIXfv3 Directory for the model grid and orography netcdf
# files. Defaults to $HOMEgfs/fix/orog
# FIXWGTS Weight file to use for interpolation
# EXECgfs Directory of the program executable. Defaults to
# $HOMEgfs/exec
# DATA Working directory
# (if nonexistent will be made, used and deleted)
# Defaults to current working directory
# COMOUT Output directory
# (if nonexistent will be made)
# defaults to current working directory
# XC Suffix to add to executables. Defaults to none.
# GAUSFCANLEXE Program executable.
# Defaults to $EXECgfs/gaussian_sfcanl.x
# INISCRIPT Preprocessing script. Defaults to none.
# LOGSCRIPT Log posting script. Defaults to none.
# ERRSCRIPT Error processing script
# defaults to 'eval [[ $err = 0 ]]'
# ENDSCRIPT Postprocessing script
# defaults to none
# CDATE Output analysis date in yyyymmddhh format. Required.
# PGMOUT Executable standard output
# defaults to $pgmout, then to '&1'
# PGMERR Executable standard error
# defaults to $pgmerr, then to '&1'
# pgmout Executable standard output default
# pgmerr Executable standard error default
# REDOUT standard output redirect ('1>' or '1>>')
# defaults to '1>', or to '1>>' to append if $PGMOUT is a file
# REDERR standard error redirect ('2>' or '2>>')
# defaults to '2>', or to '2>>' to append if $PGMERR is a file
# VERBOSE Verbose flag (YES or NO)
# defaults to NO
# gfs_ver Version number of gfs directory. Default is
# v15.0.0.
# OMP_NUM_
# THREADS_SFC Number of omp threads to use. Default is 1.
# APRUNSFC Machine specific command to invoke the executable.
# Default is none.
#
# Exported Shell Variables:
# PGM Current program name
# pgm
# ERR Last return code
# err
#
# Modules and files referenced:
# scripts : $INISCRIPT
# $LOGSCRIPT
# $ERRSCRIPT
# $ENDSCRIPT
#
# programs : $GAUSFCANLEXE
#
# fixed data : $FIXfv3/${CASE}/${CASE}_oro_data.tile*.nc
# $FIXWGTS
# $FIXam/global_hyblev.l65.txt
#
# input data : $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile*.nc
#
# output data: $PGMOUT
# $PGMERR
# $COMOUT/${APREFIX}sfcanl.nc
#
# Remarks:
#
# Condition codes
# 0 - no problem encountered
# >0 - some problem encountered
#
# Control variable resolution priority
# 1 Command line argument.
# 2 Environment variable.
# 3 Inline default.
#
# Attributes:
# Language: POSIX shell
# Machine: IBM SP
#
################################################################################
source "$HOMEgfs/ush/preamble.sh"
CASE=${CASE:-C768}
res=$(echo $CASE | cut -c2-)
LONB_CASE=$((res*4))
LATB_CASE=$((res*2))
LONB_SFC=${LONB_SFC:-$LONB_CASE}
LATB_SFC=${LATB_SFC:-$LATB_CASE}
DONST=${DONST:-"NO"}
LEVS=${LEVS:-64}
LEVSP1=$(($LEVS+1))
export NETCDF_OUT=".true."
# Directories.
gfs_ver=${gfs_ver:-v16.3.0}
BASEDIR=${BASEDIR:-${PACKAGEROOT:-/lfs/h1/ops/prod/packages}}
HOMEgfs=${HOMEgfs:-$BASEDIR/gfs.${gfs_ver}}
EXECgfs=${EXECgfs:-$HOMEgfs/exec}
FIXfv3=${FIXfv3:-$HOMEgfs/fix/orog}
FIXam=${FIXam:-$HOMEgfs/fix/am}
FIXWGTS=${FIXWGTS:-$FIXfv3/$CASE/fv3_SCRIP_${CASE}_GRIDSPEC_lon${LONB_SFC}_lat${LATB_SFC}.gaussian.neareststod.nc}
DATA=${DATA:-$(pwd)}
COMOUT=${COMOUT:-$(pwd)}
# Filenames.
XC=${XC:-}
GAUSFCANLEXE=${GAUSFCANLEXE:-$EXECgfs/gaussian_sfcanl.x}
SIGLEVEL=${SIGLEVEL:-$FIXam/global_hyblev.l${LEVSP1}.txt}
CDATE=${CDATE:?}
# Other variables.
export NLN=${NLN:-"/bin/ln -sf"}
export PGMOUT=${PGMOUT:-${pgmout:-'&1'}}
export PGMERR=${PGMERR:-${pgmerr:-'&2'}}
export REDOUT=${REDOUT:-'1>'}
export REDERR=${REDERR:-'2>'}
# Set defaults
################################################################################
# Preprocessing
${INISCRIPT:-}
pwd=$(pwd)
if [[ -d $DATA ]]
then
mkdata=NO
else
mkdir -p $DATA
mkdata=YES
fi
cd $DATA||exit 99
[[ -d $COMOUT ]]||mkdir -p $COMOUT
cd $DATA
################################################################################
# Make surface analysis
export PGM=$GAUSFCANLEXE
export pgm=$PGM
$LOGSCRIPT
PDY=$(echo $CDATE | cut -c1-8)
cyc=$(echo $CDATE | cut -c9-10)
iy=$(echo $CDATE | cut -c1-4)
im=$(echo $CDATE | cut -c5-6)
id=$(echo $CDATE | cut -c7-8)
ih=$(echo $CDATE | cut -c9-10)
export OMP_NUM_THREADS=${OMP_NUM_THREADS_SFC:-1}
# input interpolation weights
$NLN $FIXWGTS ./weights.nc
# input analysis tiles (with nst records)
$NLN $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile1.nc ./anal.tile1.nc
$NLN $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile2.nc ./anal.tile2.nc
$NLN $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile3.nc ./anal.tile3.nc
$NLN $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile4.nc ./anal.tile4.nc
$NLN $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile5.nc ./anal.tile5.nc
$NLN $COMOUT/RESTART/${PDY}.${cyc}0000.sfcanl_data.tile6.nc ./anal.tile6.nc
# input orography tiles
$NLN $FIXfv3/$CASE/${CASE}_oro_data.tile1.nc ./orog.tile1.nc
$NLN $FIXfv3/$CASE/${CASE}_oro_data.tile2.nc ./orog.tile2.nc
$NLN $FIXfv3/$CASE/${CASE}_oro_data.tile3.nc ./orog.tile3.nc
$NLN $FIXfv3/$CASE/${CASE}_oro_data.tile4.nc ./orog.tile4.nc
$NLN $FIXfv3/$CASE/${CASE}_oro_data.tile5.nc ./orog.tile5.nc
$NLN $FIXfv3/$CASE/${CASE}_oro_data.tile6.nc ./orog.tile6.nc
$NLN $SIGLEVEL ./vcoord.txt
# output gaussian global surface analysis files
$NLN $COMOUT/${APREFIX}sfcanl.nc ./sfc.gaussian.analysis.file
# Executable namelist
cat <<EOF > fort.41
&setup
yy=$iy,
mm=$im,
dd=$id,
hh=$ih,
igaus=$LONB_SFC,
jgaus=$LATB_SFC,
donst=$DONST,
netcdf_out=$NETCDF_OUT
/
EOF
$APRUNSFC $GAUSFCANLEXE
export ERR=$?
export err=$ERR
$ERRSCRIPT||exit 2
################################################################################
# Postprocessing
cd $pwd
[[ $mkdata = YES ]]&&rmdir $DATA
exit ${err}